LibreOffice Module vcl (master)  1
FontSelectPattern.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 
24 #include <vcl/font.hxx>
25 
28 
29 namespace vcl::font
30 {
31 
32 // These mustn't conflict with font name lists which use ; and ,
33 const char FontSelectPattern::FEAT_PREFIX = ':';
34 const char FontSelectPattern::FEAT_SEPARATOR = '&';
35 
37  const OUString& rSearchName, const Size& rSize, float fExactHeight, bool bNonAntialias)
38  : maSearchName( rSearchName )
39  , mnWidth( rSize.Width() )
40  , mnHeight( rSize.Height() )
41  , mfExactHeight( fExactHeight)
42  , mnOrientation( rFont.GetOrientation() )
43  , meLanguage( rFont.GetLanguage() )
44  , mbVertical( rFont.IsVertical() )
45  , mbNonAntialiased(bNonAntialias)
46  , mbEmbolden( false )
47 {
49 
50  rFont.GetFontAttributes( *this );
51 
52  // normalize orientation between 0 and 3600
53  if( mnOrientation < 0_deg10 || mnOrientation >= 3600_deg10 )
54  {
55  if( mnOrientation >= 0_deg10 )
56  mnOrientation %= 3600_deg10;
57  else
58  mnOrientation = 3600_deg10 - (-mnOrientation % 3600_deg10);
59  }
60 
61  // normalize width and height
62  if( mnHeight < 0 )
64  if( mnWidth < 0 )
66 }
67 
68 
69 // NOTE: this ctor is still used on Windows. Do not remove.
70 #ifdef _WIN32
72  const Size& rSize, float fExactHeight, int nOrientation, bool bVertical )
73  : FontAttributes( rFontData )
74  , mnWidth( rSize.Width() )
75  , mnHeight( rSize.Height() )
76  , mfExactHeight( fExactHeight )
77  , mnOrientation( nOrientation )
78  , meLanguage( 0 )
79  , mbVertical( bVertical )
80  , mbNonAntialiased( false )
81  , mbEmbolden( false )
82 {
84  // NOTE: no normalization for width/height/orientation
85 }
86 
87 #endif
88 
90 {
91  // TODO: does it pay off to improve this hash function?
92  size_t nHash;
93  // check for features and generate a unique hash if necessary
94  if (maTargetName.indexOf(FontSelectPattern::FEAT_PREFIX)
95  != -1)
96  {
97  nHash = maTargetName.hashCode();
98  }
99  else
100  {
101  nHash = maSearchName.hashCode();
102  }
103  nHash += 11U * mnHeight;
104  nHash += 19 * GetWeight();
105  nHash += 29 * GetItalic();
106  nHash += 37 * mnOrientation.get();
107  nHash += 41 * static_cast<sal_uInt16>(meLanguage);
108  if( mbVertical )
109  nHash += 53;
110  return nHash;
111 }
112 
114 {
116  return false;
117 
118  if (maTargetName != rOther.maTargetName)
119  return false;
120 
121  if (maSearchName != rOther.maSearchName)
122  return false;
123 
124  if (mnWidth != rOther.mnWidth)
125  return false;
126 
127  if (mnHeight != rOther.mnHeight)
128  return false;
129 
130  if (mfExactHeight != rOther.mfExactHeight)
131  return false;
132 
133  if (mnOrientation != rOther.mnOrientation)
134  return false;
135 
136  if (meLanguage != rOther.meLanguage)
137  return false;
138 
139  if (mbVertical != rOther.mbVertical)
140  return false;
141 
142  if (mbNonAntialiased != rOther.mbNonAntialiased)
143  return false;
144 
145  if (mbEmbolden != rOther.mbEmbolden)
146  return false;
147 
148  if (maItalicMatrix != rOther.maItalicMatrix)
149  return false;
150 
151  return true;
152 }
153 }
154 
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool CompareDeviceIndependentFontAttributes(const FontAttributes &rOther) const
double mnHeight
void GetFontAttributes(FontAttributes &rAttrs) const
Definition: font/font.cxx:397
LanguageType meLanguage
std::enable_if< std::is_signed< T >::value, T >::type saturating_toggle_sign(T a)
FontItalic GetItalic() const
UNDERLYING_TYPE get() const
FontWeight GetWeight() const
LanguageType GetLanguage(SwWrtShell &rSh, sal_uInt16 nLangWhichId)
bool operator==(const FontSelectPattern &rOther) const
FontSelectPattern(const vcl::Font &, const OUString &rSearchName, const Size &, float fExactHeight, bool bNonAntialias=false)
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
abstract base class for physical font faces
double mnWidth
const OUString & GetFamilyName() const
bool m_bDetectedRangeSegmentation false