bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / font / fontselect.cxx
blobfaafdb61b398e08a2d885c761439cbf43e0bdbde
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>
23 #include <vcl/font.hxx>
25 #include <PhysicalFontFace.hxx>
26 #include <fontselect.hxx>
28 // These mustn't conflict with font name lists which use ; and ,
29 const char FontSelectPattern::FEAT_PREFIX = ':';
30 const char FontSelectPattern::FEAT_SEPARATOR = '&';
32 FontSelectPattern::FontSelectPattern( const vcl::Font& rFont,
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 )
44 maTargetName = GetFamilyName();
46 rFont.GetFontAttributes( *this );
48 // normalize orientation between 0 and 3600
49 if( 3600 <= static_cast<unsigned>(mnOrientation) )
51 if( mnOrientation >= 0 )
52 mnOrientation %= 3600;
53 else
54 mnOrientation = 3600 - (-mnOrientation % 3600);
57 // normalize width and height
58 if( mnHeight < 0 )
59 mnHeight = o3tl::saturating_toggle_sign(mnHeight);
60 if( mnWidth < 0 )
61 mnWidth = o3tl::saturating_toggle_sign(mnWidth);
65 // NOTE: this ctor is still used on Windows. Do not remove.
66 #ifdef _WIN32
67 FontSelectPattern::FontSelectPattern( const PhysicalFontFace& rFontData,
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 )
79 maTargetName = maSearchName = GetFamilyName();
80 // NOTE: no normalization for width/height/orientation
83 #endif
85 size_t FontSelectPattern::hashCode() const
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
90 if (maTargetName.indexOf(FontSelectPattern::FEAT_PREFIX)
91 != -1)
93 nHash = maTargetName.hashCode();
95 else
97 nHash = maSearchName.hashCode();
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;
109 bool FontSelectPattern::operator==(const FontSelectPattern& rOther) const
111 if (!CompareDeviceIndependentFontAttributes(rOther))
112 return false;
114 if (maTargetName != rOther.maTargetName)
115 return false;
117 if (maSearchName != rOther.maSearchName)
118 return false;
120 if (mnWidth != rOther.mnWidth)
121 return false;
123 if (mnHeight != rOther.mnHeight)
124 return false;
126 if (mfExactHeight != rOther.mfExactHeight)
127 return false;
129 if (mnOrientation != rOther.mnOrientation)
130 return false;
132 if (meLanguage != rOther.meLanguage)
133 return false;
135 if (mbVertical != rOther.mbVertical)
136 return false;
138 if (mbNonAntialiased != rOther.mbNonAntialiased)
139 return false;
141 if (mbEmbolden != rOther.mbEmbolden)
142 return false;
144 if (maItalicMatrix != rOther.maItalicMatrix)
145 return false;
147 return true;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */