Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_OUTFONT_HXX
30 : : #define _SV_OUTFONT_HXX
31 : :
32 : : #include <tools/string.hxx>
33 : : #include <i18npool/lang.h>
34 : : #include <tools/gen.hxx>
35 : : #include <tools/solar.h>
36 : : #include <vcl/dllapi.h>
37 : : #include <unotools/fontdefs.hxx>
38 : : #include <vcl/vclenum.hxx>
39 : :
40 : : #include <boost/unordered_map.hpp>
41 : :
42 : : class ImplDevFontListData;
43 : : class ImplGetDevFontList;
44 : : class ImplGetDevSizeList;
45 : : class ImplFontEntry;
46 : : class ImplDirectFontSubstitution;
47 : : class ImplPreMatchFontSubstitution;
48 : : class ImplGlyphFallbackFontSubstitution;
49 : : class FontSelectPattern;
50 : : class Font;
51 : : class ConvertChar;
52 : : struct FontMatchStatus;
53 : : class OutputDevice;
54 : :
55 : : namespace com { namespace sun { namespace star { namespace lang { struct Locale; }}}}
56 : :
57 : : // ----------------------
58 : : // - ImplFontAttributes -
59 : : // ----------------------
60 : : // device independent font properties
61 : :
62 [ + - # ]: 3150059 : class ImplFontAttributes
[ + - ]
[ # # # ]
[ # + - ]
[ # # ][ + - ]
63 : : {
64 : : public: // TODO: create matching interface class
65 : 147736 : const String& GetFamilyName() const { return maName; }
66 : 0 : const String& GetStyleName() const { return maStyleName; }
67 : 15239 : FontWeight GetWeight() const { return meWeight; }
68 : 515 : FontItalic GetSlant() const { return meItalic; }
69 : 0 : FontFamily GetFamilyType() const { return meFamily; }
70 : 0 : FontPitch GetPitch() const { return mePitch; }
71 : 0 : FontWidth GetWidthType() const { return meWidthType; }
72 : 24737494 : bool IsSymbolFont() const { return mbSymbolFlag; }
73 : :
74 : : bool operator==(const ImplFontAttributes& rOther) const;
75 : 188552 : bool operator!=(const ImplFontAttributes& rOther) const
76 : : {
77 : 188552 : return !(*this == rOther);
78 : : }
79 : :
80 : : public: // TODO: hide members behind accessor methods
81 : : String maName; // Font Family Name
82 : : String maStyleName; // Font Style Name
83 : : FontWeight meWeight; // Weight Type
84 : : FontItalic meItalic; // Slant Type
85 : : FontFamily meFamily; // Family Type
86 : : FontPitch mePitch; // Pitch Type
87 : : FontWidth meWidthType; // Width Type
88 : : bool mbSymbolFlag;
89 : : };
90 : :
91 : : // -------------------------
92 : : // - ImplDevFontAttributes -
93 : : // -------------------------
94 : : // device dependent font properties
95 : :
96 [ + + - ]: 767236 : class ImplDevFontAttributes : public ImplFontAttributes
[ + - # ]
[ # # ]
97 : : {
98 : : public: // TODO: create matching interface class
99 : : const String& GetAliasNames() const { return maMapNames; }
100 : : int GetQuality() const { return mnQuality; }
101 : : bool IsRotatable() const { return mbOrientation; }
102 : : bool IsDeviceFont() const { return mbDevice; }
103 : 0 : bool IsEmbeddable() const { return mbEmbeddable; }
104 : 0 : bool IsSubsettable() const { return mbSubsettable; }
105 : :
106 : : public: // TODO: hide members behind accessor methods
107 : : String maMapNames; // List of family name aliass separated with ';'
108 : : int mnQuality; // Quality (used when similar fonts compete)
109 : : bool mbOrientation; // true: physical font can be rotated
110 : : bool mbDevice; // true: built in font
111 : : bool mbSubsettable; // true: a subset of the font can be created
112 : : bool mbEmbeddable; // true: the font can be embedded
113 : : };
114 : :
115 : : // ----------------
116 : : // - PhysicalFontFace -
117 : : // ----------------
118 : : // TODO: no more direct access to members
119 : : // TODO: add reference counting
120 : : // TODO: get rid of height/width for scalable fonts
121 : : // TODO: make cloning cheaper
122 : :
123 : : // abstract base class for physical font faces
124 : 243408 : class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplDevFontAttributes
125 : : {
126 : : public:
127 : : // by using an PhysicalFontFace object as a factory for its corresponding
128 : : // ImplFontEntry an ImplFontEntry can be extended to cache device and
129 : : // font instance specific data
130 : : virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const = 0;
131 : :
132 : 5856 : virtual int GetHeight() const { return mnHeight; }
133 : 0 : virtual int GetWidth() const { return mnWidth; }
134 : : virtual sal_IntPtr GetFontId() const = 0;
135 : 0 : int GetFontMagic() const { return mnMagic; }
136 : 1100010 : bool IsScalable() const { return (mnHeight == 0); }
137 : 0 : bool CheckMagic( int n ) const { return (n == mnMagic); }
138 : 922544 : PhysicalFontFace* GetNextFace() const { return mpNext; }
139 : : PhysicalFontFace* CreateAlias() const { return Clone(); }
140 : :
141 : : bool IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
142 : : StringCompare CompareWithSize( const PhysicalFontFace& ) const;
143 : : StringCompare CompareIgnoreSize( const PhysicalFontFace& ) const;
144 [ - + ]: 278666 : virtual ~PhysicalFontFace() {}
145 : : virtual PhysicalFontFace* Clone() const = 0;
146 : :
147 : : protected:
148 : : explicit PhysicalFontFace( const ImplDevFontAttributes&, int nMagic );
149 : : void SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
150 : :
151 : : long mnWidth; // Width (in pixels)
152 : : long mnHeight; // Height (in pixels)
153 : :
154 : : private:
155 : : friend class ImplDevFontListData;
156 : : const int mnMagic; // poor man's RTTI
157 : : PhysicalFontFace* mpNext;
158 : : };
159 : :
160 [ # # ][ # # ]: 1489722 : class FontSelectPatternAttributes : public ImplFontAttributes
[ + - ][ + - ]
[ # # ][ # # ]
[ + - ][ + - ]
161 : : {
162 : : public:
163 : : FontSelectPatternAttributes( const Font&, const String& rSearchName,
164 : : const Size&, float fExactHeight );
165 : : FontSelectPatternAttributes( const PhysicalFontFace&, const Size&,
166 : : float fExactHeight, int nOrientation, bool bVertical );
167 : :
168 : : size_t hashCode() const;
169 : : bool operator==(const FontSelectPatternAttributes& rOther) const;
170 : : bool operator!=(const FontSelectPatternAttributes& rOther) const
171 : : {
172 : : return !(*this == rOther);
173 : : }
174 : :
175 : : public:
176 : : String maTargetName; // name of the font name token that is chosen
177 : : String maSearchName; // name of the font that matches best
178 : : int mnWidth; // width of font in pixel units
179 : : int mnHeight; // height of font in pixel units
180 : : float mfExactHeight; // requested height (in pixels with subpixel details)
181 : : int mnOrientation; // text orientation in 3600 system
182 : : LanguageType meLanguage; // text language
183 : : bool mbVertical; // vertical mode of requested font
184 : : bool mbNonAntialiased; // true if antialiasing is disabled
185 : :
186 : : bool mbEmbolden; // Force emboldening
187 : : ItalicMatrix maItalicMatrix; // Force matrix for slant
188 : : };
189 : :
190 : 1357118 : class FontSelectPattern : public FontSelectPatternAttributes
191 : : {
192 : : public:
193 : : FontSelectPattern( const Font&, const String& rSearchName,
194 : : const Size&, float fExactHeight );
195 : : FontSelectPattern( const PhysicalFontFace&, const Size&,
196 : : float fExactHeight, int nOrientation, bool bVertical );
197 : :
198 : : public: // TODO: change to private
199 : : const PhysicalFontFace* mpFontData; // a matching PhysicalFontFace object
200 : : ImplFontEntry* mpFontEntry; // pointer to the resulting FontCache entry
201 : : void copyAttributes(const FontSelectPatternAttributes &rAttributes);
202 : : };
203 : :
204 : : // -------------------
205 : : // - ImplDevFontList -
206 : : // -------------------
207 : : // TODO: merge with ImplFontCache
208 : : // TODO: rename to LogicalFontManager
209 : :
210 : : class VCL_PLUGIN_PUBLIC ImplDevFontList
211 : : {
212 : : private:
213 : : friend class WinGlyphFallbackSubstititution;
214 : : mutable bool mbMatchData; // true if matching attributes are initialized
215 : : bool mbMapNames; // true if MapNames are available
216 : :
217 : : typedef boost::unordered_map<const String, ImplDevFontListData*,FontNameHash> DevFontList;
218 : : DevFontList maDevFontList;
219 : :
220 : : ImplPreMatchFontSubstitution* mpPreMatchHook; // device specific prematch substitution
221 : : ImplGlyphFallbackFontSubstitution* mpFallbackHook; // device specific glyh fallback substitution
222 : :
223 : : public:
224 : : explicit ImplDevFontList();
225 : : virtual ~ImplDevFontList();
226 : :
227 : : // fill the list with device fonts
228 : : void Add( PhysicalFontFace* );
229 : : void Clear();
230 : 1879504 : int Count() const { return maDevFontList.size(); }
231 : :
232 : : // find the device font
233 : : ImplDevFontListData* FindFontFamily( const String& rFontName ) const;
234 : : ImplDevFontListData* ImplFindByFont( FontSelectPattern&, bool bPrinter, ImplDirectFontSubstitution* ) const;
235 : : ImplDevFontListData* ImplFindBySearchName( const String& ) const;
236 : :
237 : : // suggest fonts for glyph fallback
238 : : ImplDevFontListData* GetGlyphFallbackFont( FontSelectPattern&,
239 : : rtl::OUString& rMissingCodes, int nFallbackLevel ) const;
240 : :
241 : : // prepare platform specific font substitutions
242 : : void SetPreMatchHook( ImplPreMatchFontSubstitution* );
243 : : void SetFallbackHook( ImplGlyphFallbackFontSubstitution* );
244 : :
245 : : // misc utilities
246 : : ImplDevFontList* Clone( bool bScalable, bool bEmbeddable ) const;
247 : : ImplGetDevFontList* GetDevFontList() const;
248 : : ImplGetDevSizeList* GetDevSizeList( const String& rFontName ) const;
249 : :
250 : : ImplDevFontListData* ImplFindByTokenNames(const rtl::OUString& rTokenStr) const;
251 : :
252 : : protected:
253 : : void InitMatchData() const;
254 : : bool AreMapNamesAvailable() const { return mbMapNames; }
255 : :
256 : : ImplDevFontListData* ImplFindByAliasName(const rtl::OUString& rSearchName,
257 : : const rtl::OUString& rShortName) const;
258 : : ImplDevFontListData* ImplFindBySubstFontAttr( const utl::FontNameAttr& ) const;
259 : : ImplDevFontListData* ImplFindByAttributes(sal_uLong nSearchType, FontWeight, FontWidth,
260 : : FontItalic, const rtl::OUString& rSearchFamily) const;
261 : : ImplDevFontListData* FindDefaultFont() const;
262 : :
263 : : private:
264 : : void InitGenericGlyphFallback() const;
265 : : mutable ImplDevFontListData** mpFallbackList;
266 : : mutable int mnFallbackCount;
267 : : };
268 : :
269 : : // --------------------
270 : : // - ImplKernPairData -
271 : : // --------------------
272 : : // TODO: get rid of ImplKernPairData and use outdev.hxx's KerningPair struct
273 : : // the problem is that outdev.hxx is too high level for the device layers
274 : : // and outdev.hxx's customers depend on KerningPair being defined there
275 : :
276 : : struct ImplKernPairData
277 : : {
278 : : sal_uInt16 mnChar1;
279 : : sal_uInt16 mnChar2;
280 : : long mnKern;
281 : : };
282 : :
283 : :
284 : : // -----------------------
285 : : // - ImplFontMetricData -
286 : : // -----------------------
287 : :
288 : 16288 : class ImplFontMetricData : public ImplFontAttributes
289 : : {
290 : : public:
291 : : explicit ImplFontMetricData( const FontSelectPattern& );
292 : : void ImplInitTextLineSize( const OutputDevice* pDev );
293 : : void ImplInitAboveTextLineSize();
294 : :
295 : : public: // TODO: hide members behind accessor methods
296 : : // font instance attributes from the font request
297 : : long mnWidth; // Reference Width
298 : : short mnOrientation; // Rotation in 1/10 degrees
299 : :
300 : : // font metrics measured for the font instance
301 : : long mnAscent; // Ascent
302 : : long mnDescent; // Descent
303 : : long mnIntLeading; // Internal Leading
304 : : long mnExtLeading; // External Leading
305 : : int mnSlant; // Slant (Italic/Oblique)
306 : : long mnMinKashida; // Minimal width of kashida (Arabic)
307 : :
308 : : // font attributes queried from the font instance
309 : : int meFamilyType; // Font Family Type
310 : : bool mbDevice; // Flag for Device Fonts
311 : : bool mbScalableFont;
312 : : bool mbKernableFont;
313 : :
314 : : // font metrics that are usually derived from the measurements
315 : : long mnUnderlineSize; // Lineheight of Underline
316 : : long mnUnderlineOffset; // Offset from Underline to Baseline
317 : : long mnBUnderlineSize; // Height of bold underline
318 : : long mnBUnderlineOffset; // Offset from bold underline to baseline
319 : : long mnDUnderlineSize; // Height of double underline
320 : : long mnDUnderlineOffset1; // Offset from double underline to baseline
321 : : long mnDUnderlineOffset2; // Offset from double underline to baseline
322 : : long mnWUnderlineSize; // Height of WaveLine underline
323 : : long mnWUnderlineOffset; // Offset from WaveLine underline to baseline, but centrered to WaveLine
324 : : long mnAboveUnderlineSize; // Height of single underline (for Vertical Right)
325 : : long mnAboveUnderlineOffset; // Offset from single underline to baseline (for Vertical Right)
326 : : long mnAboveBUnderlineSize; // Height of bold underline (for Vertical Right)
327 : : long mnAboveBUnderlineOffset; // Offset from bold underline to baseline (for Vertical Right)
328 : : long mnAboveDUnderlineSize; // Height of double underline (for Vertical Right)
329 : : long mnAboveDUnderlineOffset1; // Offset from double underline to baseline (for Vertical Right)
330 : : long mnAboveDUnderlineOffset2; // Offset from double underline to baseline (for Vertical Right)
331 : : long mnAboveWUnderlineSize; // Height of WaveLine-strike-out (for Vertical Right)
332 : : long mnAboveWUnderlineOffset; // Offset from WaveLine-strike-out to baseline, but centrered to to WaveLine (for Vertical Right)
333 : : long mnStrikeoutSize; // Height of single strike-out
334 : : long mnStrikeoutOffset; // Offset from single strike-out to baseline
335 : : long mnBStrikeoutSize; // Height of bold strike-out
336 : : long mnBStrikeoutOffset; // Offset of bold strike-out to baseline
337 : : long mnDStrikeoutSize; // Height of double strike-out
338 : : long mnDStrikeoutOffset1; // Offset of double strike-out to baseline
339 : : long mnDStrikeoutOffset2; // Offset of double strike-out to baseline
340 : : };
341 : :
342 : : // -----------------
343 : : // - ImplFontEntry -
344 : : // ------------------
345 : : // TODO: rename ImplFontEntry to LogicalFontInstance
346 : : // TODO: allow sharing of metrics for related fonts
347 : :
348 : : class VCL_PLUGIN_PUBLIC ImplFontEntry
349 : : {
350 : : public:
351 : : explicit ImplFontEntry( const FontSelectPattern& );
352 : : virtual ~ImplFontEntry();
353 : :
354 : : public: // TODO: make data members private
355 : : FontSelectPattern maFontSelData; // FontSelectionData
356 : : ImplFontMetricData maMetric; // Font Metric
357 : : const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
358 : : long mnLineHeight;
359 : : sal_uLong mnRefCount;
360 : : sal_uInt16 mnSetFontFlags; // Flags returned by SalGraphics::SetFont()
361 : : short mnOwnOrientation; // text angle if lower layers don't rotate text themselves
362 : : short mnOrientation; // text angle in 3600 system
363 : : bool mbInit; // true if maMetric member is valid
364 : :
365 : : void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
366 : : bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, String* pFontName ) const;
367 : : void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
368 : :
369 : : private:
370 : : // cache of Unicode characters and replacement font names
371 : : // TODO: a fallback map can be shared with many other ImplFontEntries
372 : : // TODO: at least the ones which just differ in orientation, stretching or height
373 : : typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
374 : : struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
375 : : typedef ::boost::unordered_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
376 : : UnicodeFallbackList* mpUnicodeFallbackList;
377 : : };
378 : :
379 : :
380 : : class ImplTextLineInfo
381 : : {
382 : : private:
383 : : long mnWidth;
384 : : xub_StrLen mnIndex;
385 : : xub_StrLen mnLen;
386 : :
387 : : public:
388 : 2404 : ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
389 : : {
390 : 2404 : mnWidth = nWidth;
391 : 2404 : mnIndex = nIndex;
392 : 2404 : mnLen = nLen;
393 : 2404 : }
394 : :
395 : 1743 : long GetWidth() const { return mnWidth; }
396 : 1773 : xub_StrLen GetIndex() const { return mnIndex; }
397 : 1770 : xub_StrLen GetLen() const { return mnLen; }
398 : : };
399 : :
400 : : #define MULTITEXTLINEINFO_RESIZE 16
401 : : typedef ImplTextLineInfo* PImplTextLineInfo;
402 : :
403 : : class ImplMultiTextLineInfo
404 : : {
405 : : private:
406 : : PImplTextLineInfo* mpLines;
407 : : xub_StrLen mnLines;
408 : : xub_StrLen mnSize;
409 : :
410 : : public:
411 : : ImplMultiTextLineInfo();
412 : : ~ImplMultiTextLineInfo();
413 : :
414 : : void AddLine( ImplTextLineInfo* pLine );
415 : : void Clear();
416 : :
417 : 2401 : ImplTextLineInfo* GetLine( sal_uInt16 nLine ) const
418 : 2401 : { return mpLines[nLine]; }
419 : 2634 : xub_StrLen Count() const { return mnLines; }
420 : :
421 : : private:
422 : : ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
423 : : ImplMultiTextLineInfo& operator=( const ImplMultiTextLineInfo& );
424 : : };
425 : :
426 : : #endif // _SV_OUTFONT_HXX
427 : :
428 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|