xref: /trunk/main/vcl/inc/outfont.hxx (revision 161f4cd1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_OUTFONT_HXX
25 #define _SV_OUTFONT_HXX
26 
27 #include <tools/string.hxx>
28 #include <tools/list.hxx>
29 #include <i18npool/lang.h>
30 #include <tools/gen.hxx>
31 #include <tools/solar.h>
32 #include <vcl/dllapi.h>
33 #include <unotools/fontdefs.hxx>
34 #include <vcl/vclenum.hxx>
35 
36 #include <hash_map>
37 
38 class ImplDevFontListData;
39 class ImplGetDevFontList;
40 class ImplGetDevSizeList;
41 class ImplFontEntry;
42 class ImplDirectFontSubstitution;
43 class ImplPreMatchFontSubstitution;
44 class ImplGlyphFallbackFontSubstitution;
45 class ImplFontSelectData;
46 class Font;
47 class ConvertChar;
48 struct FontMatchStatus;
49 class OutputDevice;
50 
51 namespace com { namespace sun { namespace star { namespace lang { struct Locale; }}}}
52 
53 // ----------------------
54 // - ImplFontAttributes -
55 // ----------------------
56 // device independent font properties
57 
58 class ImplFontAttributes
59 {
60 public: // TODO: create matching interface class
GetFamilyName() const61     const String&   GetFamilyName() const   { return maName; }
GetStyleName() const62     const String&   GetStyleName() const    { return maStyleName; }
GetWeight() const63     FontWeight      GetWeight() const       { return meWeight; }
GetSlant() const64     FontItalic      GetSlant() const        { return meItalic; }
GetFamilyType() const65     FontFamily      GetFamilyType() const   { return meFamily; }
GetPitch() const66     FontPitch       GetPitch() const        { return mePitch; }
GetWidthType() const67     FontWidth       GetWidthType() const    { return meWidthType; }
IsSymbolFont() const68     bool            IsSymbolFont() const    { return mbSymbolFlag; }
69 
70 public: // TODO: hide members behind accessor methods
71     String          maName;         // Font Family Name
72     String          maStyleName;    // Font Style Name
73     FontWeight      meWeight;       // Weight Type
74     FontItalic      meItalic;       // Slant Type
75     FontFamily      meFamily;       // Family Type
76     FontPitch       mePitch;        // Pitch Type
77     FontWidth       meWidthType;    // Width Type
78     bool            mbSymbolFlag;
79 };
80 
81 // -------------------------
82 // - ImplDevFontAttributes -
83 // -------------------------
84 // device dependent font properties
85 
86 class ImplDevFontAttributes : public ImplFontAttributes
87 {
88 public: // TODO: create matching interface class
GetAliasNames() const89     const String&      GetAliasNames() const     { return maMapNames; }
GetQuality() const90     int                GetQuality() const        { return mnQuality; }
IsRotatable() const91     bool               IsRotatable() const       { return mbOrientation; }
IsDeviceFont() const92     bool               IsDeviceFont() const      { return mbDevice; }
IsEmbeddable() const93     bool               IsEmbeddable() const      { return mbEmbeddable; }
IsSubsettable() const94     bool               IsSubsettable() const     { return mbSubsettable; }
95 
96 public: // TODO: hide members behind accessor methods
97     String             maMapNames;       // List of family name aliass separated with ';'
98     int                mnQuality;        // Quality (used when similar fonts compete)
99     bool               mbOrientation;    // true: physical font can be rotated
100     bool               mbDevice;         // true: built in font
101     bool               mbSubsettable;    // true: a subset of the font can be created
102     bool               mbEmbeddable;     // true: the font can be embedded
103 };
104 
105 // ----------------
106 // - ImplFontData -
107 // ----------------
108 // TODO: rename ImplFontData to PhysicalFontFace
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 class VCL_PLUGIN_PUBLIC ImplFontData : public ImplDevFontAttributes
116 {
117 public:
118     // by using an ImplFontData 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( ImplFontSelectData& ) const = 0;
122 
GetHeight() const123     virtual int             GetHeight() const           { return mnHeight; }
GetWidth() const124     virtual int             GetWidth() const            { return mnWidth; }
125     virtual sal_IntPtr      GetFontId() const = 0;
GetFontMagic() const126     int                     GetFontMagic() const        { return mnMagic; }
IsScalable() const127     bool                    IsScalable() const          { return (mnHeight == 0); }
CheckMagic(int n) const128     bool                    CheckMagic( int n ) const   { return (n == mnMagic); }
GetNextFace() const129     ImplFontData*           GetNextFace() const         { return mpNext; }
CreateAlias() const130     ImplFontData*           CreateAlias() const         { return Clone(); }
131 
132     bool                    IsBetterMatch( const ImplFontSelectData&, FontMatchStatus& ) const;
133     StringCompare           CompareWithSize( const ImplFontData& ) const;
134     StringCompare           CompareIgnoreSize( const ImplFontData& ) const;
~ImplFontData()135     virtual                 ~ImplFontData() {}
136     virtual ImplFontData*   Clone() const = 0;
137 
138 protected:
139     explicit                ImplFontData( const ImplDevFontAttributes&, int nMagic );
SetBitmapSize(int nW,int nH)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     ImplFontData*           mpNext;
149 };
150 
151 // ----------------------
152 // - ImplFontSelectData -
153 // ----------------------
154 
155 class ImplFontSelectData : public ImplFontAttributes
156 {
157 public:
158                         ImplFontSelectData( const Font&, const String& rSearchName,
159                             const Size&, float fExactHeight );
160                         ImplFontSelectData( const ImplFontData&, const Size&,
161                             float fExactHeight, int nOrientation, bool bVertical );
162 
163 public: // TODO: change to private
164     String              maTargetName;       // name of the font name token that is chosen
165     String              maSearchName;       // name of the font that matches best
166     int                 mnWidth;            // width of font in pixel units
167     int                 mnHeight;           // height of font in pixel units
168     float               mfExactHeight;       // requested height (in pixels with subpixel details)
169     int                 mnOrientation;      // text orientation in 3600 system
170     LanguageType        meLanguage;         // text language
171     bool                mbVertical;         // vertical mode of requested font
172     bool                mbNonAntialiased;   // true if antialiasing is disabled
173 
174     const ImplFontData* mpFontData;         // a matching ImplFontData object
175     ImplFontEntry*      mpFontEntry;        // pointer to the resulting FontCache entry
176 };
177 
178 // -------------------
179 // - ImplDevFontList -
180 // -------------------
181 // TODO: merge with ImplFontCache
182 // TODO: rename to LogicalFontManager
183 
184 class VCL_PLUGIN_PUBLIC ImplDevFontList
185 {
186 private:
187 	friend class WinGlyphFallbackSubstititution;
188     mutable bool            mbMatchData;    // true if matching attributes are initialized
189     bool                    mbMapNames;     // true if MapNames are available
190 
191     typedef std::hash_map<const String, ImplDevFontListData*,FontNameHash> DevFontList;
192     DevFontList             maDevFontList;
193 
194     ImplPreMatchFontSubstitution* mpPreMatchHook;       // device specific prematch substitution
195     ImplGlyphFallbackFontSubstitution* mpFallbackHook;  // device specific glyh fallback substitution
196 
197 public:
198     explicit                ImplDevFontList();
199     virtual                 ~ImplDevFontList();
200 
201     // fill the list with device fonts
202     void                    Add( ImplFontData* );
203     void                    Clear();
Count() const204     int                     Count() const { return maDevFontList.size(); }
205 
206     // find the device font
207     ImplDevFontListData*    FindFontFamily( const String& rFontName ) const;
208     ImplDevFontListData*    ImplFindByFont( ImplFontSelectData&, bool bPrinter, ImplDirectFontSubstitution* ) const;
209     ImplDevFontListData*    ImplFindBySearchName( const String& ) const;
210 
211     // suggest fonts for glyph fallback
212     ImplDevFontListData*    GetGlyphFallbackFont( ImplFontSelectData&,
213 		                rtl::OUString& rMissingCodes, int nFallbackLevel ) const;
214 
215     // prepare platform specific font substitutions
216     void                    SetPreMatchHook( ImplPreMatchFontSubstitution* );
217     void                    SetFallbackHook( ImplGlyphFallbackFontSubstitution* );
218 
219     // misc utilities
220     ImplDevFontList*        Clone( bool bScalable, bool bEmbeddable ) const;
221     ImplGetDevFontList*     GetDevFontList() const;
222     ImplGetDevSizeList*     GetDevSizeList( const String& rFontName ) const;
223 
224 	//used by 2-level font fallback
225 	ImplDevFontListData* ImplFindByLocale( com::sun::star::lang::Locale& ) const;
226 
227 protected:
228     void                    InitMatchData() const;
AreMapNamesAvailable() const229     bool                    AreMapNamesAvailable() const { return mbMapNames; }
230 
231     ImplDevFontListData*    ImplFindByTokenNames( const String& ) const;
232     ImplDevFontListData*    ImplFindByAliasName( const String& rSearchName, const String& rShortName ) const;
233     ImplDevFontListData*    ImplFindBySubstFontAttr( const utl::FontNameAttr& ) const;
234     ImplDevFontListData*    ImplFindByAttributes( sal_uLong nSearchType, FontWeight, FontWidth,
235                                 FontFamily, FontItalic, const String& rSearchFamily ) const;
236     ImplDevFontListData*    FindDefaultFont() const;
237 
238 private:
239     void                    InitGenericGlyphFallback() const;
240     mutable ImplDevFontListData**   mpFallbackList;
241     mutable int                     mnFallbackCount;
242 };
243 
244 // --------------------
245 // - ImplKernPairData -
246 // --------------------
247 // TODO: get rid of ImplKernPairData and use outdev.hxx's KerningPair struct
248 // the problem is that outdev.hxx is too high level for the device layers
249 // and outdev.hxx's customers depend on KerningPair being defined there
250 
251 struct ImplKernPairData
252 {
253     sal_uInt16              mnChar1;
254     sal_uInt16              mnChar2;
255     long                mnKern;
256 };
257 
258 
259 // -----------------------
260 // - ImplFontMetricData -
261 // -----------------------
262 
263 class ImplFontMetricData : public ImplFontAttributes
264 {
265 public:
266     explicit ImplFontMetricData( const ImplFontSelectData& );
267     void    ImplInitTextLineSize( const OutputDevice* pDev );
268     void    ImplInitAboveTextLineSize();
269 
270 public: // TODO: hide members behind accessor methods
271 	// font instance attributes from the font request
272     long                mnWidth;                    // Reference Width
273     short               mnOrientation;              // Rotation in 1/10 degrees
274 
275 	// font metrics measured for the font instance
276     long                mnAscent;                   // Ascent
277     long                mnDescent;                  // Descent
278     long                mnIntLeading;               // Internal Leading
279     long                mnExtLeading;               // External Leading
280     int                 mnSlant;                    // Slant (Italic/Oblique)
281     long                mnMinKashida;               // Minimal width of kashida (Arabic)
282 
283 	// font attributes queried from the font instance
284     int                 meFamilyType;               // Font Family Type
285     bool                mbDevice;                   // Flag for Device Fonts
286     bool                mbScalableFont;
287     bool                mbKernableFont;
288 
289 	// font metrics that are usually derived from the measurements
290     long                mnUnderlineSize;            // Lineheight of Underline
291     long                mnUnderlineOffset;          // Offset from Underline to Baseline
292     long                mnBUnderlineSize;           // Hoehe von fetter Unterstreichung
293     long                mnBUnderlineOffset;         // Offset von fetter Unterstreichung zur Baseline
294     long                mnDUnderlineSize;           // Hoehe von doppelter Unterstreichung
295     long                mnDUnderlineOffset1;        // Offset von doppelter Unterstreichung zur Baseline
296     long                mnDUnderlineOffset2;        // Offset von doppelter Unterstreichung zur Baseline
297     long                mnWUnderlineSize;           // Hoehe von WaveLine-Unterstreichung
298     long                mnWUnderlineOffset;         // Offset von WaveLine-Unterstreichung zur Baseline, jedoch zentriert zur WaveLine
299     long                mnAboveUnderlineSize;       // Hoehe von einfacher Unterstreichung (for Vertical Right)
300     long                mnAboveUnderlineOffset;     // Offset von einfacher Unterstreichung zur Baseline (for Vertical Right)
301     long                mnAboveBUnderlineSize;      // Hoehe von fetter Unterstreichung (for Vertical Right)
302     long                mnAboveBUnderlineOffset;    // Offset von fetter Unterstreichung zur Baseline (for Vertical Right)
303     long                mnAboveDUnderlineSize;      // Hoehe von doppelter Unterstreichung (for Vertical Right)
304     long                mnAboveDUnderlineOffset1;   // Offset von doppelter Unterstreichung zur Baseline (for Vertical Right)
305     long                mnAboveDUnderlineOffset2;   // Offset von doppelter Unterstreichung zur Baseline (for Vertical Right)
306     long                mnAboveWUnderlineSize;      // Hoehe von WaveLine-Unterstreichung (for Vertical Right)
307     long                mnAboveWUnderlineOffset;    // Offset von WaveLine-Unterstreichung zur Baseline, jedoch zentriert zur WaveLine (for Vertical Right)
308     long                mnStrikeoutSize;            // Hoehe von einfacher Durchstreichung
309     long                mnStrikeoutOffset;          // Offset von einfacher Durchstreichung zur Baseline
310     long                mnBStrikeoutSize;           // Hoehe von fetter Durchstreichung
311     long                mnBStrikeoutOffset;         // Offset von fetter Durchstreichung zur Baseline
312     long                mnDStrikeoutSize;           // Hoehe von doppelter Durchstreichung
313     long                mnDStrikeoutOffset1;        // Offset von doppelter Durchstreichung zur Baseline
314     long                mnDStrikeoutOffset2;        // Offset von doppelter Durchstreichung zur Baseline
315 };
316 
317 // -----------------
318 // - ImplFontEntry -
319 // ------------------
320 // TODO: rename ImplFontEntry to LogicalFontInstance
321 // TODO: allow sharing of metrics for related fonts
322 
323 class VCL_PLUGIN_PUBLIC ImplFontEntry
324 {
325 public:
326     explicit            ImplFontEntry( const ImplFontSelectData& );
327     virtual             ~ImplFontEntry();
328 
329 public: // TODO: make data members private
330     ImplFontSelectData  maFontSelData;      // FontSelectionData
331     ImplFontMetricData  maMetric;           // Font Metric
332     const ConvertChar*  mpConversion;       // used e.g. for StarBats->StarSymbol
333     long                mnLineHeight;
334     sal_uLong               mnRefCount;
335     sal_uInt16              mnSetFontFlags;     // Flags returned by SalGraphics::SetFont()
336     short               mnOwnOrientation;   // text angle if lower layers don't rotate text themselves
337     short               mnOrientation;      // text angle in 3600 system
338     bool                mbInit;             // true if maMetric member is valid
339 
340     void                AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
341     bool                GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, String* pFontName ) const;
342     void                IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
343 
344 private:
345     // cache of Unicode characters and replacement font names
346     // TODO: a fallback map can be shared with many other ImplFontEntries
347     // TODO: at least the ones which just differ in orientation, stretching or height
348     typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
349     struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
350     typedef ::std::hash_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
351     UnicodeFallbackList* mpUnicodeFallbackList;
352 };
353 
354 
355 class ImplTextLineInfo
356 {
357 private:
358     long        mnWidth;
359     xub_StrLen  mnIndex;
360     xub_StrLen  mnLen;
361 
362 public:
ImplTextLineInfo(long nWidth,xub_StrLen nIndex,xub_StrLen nLen)363                 ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
364                 {
365                     mnWidth = nWidth;
366                     mnIndex = nIndex;
367                     mnLen   = nLen;
368                 }
369 
GetWidth() const370     long        GetWidth() const { return mnWidth; }
GetIndex() const371     xub_StrLen  GetIndex() const { return mnIndex; }
GetLen() const372     xub_StrLen  GetLen() const { return mnLen; }
373 };
374 
375 #define MULTITEXTLINEINFO_RESIZE    16
376 typedef ImplTextLineInfo* PImplTextLineInfo;
377 
378 class ImplMultiTextLineInfo
379 {
380 private:
381     PImplTextLineInfo*  mpLines;
382     xub_StrLen          mnLines;
383     xub_StrLen          mnSize;
384 
385 public:
386                         ImplMultiTextLineInfo();
387                         ~ImplMultiTextLineInfo();
388 
389     void                AddLine( ImplTextLineInfo* pLine );
390     void                Clear();
391 
GetLine(sal_uInt16 nLine) const392     ImplTextLineInfo*   GetLine( sal_uInt16 nLine ) const
393                             { return mpLines[nLine]; }
Count() const394     xub_StrLen          Count() const { return mnLines; }
395 
396 private:
397                             ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
398     ImplMultiTextLineInfo&  operator=( const ImplMultiTextLineInfo& );
399 };
400 
401 #endif // _SV_OUTFONT_HXX
402 
403