1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <vcl/font.hxx>
27 #include <font/FontSelectPattern.hxx>
28 #include <font/PhysicalFontFace.hxx>
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
)
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
;
59 mnOrientation
= 3600_deg10
- (-mnOrientation
% 3600_deg10
);
62 // normalize width and height
64 mnHeight
= o3tl::saturating_toggle_sign(mnHeight
);
66 mnWidth
= o3tl::saturating_toggle_sign(mnWidth
);
70 // NOTE: this ctor is still used on Windows. Do not remove.
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
)
80 , mbVertical( bVertical
)
81 , mbNonAntialiased( false )
84 maTargetName
= maSearchName
= GetFamilyName();
85 // NOTE: no normalization for width/height/orientation
90 size_t FontSelectPattern::hashCode() const
92 // TODO: does it pay off to improve this hash function?
94 // check for features and generate a unique hash if necessary
95 if (maTargetName
.indexOf(FontSelectPattern::FEAT_PREFIX
)
98 nHash
= maTargetName
.hashCode();
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
);
114 bool FontSelectPattern::operator==(const FontSelectPattern
& rOther
) const
116 if (!CompareDeviceIndependentFontAttributes(rOther
))
119 if (maTargetName
!= rOther
.maTargetName
)
122 if (maSearchName
!= rOther
.maSearchName
)
125 if (mnWidth
!= rOther
.mnWidth
)
128 if (mnHeight
!= rOther
.mnHeight
)
131 if (mfExactHeight
!= rOther
.mfExactHeight
)
134 if (mnOrientation
!= rOther
.mnOrientation
)
137 if (meLanguage
!= rOther
.meLanguage
)
140 if (mbVertical
!= rOther
.mbVertical
)
143 if (mbNonAntialiased
!= rOther
.mbNonAntialiased
)
146 if (mbEmbolden
!= rOther
.mbEmbolden
)
149 if (maItalicMatrix
!= rOther
.maItalicMatrix
)
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */