Hash :
f9b8dec4
Author :
Date :
2000-06-16T19:34:52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
/*******************************************************************
*
* t1tokens.h
*
* Type 1 tokenizer
*
* Copyright 1996 David Turner, Robert Wilhelm and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
* The tokenizer is in charge of loading and reading a Type1 font
* file (either in PFB or PFA format), and extract successive tokens
* and keywords from its two streams (i.e. the font program, and the
* private dictionary).
*
* Eexec decryption is performed automatically when entering the
* private dictionary, or when retrieving char strings..
*
******************************************************************/
#ifndef T1TOKENS_H
#define T1TOKENS_H
#include <t1objs.h>
/* enum value of first keyword */
#define key_first_ 100
/* enum value of first immediate name */
#define imm_first_ 200
typedef enum T1_TokenType_
{
tok_error = 0,
tok_eof, /* end of file */
/* simple token types */
tok_keyword, /* keyword */
tok_number, /* number (integer or real) */
tok_string, /* postscript string */
tok_program, /* postscript program */
tok_immediate, /* any immediate name */
tok_array, /* matrix, array, etc.. */
tok_hexarray, /* array of hexadecimal nibbles */
tok_any, /* anything else */
/* Postscript keywords - placed in lexicographical order */
key_RD_alternate = key_first_, /* "-|" = alternate form of RD */
key_ExpertEncoding,
key_ND,
key_NP,
key_RD,
key_StandardEncoding,
key_array,
key_begin,
key_closefile,
key_currentdict,
key_currentfile,
key_def,
key_dict,
key_dup,
key_eexec,
key_end,
key_execonly,
key_false,
key_for,
key_index,
key_noaccess,
key_put,
key_readonly,
key_true,
key_userdict,
key_NP_alternate, /* "|" = alternate form of NP */
key_ND_alternate, /* "|-" = alternate form of ND */
key_max, /* always keep this value there */
/* Postscript immediate names - other names will be ignored, except */
/* in charstrings.. */
imm_RD_alternate = imm_first_, /* "-|" = alternate form of RD */
imm_notdef, /* "/.notdef" immediate */
imm_BlendAxisTypes,
imm_BlueFuzz,
imm_BlueScale,
imm_BlueShift,
imm_BlueValues,
imm_CharStrings,
imm_Encoding,
imm_FamilyBlues,
imm_FamilyName,
imm_FamilyOtherBlues,
imm_FID,
imm_FontBBox,
imm_FontID,
imm_FontInfo,
imm_FontMatrix,
imm_FontName,
imm_FontType,
imm_ForceBold,
imm_FullName,
imm_ItalicAngle,
imm_LanguageGroup,
imm_Metrics,
imm_MinFeature,
imm_ND,
imm_NP,
imm_Notice,
imm_OtherBlues,
imm_OtherSubrs,
imm_PaintType,
imm_Private,
imm_RD,
imm_RndStemUp,
imm_StdHW,
imm_StdVW,
imm_StemSnapH,
imm_StemSnapV,
imm_StrokeWidth,
imm_Subrs,
imm_UnderlinePosition,
imm_UnderlineThickness,
imm_UniqueID,
imm_Weight,
imm_isFixedPitch,
imm_lenIV,
imm_password,
imm_version,
imm_NP_alternate, /* "|" = alternate form of NP */
imm_ND_alternate, /* "|-" = alternate form of ND */
imm_max /* always keep this value here */
} T1_TokenType;
/* these arrays are visible for debugging purposes.. */
extern const char* t1_keywords[];
extern const char* t1_immediates[];
/*************************************************************************/
/* */
/* <Struct> T1_Token */
/* */
/* <Description> */
/* A structure used to describe a token in the current input */
/* stream. Note that the Type1 driver doesn't try to interpret */
/* tokens until it really needs to.. */
/* */
/* <Fields> */
/* kind :: token type. Describes the token to the loader */
/* kind2 :: detailed token type. */
/* */
/* start :: index of first character of token in input stream */
/* */
/* len :: length of token in characters. */
/* */
typedef struct T1_Token_
{
T1_TokenType kind; /* simple type */
T1_TokenType kind2; /* detailed type */
FT_Int start; /* index of first token character */
FT_Int len; /* length of token in chars */
} T1_Token;
typedef struct T1_TokenParser_
{
FT_Memory memory;
FT_Stream stream;
FT_Bool in_pfb; /* true if PFB file, PFA otherwise */
FT_Bool in_private; /* true if in private dictionary */
FT_Byte* base; /* base address of current read buffer */
FT_Long cursor; /* current position in read buffer */
FT_Long limit; /* limit of current read buffer */
FT_Long max; /* maximum size of read buffer */
FT_Error error; /* last error */
T1_Token token; /* last token read */
} T1_TokenParser;
/*************************************************************************/
/* */
/* <Type> T1_Tokenizer */
/* */
/* <Description> */
/* A handle to an object used to extract tokens from the input. */
/* The object is able to perform PFA/PFB recognition, eexec */
/* decryption of the private dictionary, as well as eexec decryption */
/* of the charstrings.. */
/* */
typedef T1_TokenParser* T1_Tokenizer;
/*************************************************************************/
/* */
/* <Function> New_Tokenizer */
/* */
/* <Description> */
/* Creates a new tokenizer from a given input stream. This function */
/* automatically recognizes "pfa" or "pfb" files. The function */
/* "Read_Token" can then be used to extract successive tokens from */
/* the stream.. */
/* */
/* <Input> */
/* stream :: input stream */
/* */
/* <Output> */
/* tokenizer :: handle to new tokenizer object.. */
/* */
/* <Return> */
/* Type1 error code. 0 means success.. */
/* */
/* <Note> */
/* This function copies the stream handle within the object. Callers */
/* should not discard "stream". This is done by the Done_Tokenizer */
/* function.. */
/* */
LOCAL_DEF
FT_Error New_Tokenizer( FT_Stream stream,
T1_Tokenizer* tokenizer );
/*************************************************************************/
/* */
/* <Function> Done_Tokenizer */
/* */
/* <Description> */
/* Closes a given tokenizer. This function will also close the */
/* stream embedded in the object.. */
/* */
/* <Input> */
/* tokenizer :: target tokenizer object */
/* */
/* <Return> */
/* Type1 error code. 0 means success.. */
/* */
LOCAL_DEF
FT_Error Done_Tokenizer( T1_Tokenizer tokenizer );
/*************************************************************************/
/* */
/* <Function> Open_PrivateDict */
/* */
/* <Description> */
/* This function must be called to set the tokenizer to the private */
/* section of the Type1 file. It recognizes automatically the */
/* the kind of eexec encryption used (ascii or binary).. */
/* */
/* <Input> */
/* tokenizer :: target tokenizer object */
/* lenIV :: value of the "lenIV" variable.. */
/* */
/* <Return> */
/* Type1 error code. 0 means success.. */
/* */
LOCAL_DEF
FT_Error Open_PrivateDict( T1_Tokenizer tokenizer );
/*************************************************************************/
/* */
/* <Function> Read_Token */
/* */
/* <Description> */
/* Read a new token from the current input stream. This function */
/* extracts a token from the font program until "Open_PrivateDict" */
/* has been called. After this, it returns tokens from the */
/* (eexec-encrypted) private dictionnary.. */
/* */
/* <Input> */
/* tokenizer :: target tokenizer object */
/* */
/* <Return> */
/* Type1 error code. 0 means success.. */
/* */
/* <Note> */
/* One should use the function Read_CharStrings to read the binary */
/* charstrings from the private dict.. */
/* */
LOCAL_DEF
FT_Error Read_Token( T1_Tokenizer tokenizer );
#if 0
/*************************************************************************/
/* */
/* <Function> Read_CharStrings */
/* */
/* <Description> */
/* Read a charstrings from the current input stream. These are */
/* binary bytes that encode each individual glyph outline. */
/* */
/* <Input> */
/* tokenizer :: target tokenizer object */
/* num_chars :: number of binary bytes to read */
/* */
/* <Output> */
/* buffer :: target array of bytes. These are eexec-decrypted.. */
/* */
/* <Return> */
/* Type1 error code. 0 means success.. */
/* */
/* <Note> */
/* One should use the function Read_CharStrings to read the binary */
/* charstrings from the private dict.. */
/* */
LOCAL_DEF
FT_Error Read_CharStrings( T1_Tokenizer tokenizer,
FT_Int num_chars,
FT_Byte* buffer );
#endif
/*************************************************************************/
/* */
/* <Function> t1_decrypt */
/* */
/* <Description> */
/* Performs the Type 1 charstring decryption process.. */
/* */
/* <Input> */
/* buffer :: base address of data to decrypt */
/* length :: number of bytes to decrypt from base address */
/* seed :: ecnryption seed (4330 for charstrings). */
/* */
LOCAL_DEF
void t1_decrypt( FT_Byte* buffer,
FT_Int length,
FT_UShort seed );
#endif /* T1TOKENS_H */