xref: /aoo41x/main/vcl/inc/impfont.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_IMPFONT_HXX
29 #define _SV_IMPFONT_HXX
30 
31 #include <tools/gen.hxx>
32 #include <tools/string.hxx>
33 #include <i18npool/lang.h>
34 #include <tools/color.hxx>
35 #include <vcl/dllapi.h>
36 #include <vcl/vclenum.hxx>
37 #include <vcl/fntstyle.hxx>
38 
39 // ------------
40 // - Impl_Font -
41 // ------------
42 
43 class Impl_Font
44 {
45 public:
46              Impl_Font();
47              Impl_Font( const Impl_Font& );
48 
49     bool     operator==( const Impl_Font& ) const;
50 
51     FontPitch           GetPitch()      { if(mePitch==PITCH_DONTKNOW)    AskConfig(); return mePitch; }
52     FontFamily          GetFamily()     { if(meFamily==FAMILY_DONTKNOW)  AskConfig(); return meFamily; }
53     FontItalic          GetItalic()     { if(meItalic==ITALIC_DONTKNOW)  AskConfig(); return meItalic; }
54     FontWeight          GetWeight()     { if(meWeight==WEIGHT_DONTKNOW)  AskConfig(); return meWeight; }
55     FontWidth           GetWidthType()  { if(meWidthType==WIDTH_DONTKNOW)AskConfig(); return meWidthType; }
56 
57 private:
58     friend class Font;
59     void                AskConfig();
60 
61 	int					mnRefCount;
62 	String				maFamilyName;
63 	String				maStyleName;
64 	Size				maSize;
65 	Color				maColor;		// compatibility, now on output device
66 	Color				maFillColor;	// compatibility, now on output device
67 	rtl_TextEncoding	meCharSet;
68 	LanguageType		meLanguage;
69 	LanguageType		meCJKLanguage;
70 	FontFamily			meFamily;
71 	FontPitch			mePitch;
72 	TextAlign			meAlign;
73 	FontWeight			meWeight;
74 	FontWidth			meWidthType;
75 	FontItalic			meItalic;
76 	FontUnderline		meUnderline;
77 	FontUnderline		meOverline;
78 	FontStrikeout		meStrikeout;
79 	FontRelief			meRelief;
80 	FontEmphasisMark	meEmphasisMark;
81 	FontType			meType;			// used by metrics only
82 	short				mnOrientation;
83 	FontKerning 		mnKerning;
84 	sal_Bool				mbWordLine:1,
85                         mbOutline:1,
86                         mbConfigLookup:1,   // there was a config lookup
87 						mbShadow:1,
88 						mbVertical:1,
89 						mbTransparent:1;	// compatibility, now on output device
90 
91 	friend SvStream&	operator>>( SvStream& rIStm, Impl_Font& );
92 	friend SvStream&	operator<<( SvStream& rOStm, const Impl_Font& );
93 };
94 
95 // ------------------
96 // - ImplFontMetric -
97 // ------------------
98 
99 class ImplFontMetric
100 {
101     friend class OutputDevice;
102 
103 private:
104     long    mnAscent;      // Ascent
105     long    mnDescent;     // Descent
106     long    mnIntLeading;  // Internal Leading
107     long    mnExtLeading;  // External Leading
108     long    mnLineHeight;  // Ascent+Descent+EmphasisMark
109     long    mnSlant;       // Slant
110     sal_uInt16  mnMiscFlags;   // Misc Flags
111     sal_uInt32  mnRefCount;    // Reference Counter
112 
113     enum { DEVICE_FLAG=1, SCALABLE_FLAG=2, LATIN_FLAG=4, CJK_FLAG=8, CTL_FLAG=16 };
114 
115 public:
116             ImplFontMetric();
117     void    AddReference();
118     void    DeReference();
119 
120     long    GetAscent() const       { return mnAscent; }
121     long    GetDescent() const      { return mnDescent; }
122     long    GetIntLeading() const   { return mnIntLeading; }
123     long    GetExtLeading() const   { return mnExtLeading; }
124     long    GetLineHeight() const   { return mnLineHeight; }
125     long    GetSlant() const        { return mnSlant; }
126 
127     bool    IsDeviceFont() const    { return ((mnMiscFlags & DEVICE_FLAG) != 0); }
128     bool    IsScalable() const      { return ((mnMiscFlags & SCALABLE_FLAG) != 0); }
129     bool    SupportsLatin() const   { return ((mnMiscFlags & LATIN_FLAG) != 0); }
130     bool    SupportsCJK() const     { return ((mnMiscFlags & CJK_FLAG) != 0); }
131     bool    SupportsCTL() const     { return ((mnMiscFlags & CTL_FLAG) != 0); }
132 
133     bool    operator==( const ImplFontMetric& ) const;
134 };
135 
136 // ------------------
137 // - ImplFontHints -
138 // ------------------
139 
140 class ImplFontOptions
141 {
142 public:
143     FontEmbeddedBitmap meEmbeddedBitmap; // whether the embedded bitmaps should be used
144     FontAntiAlias      meAntiAlias;      // whether the font should be antialiased
145     FontAutoHint       meAutoHint;       // whether the font should be autohinted
146     FontHinting        meHinting;        // whether the font should be hinted
147     FontHintStyle      meHintStyle;      // type of font hinting to be used
148 public:
149     ImplFontOptions() :
150         meEmbeddedBitmap(EMBEDDEDBITMAP_DONTKNOW),
151         meAntiAlias(ANTIALIAS_DONTKNOW),
152         meAutoHint(AUTOHINT_DONTKNOW),
153         meHinting(HINTING_DONTKNOW),
154         meHintStyle(HINT_SLIGHT)
155     {}
156     ImplFontOptions( FontEmbeddedBitmap eEmbeddedBitmap, FontAntiAlias eAntiAlias,
157         FontAutoHint eAutoHint, FontHinting eHinting, FontHintStyle eHintStyle) :
158         meEmbeddedBitmap(eEmbeddedBitmap),
159         meAntiAlias(eAntiAlias),
160         meAutoHint(eAutoHint),
161         meHinting(eHinting),
162         meHintStyle(eHintStyle)
163     {}
164     FontAutoHint GetUseAutoHint() const { return meAutoHint; }
165     FontHintStyle GetHintStyle() const { return meHintStyle; }
166     bool DontUseEmbeddedBitmaps() const { return meEmbeddedBitmap == EMBEDDEDBITMAP_FALSE; }
167     bool DontUseAntiAlias() const { return meAntiAlias == ANTIALIAS_FALSE; }
168     bool DontUseHinting() const { return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); }
169 };
170 
171 // -------------------
172 // - ImplFontCharMap -
173 // -------------------
174 
175 class CmapResult;
176 
177 class VCL_PLUGIN_PUBLIC ImplFontCharMap
178 {
179 public:
180     explicit             ImplFontCharMap( const CmapResult& );
181     virtual              ~ImplFontCharMap();
182 
183 	static ImplFontCharMap* GetDefaultMap( bool bSymbols=false);
184 
185     bool                IsDefaultMap() const;
186     bool                HasChar( sal_uInt32 ) const;
187     int                 CountCharsInRange( sal_uInt32 cMin, sal_uInt32 cMax ) const;
188     int                 GetCharCount() const;
189 
190     sal_uInt32          GetFirstChar() const;
191     sal_uInt32          GetLastChar() const;
192 
193     sal_uInt32          GetNextChar( sal_uInt32 ) const;
194     sal_uInt32          GetPrevChar( sal_uInt32 ) const;
195 
196     int                 GetIndexFromChar( sal_uInt32 ) const;
197     sal_uInt32          GetCharFromIndex( int ) const;
198 
199     void                AddReference() const;
200     void                DeReference() const;
201 
202     int                 GetGlyphIndex( sal_uInt32 ) const;
203 
204 private:
205     int                 ImplFindRangeIndex( sal_uInt32 ) const;
206 
207     // prevent assignment and copy construction
208     explicit            ImplFontCharMap( const ImplFontCharMap& );
209     void                operator=( const ImplFontCharMap& );
210 
211 private:
212     const sal_uInt32*   mpRangeCodes;     // pairs of StartCode/(EndCode+1)
213     const int*          mpStartGlyphs;    // range-specific mapper to glyphs
214     const sal_uInt16*       mpGlyphIds;       // individual glyphid mappings
215     int                 mnRangeCount;
216     int                 mnCharCount;      // covered codepoints
217     mutable int         mnRefCount;
218 };
219 
220 // CmapResult is a normalized version of the many CMAP formats
221 class VCL_PLUGIN_PUBLIC CmapResult
222 {
223 public:
224 	explicit	CmapResult( bool bSymbolic = false,
225 					const sal_uInt32* pRangeCodes = NULL, int nRangeCount = 0,
226 					const int* pStartGlyphs = 0, const sal_uInt16* pGlyphIds = NULL );
227 
228 	const sal_uInt32* mpRangeCodes;
229 	const int*        mpStartGlyphs;
230 	const sal_uInt16*     mpGlyphIds;
231 	int			      mnRangeCount;
232 	bool		      mbSymbolic;
233 	bool			  mbRecoded;
234 };
235 
236 bool ParseCMAP( const unsigned char* pRawData, int nRawLength, CmapResult& );
237 
238 #endif // _SV_IMPFONT_HXX
239 
240