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 #ifndef INCLUDED_VCL_INC_OUTFONT_HXX
21 #define INCLUDED_VCL_INC_OUTFONT_HXX
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
25 #include <i18nlangtag/lang.h>
26 #include <tools/solar.h>
27 #include <vcl/dllapi.h>
28 #include <unotools/fontdefs.hxx>
29 #include <vcl/vclenum.hxx>
31 #include <boost/unordered_map.hpp>
33 class ImplDevFontListData
;
34 class ImplGetDevFontList
;
35 class ImplGetDevSizeList
;
37 class ImplDirectFontSubstitution
;
38 class ImplPreMatchFontSubstitution
;
39 class ImplGlyphFallbackFontSubstitution
;
40 class FontSelectPattern
;
43 struct FontMatchStatus
;
47 namespace com
{ namespace sun
{ namespace star
{ namespace lang
{ struct Locale
; }}}}
49 // ----------------------
50 // - ImplFontAttributes -
51 // ----------------------
52 // device independent font properties
54 class ImplFontAttributes
56 public: // TODO: create matching interface class
57 const OUString
& GetFamilyName() const { return maName
; }
58 const OUString
& GetStyleName() const { return maStyleName
; }
59 FontWeight
GetWeight() const { return meWeight
; }
60 FontItalic
GetSlant() const { return meItalic
; }
61 FontFamily
GetFamilyType() const { return meFamily
; }
62 FontPitch
GetPitch() const { return mePitch
; }
63 FontWidth
GetWidthType() const { return meWidthType
; }
64 bool IsSymbolFont() const { return mbSymbolFlag
; }
65 void SetFamilyName(const OUString sFamilyName
) { maName
= sFamilyName
; }
66 void SetStyleName( const OUString sStyleName
) { maStyleName
= sStyleName
; }
67 void SetFamilyType(const FontFamily eFontFamily
) { meFamily
= eFontFamily
; }
68 void SetPitch(const FontPitch ePitch
) { mePitch
= ePitch
; }
69 void SetItalic(const FontItalic eItalic
) { meItalic
= eItalic
; }
70 void SetWeight(const FontWeight eWeight
) { meWeight
= eWeight
; }
71 void SetWidthType(const FontWidth eWidthType
) { meWidthType
= eWidthType
; }
72 void SetSymbolFlag(const bool bSymbolFlag
) { mbSymbolFlag
= bSymbolFlag
; }
73 bool operator==(const ImplFontAttributes
& rOther
) const;
74 bool operator!=(const ImplFontAttributes
& rOther
) const
76 return !(*this == rOther
);
80 OUString maName
; // Font Family Name
81 OUString maStyleName
; // Font Style Name
82 FontWeight meWeight
; // Weight Type
83 FontItalic meItalic
; // Slant Type
84 FontFamily meFamily
; // Family Type
85 FontPitch mePitch
; // Pitch Type
86 FontWidth meWidthType
; // Width Type
90 // -------------------------
91 // - ImplDevFontAttributes -
92 // -------------------------
93 // device dependent font properties
95 class ImplDevFontAttributes
: public ImplFontAttributes
97 public: // TODO: create matching interface class
98 const OUString
& GetAliasNames() const { return maMapNames
; }
99 int GetQuality() const { return mnQuality
; }
100 bool IsRotatable() const { return mbOrientation
; }
101 bool IsDeviceFont() const { return mbDevice
; }
102 bool IsEmbeddable() const { return mbEmbeddable
; }
103 bool IsSubsettable() const { return mbSubsettable
; }
105 public: // TODO: hide members behind accessor methods
106 OUString maMapNames
; // List of family name aliass separated with ';'
107 int mnQuality
; // Quality (used when similar fonts compete)
108 bool mbOrientation
; // true: physical font can be rotated
109 bool mbDevice
; // true: built in font
110 bool mbSubsettable
; // true: a subset of the font can be created
111 bool mbEmbeddable
; // true: the font can be embedded
115 // - PhysicalFontFace -
117 // TODO: no more direct access to members
118 // TODO: add reference counting
119 // TODO: get rid of height/width for scalable fonts
120 // TODO: make cloning cheaper
122 // abstract base class for physical font faces
123 class VCL_PLUGIN_PUBLIC PhysicalFontFace
: public ImplDevFontAttributes
126 // by using an PhysicalFontFace object as a factory for its corresponding
127 // ImplFontEntry an ImplFontEntry can be extended to cache device and
128 // font instance specific data
129 virtual ImplFontEntry
* CreateFontInstance( FontSelectPattern
& ) const = 0;
131 virtual int GetHeight() const { return mnHeight
; }
132 virtual int GetWidth() const { return mnWidth
; }
133 virtual sal_IntPtr
GetFontId() const = 0;
134 int GetFontMagic() const { return mnMagic
; }
135 bool IsScalable() const { return (mnHeight
== 0); }
136 bool CheckMagic( int n
) const { return (n
== mnMagic
); }
137 PhysicalFontFace
* GetNextFace() const { return mpNext
; }
138 PhysicalFontFace
* CreateAlias() const { return Clone(); }
140 bool IsBetterMatch( const FontSelectPattern
&, FontMatchStatus
& ) const;
141 sal_Int32
CompareWithSize( const PhysicalFontFace
& ) const;
142 sal_Int32
CompareIgnoreSize( const PhysicalFontFace
& ) const;
143 virtual ~PhysicalFontFace() {}
144 virtual PhysicalFontFace
* Clone() const = 0;
147 explicit PhysicalFontFace( const ImplDevFontAttributes
&, int nMagic
);
148 void SetBitmapSize( int nW
, int nH
) { mnWidth
=nW
; mnHeight
=nH
; }
150 long mnWidth
; // Width (in pixels)
151 long mnHeight
; // Height (in pixels)
154 friend class ImplDevFontListData
;
155 const int mnMagic
; // poor man's RTTI
156 PhysicalFontFace
* mpNext
;
159 class FontSelectPatternAttributes
: public ImplFontAttributes
162 FontSelectPatternAttributes( const Font
&, const OUString
& rSearchName
,
163 const Size
&, float fExactHeight
);
164 FontSelectPatternAttributes( const PhysicalFontFace
&, const Size
&,
165 float fExactHeight
, int nOrientation
, bool bVertical
);
167 size_t hashCode() const;
168 bool operator==(const FontSelectPatternAttributes
& rOther
) const;
169 bool operator!=(const FontSelectPatternAttributes
& rOther
) const
171 return !(*this == rOther
);
175 OUString maTargetName
; // name of the font name token that is chosen
176 OUString maSearchName
; // name of the font that matches best
177 int mnWidth
; // width of font in pixel units
178 int mnHeight
; // height of font in pixel units
179 float mfExactHeight
; // requested height (in pixels with subpixel details)
180 int mnOrientation
; // text orientation in 3600 system
181 LanguageType meLanguage
; // text language
182 bool mbVertical
; // vertical mode of requested font
183 bool mbNonAntialiased
; // true if antialiasing is disabled
185 bool mbEmbolden
; // Force emboldening
186 ItalicMatrix maItalicMatrix
; // Force matrix for slant
189 class FontSelectPattern
: public FontSelectPatternAttributes
192 FontSelectPattern( const Font
&, const OUString
& rSearchName
,
193 const Size
&, float fExactHeight
);
195 // ifdeffed to prevent it going into unusedcode.easy
196 FontSelectPattern( const PhysicalFontFace
&, const Size
&,
197 float fExactHeight
, int nOrientation
, bool bVertical
);
200 public: // TODO: change to private
201 const PhysicalFontFace
* mpFontData
; // a matching PhysicalFontFace object
202 ImplFontEntry
* mpFontEntry
; // pointer to the resulting FontCache entry
203 void copyAttributes(const FontSelectPatternAttributes
&rAttributes
);
206 // -------------------
207 // - ImplDevFontList -
208 // -------------------
209 // TODO: merge with ImplFontCache
210 // TODO: rename to LogicalFontManager
212 class VCL_PLUGIN_PUBLIC ImplDevFontList
215 friend class WinGlyphFallbackSubstititution
;
216 mutable bool mbMatchData
; // true if matching attributes are initialized
217 bool mbMapNames
; // true if MapNames are available
219 typedef boost::unordered_map
<const OUString
, ImplDevFontListData
*,FontNameHash
> DevFontList
;
220 DevFontList maDevFontList
;
222 ImplPreMatchFontSubstitution
* mpPreMatchHook
; // device specific prematch substitution
223 ImplGlyphFallbackFontSubstitution
* mpFallbackHook
; // device specific glyh fallback substitution
226 explicit ImplDevFontList();
227 virtual ~ImplDevFontList();
229 // fill the list with device fonts
230 void Add( PhysicalFontFace
* );
232 int Count() const { return maDevFontList
.size(); }
234 // find the device font
235 ImplDevFontListData
* FindFontFamily( const OUString
& rFontName
) const;
236 ImplDevFontListData
* ImplFindByFont( FontSelectPattern
&, bool bPrinter
, ImplDirectFontSubstitution
* ) const;
237 ImplDevFontListData
* ImplFindBySearchName( const OUString
& ) const;
239 // suggest fonts for glyph fallback
240 ImplDevFontListData
* GetGlyphFallbackFont( FontSelectPattern
&,
241 OUString
& rMissingCodes
, int nFallbackLevel
) const;
243 // prepare platform specific font substitutions
244 void SetPreMatchHook( ImplPreMatchFontSubstitution
* );
245 void SetFallbackHook( ImplGlyphFallbackFontSubstitution
* );
248 ImplDevFontList
* Clone( bool bScalable
, bool bEmbeddable
) const;
249 ImplGetDevFontList
* GetDevFontList() const;
250 ImplGetDevSizeList
* GetDevSizeList( const OUString
& rFontName
) const;
252 ImplDevFontListData
* ImplFindByTokenNames(const OUString
& rTokenStr
) const;
255 void InitMatchData() const;
256 bool AreMapNamesAvailable() const { return mbMapNames
; }
258 ImplDevFontListData
* ImplFindByAliasName(const OUString
& rSearchName
,
259 const OUString
& rShortName
) const;
260 ImplDevFontListData
* ImplFindBySubstFontAttr( const utl::FontNameAttr
& ) const;
261 ImplDevFontListData
* ImplFindByAttributes(sal_uLong nSearchType
, FontWeight
, FontWidth
,
262 FontItalic
, const OUString
& rSearchFamily
) const;
263 ImplDevFontListData
* FindDefaultFont() const;
266 void InitGenericGlyphFallback() const;
267 mutable ImplDevFontListData
** mpFallbackList
;
268 mutable int mnFallbackCount
;
271 // -----------------------
272 // - ImplFontMetricData -
273 // -----------------------
275 class ImplFontMetricData
: public ImplFontAttributes
278 explicit ImplFontMetricData( const FontSelectPattern
& );
279 void ImplInitTextLineSize( const OutputDevice
* pDev
);
280 void ImplInitAboveTextLineSize();
282 public: // TODO: hide members behind accessor methods
283 // font instance attributes from the font request
284 long mnWidth
; // Reference Width
285 short mnOrientation
; // Rotation in 1/10 degrees
287 // font metrics measured for the font instance
288 long mnAscent
; // Ascent
289 long mnDescent
; // Descent
290 long mnIntLeading
; // Internal Leading
291 long mnExtLeading
; // External Leading
292 int mnSlant
; // Slant (Italic/Oblique)
293 long mnMinKashida
; // Minimal width of kashida (Arabic)
295 // font attributes queried from the font instance
296 int meFamilyType
; // Font Family Type
297 bool mbDevice
; // Flag for Device Fonts
301 // font metrics that are usually derived from the measurements
302 long mnUnderlineSize
; // Lineheight of Underline
303 long mnUnderlineOffset
; // Offset from Underline to Baseline
304 long mnBUnderlineSize
; // Height of bold underline
305 long mnBUnderlineOffset
; // Offset from bold underline to baseline
306 long mnDUnderlineSize
; // Height of double underline
307 long mnDUnderlineOffset1
; // Offset from double underline to baseline
308 long mnDUnderlineOffset2
; // Offset from double underline to baseline
309 long mnWUnderlineSize
; // Height of WaveLine underline
310 long mnWUnderlineOffset
; // Offset from WaveLine underline to baseline, but centrered to WaveLine
311 long mnAboveUnderlineSize
; // Height of single underline (for Vertical Right)
312 long mnAboveUnderlineOffset
; // Offset from single underline to baseline (for Vertical Right)
313 long mnAboveBUnderlineSize
; // Height of bold underline (for Vertical Right)
314 long mnAboveBUnderlineOffset
; // Offset from bold underline to baseline (for Vertical Right)
315 long mnAboveDUnderlineSize
; // Height of double underline (for Vertical Right)
316 long mnAboveDUnderlineOffset1
; // Offset from double underline to baseline (for Vertical Right)
317 long mnAboveDUnderlineOffset2
; // Offset from double underline to baseline (for Vertical Right)
318 long mnAboveWUnderlineSize
; // Height of WaveLine-strike-out (for Vertical Right)
319 long mnAboveWUnderlineOffset
; // Offset from WaveLine-strike-out to baseline, but centrered to to WaveLine (for Vertical Right)
320 long mnStrikeoutSize
; // Height of single strike-out
321 long mnStrikeoutOffset
; // Offset from single strike-out to baseline
322 long mnBStrikeoutSize
; // Height of bold strike-out
323 long mnBStrikeoutOffset
; // Offset of bold strike-out to baseline
324 long mnDStrikeoutSize
; // Height of double strike-out
325 long mnDStrikeoutOffset1
; // Offset of double strike-out to baseline
326 long mnDStrikeoutOffset2
; // Offset of double strike-out to baseline
331 // ------------------
332 // TODO: rename ImplFontEntry to LogicalFontInstance
333 // TODO: allow sharing of metrics for related fonts
335 class VCL_PLUGIN_PUBLIC ImplFontEntry
338 explicit ImplFontEntry( const FontSelectPattern
& );
339 virtual ~ImplFontEntry();
341 public: // TODO: make data members private
342 FontSelectPattern maFontSelData
; // FontSelectionData
343 ImplFontMetricData maMetric
; // Font Metric
344 const ConvertChar
* mpConversion
; // used e.g. for StarBats->StarSymbol
346 sal_uLong mnRefCount
;
347 sal_uInt16 mnSetFontFlags
; // Flags returned by SalGraphics::SetFont()
348 short mnOwnOrientation
; // text angle if lower layers don't rotate text themselves
349 short mnOrientation
; // text angle in 3600 system
350 bool mbInit
; // true if maMetric member is valid
352 void AddFallbackForUnicode( sal_UCS4
, FontWeight eWeight
, const OUString
& rFontName
);
353 bool GetFallbackForUnicode( sal_UCS4
, FontWeight eWeight
, OUString
* pFontName
) const;
354 void IgnoreFallbackForUnicode( sal_UCS4
, FontWeight eWeight
, const OUString
& rFontName
);
357 // cache of Unicode characters and replacement font names
358 // TODO: a fallback map can be shared with many other ImplFontEntries
359 // TODO: at least the ones which just differ in orientation, stretching or height
360 typedef ::std::pair
<sal_UCS4
,FontWeight
> GFBCacheKey
;
361 struct GFBCacheKey_Hash
{ size_t operator()( const GFBCacheKey
& ) const; };
362 typedef ::boost::unordered_map
<GFBCacheKey
,OUString
,GFBCacheKey_Hash
> UnicodeFallbackList
;
363 UnicodeFallbackList
* mpUnicodeFallbackList
;
367 class ImplTextLineInfo
375 ImplTextLineInfo( long nWidth
, xub_StrLen nIndex
, xub_StrLen nLen
)
382 long GetWidth() const { return mnWidth
; }
383 xub_StrLen
GetIndex() const { return mnIndex
; }
384 xub_StrLen
GetLen() const { return mnLen
; }
387 #define MULTITEXTLINEINFO_RESIZE 16
388 typedef ImplTextLineInfo
* PImplTextLineInfo
;
390 class ImplMultiTextLineInfo
393 PImplTextLineInfo
* mpLines
;
398 ImplMultiTextLineInfo();
399 ~ImplMultiTextLineInfo();
401 void AddLine( ImplTextLineInfo
* pLine
);
404 ImplTextLineInfo
* GetLine( sal_uInt16 nLine
) const
405 { return mpLines
[nLine
]; }
406 xub_StrLen
Count() const { return mnLines
; }
409 ImplMultiTextLineInfo( const ImplMultiTextLineInfo
& );
410 ImplMultiTextLineInfo
& operator=( const ImplMultiTextLineInfo
& );
413 #endif // INCLUDED_VCL_INC_OUTFONT_HXX
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */