Remove duplicated include
[LibreOffice.git] / vcl / source / font / FontSelectPattern.cxx
blob30c2c9aaa574ecd87d3f294ef47ee878a28290bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <o3tl/safeint.hxx>
22 #include <tools/gen.hxx>
24 #include <utility>
25 #include <vcl/font.hxx>
27 #include <font/FontSelectPattern.hxx>
28 #include <font/PhysicalFontFace.hxx>
30 namespace vcl::font
33 // These mustn't conflict with font name lists which use ; and ,
34 const char FontSelectPattern::FEAT_PREFIX = ':';
35 const char FontSelectPattern::FEAT_SEPARATOR = '&';
37 FontSelectPattern::FontSelectPattern( const vcl::Font& rFont,
38 OUString aSearchName, const Size& rSize, float fExactHeight, bool bNonAntialias)
39 : maSearchName(std::move( aSearchName ))
40 , mnWidth( rSize.Width() )
41 , mnHeight( rSize.Height() )
42 , mfExactHeight( fExactHeight)
43 , mnOrientation( rFont.GetOrientation() )
44 , meLanguage( rFont.GetLanguage() )
45 , mbVertical( rFont.IsVertical() )
46 , mbNonAntialiased(bNonAntialias)
47 , mbEmbolden( false )
49 maTargetName = GetFamilyName();
51 rFont.GetFontAttributes( *this );
53 // normalize orientation between 0 and 3600
54 if( mnOrientation < 0_deg10 || mnOrientation >= 3600_deg10 )
56 if( mnOrientation >= 0_deg10 )
57 mnOrientation %= 3600_deg10;
58 else
59 mnOrientation = 3600_deg10 - (-mnOrientation % 3600_deg10);
62 // normalize width and height
63 if( mnHeight < 0 )
64 mnHeight = o3tl::saturating_toggle_sign(mnHeight);
65 if( mnWidth < 0 )
66 mnWidth = o3tl::saturating_toggle_sign(mnWidth);
70 // NOTE: this ctor is still used on Windows. Do not remove.
71 #ifdef _WIN32
72 FontSelectPattern::FontSelectPattern( const PhysicalFontFace& rFontData,
73 const Size& rSize, float fExactHeight, int nOrientation, bool bVertical )
74 : FontAttributes( rFontData )
75 , mnWidth( rSize.Width() )
76 , mnHeight( rSize.Height() )
77 , mfExactHeight( fExactHeight )
78 , mnOrientation( nOrientation )
79 , meLanguage( 0 )
80 , mbVertical( bVertical )
81 , mbNonAntialiased( false )
82 , mbEmbolden( false )
84 maTargetName = maSearchName = GetFamilyName();
85 // NOTE: no normalization for width/height/orientation
88 #endif
90 size_t FontSelectPattern::hashCode() const
92 // TODO: does it pay off to improve this hash function?
93 size_t nHash;
94 // check for features and generate a unique hash if necessary
95 if (maTargetName.indexOf(FontSelectPattern::FEAT_PREFIX)
96 != -1)
98 nHash = maTargetName.hashCode();
100 else
102 nHash = maSearchName.hashCode();
104 nHash += 11U * mnHeight;
105 nHash += 19 * GetWeight();
106 nHash += 29 * GetItalic();
107 nHash += 37 * mnOrientation.get();
108 nHash += 41 * static_cast<sal_uInt16>(meLanguage);
109 if( mbVertical )
110 nHash += 53;
111 return nHash;
114 bool FontSelectPattern::operator==(const FontSelectPattern& rOther) const
116 if (!CompareDeviceIndependentFontAttributes(rOther))
117 return false;
119 if (maTargetName != rOther.maTargetName)
120 return false;
122 if (maSearchName != rOther.maSearchName)
123 return false;
125 if (mnWidth != rOther.mnWidth)
126 return false;
128 if (mnHeight != rOther.mnHeight)
129 return false;
131 if (mfExactHeight != rOther.mfExactHeight)
132 return false;
134 if (mnOrientation != rOther.mnOrientation)
135 return false;
137 if (meLanguage != rOther.meLanguage)
138 return false;
140 if (mbVertical != rOther.mbVertical)
141 return false;
143 if (mbNonAntialiased != rOther.mbNonAntialiased)
144 return false;
146 if (mbEmbolden != rOther.mbEmbolden)
147 return false;
149 if (maItalicMatrix != rOther.maItalicMatrix)
150 return false;
152 return true;
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */