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>
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
)
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;
54 mnOrientation
= 3600 - (-mnOrientation
% 3600);
57 // normalize width and height
59 mnHeight
= o3tl::saturating_toggle_sign(mnHeight
);
61 mnWidth
= o3tl::saturating_toggle_sign(mnWidth
);
65 // NOTE: this ctor is still used on Windows. Do not remove.
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
)
75 , mbVertical( bVertical
)
76 , mbNonAntialiased( false )
79 maTargetName
= maSearchName
= GetFamilyName();
80 // NOTE: no normalization for width/height/orientation
85 size_t FontSelectPattern::hashCode() const
87 // TODO: does it pay off to improve this hash function?
89 // check for features and generate a unique hash if necessary
90 if (maTargetName
.indexOf(FontSelectPattern::FEAT_PREFIX
)
93 nHash
= maTargetName
.hashCode();
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
);
109 bool FontSelectPattern::operator==(const FontSelectPattern
& rOther
) const
111 if (!CompareDeviceIndependentFontAttributes(rOther
))
114 if (maTargetName
!= rOther
.maTargetName
)
117 if (maSearchName
!= rOther
.maSearchName
)
120 if (mnWidth
!= rOther
.mnWidth
)
123 if (mnHeight
!= rOther
.mnHeight
)
126 if (mfExactHeight
!= rOther
.mfExactHeight
)
129 if (mnOrientation
!= rOther
.mnOrientation
)
132 if (meLanguage
!= rOther
.meLanguage
)
135 if (mbVertical
!= rOther
.mbVertical
)
138 if (mbNonAntialiased
!= rOther
.mbNonAntialiased
)
141 if (mbEmbolden
!= rOther
.mbEmbolden
)
144 if (maItalicMatrix
!= rOther
.maItalicMatrix
)
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */