]>
git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/GfxFont.h
6853b1cc1afd4cd98fb2e526af19dd3178201d83
1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
19 #include "FontEncoding.h"
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
28 enum GfxFontCharSet16
{
29 font16AdobeJapan12
, // Adobe-Japan1-2
30 font16AdobeGB12
, // Adobe-GB1-2 (Chinese)
31 font16AdobeCNS13
// Adobe-CNS1-3 (Chinese)
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 struct GfxFontEncoding16
{
39 int wMode
; // writing mode (0=horizontal, 1=vertical)
40 Guchar codeLen
[256]; // length of codes, in bytes, indexed by
42 Gushort map1
[256]; // one-byte code mapping:
43 // map1[code] --> 16-bit char selector
44 Gushort
*map2
; // two-byte code mapping
45 // map2[2*i] --> first code in range
46 // map2[2*i+1] --> 16-bit char selector
48 int map2Len
; // length of map2 array (divided by 2)
51 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
55 struct GfxFontWidthExcep
{
56 int first
; // this record applies to
57 int last
; // chars <first>..<last>
58 double width
; // char width
61 struct GfxFontWidthExcepV
{
62 int first
; // this record applies to
63 int last
; // chars <first>..<last>
64 double height
; // char height
65 double vx
, vy
; // origin position
68 struct GfxFontWidths16
{
69 double defWidth
; // default char width
70 double defHeight
; // default char height
71 double defVY
; // default origin position
72 GfxFontWidthExcep
*exceps
; // exceptions
73 int numExceps
; // number of valid entries in exceps
74 GfxFontWidthExcepV
*excepsV
; // exceptions for vertical font
75 int numExcepsV
; // number of valid entries in excepsV
78 //------------------------------------------------------------------------
80 //------------------------------------------------------------------------
82 #define fontFixedWidth (1 << 0)
83 #define fontSerif (1 << 1)
84 #define fontSymbolic (1 << 2)
85 #define fontItalic (1 << 6)
86 #define fontBold (1 << 18)
101 GfxFont(const char *tag1
, Ref id1
, Dict
*fontDict
);
107 GString
*getTag() { return tag
; }
109 // Get font dictionary ID.
110 Ref
getID() { return id
; }
112 // Does this font match the tag?
113 GBool
matches(const char *tag1
) { return !tag
->cmp(tag1
); }
115 // Get base font name.
116 GString
*getName() { return name
; }
119 GfxFontType
getType() { return type
; }
121 // Does this font use 16-bit characters?
122 GBool
is16Bit() { return is16
; }
124 // Get embedded font ID, i.e., a ref for the font file stream.
125 // Returns false if there is no embedded font.
126 GBool
getEmbeddedFontID(Ref
*embID
)
127 { *embID
= embFontID
; return embFontID
.num
>= 0; }
129 // Get the PostScript font name for the embedded font. Returns
130 // NULL if there is no embedded font.
131 const char *getEmbeddedFontName()
132 { return embFontName
? embFontName
->getCString() : (const char *)NULL
; }
134 // Get the name of the external font file. Returns NULL if there
135 // is no external font file.
136 GString
*getExtFontFile() { return extFontFile
; }
138 // Get font descriptor flags.
139 GBool
isFixedWidth() { return flags
& fontFixedWidth
; }
140 GBool
isSerif() { return flags
& fontSerif
; }
141 GBool
isSymbolic() { return flags
& fontSymbolic
; }
142 GBool
isItalic() { return flags
& fontItalic
; }
143 GBool
isBold() { return flags
& fontBold
; }
145 // Get width of a character or string.
146 double getWidth(Guchar c
) { return widths
[c
]; }
147 double getWidth(GString
*s
);
149 // Get character metrics for 16-bit font.
150 double getWidth16(int c
);
151 double getHeight16(int c
);
152 double getOriginX16(int c
);
153 double getOriginY16(int c
);
155 // Return the encoding.
156 FontEncoding
*getEncoding() { return encoding
; }
158 // Return the character name associated with <code>.
159 const char *getCharName(int code
) { return encoding
->getCharName(code
); }
161 // Return the code associated with <name>.
162 int getCharCode(const char *charName
) { return encoding
->getCharCode(charName
); }
164 // Return the Type 3 CharProc for the character associated with <code>.
165 Object
*getCharProc(int code
, Object
*proc
);
167 // Return the 16-bit character set and encoding.
168 GfxFontCharSet16
getCharSet16() { return enc16
.charSet
; }
169 GfxFontEncoding16
*getEncoding16() { return enc16
.enc
; }
171 // Get the writing mode (0=horizontal, 1=vertical).
172 int getWMode16() { return enc16
.enc
->wMode
; }
174 // Return the font matrix.
175 double *getFontMatrix() { return fontMat
; }
177 // Read an external or embedded font file into a buffer.
178 const char *readExtFontFile(int *len
);
179 const char *readEmbFontFile(int *len
);
183 void getEncAndWidths(Dict
*fontDict
, BuiltinFont
*builtinFont
,
185 void findExtFontFile();
186 void makeWidths(Dict
*fontDict
, FontEncoding
*builtinEncoding
,
187 Gushort
*builtinWidths
, int missingWidth
);
188 void getType0EncAndWidths(Dict
*fontDict
);
190 GString
*tag
; // PDF font tag
191 Ref id
; // reference (used as unique ID)
192 GString
*name
; // font name
193 int flags
; // font descriptor flags
194 GfxFontType type
; // type of font
195 GBool is16
; // set if font uses 16-bit chars
196 GString
*embFontName
; // name of embedded font
197 Ref embFontID
; // ref to embedded font file stream
198 GString
*extFontFile
; // external font file name
199 Object charProcs
; // Type3 CharProcs dictionary
200 double fontMat
[6]; // font matrix
202 FontEncoding
*encoding
; // 8-bit font encoding
204 GfxFontCharSet16 charSet
; // 16-bit character set
205 GfxFontEncoding16
*enc
; // 16-bit encoding (CMap)
209 double widths
[256]; // width of each char for 8-bit font
210 GfxFontWidths16 widths16
; // char widths for 16-bit font
214 //------------------------------------------------------------------------
216 //------------------------------------------------------------------------
221 // Build the font dictionary, given the PDF font dictionary.
222 GfxFontDict(Dict
*fontDict
);
227 // Get the specified font.
228 GfxFont
*lookup(const char *tag
);
231 int getNumFonts() { return numFonts
; }
232 GfxFont
*getFont(int i
) { return fonts
[i
]; }
236 GfxFont
**fonts
; // list of fonts
237 int numFonts
; // number of fonts