1 /*---------------------------------------------------------------------------* 2 | PDFlib - A library for generating PDF on the fly | 3 +---------------------------------------------------------------------------+ 4 | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. | 5 +---------------------------------------------------------------------------+ 6 | | 7 | This software is subject to the PDFlib license. It is NOT in the | 8 | public domain. Extended versions and commercial licenses are | 9 | available, please check http://www.pdflib.com. | 10 | | 11 *---------------------------------------------------------------------------*/ 12 13 /* $Id: ft_font.h,v 1.55.2.8 2010/04/23 09:47:20 kurt Exp $ 14 * 15 * Header file for font handling 16 * 17 */ 18 19 #ifndef FT_FONT_H 20 #define FT_FONT_H 21 22 #include "pc_util.h" 23 #include "pc_geom.h" 24 #include "pc_file.h" 25 #include "ft_cid.h" 26 27 #define FNT_DEFAULT_WIDTH 250 /* some reasonable default */ 28 #define FNT_DEFAULT_CIDWIDTH 1000 /* for CID fonts */ 29 #define FNT_MISSING_WIDTH -1234567890 /* missing width value */ 30 31 #define FNT_DEFAULT_UNDERLINEWIDTH 50 /* default value of underlineThickness*/ 32 33 #define FNT_MAX_METRICS 2048.0 /* maximal font metrics value */ 34 35 /* 36 * these are the font weight values of Microsoft 37 * see LOGFONT structure member lfWeight 38 */ 39 #define FNT_FW_DONTCARE 0 40 #define FNT_FW_THIN 100 41 #define FNT_FW_EXTRALIGHT 200 42 #define FNT_FW_ULTRALIGHT 200 43 #define FNT_FW_LIGHT 300 44 #define FNT_FW_NORMAL 400 45 #define FNT_FW_REGULAR 400 46 #define FNT_FW_MEDIUM 500 47 #define FNT_FW_SEMIBOLD 600 48 #define FNT_FW_DEMIBOLD 600 49 #define FNT_FW_BOLD 700 50 #define FNT_FW_EXTRABOLD 800 51 #define FNT_FW_ULTRABOLD 800 52 #define FNT_FW_HEAVY 900 53 #define FNT_FW_BLACK 900 54 55 /* 56 * these defaults are used when the stem value 57 * must be derived from the name (unused) 58 */ 59 #define FNT_STEMV_MIN 50 /* minimum StemV value */ 60 #define FNT_STEMV_LIGHT 71 /* light StemV value */ 61 #define FNT_STEMV_NORMAL 109 /* normal StemV value */ 62 #define FNT_STEMV_MEDIUM 125 /* mediumbold StemV value */ 63 #define FNT_STEMV_SEMIBOLD 135 /* semibold StemV value */ 64 #define FNT_STEMV_BOLD 165 /* bold StemV value */ 65 #define FNT_STEMV_EXTRABOLD 201 /* extrabold StemV value */ 66 #define FNT_STEMV_BLACK 241 /* black StemV value */ 67 68 /* 69 * Bit positions for the font descriptor flag 70 */ 71 #define FNT_FIXEDWIDTH (long) (1L<<0) 72 #define FNT_SERIF (long) (1L<<1) 73 #define FNT_SYMBOL (long) (1L<<2) 74 #define FNT_SCRIPT (long) (1L<<3) 75 #define FNT_ADOBESTANDARD (long) (1L<<5) 76 #define FNT_ITALIC (long) (1L<<6) 77 #define FNT_SMALLCAPS (long) (1L<<17) 78 #define FNT_FORCEBOLD (long) (1L<<18) 79 80 #define FNT_FI_ITALIC 255 81 #define FNT_FI_ITALICNAME "Italic" 82 #define FNT_DEF_ITALICANGLE -12 /* default italic angle */ 83 84 #define FNT_MISSING_FONTVAL PDC_SHRT_MIN /* missing font value */ 85 86 /* start sequence of PFA files */ 87 #define FNT_PFA_STARTSEQU "%!PS" 88 89 /* missing file name for font outline data */ 90 #define FNT_MISSING_FILENAME "__missing__filename__" 91 92 /* Font types */ 93 typedef enum 94 { 95 fnt_Type0, /* Type0 fonts */ 96 fnt_Type1, /* Type1 fonts */ 97 fnt_MMType1, /* Multiple master fonts */ 98 fnt_TrueType, /* TrueType fonts for 1-byte encoding */ 99 fnt_CIDFontType2, /* TrueType fonts for 2-byte encoding */ 100 fnt_Type1C, /* CFF PostScript fonts for 1-byte encoding */ 101 fnt_CIDFontType0, /* OpenType fonts with CFF_ table for 2-byte encoding */ 102 fnt_CIDFontType0C, /* CFF PostScript fonts for 2-byte encoding */ 103 fnt_OpenType, /* OpenType fonts for 1-byte encoding */ 104 fnt_OpenTypeC, /* OpenType fonts for 2-byte encoding */ 105 fnt_Type3, /* Type3 fonts */ 106 fnt_unknownType /* for initialization only */ 107 } 108 fnt_fonttype; 109 110 /* Font styles */ 111 typedef enum 112 { 113 fnt_Normal, 114 fnt_Bold, 115 fnt_Italic, 116 fnt_BoldItalic 117 } 118 fnt_fontstyle; 119 120 typedef struct fnt_interwidth_s fnt_interwidth; 121 typedef struct fnt_interwidth4_s fnt_interwidth4; 122 typedef struct fnt_glyphwidth_s fnt_glyphwidth; 123 typedef struct fnt_font_metric_s fnt_font_metric; 124 typedef struct fnt_font_s fnt_font; 125 126 /* Code interval for glyph width */ 127 struct fnt_interwidth_s 128 { 129 pdc_ushort startcode; /* start code of interval */ 130 pdc_short width; /* width of glyphs in the code interval */ 131 }; 132 133 struct fnt_interwidth4_s 134 { 135 int startcode; /* start UTF-32 Unicode of interval */ 136 pdc_short width; /* width of glyphs in the code interval */ 137 }; 138 139 /* Code and Unicode for glyph width */ 140 struct fnt_glyphwidth_s 141 { 142 pdc_ushort unicode; /* UTF-16 Unicode of glyph */ 143 pdc_short code; /* builtin 8-bit code */ 144 pdc_short width; /* glyph width */ 145 }; 146 147 148 /* Font metric exchange structure */ 149 struct fnt_font_metric_s 150 { 151 char *name; /* font name (/FontName) */ 152 pdc_ulong flags; /* font flags of font descriptor */ 153 fnt_fonttype type; /* type of font */ 154 int charcoll; /* supported CID character collection */ 155 /* < 0: Halfwidth Latin-1 character */ 156 /* font metric */ 157 pdc_scalar italicAngle; /* AFM key: ItalicAngle */ 158 int isFixedPitch; /* AFM key: IsFixedPitch */ 159 pdc_scalar llx; /* AFM key: FontBBox */ 160 pdc_scalar lly; /* AFM key: FontBBox */ 161 pdc_scalar urx; /* AFM key: FontBBox */ 162 pdc_scalar ury; /* AFM key: FontBBox */ 163 int underlinePosition; /* AFM key: UnderlinePosition */ 164 int underlineThickness; /* AFM key: UnderlineThickness */ 165 int capHeight; /* AFM key: CapHeight */ 166 int xHeight; /* AFM key: XHeight */ 167 int ascender; /* AFM key: Ascender */ 168 int descender; /* AFM key: Descender */ 169 int StdVW; /* AFM key: StdVW */ 170 int StdHW; /* AFM key: StdHW */ 171 172 /* glyph widths */ 173 int defwidth; /* default width */ 174 int numwidths; /* number of entries in widths */ 175 int *widths; /* ptr to glyph widths (enumerated by codes) */ 176 int numinters; /* number of entries in ciw */ 177 fnt_interwidth *ciw; /* ptr to code intervals for widths array */ 178 int numglwidths; /* number of entries in glw */ 179 fnt_glyphwidth *glw; /* ptr to glyph widths array */ 180 181 182 }; 183 184 /* Font exchange structure */ 185 struct fnt_font_s 186 { 187 char *name; /* font name (/BaseFont or /Name or 'font_#') */ 188 char *utf8name; /* UTF-8 encoded font name (maybe with BOM) */ 189 char *filename; /* font file name */ 190 191 fnt_font_metric m; /* name, type, flags, charcoll and metric */ 192 pdc_bool isstdfont; /* is an incore font 193 * or standard CJK font in pdflib */ 194 pdc_bool ishostfont; /* is an host font */ 195 pdc_bool hasdescr; /* has font descriptor */ 196 pdc_bool vertical; /* vertical writing mode */ 197 198 pdc_ushort spacechar; /* code of space character depending on enc */ 199 int spacewidth; /* width of space character */ 200 int linegap; /* OpenType lineGap */ 201 int weight; /* font weight value 0-1000 */ 202 203 pdc_matrix matrix; /* Type3 font matrix */ 204 pdc_rectangle bbox; /* Type3 font bounding box */ 205 pdc_scalar fsscale; /* Type3 fontsize scaling */ 206 207 pdc_bool issymbfont; /* is a symbol font */ 208 pdc_encoding enc; /* font encoding shortcut */ 209 210 int numglyphs; /* number of glyphs */ 211 int numcodes; /* number of codes */ 212 213 pdc_ushort *gid2code; /* mapping glyph ID -> [Uni]code or NULL */ 214 pdc_ushort *code2gid; /* mapping [Uni]code -> glyph ID or NULL */ 215 char *cmapname; /* CID CMap name */ 216 217 218 /* font in memory */ 219 pdc_bool embedded; /* embedded font */ 220 char *imgname; /* name of virtual file containing *img */ 221 size_t filelen; /* length of (uncompressed) font data */ 222 pdc_byte *img; /* font (or CFF table) data */ 223 224 }; 225 226 /* font error numbers. 227 */ 228 enum 229 { 230 #define fnt_genNames 1 231 #include "ft_generr.h" 232 233 FNT_E_dummy 234 }; 235 236 /* ft_font.c */ 237 void fnt_register_errtab(pdc_core *pdc); 238 void fnt_init_font(fnt_font *font); 239 void fnt_cleanup_font(pdc_core *pdc, fnt_font *font); 240 void fnt_cleanup_font_alien(pdc_core *pdc, fnt_font *font); 241 void fnt_cleanup_fontimg(pdc_core *pdc, fnt_font *font); 242 int fnt_get_glyphid(int code, fnt_font *font); 243 int fnt_get_code(int gid, fnt_font *font); 244 int fnt_get_glyphwidth(int code, fnt_font *font); 245 int fnt_get_pdf_fonttype_code(const char *typenam); 246 const char *fnt_get_pdf_fonttype_name(int typecode); 247 const char *fnt_get_pdf_fonttype_desc(int typecode); 248 pdc_encodingvector *fnt_create_font_ev(pdc_core *pdc, fnt_font *font); 249 int fnt_check_weight(int weight); 250 int fnt_weightname2weight(const char *weightname); 251 int fnt_stemv2weight(int stemv); 252 const char *fnt_weight2weightname(int weight); 253 int fnt_macfontstyle2weight(int macfontstyle); 254 int fnt_weight2stemv(int weight); 255 void fnt_font_logg_widths(pdc_core *pdc, fnt_font *font); 256 void fnt_font_logg_protocol(pdc_core *pdc, fnt_font *font); 257 258 /* ft_corefont.c */ 259 pdc_bool fnt_is_standard_font(const char *fontname); 260 const char *fnt_get_abb_std_fontname(const char *fontname); 261 void fnt_fill_font_metric(pdc_core *pdc, fnt_font *font, pdc_bool kerning, 262 const fnt_font_metric *metric); 263 const fnt_font_metric *fnt_get_core_metric(const char *fontname); 264 const char *fnt_get_abb_cjk_fontname(const char *fontname); 265 int fnt_get_preinstalled_cidfont(const char *fontname, 266 const fnt_font_metric **fontmetric); 267 const char **fnt_get_cid_widths_array(pdc_core *pdc, fnt_font *font); 268 269 270 /* ft_type1.c */ 271 pdc_bool fnt_test_type1_font(pdc_core *pdc, const pdc_byte *img); 272 pdc_bool fnt_get_type1_encoding(pdc_core *pdc, fnt_font *font, int glyphflags); 273 274 #endif /* FT_FONT_H */ 275