Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _SV_OUTFONT_HXX
21 : #define _SV_OUTFONT_HXX
22 :
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>
30 :
31 : #include <boost/unordered_map.hpp>
32 :
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 :
46 : namespace com { namespace sun { namespace star { namespace lang { struct Locale; }}}}
47 :
48 : // ----------------------
49 : // - ImplFontAttributes -
50 : // ----------------------
51 : // device independent font properties
52 :
53 336857 : class ImplFontAttributes
54 : {
55 : public: // TODO: create matching interface class
56 14592 : const String& GetFamilyName() const { return maName; }
57 0 : const String& GetStyleName() const { return maStyleName; }
58 5216 : FontWeight GetWeight() const { return meWeight; }
59 5181 : FontItalic GetSlant() const { return meItalic; }
60 0 : FontFamily GetFamilyType() const { return meFamily; }
61 0 : FontPitch GetPitch() const { return mePitch; }
62 0 : FontWidth GetWidthType() const { return meWidthType; }
63 493690 : bool IsSymbolFont() const { return mbSymbolFlag; }
64 :
65 : bool operator==(const ImplFontAttributes& rOther) const;
66 91037 : bool operator!=(const ImplFontAttributes& rOther) const
67 : {
68 91037 : return !(*this == rOther);
69 : }
70 :
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;
80 : };
81 :
82 : // -------------------------
83 : // - ImplDevFontAttributes -
84 : // -------------------------
85 : // device dependent font properties
86 :
87 70598 : class ImplDevFontAttributes : public ImplFontAttributes
88 : {
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 0 : bool IsEmbeddable() const { return mbEmbeddable; }
95 0 : bool IsSubsettable() const { return mbSubsettable; }
96 :
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
104 : };
105 :
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
113 :
114 : // abstract base class for physical font faces
115 39270 : class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplDevFontAttributes
116 : {
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;
122 :
123 0 : virtual int GetHeight() const { return mnHeight; }
124 0 : virtual int GetWidth() const { return mnWidth; }
125 : virtual sal_IntPtr GetFontId() const = 0;
126 0 : int GetFontMagic() const { return mnMagic; }
127 136290 : bool IsScalable() const { return (mnHeight == 0); }
128 0 : bool CheckMagic( int n ) const { return (n == mnMagic); }
129 103083 : PhysicalFontFace* GetNextFace() const { return mpNext; }
130 : PhysicalFontFace* CreateAlias() const { return Clone(); }
131 :
132 : bool IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
133 : StringCompare CompareWithSize( const PhysicalFontFace& ) const;
134 : StringCompare CompareIgnoreSize( const PhysicalFontFace& ) const;
135 18902 : virtual ~PhysicalFontFace() {}
136 : virtual PhysicalFontFace* Clone() const = 0;
137 :
138 : protected:
139 : explicit PhysicalFontFace( const ImplDevFontAttributes&, int nMagic );
140 : void SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
141 :
142 : long mnWidth; // Width (in pixels)
143 : long mnHeight; // Height (in pixels)
144 :
145 : private:
146 : friend class ImplDevFontListData;
147 : const int mnMagic; // poor man's RTTI
148 : PhysicalFontFace* mpNext;
149 : };
150 :
151 188430 : class FontSelectPatternAttributes : public ImplFontAttributes
152 : {
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 );
158 :
159 : size_t hashCode() const;
160 : bool operator==(const FontSelectPatternAttributes& rOther) const;
161 : bool operator!=(const FontSelectPatternAttributes& rOther) const
162 : {
163 : return !(*this == rOther);
164 : }
165 :
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
176 :
177 : bool mbEmbolden; // Force emboldening
178 : ItalicMatrix maItalicMatrix; // Force matrix for slant
179 : };
180 :
181 136550 : class FontSelectPattern : public FontSelectPatternAttributes
182 : {
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 );
188 :
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);
193 : };
194 :
195 : // -------------------
196 : // - ImplDevFontList -
197 : // -------------------
198 : // TODO: merge with ImplFontCache
199 : // TODO: rename to LogicalFontManager
200 :
201 : class VCL_PLUGIN_PUBLIC ImplDevFontList
202 : {
203 : private:
204 : friend class WinGlyphFallbackSubstititution;
205 : mutable bool mbMatchData; // true if matching attributes are initialized
206 : bool mbMapNames; // true if MapNames are available
207 :
208 : typedef boost::unordered_map<const String, ImplDevFontListData*,FontNameHash> DevFontList;
209 : DevFontList maDevFontList;
210 :
211 : ImplPreMatchFontSubstitution* mpPreMatchHook; // device specific prematch substitution
212 : ImplGlyphFallbackFontSubstitution* mpFallbackHook; // device specific glyh fallback substitution
213 :
214 : public:
215 : explicit ImplDevFontList();
216 : virtual ~ImplDevFontList();
217 :
218 : // fill the list with device fonts
219 : void Add( PhysicalFontFace* );
220 : void Clear();
221 198426 : int Count() const { return maDevFontList.size(); }
222 :
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;
227 :
228 : // suggest fonts for glyph fallback
229 : ImplDevFontListData* GetGlyphFallbackFont( FontSelectPattern&,
230 : rtl::OUString& rMissingCodes, int nFallbackLevel ) const;
231 :
232 : // prepare platform specific font substitutions
233 : void SetPreMatchHook( ImplPreMatchFontSubstitution* );
234 : void SetFallbackHook( ImplGlyphFallbackFontSubstitution* );
235 :
236 : // misc utilities
237 : ImplDevFontList* Clone( bool bScalable, bool bEmbeddable ) const;
238 : ImplGetDevFontList* GetDevFontList() const;
239 : ImplGetDevSizeList* GetDevSizeList( const String& rFontName ) const;
240 :
241 : ImplDevFontListData* ImplFindByTokenNames(const rtl::OUString& rTokenStr) const;
242 :
243 : protected:
244 : void InitMatchData() const;
245 : bool AreMapNamesAvailable() const { return mbMapNames; }
246 :
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;
253 :
254 : private:
255 : void InitGenericGlyphFallback() const;
256 : mutable ImplDevFontListData** mpFallbackList;
257 : mutable int mnFallbackCount;
258 : };
259 :
260 : // --------------------
261 : // - ImplKernPairData -
262 : // --------------------
263 :
264 : struct ImplKernPairData
265 : {
266 : sal_uInt16 mnChar1;
267 : sal_uInt16 mnChar2;
268 : long mnKern;
269 : };
270 :
271 :
272 : // -----------------------
273 : // - ImplFontMetricData -
274 : // -----------------------
275 :
276 4166 : class ImplFontMetricData : public ImplFontAttributes
277 : {
278 : public:
279 : explicit ImplFontMetricData( const FontSelectPattern& );
280 : void ImplInitTextLineSize( const OutputDevice* pDev );
281 : void ImplInitAboveTextLineSize();
282 :
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
287 :
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)
295 :
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;
301 :
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
328 : };
329 :
330 : // -----------------
331 : // - ImplFontEntry -
332 : // ------------------
333 : // TODO: rename ImplFontEntry to LogicalFontInstance
334 : // TODO: allow sharing of metrics for related fonts
335 :
336 : class VCL_PLUGIN_PUBLIC ImplFontEntry
337 : {
338 : public:
339 : explicit ImplFontEntry( const FontSelectPattern& );
340 : virtual ~ImplFontEntry();
341 :
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
352 :
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 );
356 :
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;
365 : };
366 :
367 :
368 : class ImplTextLineInfo
369 : {
370 : private:
371 : long mnWidth;
372 : xub_StrLen mnIndex;
373 : xub_StrLen mnLen;
374 :
375 : public:
376 0 : ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
377 : {
378 0 : mnWidth = nWidth;
379 0 : mnIndex = nIndex;
380 0 : mnLen = nLen;
381 0 : }
382 :
383 0 : long GetWidth() const { return mnWidth; }
384 0 : xub_StrLen GetIndex() const { return mnIndex; }
385 0 : xub_StrLen GetLen() const { return mnLen; }
386 : };
387 :
388 : #define MULTITEXTLINEINFO_RESIZE 16
389 : typedef ImplTextLineInfo* PImplTextLineInfo;
390 :
391 : class ImplMultiTextLineInfo
392 : {
393 : private:
394 : PImplTextLineInfo* mpLines;
395 : xub_StrLen mnLines;
396 : xub_StrLen mnSize;
397 :
398 : public:
399 : ImplMultiTextLineInfo();
400 : ~ImplMultiTextLineInfo();
401 :
402 : void AddLine( ImplTextLineInfo* pLine );
403 : void Clear();
404 :
405 0 : ImplTextLineInfo* GetLine( sal_uInt16 nLine ) const
406 0 : { return mpLines[nLine]; }
407 0 : xub_StrLen Count() const { return mnLines; }
408 :
409 : private:
410 : ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
411 : ImplMultiTextLineInfo& operator=( const ImplMultiTextLineInfo& );
412 : };
413 :
414 : #endif // _SV_OUTFONT_HXX
415 :
416 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|