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>
22 #include <PhysicalFontFace.hxx>
25 // These mustn't conflict with font name lists which use ; and ,
26 const char FontSelectPatternAttributes::FEAT_PREFIX
= ':';
27 const char FontSelectPatternAttributes::FEAT_SEPARATOR
= '&';
29 FontSelectPattern::FontSelectPattern( const vcl::Font
& rFont
,
30 const OUString
& rSearchName
, const Size
& rSize
, float fExactHeight
)
31 : FontSelectPatternAttributes(rFont
, rSearchName
, rSize
, fExactHeight
)
32 , mpFontData( nullptr )
33 , mpFontInstance( nullptr )
38 FontSelectPatternAttributes::FontSelectPatternAttributes( const vcl::Font
& rFont
,
39 const OUString
& rSearchName
, const Size
& rSize
, float fExactHeight
)
40 : maSearchName( rSearchName
)
41 , mnWidth( rSize
.Width() )
42 , mnHeight( rSize
.Height() )
43 , mfExactHeight( fExactHeight
)
44 , mnOrientation( rFont
.GetOrientation() )
45 , meLanguage( rFont
.GetLanguage() )
46 , mbVertical( rFont
.IsVertical() )
47 , mbNonAntialiased( false )
50 maTargetName
= GetFamilyName();
52 rFont
.GetFontAttributes( *this );
54 // normalize orientation between 0 and 3600
55 if( 3600 <= (unsigned)mnOrientation
)
57 if( mnOrientation
>= 0 )
58 mnOrientation
%= 3600;
60 mnOrientation
= 3600 - (-mnOrientation
% 3600);
63 // normalize width and height
71 // NOTE: this ctor is still used on Windows. Do not remove.
73 FontSelectPatternAttributes::FontSelectPatternAttributes( const PhysicalFontFace
& rFontData
,
74 const Size
& rSize
, float fExactHeight
, int nOrientation
, bool bVertical
)
75 : FontAttributes( rFontData
)
76 , mnWidth( rSize
.Width() )
77 , mnHeight( rSize
.Height() )
78 , mfExactHeight( fExactHeight
)
79 , mnOrientation( nOrientation
)
81 , mbVertical( bVertical
)
82 , mbNonAntialiased( false )
85 maTargetName
= maSearchName
= GetFamilyName();
86 // NOTE: no normalization for width/height/orientation
89 FontSelectPattern::FontSelectPattern( const PhysicalFontFace
& rFontData
,
90 const Size
& rSize
, float fExactHeight
, int nOrientation
, bool bVertical
)
91 : FontSelectPatternAttributes(rFontData
, rSize
, fExactHeight
, nOrientation
, bVertical
)
92 , mpFontData( &rFontData
)
93 , mpFontInstance( nullptr )
98 void FontSelectPattern::copyAttributes(const FontSelectPatternAttributes
&rAttributes
)
100 static_cast<FontSelectPatternAttributes
&>(*this) = rAttributes
;
103 size_t FontSelectPatternAttributes::hashCode() const
105 // TODO: does it pay off to improve this hash function?
107 // check for features and generate a unique hash if necessary
108 if (maTargetName
.indexOf(FontSelectPatternAttributes::FEAT_PREFIX
)
111 nHash
= maTargetName
.hashCode();
115 nHash
= maSearchName
.hashCode();
117 nHash
+= 11 * mnHeight
;
118 nHash
+= 19 * GetWeight();
119 nHash
+= 29 * GetItalic();
120 nHash
+= 37 * mnOrientation
;
121 nHash
+= 41 * (sal_uInt16
)meLanguage
;
127 bool FontSelectPatternAttributes::operator==(const FontSelectPatternAttributes
& rOther
) const
129 if (!CompareDeviceIndependentFontAttributes(rOther
))
132 if (maTargetName
!= rOther
.maTargetName
)
135 if (maSearchName
!= rOther
.maSearchName
)
138 if (mnWidth
!= rOther
.mnWidth
)
141 if (mnHeight
!= rOther
.mnHeight
)
144 if (mfExactHeight
!= rOther
.mfExactHeight
)
147 if (mnOrientation
!= rOther
.mnOrientation
)
150 if (meLanguage
!= rOther
.meLanguage
)
153 if (mbVertical
!= rOther
.mbVertical
)
156 if (mbNonAntialiased
!= rOther
.mbNonAntialiased
)
159 if (mbEmbolden
!= rOther
.mbEmbolden
)
162 if (maItalicMatrix
!= rOther
.maItalicMatrix
)
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */