bump product version to 4.1.6.2
[LibreOffice.git] / vcl / inc / outfont.hxx
blob140af384f13a29d0c2fb590e50621eed8f20cb31
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 #ifndef _SV_OUTFONT_HXX
21 #define _SV_OUTFONT_HXX
23 #include <sal/types.h>
24 #include <tools/string.hxx>
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;
36 class ImplFontEntry;
37 class ImplDirectFontSubstitution;
38 class ImplPreMatchFontSubstitution;
39 class ImplGlyphFallbackFontSubstitution;
40 class FontSelectPattern;
41 class Font;
42 class ConvertChar;
43 struct FontMatchStatus;
44 class OutputDevice;
45 class Size;
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);
79 private:
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
87 bool mbSymbolFlag;
90 // -------------------------
91 // - ImplDevFontAttributes -
92 // -------------------------
93 // device dependent font properties
95 class ImplDevFontAttributes : public ImplFontAttributes
97 public: // TODO: create matching interface class
98 const String& 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 String 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
114 // ----------------
115 // - PhysicalFontFace -
116 // ----------------
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
125 public:
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;
146 protected:
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)
153 private:
154 friend class ImplDevFontListData;
155 const int mnMagic; // poor man's RTTI
156 PhysicalFontFace* mpNext;
159 class FontSelectPatternAttributes : public ImplFontAttributes
161 public:
162 FontSelectPatternAttributes( const Font&, const String& 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);
174 public:
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
191 public:
192 FontSelectPattern( const Font&, const String& rSearchName,
193 const Size&, float fExactHeight );
194 #ifdef WNT
195 // ifdeffed to prevent it going into unusedcode.easy
196 FontSelectPattern( const PhysicalFontFace&, const Size&,
197 float fExactHeight, int nOrientation, bool bVertical );
198 #endif
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
214 private:
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 String, ImplDevFontListData*,FontNameHash> DevFontList;
220 DevFontList maDevFontList;
222 ImplPreMatchFontSubstitution* mpPreMatchHook; // device specific prematch substitution
223 ImplGlyphFallbackFontSubstitution* mpFallbackHook; // device specific glyh fallback substitution
225 public:
226 explicit ImplDevFontList();
227 virtual ~ImplDevFontList();
229 // fill the list with device fonts
230 void Add( PhysicalFontFace* );
231 void Clear();
232 int Count() const { return maDevFontList.size(); }
234 // find the device font
235 ImplDevFontListData* FindFontFamily( const String& 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* );
247 // misc utilities
248 ImplDevFontList* Clone( bool bScalable, bool bEmbeddable ) const;
249 ImplGetDevFontList* GetDevFontList() const;
250 ImplGetDevSizeList* GetDevSizeList( const String& rFontName ) const;
252 ImplDevFontListData* ImplFindByTokenNames(const OUString& rTokenStr) const;
254 protected:
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;
265 private:
266 void InitGenericGlyphFallback() const;
267 mutable ImplDevFontListData** mpFallbackList;
268 mutable int mnFallbackCount;
271 // --------------------
272 // - ImplKernPairData -
273 // --------------------
275 struct ImplKernPairData
277 sal_uInt16 mnChar1;
278 sal_uInt16 mnChar2;
279 long mnKern;
283 // -----------------------
284 // - ImplFontMetricData -
285 // -----------------------
287 class ImplFontMetricData : public ImplFontAttributes
289 public:
290 explicit ImplFontMetricData( const FontSelectPattern& );
291 void ImplInitTextLineSize( const OutputDevice* pDev );
292 void ImplInitAboveTextLineSize();
294 public: // TODO: hide members behind accessor methods
295 // font instance attributes from the font request
296 long mnWidth; // Reference Width
297 short mnOrientation; // Rotation in 1/10 degrees
299 // font metrics measured for the font instance
300 long mnAscent; // Ascent
301 long mnDescent; // Descent
302 long mnIntLeading; // Internal Leading
303 long mnExtLeading; // External Leading
304 int mnSlant; // Slant (Italic/Oblique)
305 long mnMinKashida; // Minimal width of kashida (Arabic)
307 // font attributes queried from the font instance
308 int meFamilyType; // Font Family Type
309 bool mbDevice; // Flag for Device Fonts
310 bool mbScalableFont;
311 bool mbKernableFont;
313 // font metrics that are usually derived from the measurements
314 long mnUnderlineSize; // Lineheight of Underline
315 long mnUnderlineOffset; // Offset from Underline to Baseline
316 long mnBUnderlineSize; // Height of bold underline
317 long mnBUnderlineOffset; // Offset from bold underline to baseline
318 long mnDUnderlineSize; // Height of double underline
319 long mnDUnderlineOffset1; // Offset from double underline to baseline
320 long mnDUnderlineOffset2; // Offset from double underline to baseline
321 long mnWUnderlineSize; // Height of WaveLine underline
322 long mnWUnderlineOffset; // Offset from WaveLine underline to baseline, but centrered to WaveLine
323 long mnAboveUnderlineSize; // Height of single underline (for Vertical Right)
324 long mnAboveUnderlineOffset; // Offset from single underline to baseline (for Vertical Right)
325 long mnAboveBUnderlineSize; // Height of bold underline (for Vertical Right)
326 long mnAboveBUnderlineOffset; // Offset from bold underline to baseline (for Vertical Right)
327 long mnAboveDUnderlineSize; // Height of double underline (for Vertical Right)
328 long mnAboveDUnderlineOffset1; // Offset from double underline to baseline (for Vertical Right)
329 long mnAboveDUnderlineOffset2; // Offset from double underline to baseline (for Vertical Right)
330 long mnAboveWUnderlineSize; // Height of WaveLine-strike-out (for Vertical Right)
331 long mnAboveWUnderlineOffset; // Offset from WaveLine-strike-out to baseline, but centrered to to WaveLine (for Vertical Right)
332 long mnStrikeoutSize; // Height of single strike-out
333 long mnStrikeoutOffset; // Offset from single strike-out to baseline
334 long mnBStrikeoutSize; // Height of bold strike-out
335 long mnBStrikeoutOffset; // Offset of bold strike-out to baseline
336 long mnDStrikeoutSize; // Height of double strike-out
337 long mnDStrikeoutOffset1; // Offset of double strike-out to baseline
338 long mnDStrikeoutOffset2; // Offset of double strike-out to baseline
341 // -----------------
342 // - ImplFontEntry -
343 // ------------------
344 // TODO: rename ImplFontEntry to LogicalFontInstance
345 // TODO: allow sharing of metrics for related fonts
347 class VCL_PLUGIN_PUBLIC ImplFontEntry
349 public:
350 explicit ImplFontEntry( const FontSelectPattern& );
351 virtual ~ImplFontEntry();
353 public: // TODO: make data members private
354 FontSelectPattern maFontSelData; // FontSelectionData
355 ImplFontMetricData maMetric; // Font Metric
356 const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
357 long mnLineHeight;
358 sal_uLong mnRefCount;
359 sal_uInt16 mnSetFontFlags; // Flags returned by SalGraphics::SetFont()
360 short mnOwnOrientation; // text angle if lower layers don't rotate text themselves
361 short mnOrientation; // text angle in 3600 system
362 bool mbInit; // true if maMetric member is valid
364 void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
365 bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
366 void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
368 private:
369 // cache of Unicode characters and replacement font names
370 // TODO: a fallback map can be shared with many other ImplFontEntries
371 // TODO: at least the ones which just differ in orientation, stretching or height
372 typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
373 struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
374 typedef ::boost::unordered_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
375 UnicodeFallbackList* mpUnicodeFallbackList;
379 class ImplTextLineInfo
381 private:
382 long mnWidth;
383 xub_StrLen mnIndex;
384 xub_StrLen mnLen;
386 public:
387 ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
389 mnWidth = nWidth;
390 mnIndex = nIndex;
391 mnLen = nLen;
394 long GetWidth() const { return mnWidth; }
395 xub_StrLen GetIndex() const { return mnIndex; }
396 xub_StrLen GetLen() const { return mnLen; }
399 #define MULTITEXTLINEINFO_RESIZE 16
400 typedef ImplTextLineInfo* PImplTextLineInfo;
402 class ImplMultiTextLineInfo
404 private:
405 PImplTextLineInfo* mpLines;
406 xub_StrLen mnLines;
407 xub_StrLen mnSize;
409 public:
410 ImplMultiTextLineInfo();
411 ~ImplMultiTextLineInfo();
413 void AddLine( ImplTextLineInfo* pLine );
414 void Clear();
416 ImplTextLineInfo* GetLine( sal_uInt16 nLine ) const
417 { return mpLines[nLine]; }
418 xub_StrLen Count() const { return mnLines; }
420 private:
421 ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
422 ImplMultiTextLineInfo& operator=( const ImplMultiTextLineInfo& );
425 #endif // _SV_OUTFONT_HXX
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */