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