Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / font / fontselect.cxx
blob8141c859ba943185097600ad9b9bdc699f5f2414
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>
22 #include <PhysicalFontFace.hxx>
23 #include "svdata.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 )
48 , mbEmbolden( 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;
59 else
60 mnOrientation = 3600 - (-mnOrientation % 3600);
63 // normalize width and height
64 if( mnHeight < 0 )
65 mnHeight = -mnHeight;
66 if( mnWidth < 0 )
67 mnWidth = -mnWidth;
71 // NOTE: this ctor is still used on Windows. Do not remove.
72 #ifdef _WIN32
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 )
80 , meLanguage( 0 )
81 , mbVertical( bVertical )
82 , mbNonAntialiased( false )
83 , mbEmbolden( 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 )
96 #endif
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?
106 size_t nHash;
107 // check for features and generate a unique hash if necessary
108 if (maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
109 != -1)
111 nHash = maTargetName.hashCode();
113 else
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;
122 if( mbVertical )
123 nHash += 53;
124 return nHash;
127 bool FontSelectPatternAttributes::operator==(const FontSelectPatternAttributes& rOther) const
129 if (!CompareDeviceIndependentFontAttributes(rOther))
130 return false;
132 if (maTargetName != rOther.maTargetName)
133 return false;
135 if (maSearchName != rOther.maSearchName)
136 return false;
138 if (mnWidth != rOther.mnWidth)
139 return false;
141 if (mnHeight != rOther.mnHeight)
142 return false;
144 if (mfExactHeight != rOther.mfExactHeight)
145 return false;
147 if (mnOrientation != rOther.mnOrientation)
148 return false;
150 if (meLanguage != rOther.meLanguage)
151 return false;
153 if (mbVertical != rOther.mbVertical)
154 return false;
156 if (mbNonAntialiased != rOther.mbNonAntialiased)
157 return false;
159 if (mbEmbolden != rOther.mbEmbolden)
160 return false;
162 if (maItalicMatrix != rOther.maItalicMatrix)
163 return false;
165 return true;
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */