LibreOffice Module vcl (master)  1
fontselect.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <o3tl/safeint.hxx>
22 #include <tools/gen.hxx>
23 #include <vcl/font.hxx>
24 
25 #include <PhysicalFontFace.hxx>
26 #include <fontselect.hxx>
27 
28 // These mustn't conflict with font name lists which use ; and ,
29 const char FontSelectPattern::FEAT_PREFIX = ':';
30 const char FontSelectPattern::FEAT_SEPARATOR = '&';
31 
33  const OUString& rSearchName, const Size& rSize, float fExactHeight, bool bNonAntialias)
34  : maSearchName( rSearchName )
35  , mnWidth( rSize.Width() )
36  , mnHeight( rSize.Height() )
37  , mfExactHeight( fExactHeight)
38  , mnOrientation( rFont.GetOrientation() )
39  , meLanguage( rFont.GetLanguage() )
40  , mbVertical( rFont.IsVertical() )
41  , mbNonAntialiased(bNonAntialias)
42  , mbEmbolden( false )
43 {
45 
46  rFont.GetFontAttributes( *this );
47 
48  // normalize orientation between 0 and 3600
49  if( 3600 <= static_cast<unsigned>(mnOrientation) )
50  {
51  if( mnOrientation >= 0 )
52  mnOrientation %= 3600;
53  else
54  mnOrientation = 3600 - (-mnOrientation % 3600);
55  }
56 
57  // normalize width and height
58  if( mnHeight < 0 )
60  if( mnWidth < 0 )
62 }
63 
64 
65 // NOTE: this ctor is still used on Windows. Do not remove.
66 #ifdef _WIN32
68  const Size& rSize, float fExactHeight, int nOrientation, bool bVertical )
69  : FontAttributes( rFontData )
70  , mnWidth( rSize.Width() )
71  , mnHeight( rSize.Height() )
72  , mfExactHeight( fExactHeight )
73  , mnOrientation( nOrientation )
74  , meLanguage( 0 )
75  , mbVertical( bVertical )
76  , mbNonAntialiased( false )
77  , mbEmbolden( false )
78 {
80  // NOTE: no normalization for width/height/orientation
81 }
82 
83 #endif
84 
86 {
87  // TODO: does it pay off to improve this hash function?
88  size_t nHash;
89  // check for features and generate a unique hash if necessary
91  != -1)
92  {
93  nHash = maTargetName.hashCode();
94  }
95  else
96  {
97  nHash = maSearchName.hashCode();
98  }
99  nHash += 11U * mnHeight;
100  nHash += 19 * GetWeight();
101  nHash += 29 * GetItalic();
102  nHash += 37 * mnOrientation;
103  nHash += 41 * static_cast<sal_uInt16>(meLanguage);
104  if( mbVertical )
105  nHash += 53;
106  return nHash;
107 }
108 
110 {
112  return false;
113 
114  if (maTargetName != rOther.maTargetName)
115  return false;
116 
117  if (maSearchName != rOther.maSearchName)
118  return false;
119 
120  if (mnWidth != rOther.mnWidth)
121  return false;
122 
123  if (mnHeight != rOther.mnHeight)
124  return false;
125 
126  if (mfExactHeight != rOther.mfExactHeight)
127  return false;
128 
129  if (mnOrientation != rOther.mnOrientation)
130  return false;
131 
132  if (meLanguage != rOther.meLanguage)
133  return false;
134 
135  if (mbVertical != rOther.mbVertical)
136  return false;
137 
138  if (mbNonAntialiased != rOther.mbNonAntialiased)
139  return false;
140 
141  if (mbEmbolden != rOther.mbEmbolden)
142  return false;
143 
144  if (maItalicMatrix != rOther.maItalicMatrix)
145  return false;
146 
147  return true;
148 }
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool CompareDeviceIndependentFontAttributes(const FontAttributes &rOther) const
double mnHeight
void GetFontAttributes(FontAttributes &rAttrs) const
Definition: font/font.cxx:348
bool operator==(const FontSelectPattern &rOther) const
Definition: fontselect.cxx:109
LanguageType meLanguage
size_t hashCode() const
Definition: fontselect.cxx:85
ItalicMatrix maItalicMatrix
Definition: fontselect.hxx:68
std::enable_if< std::is_signed< T >::value, T >::type saturating_toggle_sign(T a)
FontItalic GetItalic() const
abstract base class for physical font faces
FontWeight GetWeight() const
LanguageType GetLanguage(SwWrtShell &rSh, sal_uInt16 nLangWhichId)
static const char FEAT_SEPARATOR
Definition: fontselect.hxx:54
static const char FEAT_PREFIX
Definition: fontselect.hxx:53
double mnWidth
LanguageType meLanguage
Definition: fontselect.hxx:63
OUString maSearchName
Definition: fontselect.hxx:58
const OUString & GetFamilyName() const
OUString maTargetName
Definition: fontselect.hxx:57
FontSelectPattern(const vcl::Font &, const OUString &rSearchName, const Size &, float fExactHeight, bool bNonAntialias=false)
Definition: fontselect.cxx:32