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/types.h>
21 #include <tools/fontenum.hxx>
22 #include <unotools/fontdefs.hxx>
24 #include "fontinstance.hxx"
25 #include "fontattributes.hxx"
27 #include "PhysicalFontFace.hxx"
29 PhysicalFontFace::PhysicalFontFace( const FontAttributes
& rDFA
)
30 : FontAttributes( rDFA
)
34 // StarSymbol is a unicode font, but it still deserves the symbol flag
36 if ( IsStarSymbol( GetFamilyName() ) )
37 SetSymbolFlag( true );
40 sal_Int32
PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace
& rOther
) const
42 // compare their width, weight, italic, style name and family name
43 if( GetWidthType() < rOther
.GetWidthType() )
45 else if( GetWidthType() > rOther
.GetWidthType() )
48 if( GetWeight() < rOther
.GetWeight() )
50 else if( GetWeight() > rOther
.GetWeight() )
53 if( GetItalic() < rOther
.GetItalic() )
55 else if( GetItalic() > rOther
.GetItalic() )
58 sal_Int32 nRet
= GetFamilyName().compareTo( rOther
.GetFamilyName() );
62 nRet
= GetStyleName().compareTo( rOther
.GetStyleName() );
68 sal_Int32
PhysicalFontFace::CompareWithSize( const PhysicalFontFace
& rOther
) const
70 sal_Int32 nCompare
= CompareIgnoreSize( rOther
);
74 if( mnHeight
< rOther
.mnHeight
)
76 else if( mnHeight
> rOther
.mnHeight
)
79 if( mnWidth
< rOther
.mnWidth
)
81 else if( mnWidth
> rOther
.mnWidth
)
87 bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern
& rFSD
, FontMatchStatus
& rStatus
) const
91 const OUString
& rFontName
= rFSD
.maTargetName
;
92 if( rFontName
.equalsIgnoreAsciiCase( GetFamilyName() ) )
95 if( rStatus
.mpTargetStyleName
96 && GetStyleName().equalsIgnoreAsciiCase( *rStatus
.mpTargetStyleName
) )
99 if( (rFSD
.GetPitch() != PITCH_DONTKNOW
) && (rFSD
.GetPitch() == GetPitch()) )
102 // prefer NORMAL font width
103 // TODO: change when the upper layers can tell their width preference
104 if( GetWidthType() == WIDTH_NORMAL
)
106 else if( (GetWidthType() == WIDTH_SEMI_EXPANDED
) || (GetWidthType() == WIDTH_SEMI_CONDENSED
) )
109 if( rFSD
.GetWeight() != WEIGHT_DONTKNOW
)
111 // if not bold or requiring emboldening prefer light fonts to bold fonts
112 FontWeight ePatternWeight
= rFSD
.mbEmbolden
? WEIGHT_NORMAL
: rFSD
.GetWeight();
114 int nReqWeight
= (int)ePatternWeight
;
115 if ( ePatternWeight
> WEIGHT_MEDIUM
)
118 int nGivenWeight
= (int)GetWeight();
119 if( GetWeight() > WEIGHT_MEDIUM
)
122 int nWeightDiff
= nReqWeight
- nGivenWeight
;
124 if ( nWeightDiff
== 0 )
126 else if ( nWeightDiff
== +1 || nWeightDiff
== -1 )
128 else if ( nWeightDiff
< +50 && nWeightDiff
> -50)
131 else // requested weight == WEIGHT_DONTKNOW
133 // prefer NORMAL font weight
134 // TODO: change when the upper layers can tell their weight preference
135 if( GetWeight() == WEIGHT_NORMAL
)
137 else if( GetWeight() == WEIGHT_MEDIUM
)
139 else if( (GetWeight() == WEIGHT_SEMILIGHT
) || (GetWeight() == WEIGHT_SEMIBOLD
) )
141 else if( GetWeight() == WEIGHT_LIGHT
)
145 // if requiring custom matrix to fake italic, prefer upright font
146 FontItalic ePatternItalic
= rFSD
.maItalicMatrix
!= ItalicMatrix() ? ITALIC_NONE
: rFSD
.GetItalic();
148 if ( ePatternItalic
== ITALIC_NONE
)
150 if( GetItalic() == ITALIC_NONE
)
155 if( ePatternItalic
== GetItalic() )
157 else if( GetItalic() != ITALIC_NONE
)
161 int nHeightMatch
= 0;
164 if( rFSD
.mnOrientation
!= 0 )
166 else if( rFSD
.mnWidth
!= 0 )
171 if( rStatus
.mnFaceMatch
> nMatch
)
173 else if( rStatus
.mnFaceMatch
< nMatch
)
175 rStatus
.mnFaceMatch
= nMatch
;
176 rStatus
.mnHeightMatch
= nHeightMatch
;
177 rStatus
.mnWidthMatch
= nWidthMatch
;
181 // when two fonts are still competing prefer the
182 // one with the best matching height
183 if( rStatus
.mnHeightMatch
> nHeightMatch
)
185 else if( rStatus
.mnHeightMatch
< nHeightMatch
)
187 rStatus
.mnHeightMatch
= nHeightMatch
;
188 rStatus
.mnWidthMatch
= nWidthMatch
;
192 if( rStatus
.mnWidthMatch
> nWidthMatch
)
195 rStatus
.mnWidthMatch
= nWidthMatch
;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */