Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / vcl / inc / outfont.hxx
blob0fe3cb65e85cd169f9f55cee0ff3d7704ad9d628
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 <tools/string.hxx>
24 #include <i18npool/lang.h>
25 #include <tools/gen.hxx>
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;
46 namespace com { namespace sun { namespace star { namespace lang { struct Locale; }}}}
48 // ----------------------
49 // - ImplFontAttributes -
50 // ----------------------
51 // device independent font properties
53 class ImplFontAttributes
55 public: // TODO: create matching interface class
56 const String& GetFamilyName() const { return maName; }
57 const String& GetStyleName() const { return maStyleName; }
58 FontWeight GetWeight() const { return meWeight; }
59 FontItalic GetSlant() const { return meItalic; }
60 FontFamily GetFamilyType() const { return meFamily; }
61 FontPitch GetPitch() const { return mePitch; }
62 FontWidth GetWidthType() const { return meWidthType; }
63 bool IsSymbolFont() const { return mbSymbolFlag; }
65 bool operator==(const ImplFontAttributes& rOther) const;
66 bool operator!=(const ImplFontAttributes& rOther) const
68 return !(*this == rOther);
71 public: // TODO: hide members behind accessor methods
72 String maName; // Font Family Name
73 String maStyleName; // Font Style Name
74 FontWeight meWeight; // Weight Type
75 FontItalic meItalic; // Slant Type
76 FontFamily meFamily; // Family Type
77 FontPitch mePitch; // Pitch Type
78 FontWidth meWidthType; // Width Type
79 bool mbSymbolFlag;
82 // -------------------------
83 // - ImplDevFontAttributes -
84 // -------------------------
85 // device dependent font properties
87 class ImplDevFontAttributes : public ImplFontAttributes
89 public: // TODO: create matching interface class
90 const String& GetAliasNames() const { return maMapNames; }
91 int GetQuality() const { return mnQuality; }
92 bool IsRotatable() const { return mbOrientation; }
93 bool IsDeviceFont() const { return mbDevice; }
94 bool IsEmbeddable() const { return mbEmbeddable; }
95 bool IsSubsettable() const { return mbSubsettable; }
97 public: // TODO: hide members behind accessor methods
98 String maMapNames; // List of family name aliass separated with ';'
99 int mnQuality; // Quality (used when similar fonts compete)
100 bool mbOrientation; // true: physical font can be rotated
101 bool mbDevice; // true: built in font
102 bool mbSubsettable; // true: a subset of the font can be created
103 bool mbEmbeddable; // true: the font can be embedded
106 // ----------------
107 // - PhysicalFontFace -
108 // ----------------
109 // TODO: no more direct access to members
110 // TODO: add reference counting
111 // TODO: get rid of height/width for scalable fonts
112 // TODO: make cloning cheaper
114 // abstract base class for physical font faces
115 class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplDevFontAttributes
117 public:
118 // by using an PhysicalFontFace object as a factory for its corresponding
119 // ImplFontEntry an ImplFontEntry can be extended to cache device and
120 // font instance specific data
121 virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const = 0;
123 virtual int GetHeight() const { return mnHeight; }
124 virtual int GetWidth() const { return mnWidth; }
125 virtual sal_IntPtr GetFontId() const = 0;
126 int GetFontMagic() const { return mnMagic; }
127 bool IsScalable() const { return (mnHeight == 0); }
128 bool CheckMagic( int n ) const { return (n == mnMagic); }
129 PhysicalFontFace* GetNextFace() const { return mpNext; }
130 PhysicalFontFace* CreateAlias() const { return Clone(); }
132 bool IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
133 StringCompare CompareWithSize( const PhysicalFontFace& ) const;
134 StringCompare CompareIgnoreSize( const PhysicalFontFace& ) const;
135 virtual ~PhysicalFontFace() {}
136 virtual PhysicalFontFace* Clone() const = 0;
138 protected:
139 explicit PhysicalFontFace( const ImplDevFontAttributes&, int nMagic );
140 void SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
142 long mnWidth; // Width (in pixels)
143 long mnHeight; // Height (in pixels)
145 private:
146 friend class ImplDevFontListData;
147 const int mnMagic; // poor man's RTTI
148 PhysicalFontFace* mpNext;
151 class FontSelectPatternAttributes : public ImplFontAttributes
153 public:
154 FontSelectPatternAttributes( const Font&, const String& rSearchName,
155 const Size&, float fExactHeight );
156 FontSelectPatternAttributes( const PhysicalFontFace&, const Size&,
157 float fExactHeight, int nOrientation, bool bVertical );
159 size_t hashCode() const;
160 bool operator==(const FontSelectPatternAttributes& rOther) const;
161 bool operator!=(const FontSelectPatternAttributes& rOther) const
163 return !(*this == rOther);
166 public:
167 String maTargetName; // name of the font name token that is chosen
168 String maSearchName; // name of the font that matches best
169 int mnWidth; // width of font in pixel units
170 int mnHeight; // height of font in pixel units
171 float mfExactHeight; // requested height (in pixels with subpixel details)
172 int mnOrientation; // text orientation in 3600 system
173 LanguageType meLanguage; // text language
174 bool mbVertical; // vertical mode of requested font
175 bool mbNonAntialiased; // true if antialiasing is disabled
177 bool mbEmbolden; // Force emboldening
178 ItalicMatrix maItalicMatrix; // Force matrix for slant
181 class FontSelectPattern : public FontSelectPatternAttributes
183 public:
184 FontSelectPattern( const Font&, const String& rSearchName,
185 const Size&, float fExactHeight );
186 FontSelectPattern( const PhysicalFontFace&, const Size&,
187 float fExactHeight, int nOrientation, bool bVertical );
189 public: // TODO: change to private
190 const PhysicalFontFace* mpFontData; // a matching PhysicalFontFace object
191 ImplFontEntry* mpFontEntry; // pointer to the resulting FontCache entry
192 void copyAttributes(const FontSelectPatternAttributes &rAttributes);
195 // -------------------
196 // - ImplDevFontList -
197 // -------------------
198 // TODO: merge with ImplFontCache
199 // TODO: rename to LogicalFontManager
201 class VCL_PLUGIN_PUBLIC ImplDevFontList
203 private:
204 friend class WinGlyphFallbackSubstititution;
205 mutable bool mbMatchData; // true if matching attributes are initialized
206 bool mbMapNames; // true if MapNames are available
208 typedef boost::unordered_map<const String, ImplDevFontListData*,FontNameHash> DevFontList;
209 DevFontList maDevFontList;
211 ImplPreMatchFontSubstitution* mpPreMatchHook; // device specific prematch substitution
212 ImplGlyphFallbackFontSubstitution* mpFallbackHook; // device specific glyh fallback substitution
214 public:
215 explicit ImplDevFontList();
216 virtual ~ImplDevFontList();
218 // fill the list with device fonts
219 void Add( PhysicalFontFace* );
220 void Clear();
221 int Count() const { return maDevFontList.size(); }
223 // find the device font
224 ImplDevFontListData* FindFontFamily( const String& rFontName ) const;
225 ImplDevFontListData* ImplFindByFont( FontSelectPattern&, bool bPrinter, ImplDirectFontSubstitution* ) const;
226 ImplDevFontListData* ImplFindBySearchName( const String& ) const;
228 // suggest fonts for glyph fallback
229 ImplDevFontListData* GetGlyphFallbackFont( FontSelectPattern&,
230 rtl::OUString& rMissingCodes, int nFallbackLevel ) const;
232 // prepare platform specific font substitutions
233 void SetPreMatchHook( ImplPreMatchFontSubstitution* );
234 void SetFallbackHook( ImplGlyphFallbackFontSubstitution* );
236 // misc utilities
237 ImplDevFontList* Clone( bool bScalable, bool bEmbeddable ) const;
238 ImplGetDevFontList* GetDevFontList() const;
239 ImplGetDevSizeList* GetDevSizeList( const String& rFontName ) const;
241 ImplDevFontListData* ImplFindByTokenNames(const rtl::OUString& rTokenStr) const;
243 protected:
244 void InitMatchData() const;
245 bool AreMapNamesAvailable() const { return mbMapNames; }
247 ImplDevFontListData* ImplFindByAliasName(const rtl::OUString& rSearchName,
248 const rtl::OUString& rShortName) const;
249 ImplDevFontListData* ImplFindBySubstFontAttr( const utl::FontNameAttr& ) const;
250 ImplDevFontListData* ImplFindByAttributes(sal_uLong nSearchType, FontWeight, FontWidth,
251 FontItalic, const rtl::OUString& rSearchFamily) const;
252 ImplDevFontListData* FindDefaultFont() const;
254 private:
255 void InitGenericGlyphFallback() const;
256 mutable ImplDevFontListData** mpFallbackList;
257 mutable int mnFallbackCount;
260 // --------------------
261 // - ImplKernPairData -
262 // --------------------
264 struct ImplKernPairData
266 sal_uInt16 mnChar1;
267 sal_uInt16 mnChar2;
268 long mnKern;
272 // -----------------------
273 // - ImplFontMetricData -
274 // -----------------------
276 class ImplFontMetricData : public ImplFontAttributes
278 public:
279 explicit ImplFontMetricData( const FontSelectPattern& );
280 void ImplInitTextLineSize( const OutputDevice* pDev );
281 void ImplInitAboveTextLineSize();
283 public: // TODO: hide members behind accessor methods
284 // font instance attributes from the font request
285 long mnWidth; // Reference Width
286 short mnOrientation; // Rotation in 1/10 degrees
288 // font metrics measured for the font instance
289 long mnAscent; // Ascent
290 long mnDescent; // Descent
291 long mnIntLeading; // Internal Leading
292 long mnExtLeading; // External Leading
293 int mnSlant; // Slant (Italic/Oblique)
294 long mnMinKashida; // Minimal width of kashida (Arabic)
296 // font attributes queried from the font instance
297 int meFamilyType; // Font Family Type
298 bool mbDevice; // Flag for Device Fonts
299 bool mbScalableFont;
300 bool mbKernableFont;
302 // font metrics that are usually derived from the measurements
303 long mnUnderlineSize; // Lineheight of Underline
304 long mnUnderlineOffset; // Offset from Underline to Baseline
305 long mnBUnderlineSize; // Height of bold underline
306 long mnBUnderlineOffset; // Offset from bold underline to baseline
307 long mnDUnderlineSize; // Height of double underline
308 long mnDUnderlineOffset1; // Offset from double underline to baseline
309 long mnDUnderlineOffset2; // Offset from double underline to baseline
310 long mnWUnderlineSize; // Height of WaveLine underline
311 long mnWUnderlineOffset; // Offset from WaveLine underline to baseline, but centrered to WaveLine
312 long mnAboveUnderlineSize; // Height of single underline (for Vertical Right)
313 long mnAboveUnderlineOffset; // Offset from single underline to baseline (for Vertical Right)
314 long mnAboveBUnderlineSize; // Height of bold underline (for Vertical Right)
315 long mnAboveBUnderlineOffset; // Offset from bold underline to baseline (for Vertical Right)
316 long mnAboveDUnderlineSize; // Height of double underline (for Vertical Right)
317 long mnAboveDUnderlineOffset1; // Offset from double underline to baseline (for Vertical Right)
318 long mnAboveDUnderlineOffset2; // Offset from double underline to baseline (for Vertical Right)
319 long mnAboveWUnderlineSize; // Height of WaveLine-strike-out (for Vertical Right)
320 long mnAboveWUnderlineOffset; // Offset from WaveLine-strike-out to baseline, but centrered to to WaveLine (for Vertical Right)
321 long mnStrikeoutSize; // Height of single strike-out
322 long mnStrikeoutOffset; // Offset from single strike-out to baseline
323 long mnBStrikeoutSize; // Height of bold strike-out
324 long mnBStrikeoutOffset; // Offset of bold strike-out to baseline
325 long mnDStrikeoutSize; // Height of double strike-out
326 long mnDStrikeoutOffset1; // Offset of double strike-out to baseline
327 long mnDStrikeoutOffset2; // Offset of double strike-out to baseline
330 // -----------------
331 // - ImplFontEntry -
332 // ------------------
333 // TODO: rename ImplFontEntry to LogicalFontInstance
334 // TODO: allow sharing of metrics for related fonts
336 class VCL_PLUGIN_PUBLIC ImplFontEntry
338 public:
339 explicit ImplFontEntry( const FontSelectPattern& );
340 virtual ~ImplFontEntry();
342 public: // TODO: make data members private
343 FontSelectPattern maFontSelData; // FontSelectionData
344 ImplFontMetricData maMetric; // Font Metric
345 const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
346 long mnLineHeight;
347 sal_uLong mnRefCount;
348 sal_uInt16 mnSetFontFlags; // Flags returned by SalGraphics::SetFont()
349 short mnOwnOrientation; // text angle if lower layers don't rotate text themselves
350 short mnOrientation; // text angle in 3600 system
351 bool mbInit; // true if maMetric member is valid
353 void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
354 bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, String* pFontName ) const;
355 void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
357 private:
358 // cache of Unicode characters and replacement font names
359 // TODO: a fallback map can be shared with many other ImplFontEntries
360 // TODO: at least the ones which just differ in orientation, stretching or height
361 typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
362 struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
363 typedef ::boost::unordered_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
364 UnicodeFallbackList* mpUnicodeFallbackList;
368 class ImplTextLineInfo
370 private:
371 long mnWidth;
372 xub_StrLen mnIndex;
373 xub_StrLen mnLen;
375 public:
376 ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
378 mnWidth = nWidth;
379 mnIndex = nIndex;
380 mnLen = nLen;
383 long GetWidth() const { return mnWidth; }
384 xub_StrLen GetIndex() const { return mnIndex; }
385 xub_StrLen GetLen() const { return mnLen; }
388 #define MULTITEXTLINEINFO_RESIZE 16
389 typedef ImplTextLineInfo* PImplTextLineInfo;
391 class ImplMultiTextLineInfo
393 private:
394 PImplTextLineInfo* mpLines;
395 xub_StrLen mnLines;
396 xub_StrLen mnSize;
398 public:
399 ImplMultiTextLineInfo();
400 ~ImplMultiTextLineInfo();
402 void AddLine( ImplTextLineInfo* pLine );
403 void Clear();
405 ImplTextLineInfo* GetLine( sal_uInt16 nLine ) const
406 { return mpLines[nLine]; }
407 xub_StrLen Count() const { return mnLines; }
409 private:
410 ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
411 ImplMultiTextLineInfo& operator=( const ImplMultiTextLineInfo& );
414 #endif // _SV_OUTFONT_HXX
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */