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