1 //========================================================================
5 // Copyright 1999-2001 Emmanuel Lesueur
7 //========================================================================
18 #include "FontEncoding.h"
23 encUnknown
, encStandard
, encMacRoman
, encMacExpert
, encWinAnsi
26 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
31 enum { cacheSize
= 32 };
38 ~GfxFontCache() { clear(); }
43 // Get a font. This creates a new font if necessary.
44 GfxFont
*getGfxFont(XRef
*xref
, Ref id1
);
46 // Decrement the use counter for that font.
47 void release(GfxFont
*gfxFont
);
57 Entry
*entries
; // cache entries in reverse-LRU order
58 int nValid
; // number of valid entries in entries[]
59 int nTotal
; // size of then entries array
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
68 enum { cacheSize
= 8 };
72 BaseFont(const char *filename
);
77 // Was font created successfully?
78 virtual GBool
isOk() = 0;
80 // Returns the font name, as specified internally by the font file.
81 // Returns NULL if no name is available.
82 char *getName() { return name
.getCString(); }
84 // Returns the custom font encoding, or NULL if the encoding is
85 // not available. If <taken> is set, the caller of this function
86 // will be responsible for freeing the encoding object.
87 FontEncoding
*getEncoding(GBool taken
);
89 // Build the map from character code to internal font index.
90 virtual void buildCharMap(FontEncoding
*, short *map
) = 0;
92 // Get an output font with the given transformation matrix.
93 OutputFont
*get(double m11
, double m12
, double m21
, double m22
);
97 // Create a font with the given transformation matrix.
98 virtual OutputFont
*create(double m11
, double m12
, double m21
, double m22
) = 0;
100 virtual void loadEncoding() = 0;
104 GBool hex
; // subsetted font with hex char codes
105 // (this flag is used for text output)
107 fonts
[cacheSize
]; // font cache
108 int nFonts
; // number of fonts in cache.
110 FontEncoding
*encoding
;
116 //------------------------------------------------------------------------
118 //------------------------------------------------------------------------
120 class T3BaseFont
: public BaseFont
{
124 T3BaseFont(XRef
*xrefA
, Dict
*fontDict
);
127 virtual ~T3BaseFont();
129 // Was font created successfully?
130 virtual GBool
isOk() { return ok
; }
132 // Build the map from character code to internal font index.
133 virtual void buildCharMap(FontEncoding
*, short *map
);
135 // Get a character glyph.
136 GBool
getGlyph(int c
, Object
*result
) {
137 if (c
>= 0 && c
< numGlyphs
) {
138 glyphs
[c
].fetch(xref
, result
);
148 // Create a font with the given transformation matrix.
149 virtual OutputFont
*create(double m11
, double m12
, double m21
, double m22
) {
153 virtual void loadEncoding() {}
164 //------------------------------------------------------------------------
166 //------------------------------------------------------------------------
172 OutputFont(BaseFont
*base
,
173 double m11
, double m12
, double m21
, double m22
);
175 // Does this font match the ID, size, and angle?
176 GBool
matches(double m11
, double m12
, double m21
, double m22
)
177 { return fabs(tm11
-m11
) + fabs(tm12
-m12
) + fabs(tm21
-m21
) +
178 fabs(tm22
-m22
) < 0.1; }
180 // Was font created successfully?
181 virtual GBool
isOk() = 0;
184 virtual ~OutputFont();
186 // Get character metrics
187 virtual GBool
getMetrics(int c
,
188 double *xMin
, double *yMin
,
189 double *xMax
, double *yMax
,
190 double *advanceX
, double *avanceY
) =0;
193 BaseFont
*base
; // base font
194 double tm11
, tm12
, // original transform matrix
198 //------------------------------------------------------------------------
200 //------------------------------------------------------------------------
202 class BaseFontCache
{
203 enum { cacheSize
= 16 };
212 // Get a font. This loads a new font if necessary.
213 BaseFont
*getFont(XRef
*xref
, const char *name
, GfxFont
* gfxFont
, EncodingID
);
215 // Decrement the use count.
216 void release(BaseFont
*font
);
226 Entry
*entries
; // cache entries in reverse-LRU order
227 int nValid
; // number of valid entries in entries[]
228 int nTotal
; // size of then entries array
231 extern BaseFontCache
*baseFontCache
;
232 extern GfxFontCache
*gfxFontCache
;