| 1 |
#if 0 |
| 2 |
#include "basics.h" |
| 3 |
#else |
| 4 |
#include <stdbool.h> |
| 5 |
#include <stdint.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <time.h> |
| 9 |
#endif |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
static int verbose = false; |
| 13 |
static int max_lig_nest = 10000; |
| 14 |
static int just_headers = false; |
| 15 |
static int head_check = false; |
| 16 |
|
| 17 |
struct dup { |
| 18 |
int glyph; |
| 19 |
int enc; |
| 20 |
struct dup *prev; |
| 21 |
}; |
| 22 |
|
| 23 |
struct features { |
| 24 |
int feature; |
| 25 |
int nsettings; |
| 26 |
struct settings { uint16_t setting; int16_t nameid; char *name; } *settings; |
| 27 |
int featureflags; |
| 28 |
char *name; |
| 29 |
int nameIndex; |
| 30 |
}; |
| 31 |
|
| 32 |
struct ttfinfo { |
| 33 |
int emsize; |
| 34 |
int ascent, descent; |
| 35 |
|
| 36 |
int width_cnt; |
| 37 |
int glyph_cnt; |
| 38 |
unsigned int index_to_loc_is_long:1; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
char *copyright; |
| 43 |
char *familyname; |
| 44 |
char *fullname; |
| 45 |
char *version; |
| 46 |
char *fontname; |
| 47 |
double italicAngle; |
| 48 |
int upos, uwidth; |
| 49 |
|
| 50 |
int ttccnt; |
| 51 |
int *ttcoffsets; |
| 52 |
|
| 53 |
int numtables; |
| 54 |
|
| 55 |
int base_start; |
| 56 |
int base_length; |
| 57 |
|
| 58 |
int cff_start; |
| 59 |
int cff_length; |
| 60 |
|
| 61 |
int encoding_start; |
| 62 |
|
| 63 |
int cvt_start; |
| 64 |
int cvt_length; |
| 65 |
|
| 66 |
int glyph_start; |
| 67 |
|
| 68 |
|
| 69 |
int bitmapdata_start; |
| 70 |
|
| 71 |
|
| 72 |
int bitmaploc_start; |
| 73 |
int bitmaploc_length; |
| 74 |
|
| 75 |
int bitmapscale_start; |
| 76 |
|
| 77 |
int feat_start; |
| 78 |
|
| 79 |
int fdsc_start; |
| 80 |
|
| 81 |
int gasp_start; |
| 82 |
|
| 83 |
int gdef_start; |
| 84 |
|
| 85 |
int gpos_start; |
| 86 |
|
| 87 |
int gsub_start; |
| 88 |
|
| 89 |
int hdmx_start; |
| 90 |
|
| 91 |
int head_start; |
| 92 |
|
| 93 |
int hhea_start; |
| 94 |
|
| 95 |
int hmetrics_start; |
| 96 |
|
| 97 |
int JSTF_start; |
| 98 |
|
| 99 |
int kern_start; |
| 100 |
|
| 101 |
int lcar_start; |
| 102 |
|
| 103 |
int glyphlocations_start; |
| 104 |
int loca_length; |
| 105 |
|
| 106 |
int math_start; |
| 107 |
|
| 108 |
int maxp_start; |
| 109 |
int maxp_length; |
| 110 |
|
| 111 |
int mort_start; |
| 112 |
int mort_length; |
| 113 |
|
| 114 |
int morx_start; |
| 115 |
int morx_length; |
| 116 |
|
| 117 |
int copyright_start; |
| 118 |
|
| 119 |
int opbd_start; |
| 120 |
|
| 121 |
int postscript_start; |
| 122 |
int postscript_len; |
| 123 |
|
| 124 |
int os2_start; |
| 125 |
int os2_len; |
| 126 |
|
| 127 |
int fvar_start; |
| 128 |
int fvar_length; |
| 129 |
|
| 130 |
int gvar_start; |
| 131 |
int gvar_length; |
| 132 |
|
| 133 |
int fpgm_start; |
| 134 |
int fpgm_length; |
| 135 |
int prep_start; |
| 136 |
int prep_length; |
| 137 |
int prop_start; |
| 138 |
|
| 139 |
|
| 140 |
int fftm_start; |
| 141 |
|
| 142 |
unsigned int *glyph_unicode; |
| 143 |
char **glyph_names; |
| 144 |
struct dup *dups; |
| 145 |
struct features *features; |
| 146 |
|
| 147 |
uint16_t *morx_classes; |
| 148 |
int fvar_axiscount; |
| 149 |
}; |
| 150 |
|
| 151 |
static int getushort(FILE *ttf) { |
| 152 |
int ch1 = getc(ttf); |
| 153 |
int ch2 = getc(ttf); |
| 154 |
if ( ch2==EOF ) |
| 155 |
return( EOF ); |
| 156 |
return( (ch1<<8)|ch2 ); |
| 157 |
} |
| 158 |
|
| 159 |
static int32_t getlong(FILE *ttf) { |
| 160 |
int ch1 = getc(ttf); |
| 161 |
int ch2 = getc(ttf); |
| 162 |
int ch3 = getc(ttf); |
| 163 |
int ch4 = getc(ttf); |
| 164 |
if ( ch4==EOF ) |
| 165 |
return( EOF ); |
| 166 |
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 ); |
| 167 |
} |
| 168 |
|
| 169 |
static int32_t get3byte(FILE *ttf) { |
| 170 |
int ch1 = getc(ttf); |
| 171 |
int ch2 = getc(ttf); |
| 172 |
int ch3 = getc(ttf); |
| 173 |
if ( ch3==EOF ) |
| 174 |
return( EOF ); |
| 175 |
return( (ch1<<16)|(ch2<<8)|ch3 ); |
| 176 |
} |
| 177 |
|
| 178 |
static int32_t getoffset(FILE *ttf, int offsize) { |
| 179 |
int ch1, ch2, ch3, ch4; |
| 180 |
|
| 181 |
ch1 = getc(ttf); |
| 182 |
if ( offsize==1 ) |
| 183 |
return( ch1 ); |
| 184 |
ch2 = getc(ttf); |
| 185 |
if ( offsize==2 ) { |
| 186 |
if ( ch2==EOF ) |
| 187 |
return( EOF ); |
| 188 |
return( (ch1<<8)|ch2); |
| 189 |
} |
| 190 |
ch3 = getc(ttf); |
| 191 |
if ( offsize==3 ) { |
| 192 |
if ( ch3==EOF ) |
| 193 |
return( EOF ); |
| 194 |
return( (ch1<<16)|(ch2<<8)|ch3 ); |
| 195 |
} |
| 196 |
ch4 = getc(ttf); |
| 197 |
if ( ch4==EOF ) |
| 198 |
return( EOF ); |
| 199 |
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 ); |
| 200 |
} |
| 201 |
|
| 202 |
static double getfixed(FILE *ttf) { |
| 203 |
int32_t val = getlong(ttf); |
| 204 |
int mant = val&0xffff; |
| 205 |
|
| 206 |
|
| 207 |
return( (double) (val>>16) + (mant/65536.0) ); |
| 208 |
} |
| 209 |
|
| 210 |
static double long2fixed(int32_t val) { |
| 211 |
int mant = val&0xffff; |
| 212 |
|
| 213 |
|
| 214 |
return( (double) (val>>16) + (mant/65536.0) ); |
| 215 |
} |
| 216 |
|
| 217 |
static int32_t filecheck(FILE *file, int start, int len) { |
| 218 |
uint32_t sum = 0, chunk; |
| 219 |
|
| 220 |
fseek(file,start,SEEK_SET); |
| 221 |
if ( len!=-1 ) len=(len+3)>>2; |
| 222 |
while ( len==-1 || --len>=0 ) { |
| 223 |
chunk = getlong(file); |
| 224 |
if ( feof(file)) |
| 225 |
break; |
| 226 |
sum += chunk; |
| 227 |
} |
| 228 |
return( sum ); |
| 229 |
} |
| 230 |
|
| 231 |
#define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4)) |
| 232 |
|
| 233 |
static int readcff(FILE *ttf,FILE *util, struct ttfinfo *info); |
| 234 |
|
| 235 |
static int readttfheader(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 236 |
int i; |
| 237 |
int tag, checksum, offset, length, sr, es, rs, cs; uint32_t v; |
| 238 |
int e_sr, e_es, e_rs; |
| 239 |
double version; |
| 240 |
|
| 241 |
v = getlong(ttf); |
| 242 |
if ( v==CHR('t','t','c','f')) { |
| 243 |
v = getlong(ttf); |
| 244 |
info->ttccnt = getlong(ttf); |
| 245 |
printf( "This is a TrueType Font Collection file (version=%x), with %d fonts\n", v, info->ttccnt ); |
| 246 |
info->ttcoffsets = calloc(info->ttccnt,sizeof(int)); |
| 247 |
for ( i = 0; i<info->ttccnt; ++i ) { |
| 248 |
info->ttcoffsets[i] = getlong(ttf); |
| 249 |
printf( " Offset to font %d header: %d\n", i, info->ttcoffsets[i]); |
| 250 |
} |
| 251 |
return(true); |
| 252 |
} |
| 253 |
|
| 254 |
version = long2fixed(v); |
| 255 |
info->numtables = getushort(ttf); |
| 256 |
sr = getushort(ttf), |
| 257 |
es = getushort(ttf), |
| 258 |
rs = getushort(ttf); |
| 259 |
if ( v==CHR('O','T','T','O')) |
| 260 |
printf( "version='OTTO', " ); |
| 261 |
else if ( v==CHR('t','r','u','e')) |
| 262 |
printf( "version='true', " ); |
| 263 |
else if ( v==CHR('S','p','l','i')) { |
| 264 |
fprintf(stderr, "This looks like one of fontforge's spline font databases, and not a truetype font.\n" ); |
| 265 |
exit ( 1 ); |
| 266 |
} else if ( v==CHR('%','!','P','S')) { |
| 267 |
fprintf(stderr, "This looks like a postscript (pfa) file, and not a truetype font.\n" ); |
| 268 |
exit ( 1 ); |
| 269 |
} else if ( v>=0x80000000 && info->numtables==0 ) { |
| 270 |
fprintf(stderr, "This looks like a postscript (pfb) file, and not a truetype font.\n" ); |
| 271 |
exit ( 1 ); |
| 272 |
} else if ( (v>>24)==1 && ((v>>16)&0xff)==0 && ((v>>8)&0xff)==4 ) { |
| 273 |
fprintf( stderr, "This looks like a bare CFF file. Proceeding under that assumption.\n"); |
| 274 |
info->cff_start = 0; |
| 275 |
fseek(ttf,0,SEEK_END); |
| 276 |
info->cff_length = ftell(ttf); |
| 277 |
rewind(ttf); |
| 278 |
readcff(ttf,util,info); |
| 279 |
exit(0); |
| 280 |
} else if ( v==CHR('t','y','p','1')) { |
| 281 |
printf( "version='typ1', " ); |
| 282 |
|
| 283 |
} else |
| 284 |
printf( "version=%g, ", version ); |
| 285 |
printf( "numtables=%d, searchRange=%d entrySel=%d rangeshift=%d\n", |
| 286 |
info->numtables, sr, es, rs); |
| 287 |
e_sr = (info->numtables<8?4:info->numtables<16?8:info->numtables<32?16:info->numtables<64?32:64)*16; |
| 288 |
e_es = (info->numtables<8?2:info->numtables<16?3:info->numtables<32?4:info->numtables<64?5:6); |
| 289 |
e_rs = info->numtables*16-e_sr; |
| 290 |
if ( e_sr!=sr || e_es!=es || e_rs!=rs ) |
| 291 |
printf( "!!!! Unexpected values for binsearch header. Based on the number of tables I\n!!!!! expect searchRange=%d (not %d), entrySel=%d (not %d) rangeShift=%d (not %d)\n", |
| 292 |
e_sr, sr, e_es, es, e_rs, rs ); |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
printf( "File Checksum =%x (should be 0xb1b0afba), diff=%x\n", |
| 299 |
(unsigned int)(filecheck(util,0,-1)), (unsigned int)((0xb1b0afba-filecheck(util,0,-1))) ); |
| 300 |
|
| 301 |
for ( i=0; i<info->numtables; ++i ) { |
| 302 |
tag = getlong(ttf); |
| 303 |
checksum = getlong(ttf); |
| 304 |
offset = getlong(ttf); |
| 305 |
length = getlong(ttf); |
| 306 |
cs = filecheck(util,offset,length); |
| 307 |
printf( "%c%c%c%c checksum=%08x actual=%08x diff=%x offset=%d len=%d\n", |
| 308 |
(char)((tag>>24)&0xff), (char)((tag>>16)&0xff), |
| 309 |
(char)((tag>>8)&0xff), (char)(tag&0xff), |
| 310 |
(unsigned int)(checksum), (unsigned int)(cs), (unsigned int)((checksum^cs)), |
| 311 |
offset, length ); |
| 312 |
switch ( tag ) { |
| 313 |
case CHR('B','A','S','E'): |
| 314 |
info->base_start = offset; |
| 315 |
info->base_length = length; |
| 316 |
break; |
| 317 |
case CHR('C','F','F',' '): |
| 318 |
info->cff_start = offset; |
| 319 |
info->cff_length = length; |
| 320 |
break; |
| 321 |
case CHR('c','m','a','p'): |
| 322 |
info->encoding_start = offset; |
| 323 |
break; |
| 324 |
case CHR('c','v','t',' '): |
| 325 |
info->cvt_start = offset; |
| 326 |
info->cvt_length = length; |
| 327 |
break; |
| 328 |
case CHR('F','F','T','M'): |
| 329 |
info->fftm_start = offset; |
| 330 |
break; |
| 331 |
case CHR('f','p','g','m'): |
| 332 |
info->fpgm_start = offset; |
| 333 |
info->fpgm_length = length; |
| 334 |
break; |
| 335 |
case CHR('f','v','a','r'): |
| 336 |
info->fvar_start = offset; |
| 337 |
info->fvar_length = length; |
| 338 |
break; |
| 339 |
case CHR('f','e','a','t'): |
| 340 |
info->feat_start = offset; |
| 341 |
break; |
| 342 |
case CHR('f','d','s','c'): |
| 343 |
info->fdsc_start = offset; |
| 344 |
break; |
| 345 |
case CHR('g','a','s','p'): |
| 346 |
info->gasp_start = offset; |
| 347 |
break; |
| 348 |
case CHR('g','l','y','f'): |
| 349 |
info->glyph_start = offset; |
| 350 |
break; |
| 351 |
case CHR('G','D','E','F'): |
| 352 |
info->gdef_start = offset; |
| 353 |
break; |
| 354 |
case CHR('G','P','O','S'): |
| 355 |
info->gpos_start = offset; |
| 356 |
break; |
| 357 |
case CHR('G','S','U','B'): |
| 358 |
info->gsub_start = offset; |
| 359 |
break; |
| 360 |
case CHR('g','v','a','r'): |
| 361 |
info->gvar_start = offset; |
| 362 |
info->gvar_length = length; |
| 363 |
break; |
| 364 |
case CHR('m','o','r','t'): |
| 365 |
info->mort_start = offset; |
| 366 |
info->mort_length = length; |
| 367 |
break; |
| 368 |
case CHR('m','o','r','x'): |
| 369 |
info->morx_start = offset; |
| 370 |
info->morx_length = length; |
| 371 |
break; |
| 372 |
case CHR('b','d','a','t'): |
| 373 |
case CHR('E','B','D','T'): |
| 374 |
info->bitmapdata_start = offset; |
| 375 |
break; |
| 376 |
case CHR('b','l','o','c'): |
| 377 |
case CHR('E','B','L','C'): |
| 378 |
info->bitmaploc_start = offset; |
| 379 |
info->bitmaploc_length = length; |
| 380 |
break; |
| 381 |
case CHR('E','B','S','C'): |
| 382 |
info->bitmapscale_start = offset; |
| 383 |
break; |
| 384 |
case CHR('h','d','m','x'): |
| 385 |
info->hdmx_start = offset; |
| 386 |
break; |
| 387 |
case CHR('b','h','e','d'): |
| 388 |
case CHR('h','e','a','d'): |
| 389 |
info->head_start = offset; |
| 390 |
if ( length!=54 ) fprintf( stderr, "> ! Unexpected length for head table, was %d expected 54 ! <\n", length ); |
| 391 |
break; |
| 392 |
case CHR('h','h','e','a'): |
| 393 |
info->hhea_start = offset; |
| 394 |
if ( length!=36 ) fprintf( stderr, "> ! Unexpected length for hhea table, was %d expected 36 ! <\n", length ); |
| 395 |
break; |
| 396 |
case CHR('h','m','t','x'): |
| 397 |
info->hmetrics_start = offset; |
| 398 |
break; |
| 399 |
case CHR('k','e','r','n'): |
| 400 |
info->kern_start = offset; |
| 401 |
break; |
| 402 |
case CHR('J','S','T','F'): |
| 403 |
info->JSTF_start = offset; |
| 404 |
break; |
| 405 |
case CHR('l','o','c','a'): |
| 406 |
info->glyphlocations_start = offset; |
| 407 |
info->loca_length = length; |
| 408 |
info->glyph_cnt = length/2-1; |
| 409 |
break; |
| 410 |
case CHR('M','A','T','H'): |
| 411 |
info->math_start = offset; |
| 412 |
break; |
| 413 |
case CHR('m','a','x','p'): |
| 414 |
info->maxp_start = offset; |
| 415 |
if ( length!=32 && length!=6 ) fprintf( stderr, "> ! Unexpected length for maxp table, was %d expected 32 ! <\n", length ); |
| 416 |
info->maxp_length = length; |
| 417 |
break; |
| 418 |
case CHR('n','a','m','e'): |
| 419 |
info->copyright_start = offset; |
| 420 |
break; |
| 421 |
case CHR('o','p','b','d'): |
| 422 |
info->opbd_start = offset; |
| 423 |
break; |
| 424 |
case CHR('p','o','s','t'): |
| 425 |
info->postscript_start = offset; |
| 426 |
info->postscript_len = length; |
| 427 |
break; |
| 428 |
case CHR('O','S','/','2'): |
| 429 |
info->os2_start = offset; |
| 430 |
info->os2_len = length; |
| 431 |
if ( length!=78 && length!=86 && length!=96 ) |
| 432 |
fprintf( stderr, "> ! Unexpected length for OS/2 table, was %d expected either 78 or 86 ! <\n", length ); |
| 433 |
break; |
| 434 |
case CHR('p','r','e','p'): |
| 435 |
info->prep_start = offset; |
| 436 |
info->prep_length = length; |
| 437 |
break; |
| 438 |
case CHR('p','r','o','p'): |
| 439 |
info->prop_start = offset; |
| 440 |
break; |
| 441 |
} |
| 442 |
} |
| 443 |
if ( (info->encoding_start!=0 && info->glyph_start==0 && info->head_start!=0 && |
| 444 |
info->hhea_start!=0 && info->hmetrics_start!=0 && info->glyphlocations_start == 0 && |
| 445 |
info->maxp_start!=0 && info->copyright_start!=0 && info->postscript_start!=0 && |
| 446 |
info->os2_start!=0 ) && info->cff_start!=0 ) { |
| 447 |
fprintf( stderr, "Required tables: glyf and loca have been replaced by CFF => OpenType\n" ); |
| 448 |
} else if ( info->encoding_start==0 || info->glyph_start==0 || info->head_start==0 || |
| 449 |
info->hhea_start==0 || info->hmetrics_start==0 || info->glyphlocations_start == 0 || |
| 450 |
info->maxp_start==0 || info->copyright_start==0 || info->postscript_start==0 || |
| 451 |
info->os2_start==0 ) { |
| 452 |
fprintf( stderr, "Required table(s) missing: " ); |
| 453 |
if ( info->encoding_start==0 ) fprintf(stderr,"cmap "); |
| 454 |
if ( info->glyph_start==0 ) fprintf(stderr,"glyf "); |
| 455 |
if ( info->head_start==0 ) fprintf(stderr,"head "); |
| 456 |
if ( info->hhea_start==0 ) fprintf(stderr,"hhea "); |
| 457 |
if ( info->hmetrics_start==0 ) fprintf(stderr,"hmtx "); |
| 458 |
if ( info->glyphlocations_start==0 ) fprintf(stderr,"loca "); |
| 459 |
if ( info->maxp_start==0 ) fprintf(stderr,"maxp "); |
| 460 |
if ( info->copyright_start==0 ) fprintf(stderr,"name "); |
| 461 |
if ( info->postscript_start==0 ) fprintf(stderr,"post "); |
| 462 |
if ( info->os2_start==0 ) fprintf(stderr,"OS/2"); |
| 463 |
fprintf(stderr,"\n"); |
| 464 |
} |
| 465 |
return( true ); |
| 466 |
} |
| 467 |
|
| 468 |
static time_t readdate(FILE *ttf) { |
| 469 |
int date[4], date1970[4], year[2]; |
| 470 |
int i; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
date[3] = getushort(ttf); |
| 475 |
date[2] = getushort(ttf); |
| 476 |
date[1] = getushort(ttf); |
| 477 |
date[0] = getushort(ttf); |
| 478 |
memset(date1970,0,sizeof(date1970)); |
| 479 |
year[0] = (60*60*24*365L)&0xffff; |
| 480 |
year[1] = (60*60*24*365L)>>16; |
| 481 |
for ( i=1904; i<1970; ++i ) { |
| 482 |
date1970[0] += year[0]; |
| 483 |
date1970[1] += year[1]; |
| 484 |
if ( (i&3)==0 && (i%100!=0 || i%400==0)) |
| 485 |
date1970[0] += 24*60*60L; |
| 486 |
date1970[1] += (date1970[0]>>16); |
| 487 |
date1970[0] &= 0xffff; |
| 488 |
date1970[2] += date1970[1]>>16; |
| 489 |
date1970[1] &= 0xffff; |
| 490 |
date1970[3] += date1970[2]>>16; |
| 491 |
date1970[2] &= 0xffff; |
| 492 |
} |
| 493 |
|
| 494 |
for ( i=0; i<3; ++i ) { |
| 495 |
date[i] -= date1970[i]; |
| 496 |
date[i+1] += date[i]>>16; |
| 497 |
date[i] &= 0xffff; |
| 498 |
} |
| 499 |
date[3] -= date1970[3]; |
| 500 |
return( (date[1]<<16) | date[0] ); |
| 501 |
} |
| 502 |
|
| 503 |
static void readttfFFTM(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 504 |
time_t unix_date; |
| 505 |
struct tm *tm; |
| 506 |
static const char *months[] = { "Jan", "Feb", "March", "April", "May", |
| 507 |
"June", "July", "August", "Sept", "Oct", "Nov", "Dec", NULL }; |
| 508 |
|
| 509 |
fseek(ttf,info->fftm_start,SEEK_SET); |
| 510 |
printf( "\n\nCreated by FontForge " ); |
| 511 |
if ( getlong(ttf)!=0x00000001 ) { |
| 512 |
fprintf( stderr, "Unknown version for 'FFTM' table\n" ); |
| 513 |
} else { |
| 514 |
unix_date = readdate(ttf); |
| 515 |
tm = localtime(&unix_date); |
| 516 |
printf( "%d:%02d %02d-%s-%d\n", |
| 517 |
tm->tm_hour, tm->tm_min, tm->tm_mday, months[tm->tm_mon], |
| 518 |
tm->tm_year+1900 ); |
| 519 |
unix_date = readdate(ttf); |
| 520 |
printf( "\tFont created: %s", ctime(&unix_date)); |
| 521 |
unix_date = readdate(ttf); |
| 522 |
printf( "\tFont modified: %s", ctime(&unix_date)); |
| 523 |
} |
| 524 |
printf( "\n" ); |
| 525 |
} |
| 526 |
|
| 527 |
static void readttfhead(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 528 |
int mn, flags, fd; |
| 529 |
time_t unix_date; |
| 530 |
|
| 531 |
fseek(ttf,info->head_start,SEEK_SET); |
| 532 |
printf( "\nHEAD table (at %d)\n", info->head_start ); |
| 533 |
printf( "\tVersion=%g\n", getfixed(ttf)); |
| 534 |
printf( "\tfontRevision=%g\n", getfixed(ttf)); |
| 535 |
printf( "\tchecksumAdj=%x\n", (unsigned int)(getlong(ttf)) ); |
| 536 |
mn = getlong(ttf); |
| 537 |
printf( "\tmagicNumber=%x (0x5f0f3cf5, diff=%x)\n", |
| 538 |
(unsigned int)(mn), (unsigned int)(mn-0x5f0f3cf5) ); |
| 539 |
printf( "\tflags=%x ", (unsigned int)((flags=getushort(ttf))) ); |
| 540 |
if ( flags&1 ) printf( "baseline_at_0 " ); |
| 541 |
if ( flags&2 ) printf( "lsb_at_0 " ); |
| 542 |
if ( flags&4 ) printf( "instrs_depend_on_size " ); |
| 543 |
if ( flags&8 ) printf( "ppem_to_int " ); |
| 544 |
if ( flags&16 ) printf( "instr_set_width " ); |
| 545 |
printf( "\n" ); |
| 546 |
printf( "\tunitsPerEm=%d\n", getushort(ttf)); |
| 547 |
printf( "\tcreate[0]=%x\n", (unsigned int)(getlong(ttf)) ); |
| 548 |
printf( "\t create[1]=%x\n", (unsigned int)(getlong(ttf)) ); |
| 549 |
fseek(ttf,-8,SEEK_CUR); |
| 550 |
unix_date = readdate(ttf); |
| 551 |
printf( "\tFile created: %s", ctime(&unix_date)); |
| 552 |
printf( "\tmodtime[0]=%x\n", (unsigned int)(getlong(ttf)) ); |
| 553 |
printf( "\t modtime[1]=%x\n", (unsigned int)(getlong(ttf)) ); |
| 554 |
fseek(ttf,-8,SEEK_CUR); |
| 555 |
unix_date = readdate(ttf); |
| 556 |
printf( "\tFile modified: %s", ctime(&unix_date)); |
| 557 |
printf( "\txmin=%d\n", (short) getushort(ttf)); |
| 558 |
printf( "\tymin=%d\n", (short) getushort(ttf)); |
| 559 |
printf( "\txmax=%d\n", (short) getushort(ttf)); |
| 560 |
printf( "\tymax=%d\n", (short) getushort(ttf)); |
| 561 |
printf( "\tmacstyle=%x\n", (unsigned int)(getushort(ttf)) ); |
| 562 |
printf( "\tlowestppem=%d\n", getushort(ttf)); |
| 563 |
printf( "\tfontdirhint=%d ", fd = getushort(ttf)); |
| 564 |
switch ( fd ) { |
| 565 |
case 0: printf("mixed directional glyphs\n" ); break; |
| 566 |
case 1: printf("strongly left to right glyphs\n" ); break; |
| 567 |
case 2: printf("left to right and neutrals\n" ); break; |
| 568 |
case -1: printf("strongly right to left glyphs\n" ); break; |
| 569 |
case -2: printf("right to left and neutrals\n" ); break; |
| 570 |
default: printf("???\n" ); break; |
| 571 |
} |
| 572 |
printf( "\tloca_is_32=%d\n", info->index_to_loc_is_long = getushort(ttf)); |
| 573 |
if ( info->index_to_loc_is_long ) |
| 574 |
info->glyph_cnt = info->loca_length/4-1; |
| 575 |
printf( "\tglyphdataformat=%d\n", getushort(ttf)); |
| 576 |
} |
| 577 |
|
| 578 |
static void readttfhhead(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 579 |
|
| 580 |
fseek(ttf,info->hhea_start,SEEK_SET); |
| 581 |
printf( "\nHHEAD table (at %d)\n", info->hhea_start ); |
| 582 |
printf( "\tVersion=%g\n", getfixed(ttf)); |
| 583 |
printf( "\tascender=%d\n", (short) getushort(ttf)); |
| 584 |
printf( "\tdescender=%d\n", (short) getushort(ttf)); |
| 585 |
printf( "\tlinegap=%d\n", (short) getushort(ttf)); |
| 586 |
printf( "\tadvanceWidthMax=%d\n", getushort(ttf)); |
| 587 |
printf( "\tminlsb=%d\n", (short) getushort(ttf)); |
| 588 |
printf( "\tminrsb=%d\n", (short) getushort(ttf)); |
| 589 |
printf( "\tmaxextent=%d\n", (short) getushort(ttf)); |
| 590 |
printf( "\tcaretsloperise=%d\n", (short) getushort(ttf)); |
| 591 |
printf( "\tcaretsloperun=%d\n", (short) getushort(ttf)); |
| 592 |
printf( "\tmbz=%d\n", (short) getushort(ttf)); |
| 593 |
printf( "\tmbz=%d\n", (short) getushort(ttf)); |
| 594 |
printf( "\tmbz=%d\n", (short) getushort(ttf)); |
| 595 |
printf( "\tmbz=%d\n", (short) getushort(ttf)); |
| 596 |
printf( "\tmbz=%d\n", (short) getushort(ttf)); |
| 597 |
printf( "\tmetricdataformat=%d\n", (short) getushort(ttf)); |
| 598 |
printf( "\tnumberOfHMetrics=%d\n", getushort(ttf)); |
| 599 |
} |
| 600 |
|
| 601 |
static char *getttfname(FILE *util, struct ttfinfo *info, int nameid) { |
| 602 |
int nrec, taboff, stroff, strlen, platform; |
| 603 |
int i,j,id; |
| 604 |
|
| 605 |
fseek(util,info->copyright_start,SEEK_SET); |
| 606 |
getushort(util); |
| 607 |
nrec=getushort(util); |
| 608 |
taboff=getushort(util); |
| 609 |
for ( i=0; i<nrec; ++i ) { |
| 610 |
platform = getushort(util); |
| 611 |
getushort(util); |
| 612 |
getushort(util); |
| 613 |
id=getushort(util); |
| 614 |
strlen=getushort(util); |
| 615 |
stroff=getushort(util); |
| 616 |
if ( platform==1 && id==nameid ) { |
| 617 |
char *ret = malloc(strlen+2); |
| 618 |
fseek(util,info->copyright_start+taboff+stroff,SEEK_SET); |
| 619 |
for ( j=0; j<strlen; ++j ) |
| 620 |
ret[j] = getc(util); |
| 621 |
ret[strlen] = '\0'; |
| 622 |
ret[strlen+1] = '\0'; |
| 623 |
return( ret ); |
| 624 |
} |
| 625 |
} |
| 626 |
return( NULL ); |
| 627 |
} |
| 628 |
|
| 629 |
static void readttfname(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 630 |
int nrec, taboff, stroff, strlen; |
| 631 |
int i,j,id; |
| 632 |
|
| 633 |
fseek(ttf,info->copyright_start,SEEK_SET); |
| 634 |
printf( "\nNAME table (at %d)\n", info->copyright_start ); |
| 635 |
printf( "\tformat=%d\n", getushort(ttf)); |
| 636 |
printf( "\tnrecords=%d\n", nrec=getushort(ttf)); |
| 637 |
printf( "\ttaboff=%d\n", taboff=getushort(ttf)); |
| 638 |
for ( i=0; i<nrec; ++i ) { |
| 639 |
printf( "\t platform=%d", getushort(ttf)); |
| 640 |
printf( " plat spec encoding=%d", getushort(ttf)); |
| 641 |
printf( " language=%x", (unsigned int)(getushort(ttf)) ); |
| 642 |
printf( " name=%d ", id=getushort(ttf)); |
| 643 |
|
| 644 |
printf( id==0?"Copyright\n":id==1?"Family\n":id==2?"Subfamily\n":id==3? |
| 645 |
"UniqueID\n":id==4?"FullName\n":id==5?"Version\n":id==6?"Postscript\n": |
| 646 |
id==7?"Trademark\n": |
| 647 |
|
| 648 |
id==8?"Manufacturer\n": |
| 649 |
id==9?"Designer\n": |
| 650 |
id==10?"Descriptor\n": |
| 651 |
id==11?"Vendor URL\n": |
| 652 |
id==12?"Designer URL\n": |
| 653 |
|
| 654 |
id==13?"License\n": |
| 655 |
|
| 656 |
id==14?"License URL\n": |
| 657 |
|
| 658 |
id==16?"Preferred Family Name\n": |
| 659 |
id==17?"Preferred Subfamily\n": |
| 660 |
id==18?"Compatible full\n": |
| 661 |
id==19?"Sample Text\n": |
| 662 |
|
| 663 |
"???????\n"); |
| 664 |
printf( "\t strlen=%d ", strlen=getushort(ttf)); |
| 665 |
printf( " stroff=%d\t ", stroff=getushort(ttf)); |
| 666 |
fseek(util,info->copyright_start+taboff+stroff,SEEK_SET); |
| 667 |
for ( j=0; j<strlen; ++j ) { |
| 668 |
int ch = getc(util); |
| 669 |
if ( ch<' ' ) { |
| 670 |
putchar('^'); |
| 671 |
putchar(ch+'@'); |
| 672 |
} else if ( ch=='\177' ) { |
| 673 |
putchar('^'); |
| 674 |
putchar('?'); |
| 675 |
} else if ( ch>=0x80 && ch<0xa0 ) { |
| 676 |
printf("<%2X>", (unsigned int)(ch) ); |
| 677 |
} else |
| 678 |
putchar(ch); |
| 679 |
} |
| 680 |
putchar('\n'); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
static void readttfmaxp(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 685 |
int ng; |
| 686 |
|
| 687 |
fseek(ttf,info->maxp_start,SEEK_SET); |
| 688 |
printf( "\nMAXP table (at %d)\n", info->maxp_start ); |
| 689 |
printf( "\tVersion=%g\n", getfixed(ttf)); |
| 690 |
printf( "\t numGlyphs=%d\n", ng = getushort(ttf)); |
| 691 |
info->glyph_cnt = ng; |
| 692 |
if ( info->maxp_length==6 ) |
| 693 |
return; |
| 694 |
printf( "\t maxPoints=%d\n", getushort(ttf)); |
| 695 |
printf( "\t maxContours=%d\n", getushort(ttf)); |
| 696 |
printf( "\t maxCompositPoints=%d\n", getushort(ttf)); |
| 697 |
printf( "\t maxCompositContours=%d\n", getushort(ttf)); |
| 698 |
printf( "\t maxZones=%d\n", getushort(ttf)); |
| 699 |
printf( "\t maxTwilightPoints=%d\n", getushort(ttf)); |
| 700 |
printf( "\t maxStorage=%d\n", getushort(ttf)); |
| 701 |
printf( "\t maxFunctionDefs=%d\n", getushort(ttf)); |
| 702 |
printf( "\t maxInstructionDefs=%d\n", getushort(ttf)); |
| 703 |
printf( "\t maxStackElements=%d\n", getushort(ttf)); |
| 704 |
printf( "\t maxSizeOfInstructions=%d\n", getushort(ttf)); |
| 705 |
printf( "\t maxComponentElements=%d\n", getushort(ttf)); |
| 706 |
printf( "\t maxComponentDepth=%d\n", getushort(ttf)); |
| 707 |
} |
| 708 |
|
| 709 |
static void readttfcvt(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 710 |
int i; |
| 711 |
|
| 712 |
if ( info->cvt_start==0 ) |
| 713 |
return; |
| 714 |
fseek(ttf,info->cvt_start,SEEK_SET); |
| 715 |
printf( "\nCVT table (at %d, len=%d)\n", info->cvt_start, info->cvt_length ); |
| 716 |
for ( i=0; i<info->cvt_length/2; ++i ) |
| 717 |
printf( " CVT[%d] = %d\n", i, (short) getushort(ttf)); |
| 718 |
} |
| 719 |
|
| 720 |
static void readttfos2(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 721 |
int i, val; |
| 722 |
static const char *weights[] = { "Unspecified", "Thin", "Extra-Light", "Light", "Normal", "Medium", "Semi-Bold", "Bold", "Extra-Bold", "Black", "???" }; |
| 723 |
static const char *widths[] = { "Unspecified", "Ultra-Condensed", "Extra-Condensed", "Condensed", "Semi-Condensed", "Medium", "Semi-Expanded", "Expanded", "Extra-Expanded", "Ultra-Expanded", "???" }; |
| 724 |
static const char *class[16] = { "No classification", "Old Style Serifs", "Transitional Serifs", "Modern Serifs", "Clarendon Serifs", "Slab Serifs", "???", "Freeform Serifs", "Sans Serif", "Ornamentals", "Scripts", "???", "Symbolic", "???", "???", "???" }; |
| 725 |
static const char *subclass0[16] = { "", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 726 |
static const char *subclass1[16] = { "", "ibm rounded", "garalde", "venetian", "modified venetian", "dutch modern", "dutch traditional", "contemporary", "caligraphic", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 727 |
static const char *subclass2[16] = { "", "direct line", "script", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 728 |
static const char *subclass3[16] = { "", "italian", "script", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 729 |
static const char *subclass4[16] = { "", "clarendon", "modern", "traditional", "newspaper", "stub", "monotone", "typewriter", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 730 |
static const char *subclass5[16] = { "", "monotone", "humanist", "geometric", "swiss", "typewriter", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 731 |
static const char *subclass7[16] = { "", "modern", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 732 |
static const char *subclass8[16] = { "", "ibm neogrotesque", "humanist", "low-x rounded", "high-x rounded", "neo-grotesque", "modified neo-grotesque", "???", "???", "typewriter", "matrix", "???", "???", "???", "???", "Misc" }; |
| 733 |
static const char *subclass9[16] = { "", "engraver", "black letter", "decorative", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 734 |
static const char *subclass10[16] = { "", "???", "uncial", "brush joined", "formal joined", "monotone joined", "calligraphic", "brush unjoined", "formal unjoined", "monotone unjoined", "???", "???", "???", "???", "???", "Misc" }; |
| 735 |
static const char *subclass12[16] = { "", "???", "???", "mixed serif", "???", "???", "old style serif", "neo-grotesque sans", "???", "???", "???", "???", "???", "???", "???", "Misc" }; |
| 736 |
static const char **subclasses[16] = { subclass0, subclass1, subclass2, subclass3, |
| 737 |
subclass4, subclass5, subclass0, subclass7, subclass8, subclass9, |
| 738 |
subclass10, subclass0, subclass12, subclass0, subclass0, subclass0 }; |
| 739 |
static const char *panose0[] = { "Any", "No Fit", "Text & Display", "Script", "Decorative", "Pictoral" }; |
| 740 |
static const char *panose1[] = { "Any", "No Fit", "Cove", "Obtuse Cove", "Square Cove", "Obtuse Square Cove", "Square", "Thin", "Bone", "Exaggerated", "Triangle", "Normal Sans", "Obtuse Sans", "Perp Sans", "Flared", "Rounded" }; |
| 741 |
static const char *panose2[] = { "Any", "No Fit", "Very Light", "Light", "Thin", "Book", "Medium", "Demi", "Bold", "Heavy", "Black", "Nord" }; |
| 742 |
static const char *panose3[] = { "Any", "No Fit", "Old Style", "Modern", "Even Width", "Expanded", "Condensed", "Very Expanded", "Very Condensed", "Monospaced" }; |
| 743 |
static const char *panose4[] = { "Any", "No Fit", "None", "Very Low", "Low", "Medium Low", "Medium", "Medium High", "High", "Very High" }; |
| 744 |
static const char *panose5[] = { "Any", "No Fit", "No Variation", "Gradual/Diagonal", "Gradual/Transitional", "Gradual/Vertical", "Gradual/Horizontal", "Rapid/Vertical", "Rapid/Horizontal", "Instant/Vertical", "Instant/Horizontal" }; |
| 745 |
static const char *panose6[] = { "Any", "No Fit", "Straight Arms/Horizontal", "Straight Arms/Wedge", "Straight Arms/Vertical", "Straight Arms/Single Serif", "Straight Arms/Double Serif", "Non-Straight Arms/Horizontal", "Non-Straight Arms/Wedge", "Non-Straight Arms/Vertical", "Non-Straight Arms/Single Serif", "Non-Straight Arms/Double Serif" }; |
| 746 |
static const char *panose7[] = { "Any", "No Fit", "Normal/Contact", "Normal/Weighted", "Normal/Boxed", "Normal/Flattened", "Normal/Rounded", "Normal/Off-Center", "Normal/Square", "Oblique/Contact", "Oblique/Weighted", "Oblique/Boxed", "Oblique/Flattened", "Oblique/Rounded", "Oblique/Off-Center", "Oblique/Square" }; |
| 747 |
static const char *panose8[] = { "Any", "No Fit", "Standard/Trimmed", "Standard/Pointed", "Standard/Serifed", "High/Trimmed", "High/Pointed", "High/Serifed", "Constant/Trimmed", "Constant/Pointed", "Constant/Serifed", "Low/Trimmed", "Low/Pointed", "Low/Serifed" }; |
| 748 |
static const char *panose9[] = { "Any", "No Fit", "Constant/Small", "Constant/Standard", "Constant/Large", "Ducking/Small", "Ducking/Standard", "Ducking/Large" }; |
| 749 |
static struct { const char *name; char const *const *const choices; int cnt; } panose[10] = { |
| 750 |
{ "Family", panose0, sizeof(panose0) }, |
| 751 |
{ "Serif Type", panose1, sizeof(panose1) }, |
| 752 |
{ "Weight", panose2, sizeof(panose2) }, |
| 753 |
{ "Proportion", panose3, sizeof(panose3) }, |
| 754 |
{ "Contrast", panose4, sizeof(panose4) }, |
| 755 |
{ "Stroke Variation", panose5, sizeof(panose5) }, |
| 756 |
{ "Arm Style", panose6, sizeof(panose6) }, |
| 757 |
{ "Letterform", panose7, sizeof(panose7) }, |
| 758 |
{ "Midline", panose8, sizeof(panose8) }, |
| 759 |
{ "X-Height", panose9, sizeof(panose9) } }; |
| 760 |
|
| 761 |
fseek(ttf,info->os2_start,SEEK_SET); |
| 762 |
printf( "\nOS/2 table (at %d for %d bytes)\n", info->os2_start, info->os2_len ); |
| 763 |
printf( "\tVersion=%d\n", getushort(ttf)); |
| 764 |
printf( "\t avgWidth=%d\n", (short)getushort(ttf)); |
| 765 |
printf( "\t weightClass=%d ", val = getushort(ttf)); |
| 766 |
if ( val>=0 && val<=999 ) printf( "%s\n", weights[val/100] ); else printf( "???\n"); |
| 767 |
printf( "\t widthClass=%d ", val = getushort(ttf)); |
| 768 |
if ( val>=0 && val<=9 ) printf( "%s\n", widths[val] ); else printf( "???\n"); |
| 769 |
printf( "\t fstype=0x%x ", (unsigned int)((val = (short) getushort(ttf))) ); |
| 770 |
if ( val&0x8 ) printf( "Editable embedding\n"); |
| 771 |
else if ( val&0x4 ) printf( "Preview & Print embedding\n"); |
| 772 |
else if ( val&0x2 ) printf( "Restricted license embedding\n"); |
| 773 |
else printf( "\n"); |
| 774 |
printf( "\t ySubscript XSize=%d\n", (short) getushort(ttf)); |
| 775 |
printf( "\t ySubscript YSize=%d\n", (short) getushort(ttf)); |
| 776 |
printf( "\t ySubscript XOffset=%d\n", (short) getushort(ttf)); |
| 777 |
printf( "\t ySubscript YOffset=%d\n", (short) getushort(ttf)); |
| 778 |
printf( "\t ySupscript XSize=%d\n", (short) getushort(ttf)); |
| 779 |
printf( "\t ySupscript YSize=%d\n", (short) getushort(ttf)); |
| 780 |
printf( "\t ySupscript XOffset=%d\n", (short) getushort(ttf)); |
| 781 |
printf( "\t ySupscript YOffset=%d\n", (short) getushort(ttf)); |
| 782 |
printf( "\t yStrikeoutSize=%d\n", (short) getushort(ttf)); |
| 783 |
printf( "\t yStrikeoutPos=%d\n", (short) getushort(ttf)); |
| 784 |
printf( "\t sFamilyClass=%04x ", (unsigned int)((val = getushort(ttf))) ); |
| 785 |
if ( (val>>8)>=0 && (val>>8)<16 ) { |
| 786 |
printf( "%s ", class[val>>8]); |
| 787 |
if ( (val&0xff)<16 ) |
| 788 |
printf( "%s\n", subclasses[val>>8][val&0xff]); |
| 789 |
else |
| 790 |
printf( "???\n" ); |
| 791 |
} else printf ( "??? ???\n" ); |
| 792 |
printf( "\t Panose\n" ); |
| 793 |
for ( i=0; i<10; ++i ) { |
| 794 |
printf( "\t\t%s: %02x ", panose[i].name, (unsigned int)(val= getc(ttf)) ); |
| 795 |
if ( val>0 && val<panose[i].cnt ) printf( "%s\n", panose[i].choices[val]); |
| 796 |
else printf( "???\n" ); |
| 797 |
} |
| 798 |
printf( "\n"); |
| 799 |
printf( "\t UnicodeRange=%08x ", (unsigned int)(getlong(ttf)) ); |
| 800 |
printf( "%08x ", (unsigned int)(getlong(ttf)) ); |
| 801 |
printf( "%08x ", (unsigned int)(getlong(ttf)) ); |
| 802 |
printf( "%08x\n", (unsigned int)(getlong(ttf)) ); |
| 803 |
printf( "\t achVendId " ); |
| 804 |
for ( i=0; i<4; ++i ) |
| 805 |
printf( "%02x ", (unsigned int)(getc(ttf)) ); |
| 806 |
printf( "\n"); |
| 807 |
printf( "\t fsSelection=%d\n", getushort(ttf)); |
| 808 |
printf( "\t firstcharindex=%d\n", getushort(ttf)); |
| 809 |
printf( "\t lastcharindex=%d\n", getushort(ttf)); |
| 810 |
printf( "\t stypeascender=%d\n", getushort(ttf)); |
| 811 |
printf( "\t stypedescender=%d\n", (short) getushort(ttf)); |
| 812 |
printf( "\t stypelinegap=%d\n", getushort(ttf)); |
| 813 |
printf( "\t usWinAscent=%d\n", getushort(ttf)); |
| 814 |
printf( "\t usWinDescent=%d\n", (short) getushort(ttf)); |
| 815 |
if ( info->os2_len==78 ) { |
| 816 |
printf( "\t (no CodePageRange)\n" ); |
| 817 |
} else { |
| 818 |
printf( "\t CodePageRange=%08x ", (unsigned int)(getlong(ttf)) ); |
| 819 |
printf( "%08x\n", (unsigned int)(getlong(ttf)) ); |
| 820 |
if ( info->os2_len==96 ) { |
| 821 |
|
| 822 |
printf( "\txHeight=%d\n", (short) getushort(ttf)); |
| 823 |
printf( "\tCapHeight=%d\n", (short) getushort(ttf)); |
| 824 |
printf( "\tDefaultChar=%d\n", getushort(ttf)); |
| 825 |
printf( "\tBreakChar=%d\n", getushort(ttf)); |
| 826 |
printf( "\tMaxContext=%d\n", getushort(ttf)); |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
const unsigned short unicode_from_mac[] = { |
| 832 |
0x0000, 0x00d0, 0x00f0, 0x0141, 0x0142, 0x0160, 0x0161, 0x00dd, |
| 833 |
0x00fd, 0x0009, 0x000a, 0x00de, 0x00fe, 0x000d, 0x017d, 0x017e, |
| 834 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x00bd, 0x00bc, 0x00b9, |
| 835 |
0x00be, 0x00b3, 0x00b2, 0x00a6, 0x00ad, 0x00d7, 0x001e, 0x001f, |
| 836 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, |
| 837 |
0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 838 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, |
| 839 |
0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 840 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, |
| 841 |
0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 842 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, |
| 843 |
0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 844 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, |
| 845 |
0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 846 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, |
| 847 |
0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 848 |
0x00c4, 0x00c5, 0x00c7, 0x00c9, 0x00d1, 0x00d6, 0x00dc, 0x00e1, |
| 849 |
0x00e0, 0x00e2, 0x00e4, 0x00e3, 0x00e5, 0x00e7, 0x00e9, 0x00e8, |
| 850 |
0x00ea, 0x00eb, 0x00ed, 0x00ec, 0x00ee, 0x00ef, 0x00f1, 0x00f3, |
| 851 |
0x00f2, 0x00f4, 0x00f6, 0x00f5, 0x00fa, 0x00f9, 0x00fb, 0x00fc, |
| 852 |
0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df, |
| 853 |
0x00ae, 0x00a9, 0x2122, 0x00b4, 0x00a8, 0x2260, 0x00c6, 0x00d8, |
| 854 |
0x221e, 0x00b1, 0x2264, 0x2265, 0x00a5, 0x00b5, 0x2202, 0x2211, |
| 855 |
0x220f, 0x03c0, 0x222b, 0x00aa, 0x00ba, 0x2126, 0x00e6, 0x00f8, |
| 856 |
0x00bf, 0x00a1, 0x00ac, 0x221a, 0x0192, 0x2248, 0x2206, 0x00ab, |
| 857 |
0x00bb, 0x2026, 0x00a0, 0x00c0, 0x00c3, 0x00d5, 0x0152, 0x0153, |
| 858 |
0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x25ca, |
| 859 |
0x00ff, 0x0178, 0x2044, 0x00a4, 0x2039, 0x203a, 0xfb01, 0xfb02, |
| 860 |
0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x00c2, 0x00ca, 0x00c1, |
| 861 |
0x00cb, 0x00c8, 0x00cd, 0x00ce, 0x00cf, 0x00cc, 0x00d3, 0x00d4, |
| 862 |
0xf8ff, 0x00d2, 0x00da, 0x00db, 0x00d9, 0x0131, 0x02c6, 0x02dc, |
| 863 |
0x00af, 0x02d8, 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7 |
| 864 |
}; |
| 865 |
|
| 866 |
static const char *standardnames[258] = { |
| 867 |
".notdef", |
| 868 |
".null", |
| 869 |
"nonmarkingreturn", |
| 870 |
"space", |
| 871 |
"exclam", |
| 872 |
"quotedbl", |
| 873 |
"numbersign", |
| 874 |
"dollar", |
| 875 |
"percent", |
| 876 |
"ampersand", |
| 877 |
"quotesingle", |
| 878 |
"parenleft", |
| 879 |
"parenright", |
| 880 |
"asterisk", |
| 881 |
"plus", |
| 882 |
"comma", |
| 883 |
"hyphen", |
| 884 |
"period", |
| 885 |
"slash", |
| 886 |
"zero", |
| 887 |
"one", |
| 888 |
"two", |
| 889 |
"three", |
| 890 |
"four", |
| 891 |
"five", |
| 892 |
"six", |
| 893 |
"seven", |
| 894 |
"eight", |
| 895 |
"nine", |
| 896 |
"colon", |
| 897 |
"semicolon", |
| 898 |
"less", |
| 899 |
"equal", |
| 900 |
"greater", |
| 901 |
"question", |
| 902 |
"at", |
| 903 |
"A", |
| 904 |
"B", |
| 905 |
"C", |
| 906 |
"D", |
| 907 |
"E", |
| 908 |
"F", |
| 909 |
"G", |
| 910 |
"H", |
| 911 |
"I", |
| 912 |
"J", |
| 913 |
"K", |
| 914 |
"L", |
| 915 |
"M", |
| 916 |
"N", |
| 917 |
"O", |
| 918 |
"P", |
| 919 |
"Q", |
| 920 |
"R", |
| 921 |
"S", |
| 922 |
"T", |
| 923 |
"U", |
| 924 |
"V", |
| 925 |
"W", |
| 926 |
"X", |
| 927 |
"Y", |
| 928 |
"Z", |
| 929 |
"bracketleft", |
| 930 |
"backslash", |
| 931 |
"bracketright", |
| 932 |
"asciicircum", |
| 933 |
"underscore", |
| 934 |
"grave", |
| 935 |
"a", |
| 936 |
"b", |
| 937 |
"c", |
| 938 |
"d", |
| 939 |
"e", |
| 940 |
"f", |
| 941 |
"g", |
| 942 |
"h", |
| 943 |
"i", |
| 944 |
"j", |
| 945 |
"k", |
| 946 |
"l", |
| 947 |
"m", |
| 948 |
"n", |
| 949 |
"o", |
| 950 |
"p", |
| 951 |
"q", |
| 952 |
"r", |
| 953 |
"s", |
| 954 |
"t", |
| 955 |
"u", |
| 956 |
"v", |
| 957 |
"w", |
| 958 |
"x", |
| 959 |
"y", |
| 960 |
"z", |
| 961 |
"braceleft", |
| 962 |
"bar", |
| 963 |
"braceright", |
| 964 |
"asciitilde", |
| 965 |
"Adieresis", |
| 966 |
"Aring", |
| 967 |
"Ccedilla", |
| 968 |
"Eacute", |
| 969 |
"Ntilde", |
| 970 |
"Odieresis", |
| 971 |
"Udieresis", |
| 972 |
"aacute", |
| 973 |
"agrave", |
| 974 |
"acircumflex", |
| 975 |
"adieresis", |
| 976 |
"atilde", |
| 977 |
"aring", |
| 978 |
"ccedilla", |
| 979 |
"eacute", |
| 980 |
"egrave", |
| 981 |
"ecircumflex", |
| 982 |
"edieresis", |
| 983 |
"iacute", |
| 984 |
"igrave", |
| 985 |
"icircumflex", |
| 986 |
"idieresis", |
| 987 |
"ntilde", |
| 988 |
"oacute", |
| 989 |
"ograve", |
| 990 |
"ocircumflex", |
| 991 |
"odieresis", |
| 992 |
"otilde", |
| 993 |
"uacute", |
| 994 |
"ugrave", |
| 995 |
"ucircumflex", |
| 996 |
"udieresis", |
| 997 |
"dagger", |
| 998 |
"degree", |
| 999 |
"cent", |
| 1000 |
"sterling", |
| 1001 |
"section", |
| 1002 |
"bullet", |
| 1003 |
"paragraph", |
| 1004 |
"germandbls", |
| 1005 |
"registered", |
| 1006 |
"copyright", |
| 1007 |
"trademark", |
| 1008 |
"acute", |
| 1009 |
"dieresis", |
| 1010 |
"notequal", |
| 1011 |
"AE", |
| 1012 |
"Oslash", |
| 1013 |
"infinity", |
| 1014 |
"plusminus", |
| 1015 |
"lessequal", |
| 1016 |
"greaterequal", |
| 1017 |
"yen", |
| 1018 |
"mu", |
| 1019 |
"partialdiff", |
| 1020 |
"summation", |
| 1021 |
"product", |
| 1022 |
"pi", |
| 1023 |
"integral", |
| 1024 |
"ordfeminine", |
| 1025 |
"ordmasculine", |
| 1026 |
"Omega", |
| 1027 |
"ae", |
| 1028 |
"oslash", |
| 1029 |
"questiondown", |
| 1030 |
"exclamdown", |
| 1031 |
"logicalnot", |
| 1032 |
"radical", |
| 1033 |
"florin", |
| 1034 |
"approxequal", |
| 1035 |
"Delta", |
| 1036 |
"guillemotleft", |
| 1037 |
"guillemotright", |
| 1038 |
"ellipsis", |
| 1039 |
"nonbreakingspace", |
| 1040 |
"Agrave", |
| 1041 |
"Atilde", |
| 1042 |
"Otilde", |
| 1043 |
"OE", |
| 1044 |
"oe", |
| 1045 |
"endash", |
| 1046 |
"emdash", |
| 1047 |
"quotedblleft", |
| 1048 |
"quotedblright", |
| 1049 |
"quoteleft", |
| 1050 |
"quoteright", |
| 1051 |
"divide", |
| 1052 |
"lozenge", |
| 1053 |
"ydieresis", |
| 1054 |
"Ydieresis", |
| 1055 |
"fraction", |
| 1056 |
"currency", |
| 1057 |
"guilsinglleft", |
| 1058 |
"guilsinglright", |
| 1059 |
"fi", |
| 1060 |
"fl", |
| 1061 |
"daggerdbl", |
| 1062 |
"periodcentered", |
| 1063 |
"quotesinglbase", |
| 1064 |
"quotedblbase", |
| 1065 |
"perthousand", |
| 1066 |
"Acircumflex", |
| 1067 |
"Ecircumflex", |
| 1068 |
"Aacute", |
| 1069 |
"Edieresis", |
| 1070 |
"Egrave", |
| 1071 |
"Iacute", |
| 1072 |
"Icircumflex", |
| 1073 |
"Idieresis", |
| 1074 |
"Igrave", |
| 1075 |
"Oacute", |
| 1076 |
"Ocircumflex", |
| 1077 |
"apple", |
| 1078 |
"Ograve", |
| 1079 |
"Uacute", |
| 1080 |
"Ucircumflex", |
| 1081 |
"Ugrave", |
| 1082 |
"dotlessi", |
| 1083 |
"circumflex", |
| 1084 |
"tilde", |
| 1085 |
"macron", |
| 1086 |
"breve", |
| 1087 |
"dotaccent", |
| 1088 |
"ring", |
| 1089 |
"cedilla", |
| 1090 |
"hungarumlaut", |
| 1091 |
"ogonek", |
| 1092 |
"caron", |
| 1093 |
"Lslash", |
| 1094 |
"lslash", |
| 1095 |
"Scaron", |
| 1096 |
"scaron", |
| 1097 |
"Zcaron", |
| 1098 |
"zcaron", |
| 1099 |
"brokenbar", |
| 1100 |
"Eth", |
| 1101 |
"eth", |
| 1102 |
"Yacute", |
| 1103 |
"yacute", |
| 1104 |
"Thorn", |
| 1105 |
"thorn", |
| 1106 |
"minus", |
| 1107 |
"multiply", |
| 1108 |
"onesuperior", |
| 1109 |
"twosuperior", |
| 1110 |
"threesuperior", |
| 1111 |
"onehalf", |
| 1112 |
"onequarter", |
| 1113 |
"threequarters", |
| 1114 |
"franc", |
| 1115 |
"Gbreve", |
| 1116 |
"gbreve", |
| 1117 |
"Idotaccent", |
| 1118 |
"Scedilla", |
| 1119 |
"scedilla", |
| 1120 |
"Cacute", |
| 1121 |
"cacute", |
| 1122 |
"Ccaron", |
| 1123 |
"ccaron", |
| 1124 |
"dcroat" |
| 1125 |
}; |
| 1126 |
|
| 1127 |
|
| 1128 |
const char *cffnames[] = { |
| 1129 |
".notdef", |
| 1130 |
"space", |
| 1131 |
"exclam", |
| 1132 |
"quotedbl", |
| 1133 |
"numbersign", |
| 1134 |
"dollar", |
| 1135 |
"percent", |
| 1136 |
"ampersand", |
| 1137 |
"quoteright", |
| 1138 |
"parenleft", |
| 1139 |
"parenright", |
| 1140 |
"asterisk", |
| 1141 |
"plus", |
| 1142 |
"comma", |
| 1143 |
"hyphen", |
| 1144 |
"period", |
| 1145 |
"slash", |
| 1146 |
"zero", |
| 1147 |
"one", |
| 1148 |
"two", |
| 1149 |
"three", |
| 1150 |
"four", |
| 1151 |
"five", |
| 1152 |
"six", |
| 1153 |
"seven", |
| 1154 |
"eight", |
| 1155 |
"nine", |
| 1156 |
"colon", |
| 1157 |
"semicolon", |
| 1158 |
"less", |
| 1159 |
"equal", |
| 1160 |
"greater", |
| 1161 |
"question", |
| 1162 |
"at", |
| 1163 |
"A", |
| 1164 |
"B", |
| 1165 |
"C", |
| 1166 |
"D", |
| 1167 |
"E", |
| 1168 |
"F", |
| 1169 |
"G", |
| 1170 |
"H", |
| 1171 |
"I", |
| 1172 |
"J", |
| 1173 |
"K", |
| 1174 |
"L", |
| 1175 |
"M", |
| 1176 |
"N", |
| 1177 |
"O", |
| 1178 |
"P", |
| 1179 |
"Q", |
| 1180 |
"R", |
| 1181 |
"S", |
| 1182 |
"T", |
| 1183 |
"U", |
| 1184 |
"V", |
| 1185 |
"W", |
| 1186 |
"X", |
| 1187 |
"Y", |
| 1188 |
"Z", |
| 1189 |
"bracketleft", |
| 1190 |
"backslash", |
| 1191 |
"bracketright", |
| 1192 |
"asciicircum", |
| 1193 |
"underscore", |
| 1194 |
"quoteleft", |
| 1195 |
"a", |
| 1196 |
"b", |
| 1197 |
"c", |
| 1198 |
"d", |
| 1199 |
"e", |
| 1200 |
"f", |
| 1201 |
"g", |
| 1202 |
"h", |
| 1203 |
"i", |
| 1204 |
"j", |
| 1205 |
"k", |
| 1206 |
"l", |
| 1207 |
"m", |
| 1208 |
"n", |
| 1209 |
"o", |
| 1210 |
"p", |
| 1211 |
"q", |
| 1212 |
"r", |
| 1213 |
"s", |
| 1214 |
"t", |
| 1215 |
"u", |
| 1216 |
"v", |
| 1217 |
"w", |
| 1218 |
"x", |
| 1219 |
"y", |
| 1220 |
"z", |
| 1221 |
"braceleft", |
| 1222 |
"bar", |
| 1223 |
"braceright", |
| 1224 |
"asciitilde", |
| 1225 |
"exclamdown", |
| 1226 |
"cent", |
| 1227 |
"sterling", |
| 1228 |
"fraction", |
| 1229 |
"yen", |
| 1230 |
"florin", |
| 1231 |
"section", |
| 1232 |
"currency", |
| 1233 |
"quotesingle", |
| 1234 |
"quotedblleft", |
| 1235 |
"guillemotleft", |
| 1236 |
"guilsinglleft", |
| 1237 |
"guilsinglright", |
| 1238 |
"fi", |
| 1239 |
"fl", |
| 1240 |
"endash", |
| 1241 |
"dagger", |
| 1242 |
"daggerdbl", |
| 1243 |
"periodcentered", |
| 1244 |
"paragraph", |
| 1245 |
"bullet", |
| 1246 |
"quotesinglbase", |
| 1247 |
"quotedblbase", |
| 1248 |
"quotedblright", |
| 1249 |
"guillemotright", |
| 1250 |
"ellipsis", |
| 1251 |
"perthousand", |
| 1252 |
"questiondown", |
| 1253 |
"grave", |
| 1254 |
"acute", |
| 1255 |
"circumflex", |
| 1256 |
"tilde", |
| 1257 |
"macron", |
| 1258 |
"breve", |
| 1259 |
"dotaccent", |
| 1260 |
"dieresis", |
| 1261 |
"ring", |
| 1262 |
"cedilla", |
| 1263 |
"hungarumlaut", |
| 1264 |
"ogonek", |
| 1265 |
"caron", |
| 1266 |
"emdash", |
| 1267 |
"AE", |
| 1268 |
"ordfeminine", |
| 1269 |
"Lslash", |
| 1270 |
"Oslash", |
| 1271 |
"OE", |
| 1272 |
"ordmasculine", |
| 1273 |
"ae", |
| 1274 |
"dotlessi", |
| 1275 |
"lslash", |
| 1276 |
"oslash", |
| 1277 |
"oe", |
| 1278 |
"germandbls", |
| 1279 |
"onesuperior", |
| 1280 |
"logicalnot", |
| 1281 |
"mu", |
| 1282 |
"trademark", |
| 1283 |
"Eth", |
| 1284 |
"onehalf", |
| 1285 |
"plusminus", |
| 1286 |
"Thorn", |
| 1287 |
"onequarter", |
| 1288 |
"divide", |
| 1289 |
"brokenbar", |
| 1290 |
"degree", |
| 1291 |
"thorn", |
| 1292 |
"threequarters", |
| 1293 |
"twosuperior", |
| 1294 |
"registered", |
| 1295 |
"minus", |
| 1296 |
"eth", |
| 1297 |
"multiply", |
| 1298 |
"threesuperior", |
| 1299 |
"copyright", |
| 1300 |
"Aacute", |
| 1301 |
"Acircumflex", |
| 1302 |
"Adieresis", |
| 1303 |
"Agrave", |
| 1304 |
"Aring", |
| 1305 |
"Atilde", |
| 1306 |
"Ccedilla", |
| 1307 |
"Eacute", |
| 1308 |
"Ecircumflex", |
| 1309 |
"Edieresis", |
| 1310 |
"Egrave", |
| 1311 |
"Iacute", |
| 1312 |
"Icircumflex", |
| 1313 |
"Idieresis", |
| 1314 |
"Igrave", |
| 1315 |
"Ntilde", |
| 1316 |
"Oacute", |
| 1317 |
"Ocircumflex", |
| 1318 |
"Odieresis", |
| 1319 |
"Ograve", |
| 1320 |
"Otilde", |
| 1321 |
"Scaron", |
| 1322 |
"Uacute", |
| 1323 |
"Ucircumflex", |
| 1324 |
"Udieresis", |
| 1325 |
"Ugrave", |
| 1326 |
"Yacute", |
| 1327 |
"Ydieresis", |
| 1328 |
"Zcaron", |
| 1329 |
"aacute", |
| 1330 |
"acircumflex", |
| 1331 |
"adieresis", |
| 1332 |
"agrave", |
| 1333 |
"aring", |
| 1334 |
"atilde", |
| 1335 |
"ccedilla", |
| 1336 |
"eacute", |
| 1337 |
"ecircumflex", |
| 1338 |
"edieresis", |
| 1339 |
"egrave", |
| 1340 |
"iacute", |
| 1341 |
"icircumflex", |
| 1342 |
"idieresis", |
| 1343 |
"igrave", |
| 1344 |
"ntilde", |
| 1345 |
"oacute", |
| 1346 |
"ocircumflex", |
| 1347 |
"odieresis", |
| 1348 |
"ograve", |
| 1349 |
"otilde", |
| 1350 |
"scaron", |
| 1351 |
"uacute", |
| 1352 |
"ucircumflex", |
| 1353 |
"udieresis", |
| 1354 |
"ugrave", |
| 1355 |
"yacute", |
| 1356 |
"ydieresis", |
| 1357 |
"zcaron", |
| 1358 |
"exclamsmall", |
| 1359 |
"Hungarumlautsmall", |
| 1360 |
"dollaroldstyle", |
| 1361 |
"dollarsuperior", |
| 1362 |
"ampersandsmall", |
| 1363 |
"Acutesmall", |
| 1364 |
"parenleftsuperior", |
| 1365 |
"parenrightsuperior", |
| 1366 |
"twodotenleader", |
| 1367 |
"onedotenleader", |
| 1368 |
"zerooldstyle", |
| 1369 |
"oneoldstyle", |
| 1370 |
"twooldstyle", |
| 1371 |
"threeoldstyle", |
| 1372 |
"fouroldstyle", |
| 1373 |
"fiveoldstyle", |
| 1374 |
"sixoldstyle", |
| 1375 |
"sevenoldstyle", |
| 1376 |
"eightoldstyle", |
| 1377 |
"nineoldstyle", |
| 1378 |
"commasuperior", |
| 1379 |
"threequartersemdash", |
| 1380 |
"periodsuperior", |
| 1381 |
"questionsmall", |
| 1382 |
"asuperior", |
| 1383 |
"bsuperior", |
| 1384 |
"centsuperior", |
| 1385 |
"dsuperior", |
| 1386 |
"esuperior", |
| 1387 |
"isuperior", |
| 1388 |
"lsuperior", |
| 1389 |
"msuperior", |
| 1390 |
"nsuperior", |
| 1391 |
"osuperior", |
| 1392 |
"rsuperior", |
| 1393 |
"ssuperior", |
| 1394 |
"tsuperior", |
| 1395 |
"ff", |
| 1396 |
"ffi", |
| 1397 |
"ffl", |
| 1398 |
"parenleftinferior", |
| 1399 |
"parenrightinferior", |
| 1400 |
"Circumflexsmall", |
| 1401 |
"hyphensuperior", |
| 1402 |
"Gravesmall", |
| 1403 |
"Asmall", |
| 1404 |
"Bsmall", |
| 1405 |
"Csmall", |
| 1406 |
"Dsmall", |
| 1407 |
"Esmall", |
| 1408 |
"Fsmall", |
| 1409 |
"Gsmall", |
| 1410 |
"Hsmall", |
| 1411 |
"Ismall", |
| 1412 |
"Jsmall", |
| 1413 |
"Ksmall", |
| 1414 |
"Lsmall", |
| 1415 |
"Msmall", |
| 1416 |
"Nsmall", |
| 1417 |
"Osmall", |
| 1418 |
"Psmall", |
| 1419 |
"Qsmall", |
| 1420 |
"Rsmall", |
| 1421 |
"Ssmall", |
| 1422 |
"Tsmall", |
| 1423 |
"Usmall", |
| 1424 |
"Vsmall", |
| 1425 |
"Wsmall", |
| 1426 |
"Xsmall", |
| 1427 |
"Ysmall", |
| 1428 |
"Zsmall", |
| 1429 |
"colonmonetary", |
| 1430 |
"onefitted", |
| 1431 |
"rupiah", |
| 1432 |
"Tildesmall", |
| 1433 |
"exclamdownsmall", |
| 1434 |
"centoldstyle", |
| 1435 |
"Lslashsmall", |
| 1436 |
"Scaronsmall", |
| 1437 |
"Zcaronsmall", |
| 1438 |
"Dieresissmall", |
| 1439 |
"Brevesmall", |
| 1440 |
"Caronsmall", |
| 1441 |
"Dotaccentsmall", |
| 1442 |
"Macronsmall", |
| 1443 |
"figuredash", |
| 1444 |
"hypheninferior", |
| 1445 |
"Ogoneksmall", |
| 1446 |
"Ringsmall", |
| 1447 |
"Cedillasmall", |
| 1448 |
"questiondownsmall", |
| 1449 |
"oneeighth", |
| 1450 |
"threeeighths", |
| 1451 |
"fiveeighths", |
| 1452 |
"seveneighths", |
| 1453 |
"onethird", |
| 1454 |
"twothirds", |
| 1455 |
"zerosuperior", |
| 1456 |
"foursuperior", |
| 1457 |
"fivesuperior", |
| 1458 |
"sixsuperior", |
| 1459 |
"sevensuperior", |
| 1460 |
"eightsuperior", |
| 1461 |
"ninesuperior", |
| 1462 |
"zeroinferior", |
| 1463 |
"oneinferior", |
| 1464 |
"twoinferior", |
| 1465 |
"threeinferior", |
| 1466 |
"fourinferior", |
| 1467 |
"fiveinferior", |
| 1468 |
"sixinferior", |
| 1469 |
"seveninferior", |
| 1470 |
"eightinferior", |
| 1471 |
"nineinferior", |
| 1472 |
"centinferior", |
| 1473 |
"dollarinferior", |
| 1474 |
"periodinferior", |
| 1475 |
"commainferior", |
| 1476 |
"Agravesmall", |
| 1477 |
"Aacutesmall", |
| 1478 |
"Acircumflexsmall", |
| 1479 |
"Atildesmall", |
| 1480 |
"Adieresissmall", |
| 1481 |
"Aringsmall", |
| 1482 |
"AEsmall", |
| 1483 |
"Ccedillasmall", |
| 1484 |
"Egravesmall", |
| 1485 |
"Eacutesmall", |
| 1486 |
"Ecircumflexsmall", |
| 1487 |
"Edieresissmall", |
| 1488 |
"Igravesmall", |
| 1489 |
"Iacutesmall", |
| 1490 |
"Icircumflexsmall", |
| 1491 |
"Idieresissmall", |
| 1492 |
"Ethsmall", |
| 1493 |
"Ntildesmall", |
| 1494 |
"Ogravesmall", |
| 1495 |
"Oacutesmall", |
| 1496 |
"Ocircumflexsmall", |
| 1497 |
"Otildesmall", |
| 1498 |
"Odieresissmall", |
| 1499 |
"OEsmall", |
| 1500 |
"Oslashsmall", |
| 1501 |
"Ugravesmall", |
| 1502 |
"Uacutesmall", |
| 1503 |
"Ucircumflexsmall", |
| 1504 |
"Udieresissmall", |
| 1505 |
"Yacutesmall", |
| 1506 |
"Thornsmall", |
| 1507 |
"Ydieresissmall", |
| 1508 |
"001.000", |
| 1509 |
"001.001", |
| 1510 |
"001.002", |
| 1511 |
"001.003", |
| 1512 |
"Black", |
| 1513 |
"Bold", |
| 1514 |
"Book", |
| 1515 |
"Light", |
| 1516 |
"Medium", |
| 1517 |
"Regular", |
| 1518 |
"Roman", |
| 1519 |
"Semibold", |
| 1520 |
NULL |
| 1521 |
}; |
| 1522 |
static const int nStdStrings = sizeof(cffnames)/sizeof(cffnames[0])-1; |
| 1523 |
|
| 1524 |
static const char *instrs[] = { |
| 1525 |
"SVTCA[y-axis]", |
| 1526 |
"SVTCA[x-axis]", |
| 1527 |
"SPVTCA[y-axis]", |
| 1528 |
"SPVTCA[x-axis]", |
| 1529 |
"SFVTCA[y-axis]", |
| 1530 |
"SFVTCA[x-axis]", |
| 1531 |
"SPVTL[parallel]", |
| 1532 |
"SPVTL[orthog]", |
| 1533 |
"SFVTL[parallel]", |
| 1534 |
"SFVTL[orthog]", |
| 1535 |
"SPVFS", |
| 1536 |
"SFVFS", |
| 1537 |
"GPV", |
| 1538 |
"GFV", |
| 1539 |
"SFVTPV", |
| 1540 |
"ISECT", |
| 1541 |
"SRP0", |
| 1542 |
"SRP1", |
| 1543 |
"SRP2", |
| 1544 |
"SZP0", |
| 1545 |
"SZP1", |
| 1546 |
"SZP2", |
| 1547 |
"SZPS", |
| 1548 |
"SLOOP", |
| 1549 |
"RTG", |
| 1550 |
"RTHG", |
| 1551 |
"SMD", |
| 1552 |
"ELSE", |
| 1553 |
"JMPR", |
| 1554 |
"SCVTCI", |
| 1555 |
"SSWCI", |
| 1556 |
"SSW", |
| 1557 |
"DUP", |
| 1558 |
"POP", |
| 1559 |
"CLEAR", |
| 1560 |
"SWAP", |
| 1561 |
"DEPTH", |
| 1562 |
"CINDEX", |
| 1563 |
"MINDEX", |
| 1564 |
"ALIGNPTS", |
| 1565 |
"Unknown28", |
| 1566 |
"UTP", |
| 1567 |
"LOOPCALL", |
| 1568 |
"CALL", |
| 1569 |
"FDEF", |
| 1570 |
"ENDF", |
| 1571 |
"MDAP[no round]", |
| 1572 |
"MDAP[round]", |
| 1573 |
"IUP[y]", |
| 1574 |
"IUP[x]", |
| 1575 |
"SHP[rp2]", |
| 1576 |
"SHP[rp1]", |
| 1577 |
"SHC[rp2]", |
| 1578 |
"SHC[rp1]", |
| 1579 |
"SHZ[rp2]", |
| 1580 |
"SHZ[rp1]", |
| 1581 |
"SHPIX", |
| 1582 |
"IP", |
| 1583 |
"MSIRP[no set rp0]", |
| 1584 |
"MSIRP[set rp0]", |
| 1585 |
"ALIGNRP", |
| 1586 |
"RTDG", |
| 1587 |
"MIAP[no round]", |
| 1588 |
"MIAP[round]", |
| 1589 |
"NPUSHB", |
| 1590 |
"NPUSHW", |
| 1591 |
"WS", |
| 1592 |
"RS", |
| 1593 |
"WCVTP", |
| 1594 |
"RCVT", |
| 1595 |
"GC[cur]", |
| 1596 |
"GC[orig]", |
| 1597 |
"SCFS", |
| 1598 |
"MD[grid]", |
| 1599 |
"MD[orig]", |
| 1600 |
"MPPEM", |
| 1601 |
"MPS", |
| 1602 |
"FLIPON", |
| 1603 |
"FLIPOFF", |
| 1604 |
"DEBUG", |
| 1605 |
"LT", |
| 1606 |
"LTEQ", |
| 1607 |
"GT", |
| 1608 |
"GTEQ", |
| 1609 |
"EQ", |
| 1610 |
"NEQ", |
| 1611 |
"ODD", |
| 1612 |
"EVEN", |
| 1613 |
"IF", |
| 1614 |
"EIF", |
| 1615 |
"AND", |
| 1616 |
"OR", |
| 1617 |
"NOT", |
| 1618 |
"DELTAP1", |
| 1619 |
"SDB", |
| 1620 |
"SDS", |
| 1621 |
"ADD", |
| 1622 |
"SUB", |
| 1623 |
"DIV", |
| 1624 |
"MUL", |
| 1625 |
"ABS", |
| 1626 |
"NEG", |
| 1627 |
"FLOOR", |
| 1628 |
"CEILING", |
| 1629 |
"ROUND[Grey]", |
| 1630 |
"ROUND[Black]", |
| 1631 |
"ROUND[White]", |
| 1632 |
"ROUND[Undef4]", |
| 1633 |
"NROUND[Grey]", |
| 1634 |
"NROUND[Black]", |
| 1635 |
"NROUND[White]", |
| 1636 |
"NROUND[Undef4]", |
| 1637 |
"WCVTF", |
| 1638 |
"DELTAP2", |
| 1639 |
"DELTAP3", |
| 1640 |
"DELTAC1", |
| 1641 |
"DELTAC2", |
| 1642 |
"DELTAC3", |
| 1643 |
"SROUND", |
| 1644 |
"S45ROUND", |
| 1645 |
"JROT", |
| 1646 |
"JROF", |
| 1647 |
"ROFF", |
| 1648 |
"Unknown7B", |
| 1649 |
"RUTG", |
| 1650 |
"RDTG", |
| 1651 |
"SANGW", |
| 1652 |
"AA", |
| 1653 |
"FLIPPT", |
| 1654 |
"FLIPRGON", |
| 1655 |
"FLIPRGOFF", |
| 1656 |
"Unknown83", |
| 1657 |
"Unknown84", |
| 1658 |
"SCANCTRL", |
| 1659 |
"SDPVTL0", |
| 1660 |
"SDPVTL1", |
| 1661 |
"GETINFO", |
| 1662 |
"IDEF", |
| 1663 |
"ROLL", |
| 1664 |
"MAX", |
| 1665 |
"MIN", |
| 1666 |
"SCANTYPE", |
| 1667 |
"INSTCTRL", |
| 1668 |
"Unknown8F", |
| 1669 |
"Unknown90", |
| 1670 |
"Unknown91", |
| 1671 |
"Unknown92", |
| 1672 |
"Unknown93", |
| 1673 |
"Unknown94", |
| 1674 |
"Unknown95", |
| 1675 |
"Unknown96", |
| 1676 |
"Unknown97", |
| 1677 |
"Unknown98", |
| 1678 |
"Unknown99", |
| 1679 |
"Unknown9A", |
| 1680 |
"Unknown9B", |
| 1681 |
"Unknown9C", |
| 1682 |
"Unknown9D", |
| 1683 |
"Unknown9E", |
| 1684 |
"Unknown9F", |
| 1685 |
"UnknownA0", |
| 1686 |
"UnknownA1", |
| 1687 |
"UnknownA2", |
| 1688 |
"UnknownA3", |
| 1689 |
"UnknownA4", |
| 1690 |
"UnknownA5", |
| 1691 |
"UnknownA6", |
| 1692 |
"UnknownA7", |
| 1693 |
"UnknownA8", |
| 1694 |
"UnknownA9", |
| 1695 |
"UnknownAA", |
| 1696 |
"UnknownAB", |
| 1697 |
"UnknownAC", |
| 1698 |
"UnknownAD", |
| 1699 |
"UnknownAE", |
| 1700 |
"UnknownAF", |
| 1701 |
"PUSHB [1]", |
| 1702 |
"PUSHB [2]", |
| 1703 |
"PUSHB [3]", |
| 1704 |
"PUSHB [4]", |
| 1705 |
"PUSHB [5]", |
| 1706 |
"PUSHB [6]", |
| 1707 |
"PUSHB [7]", |
| 1708 |
"PUSHB [8]", |
| 1709 |
"PUSHW [1]", |
| 1710 |
"PUSHW [2]", |
| 1711 |
"PUSHW [3]", |
| 1712 |
"PUSHW [4]", |
| 1713 |
"PUSHW [5]", |
| 1714 |
"PUSHW [6]", |
| 1715 |
"PUSHW [7]", |
| 1716 |
"PUSHW [8]", |
| 1717 |
"MDRP[grey]", |
| 1718 |
"MDRP[black]", |
| 1719 |
"MDRP[white]", |
| 1720 |
"MDRP03", |
| 1721 |
"MDRP[round, grey]", |
| 1722 |
"MDRP[round, black]", |
| 1723 |
"MDRP[round, white]", |
| 1724 |
"MDRP07", |
| 1725 |
"MDRP[minimum, grey]", |
| 1726 |
"MDRP[minimum, black]", |
| 1727 |
"MDRP[minimum, white]", |
| 1728 |
"MDRP0b", |
| 1729 |
"MDRP[minimum, round, grey]", |
| 1730 |
"MDRP[minimum, round, black]", |
| 1731 |
"MDRP[minimum, round, white]", |
| 1732 |
"MDRP0f", |
| 1733 |
"MDRP[rp0, grey]", |
| 1734 |
"MDRP[rp0, black]", |
| 1735 |
"MDRP[rp0, white]", |
| 1736 |
"MDRP13", |
| 1737 |
"MDRP[rp0, round, grey]", |
| 1738 |
"MDRP[rp0, round, black]", |
| 1739 |
"MDRP[rp0, round, white]", |
| 1740 |
"MDRP17", |
| 1741 |
"MDRP[rp0, minimum, grey]", |
| 1742 |
"MDRP[rp0, minimum, black]", |
| 1743 |
"MDRP[rp0, minimum, white]", |
| 1744 |
"MDRP1b", |
| 1745 |
"MDRP[rp0, minimum, round, grey]", |
| 1746 |
"MDRP[rp0, minimum, round, black]", |
| 1747 |
"MDRP[rp0, minimum, round, white]", |
| 1748 |
"MDRP1f", |
| 1749 |
"MIRP[grey]", |
| 1750 |
"MIRP[black]", |
| 1751 |
"MIRP[white]", |
| 1752 |
"MIRP03", |
| 1753 |
"MIRP[round, grey]", |
| 1754 |
"MIRP[round, black]", |
| 1755 |
"MIRP[round, white]", |
| 1756 |
"MIRP07", |
| 1757 |
"MIRP[minimum, grey]", |
| 1758 |
"MIRP[minimum, black]", |
| 1759 |
"MIRP[minimum, white]", |
| 1760 |
"MIRP0b", |
| 1761 |
"MIRP[minimum, round, grey]", |
| 1762 |
"MIRP[minimum, round, black]", |
| 1763 |
"MIRP[minimum, round, white]", |
| 1764 |
"MIRP0f", |
| 1765 |
"MIRP[rp0, grey]", |
| 1766 |
"MIRP[rp0, black]", |
| 1767 |
"MIRP[rp0, white]", |
| 1768 |
"MIRP13", |
| 1769 |
"MIRP[rp0, round, grey]", |
| 1770 |
"MIRP[rp0, round, black]", |
| 1771 |
"MIRP[rp0, round, white]", |
| 1772 |
"MIRP17", |
| 1773 |
"MIRP[rp0, minimum, grey]", |
| 1774 |
"MIRP[rp0, minimum, black]", |
| 1775 |
"MIRP[rp0, minimum, white]", |
| 1776 |
"MIRP1b", |
| 1777 |
"MIRP[rp0, minimum, round, grey]", |
| 1778 |
"MIRP[rp0, minimum, round, black]", |
| 1779 |
"MIRP[rp0, minimum, round, white]", |
| 1780 |
"MIRP1f" |
| 1781 |
}; |
| 1782 |
|
| 1783 |
static struct dup *makedup(int glyph, int uni, struct dup *prev) { |
| 1784 |
struct dup *d = calloc(1,sizeof(struct dup)); |
| 1785 |
|
| 1786 |
d->glyph = glyph; |
| 1787 |
d->enc = uni; |
| 1788 |
d->prev = prev; |
| 1789 |
return( d ); |
| 1790 |
} |
| 1791 |
|
| 1792 |
static void readttfencodings(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 1793 |
int i,j; |
| 1794 |
int nencs, version; |
| 1795 |
int enc = 0; |
| 1796 |
int platform, specific; |
| 1797 |
int offset, encoff; |
| 1798 |
int format, len; |
| 1799 |
uint16_t table[256]; |
| 1800 |
int segCount; |
| 1801 |
unsigned short *endchars, *startchars, *delta, *rangeOffset, *glyphs; |
| 1802 |
int index; |
| 1803 |
struct dup *dup; |
| 1804 |
int vs_map = -1; |
| 1805 |
|
| 1806 |
fseek(ttf,info->encoding_start,SEEK_SET); |
| 1807 |
printf( "\nEncoding (cmap) table (at %d)\n", info->encoding_start ); |
| 1808 |
version = getushort(ttf); |
| 1809 |
nencs = getushort(ttf); |
| 1810 |
if ( version!=0 && nencs==0 ) |
| 1811 |
nencs = version; |
| 1812 |
for ( i=0; i<nencs; ++i ) { |
| 1813 |
platform = getushort(ttf); |
| 1814 |
specific = getushort(ttf); |
| 1815 |
offset = (int) getlong(ttf); |
| 1816 |
if ( platform==3 ) { |
| 1817 |
enc = 1; |
| 1818 |
encoff = offset; |
| 1819 |
} else if ( platform==1 && specific==0 && enc!=1 ) { |
| 1820 |
enc = 2; |
| 1821 |
encoff = offset; |
| 1822 |
} else if ( platform==1 && specific==1 ) { |
| 1823 |
enc = 1; |
| 1824 |
encoff = offset; |
| 1825 |
} else if ( platform==0 && specific!=5 ) { |
| 1826 |
enc = 1; |
| 1827 |
encoff = offset; |
| 1828 |
} |
| 1829 |
printf( "platform=%d specific=%d offset=%d ", platform, specific, offset ); |
| 1830 |
if ( platform==3 ) { |
| 1831 |
if ( specific==0 ) printf( "MS Symbol\n" ); |
| 1832 |
else if ( specific==1 ) printf( "MS Unicode\n" ); |
| 1833 |
else if ( specific==2 ) printf( "MS Shift JIS\n" ); |
| 1834 |
else if ( specific==3 ) printf( "MS PRC\n" ); |
| 1835 |
else if ( specific==4 ) printf( "MS Big5\n" ); |
| 1836 |
else if ( specific==5 ) printf( "MS Wansung\n" ); |
| 1837 |
else if ( specific==6 ) printf( "MS Johab\n" ); |
| 1838 |
else if ( specific==10 ) printf( "MS UCS4\n" ); |
| 1839 |
else printf( "???\n" ); |
| 1840 |
} else if ( platform==1 ) { |
| 1841 |
if ( specific==0 ) printf( "Mac Roman\n" ); |
| 1842 |
else if ( specific==1 ) printf( "Japanese\n" ); |
| 1843 |
else if ( specific==2 ) printf( "Traditional Chinese\n" ); |
| 1844 |
else if ( specific==25 ) printf( "Simplified Chinese\n" ); |
| 1845 |
else if ( specific==3 ) printf( "Korean\n" ); |
| 1846 |
} else if ( platform==0 ) { |
| 1847 |
if ( specific==0 ) printf( "Unicode Default\n" ); |
| 1848 |
else if ( specific==1 ) printf( "Unicode 1.0\n" ); |
| 1849 |
else if ( specific==2 ) printf( "Unicode 1.1\n" ); |
| 1850 |
else if ( specific==3 ) printf( "Unicode 2.0+\n" ); |
| 1851 |
else if ( specific==4 ) printf( "Unicode UCS4\n" ); |
| 1852 |
else if ( specific==5 ) printf( "Unicode Variations\n" ); |
| 1853 |
else printf( "???\n" ); |
| 1854 |
if ( specific==5 ) |
| 1855 |
vs_map = offset; |
| 1856 |
} else printf( "???\n" ); |
| 1857 |
} |
| 1858 |
if ( enc!=0 ) { |
| 1859 |
info->glyph_unicode = calloc(info->glyph_cnt,sizeof(unsigned int)); |
| 1860 |
fseek(ttf,info->encoding_start+encoff,SEEK_SET); |
| 1861 |
format = getushort(ttf); |
| 1862 |
if ( format!=12 && format!=10 && format!=8 ) { |
| 1863 |
len = getushort(ttf); |
| 1864 |
printf( " Format=%d len=%d Language=%x\n", format, len, (unsigned int)(getushort(ttf)) ); |
| 1865 |
} else { |
| 1866 |
getushort(ttf); |
| 1867 |
len = (int) getlong(ttf); |
| 1868 |
printf( " Format=%d len=%d Language=%x\n", format, len, (unsigned int)(getlong(ttf)) ); |
| 1869 |
} |
| 1870 |
if ( format==0 ) { |
| 1871 |
printf( " Table: " ); |
| 1872 |
for ( i=0; i<len-6; ++i ) |
| 1873 |
printf( "%d ", table[i] = getc(ttf)); |
| 1874 |
putchar('\n'); |
| 1875 |
for ( i=0; i<256 && i<info->glyph_cnt && i<len-6; ++i ) |
| 1876 |
info->glyph_unicode[table[i]] = i; |
| 1877 |
} else if ( format==4 ) { |
| 1878 |
segCount = getushort(ttf)/2; |
| 1879 |
getushort(ttf); |
| 1880 |
getushort(ttf); |
| 1881 |
getushort(ttf); |
| 1882 |
endchars = malloc(segCount*sizeof(unsigned short)); |
| 1883 |
for ( i=0; i<segCount; ++i ) |
| 1884 |
endchars[i] = getushort(ttf); |
| 1885 |
if ( getushort(ttf)!=0 ) |
| 1886 |
fprintf(stderr,"Expected 0 in true type font"); |
| 1887 |
startchars = malloc(segCount*sizeof(unsigned short)); |
| 1888 |
for ( i=0; i<segCount; ++i ) |
| 1889 |
startchars[i] = getushort(ttf); |
| 1890 |
delta = malloc(segCount*sizeof(unsigned short)); |
| 1891 |
for ( i=0; i<segCount; ++i ) |
| 1892 |
delta[i] = getushort(ttf); |
| 1893 |
rangeOffset = malloc(segCount*sizeof(unsigned short)); |
| 1894 |
for ( i=0; i<segCount; ++i ) |
| 1895 |
rangeOffset[i] = getushort(ttf); |
| 1896 |
len -= 8*sizeof(unsigned short) + |
| 1897 |
4*segCount*sizeof(unsigned short); |
| 1898 |
if ( len<0 ) { |
| 1899 |
fprintf( stderr, "This font has an illegal format 4 subtable with too little space for all the segments.\n" ); |
| 1900 |
free(startchars); free(endchars); free(delta); free(rangeOffset); |
| 1901 |
return; |
| 1902 |
} |
| 1903 |
|
| 1904 |
|
| 1905 |
glyphs = malloc(len); |
| 1906 |
for ( i=0; i<len/2; ++i ) |
| 1907 |
glyphs[i] = getushort(ttf); |
| 1908 |
|
| 1909 |
printf( "Format 4 (Windows unicode), %d segments\n", segCount ); |
| 1910 |
|
| 1911 |
for ( i=0; i<segCount; ++i ) { |
| 1912 |
printf( " Segment=%d unicode-start=%04x end=%04x range-offset=%d delta=%d", |
| 1913 |
i, startchars[i], endchars[i], rangeOffset[i], delta[i]); |
| 1914 |
if ( rangeOffset[i]==0 ) |
| 1915 |
printf( " glyph-start=%d gend=%d\n", startchars[i]+delta[i], endchars[i]+delta[i]); |
| 1916 |
else if ( rangeOffset[i]!=0xffff ) { |
| 1917 |
index = glyphs[ (i-segCount+rangeOffset[i]/2)]; |
| 1918 |
if ( index!=0 ) index += delta[i]; |
| 1919 |
printf( " glyph-start=%d", index ); |
| 1920 |
index = glyphs[ (i-segCount+rangeOffset[i]/2) + endchars[i]-startchars[i]]; |
| 1921 |
if ( index!=0 ) index += delta[i]; |
| 1922 |
printf( " end=%d\n", index); |
| 1923 |
} else |
| 1924 |
printf ( " End\n" ); |
| 1925 |
|
| 1926 |
if ( rangeOffset[i]==0 ) { |
| 1927 |
for ( j=startchars[i]; j<=endchars[i]; ++j ) { |
| 1928 |
if ( ((unsigned short) (j+delta[i]))>=info->glyph_cnt ) |
| 1929 |
printf( "!!! Glyph index out of bounds! %d\n", (unsigned short) (j+delta[i]) ); |
| 1930 |
else if ( info->glyph_unicode[(unsigned short) (j+delta[i])] ) |
| 1931 |
info->dups = makedup((unsigned short) (j+delta[i]),j,info->dups); |
| 1932 |
else |
| 1933 |
info->glyph_unicode[(unsigned short) (j+delta[i])] = j; |
| 1934 |
} |
| 1935 |
} else if ( rangeOffset[i]!=0xffff ) { |
| 1936 |
|
| 1937 |
|
| 1938 |
for ( j=startchars[i]; j<=endchars[i]; ++j ) { |
| 1939 |
index = glyphs[ (i-segCount+rangeOffset[i]/2) + |
| 1940 |
j-startchars[i] ]; |
| 1941 |
if ( index!=0 ) { |
| 1942 |
index = (unsigned short) (index+delta[i]); |
| 1943 |
if ( index>=info->glyph_cnt || index<0 ) |
| 1944 |
printf( "!!! Glyph index out of bounds! %d\n", index ); |
| 1945 |
else if ( info->glyph_unicode[index]!=0 ) |
| 1946 |
info->dups = makedup(index,j,info->dups); |
| 1947 |
else |
| 1948 |
info->glyph_unicode[index] = j; |
| 1949 |
} |
| 1950 |
} |
| 1951 |
} |
| 1952 |
} |
| 1953 |
free(glyphs); |
| 1954 |
free(rangeOffset); |
| 1955 |
free(delta); |
| 1956 |
free(startchars); |
| 1957 |
free(endchars); |
| 1958 |
} else if ( format==6 ) { |
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
int first, count; |
| 1964 |
first = getushort(ttf); |
| 1965 |
count = getushort(ttf); |
| 1966 |
for ( i=0; i<count; ++i ) |
| 1967 |
info->glyph_unicode[getushort(ttf)] = first+i; |
| 1968 |
} else if ( format==2 ) { |
| 1969 |
int max_sub_head_key = 0, cnt, last; |
| 1970 |
struct subhead { uint16_t first, cnt, delta, rangeoff; } *subheads; |
| 1971 |
|
| 1972 |
for ( i=0; i<256; ++i ) { |
| 1973 |
table[i] = getushort(ttf)/8; |
| 1974 |
if ( table[i]>max_sub_head_key ) |
| 1975 |
max_sub_head_key = table[i]; |
| 1976 |
} |
| 1977 |
subheads = malloc((max_sub_head_key+1)*sizeof(struct subhead)); |
| 1978 |
for ( i=0; i<=max_sub_head_key; ++i ) { |
| 1979 |
subheads[i].first = getushort(ttf); |
| 1980 |
subheads[i].cnt = getushort(ttf); |
| 1981 |
subheads[i].delta = getushort(ttf); |
| 1982 |
subheads[i].rangeoff = (getushort(ttf)- |
| 1983 |
(max_sub_head_key-i)*sizeof(struct subhead)- |
| 1984 |
sizeof(short))/sizeof(short); |
| 1985 |
} |
| 1986 |
cnt = (len-(ftell(ttf)-(info->encoding_start+encoff)))/sizeof(short); |
| 1987 |
|
| 1988 |
|
| 1989 |
glyphs = malloc(cnt*sizeof(short)); |
| 1990 |
for ( i=0; i<cnt; ++i ) |
| 1991 |
glyphs[i] = getushort(ttf); |
| 1992 |
last = -1; |
| 1993 |
for ( i=0; i<256; ++i ) { |
| 1994 |
if ( table[i]==0 ) { |
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
if ( last!=-1 ) |
| 2001 |
index = 0; |
| 2002 |
else if ( i<subheads[0].first || i>=subheads[0].first+subheads[0].cnt || |
| 2003 |
subheads[0].rangeoff+(i-subheads[0].first)>=cnt ) |
| 2004 |
index = 0; |
| 2005 |
else if ( (index = glyphs[subheads[0].rangeoff+(i-subheads[0].first)])!= 0 ) |
| 2006 |
index = (uint32_t) (index+subheads[0].delta); |
| 2007 |
|
| 2008 |
if ( index!=0 && index<info->glyph_cnt ) { |
| 2009 |
if ( info->glyph_unicode[index]==0 ) |
| 2010 |
info->glyph_unicode[index] = i; |
| 2011 |
else |
| 2012 |
info->dups = makedup(index,i,info->dups); |
| 2013 |
} |
| 2014 |
} else { |
| 2015 |
int enc0, k = table[i]; |
| 2016 |
for ( j=0; j<subheads[k].cnt; ++j ) { |
| 2017 |
if ( subheads[k].rangeoff+j>=cnt ) |
| 2018 |
index = 0; |
| 2019 |
else if ( (index = glyphs[subheads[k].rangeoff+j])!= 0 ) |
| 2020 |
index = (uint16_t) (index+subheads[k].delta); |
| 2021 |
if ( index!=0 && index<info->glyph_cnt ) { |
| 2022 |
enc0 = (i<<8)|(j+subheads[k].first); |
| 2023 |
if ( info->glyph_unicode[index]==0 ) |
| 2024 |
info->glyph_unicode[index] = enc0; |
| 2025 |
else |
| 2026 |
info->dups = makedup(index,enc0,info->dups); |
| 2027 |
} |
| 2028 |
} |
| 2029 |
if ( last==-1 ) last = i; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
free(subheads); |
| 2033 |
free(glyphs); |
| 2034 |
} else if ( format==12 ) { |
| 2035 |
uint32_t ngroups, start, end, startglyph; |
| 2036 |
ngroups = getlong(ttf); |
| 2037 |
for ( j=0; j<ngroups; ++j ) { |
| 2038 |
start = getlong(ttf); |
| 2039 |
end = getlong(ttf); |
| 2040 |
startglyph = getlong(ttf); |
| 2041 |
for ( i=start; i<=end; ++i ) { |
| 2042 |
info->glyph_unicode[startglyph+i-start] = i; |
| 2043 |
} |
| 2044 |
} |
| 2045 |
} else if ( format==8 ) { |
| 2046 |
fprintf(stderr,"I don't support mixed 16/32 bit characters (no unicode surogates), format=%d", format); |
| 2047 |
} else if ( format==10 ) { |
| 2048 |
fprintf(stderr,"I don't support 32 bit characters format=%d", format); |
| 2049 |
} else { |
| 2050 |
fprintf(stderr,"Eh? Unknown encoding format=%d", format); |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
if ( info->glyph_unicode!=NULL ) { |
| 2055 |
for ( i=0; i<info->glyph_cnt && (format!=0 || i<256); ++i ) |
| 2056 |
printf( " Glyph %d -> U+%04X\n", i, info->glyph_unicode[i]); |
| 2057 |
for ( i=0; i<info->glyph_cnt; ++i ) if ( info->glyph_unicode[i]!=0 ) { |
| 2058 |
for ( j=i+1; j<info->glyph_cnt; ++j ) |
| 2059 |
if ( info->glyph_unicode[i]==info->glyph_unicode[j] ) |
| 2060 |
printf( "!!!Two glyphs %d and %d have the same encoding U+%04X", |
| 2061 |
i, j, info->glyph_unicode[i]); |
| 2062 |
} |
| 2063 |
if ( info->dups!=NULL ) { |
| 2064 |
printf("Some glyphs have multiple encodings:\n" ); |
| 2065 |
for ( dup = info->dups; dup!=NULL ; dup=dup->prev ) |
| 2066 |
printf( " Glyph %d -> U+%04X (primary=U+%04X)\n", |
| 2067 |
dup->glyph, |
| 2068 |
(unsigned int)(dup->enc), |
| 2069 |
(unsigned int)(info->glyph_unicode[dup->glyph]) ); |
| 2070 |
} |
| 2071 |
} else |
| 2072 |
printf( "Could not understand encoding table\n" ); |
| 2073 |
if ( vs_map!=-1 ) { |
| 2074 |
struct vs_data { int vs; uint32_t defoff, nondefoff; } *vs_data; |
| 2075 |
int cnt, rcnt; |
| 2076 |
|
| 2077 |
fseek(ttf,info->encoding_start+vs_map,SEEK_SET); |
| 2078 |
if ( getushort(ttf)!=14 ) { |
| 2079 |
fprintf( stderr, "A unicode variation subtable (platform=0,specific=5) must have format=14\n" ); |
| 2080 |
return; |
| 2081 |
} |
| 2082 |
len = getlong(ttf); |
| 2083 |
cnt = getlong(ttf); |
| 2084 |
printf( " Format=14 len=%d\n numVarSelRec=%d\n", len, cnt ); |
| 2085 |
vs_data = malloc( cnt*sizeof(struct vs_data)); |
| 2086 |
for ( i=0; i<cnt; ++i ) { |
| 2087 |
vs_data[i].vs = get3byte(ttf); |
| 2088 |
vs_data[i].defoff = getlong(ttf); |
| 2089 |
vs_data[i].nondefoff = getlong(ttf); |
| 2090 |
printf( " varSelector=%04x, defaultUVSOffset=%d nonDefaultOffset=%d\n", |
| 2091 |
(unsigned int)(vs_data[i].vs), |
| 2092 |
(int)(vs_data[i].defoff), |
| 2093 |
(int)(vs_data[i].nondefoff) ); |
| 2094 |
} |
| 2095 |
for ( i=0; i<cnt; ++i ) { |
| 2096 |
printf( " Variation Selector=%04x\n", (unsigned int)(vs_data[i].vs) ); |
| 2097 |
if ( vs_data[i].defoff!=0 ) { |
| 2098 |
fseek(ttf,info->encoding_start+vs_map+vs_data[i].defoff,SEEK_SET); |
| 2099 |
rcnt = getlong(ttf); |
| 2100 |
printf( " Default glyphs\n %d ranges\n", rcnt ); |
| 2101 |
for ( j=0; j<rcnt; ++j ) { |
| 2102 |
int uni = get3byte(ttf); |
| 2103 |
printf( " U+%04x and %d code points following that\n", |
| 2104 |
(unsigned int)(uni), getc(ttf)); |
| 2105 |
} |
| 2106 |
} |
| 2107 |
if ( vs_data[i].nondefoff!=0 ) { |
| 2108 |
fseek(ttf,info->encoding_start+vs_map+vs_data[i].nondefoff,SEEK_SET); |
| 2109 |
rcnt = getlong(ttf); |
| 2110 |
printf( " non Default glyphs\n %d mappings\n", rcnt ); |
| 2111 |
for ( j=0; j<rcnt; ++j ) { |
| 2112 |
int uni = get3byte(ttf); |
| 2113 |
printf( " U+%04x.U+%04x -> GID %d\n", |
| 2114 |
(unsigned int)(uni), (unsigned int)(vs_data[i].vs), getushort(ttf) ); |
| 2115 |
} |
| 2116 |
} |
| 2117 |
} |
| 2118 |
} |
| 2119 |
} |
| 2120 |
|
| 2121 |
static void readttfpost(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 2122 |
int i,j,ind, extras; |
| 2123 |
int format, gc, len; |
| 2124 |
uint16_t *indexes, *glyphs; |
| 2125 |
char **names, *name; |
| 2126 |
|
| 2127 |
fseek(ttf,info->postscript_start,SEEK_SET); |
| 2128 |
printf( "\npost table (at %d)\n", info->postscript_start ); |
| 2129 |
printf( "\t format=%08x\n", (unsigned int)((format = (int) getlong(ttf))) ); |
| 2130 |
printf( "\t italicAngle=%g\n", getfixed(ttf)); |
| 2131 |
printf( "\t underlinePos=%d\n", (short) getushort(ttf)); |
| 2132 |
printf( "\t underlineWidth=%d\n", getushort(ttf)); |
| 2133 |
printf( "\t fixedpitch=%d\n", (int) getlong(ttf)); |
| 2134 |
printf( "\t mem1=%d\n", (int) getlong(ttf)); |
| 2135 |
printf( "\t mem2=%d\n", (int) getlong(ttf)); |
| 2136 |
printf( "\t mem3=%d\n", (int) getlong(ttf)); |
| 2137 |
printf( "\t mem4=%d\n", (int) getlong(ttf)); |
| 2138 |
|
| 2139 |
gc = 0; names = NULL; |
| 2140 |
if ( format==0x00030000 ) { |
| 2141 |
|
| 2142 |
|
| 2143 |
} else if ( format==0x00020000 ) { |
| 2144 |
gc = getushort(ttf); |
| 2145 |
if ( gc!=info->glyph_cnt ) |
| 2146 |
fprintf( stderr, "!!!! Post table glyph count does not match that in 'maxp'\n" ); |
| 2147 |
indexes = calloc(65536,sizeof(uint16_t)); |
| 2148 |
glyphs = calloc(gc,sizeof(uint16_t)); |
| 2149 |
names = calloc(gc<info->glyph_cnt?info->glyph_cnt:gc,sizeof(char *)); |
| 2150 |
|
| 2151 |
extras = 0; |
| 2152 |
for ( i=0; i<gc; ++i ) { |
| 2153 |
ind = getushort(ttf); |
| 2154 |
if ( ind>=258 ) ++extras; |
| 2155 |
indexes[ind] = i; |
| 2156 |
glyphs[i] = ind; |
| 2157 |
} |
| 2158 |
for ( i=258; i<258+extras; ++i ) { |
| 2159 |
if ( indexes[i]==0 ) |
| 2160 |
break; |
| 2161 |
len = getc(ttf); |
| 2162 |
name = malloc(len+1); |
| 2163 |
for ( j=0; j<len; ++j ) |
| 2164 |
name[j] = getc(ttf); |
| 2165 |
name[j] = '\0'; |
| 2166 |
names[indexes[i]] = name; |
| 2167 |
} |
| 2168 |
for ( i=0; i<gc; ++i ) { |
| 2169 |
printf( "Glyph %d (name index=%d) -> \"", i, glyphs[i] ); |
| 2170 |
if ( names[i]!=NULL ) |
| 2171 |
printf( "%s", names[i]); |
| 2172 |
else if ( glyphs[i]<258 ) { |
| 2173 |
printf( "%s", standardnames[glyphs[i]]); |
| 2174 |
names[i] = strdup(standardnames[glyphs[i]]); |
| 2175 |
} else |
| 2176 |
printf( "Gleep!!!!! %d", glyphs[i]); |
| 2177 |
if ( info->glyph_unicode!=NULL ) |
| 2178 |
printf("\"\t U+%04X\n", info->glyph_unicode[i]); |
| 2179 |
else |
| 2180 |
printf( "\"\n" ); |
| 2181 |
} |
| 2182 |
free(indexes); |
| 2183 |
free(glyphs); |
| 2184 |
info->glyph_names = names; |
| 2185 |
} |
| 2186 |
if ( info->glyph_unicode!=NULL ) { |
| 2187 |
if ( info->glyph_names==NULL ) |
| 2188 |
info->glyph_names = calloc(info->glyph_cnt,sizeof(char *)); |
| 2189 |
for ( i=0; i<info->glyph_cnt ; ++i ) { |
| 2190 |
if ( info->glyph_names[i]!=NULL ) |
| 2191 |
; |
| 2192 |
else if ( info->glyph_unicode[i]!=0 && info->glyph_unicode[i]!=0xffff ) { |
| 2193 |
char buffer[40]; |
| 2194 |
sprintf(buffer,">U+%04X<", info->glyph_unicode[i]); |
| 2195 |
info->glyph_names[i] = strdup(buffer); |
| 2196 |
} |
| 2197 |
} |
| 2198 |
} else if ( info->glyph_names!=NULL ) { |
| 2199 |
for ( i=0; i<gc; ++i ) |
| 2200 |
free(names[i]); |
| 2201 |
free(names); |
| 2202 |
} |
| 2203 |
} |
| 2204 |
|
| 2205 |
static void showlangsys(FILE *ttf,int script_start, uint16_t ls_off, uint32_t ls_name ) { |
| 2206 |
int i,cnt; |
| 2207 |
|
| 2208 |
if ( ls_name==0 ) |
| 2209 |
printf( "\t Language System table for default language\n" ); |
| 2210 |
else |
| 2211 |
printf( "\t Language System table for '%c%c%c%c'\n", |
| 2212 |
(char)((ls_name>>24)&0xff), (char)((ls_name>>16)&0xff), |
| 2213 |
(char)((ls_name>>8)&0xff), (char)(ls_name&0xff) ); |
| 2214 |
fseek(ttf,script_start+ls_off,SEEK_SET); |
| 2215 |
printf( "\t LookupOrder=%d\n", getushort(ttf)); |
| 2216 |
printf( "\t Required Feature Index=%d\n", (short) getushort(ttf)); |
| 2217 |
printf( "\t Feature Count=%d\n", cnt = getushort(ttf)); |
| 2218 |
for ( i=0; i<cnt; ++i ) |
| 2219 |
printf( "\t Feature %d Offset=%d\n", i, getushort(ttf)); |
| 2220 |
} |
| 2221 |
|
| 2222 |
static void showscriptlist(FILE *ttf,int script_start ) { |
| 2223 |
int cnt,i, j; |
| 2224 |
uint16_t *script_table_offsets; |
| 2225 |
uint32_t *script_table_names; |
| 2226 |
int dlo, ls_cnt; |
| 2227 |
uint32_t *ls_names; |
| 2228 |
uint16_t *ls_offsets; |
| 2229 |
|
| 2230 |
fseek(ttf,script_start,SEEK_SET); |
| 2231 |
printf( "\tScript List\n" ); |
| 2232 |
printf( "\t script count=%d\n", cnt=getushort(ttf)); |
| 2233 |
script_table_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2234 |
script_table_names = malloc(cnt*sizeof(uint32_t)); |
| 2235 |
for ( i=0; i<cnt; ++i ) { |
| 2236 |
script_table_names[i] = getlong(ttf); |
| 2237 |
script_table_offsets[i] = getushort(ttf); |
| 2238 |
printf( "\t Script[%d] '%c%c%c%c' Offset=%d\n", i, |
| 2239 |
(char)((script_table_names[i]>>24)&0xff), |
| 2240 |
(char)((script_table_names[i]>>16)&0xff), |
| 2241 |
(char)((script_table_names[i]>>8)&0xff), |
| 2242 |
(char)(script_table_names[i]&0xff), |
| 2243 |
script_table_offsets[i] ); |
| 2244 |
} |
| 2245 |
printf( "\t--\n" ); |
| 2246 |
for ( i=0; i<cnt; ++i ) { |
| 2247 |
fseek(ttf,script_start+script_table_offsets[i],SEEK_SET); |
| 2248 |
printf( "\t Script table for '%c%c%c%c'\n", |
| 2249 |
(char)((script_table_names[i]>>24)&0xff), |
| 2250 |
(char)((script_table_names[i]>>16)&0xff), |
| 2251 |
(char)((script_table_names[i]>>8)&0xff), |
| 2252 |
(char)(script_table_names[i]&0xff) ); |
| 2253 |
printf( "\t default language offset=%d\n", dlo=getushort(ttf)); |
| 2254 |
printf( "\t language systems count=%d\n", ls_cnt = getushort(ttf)); |
| 2255 |
ls_names = malloc(ls_cnt*sizeof(uint32_t)); |
| 2256 |
ls_offsets = malloc(ls_cnt*sizeof(uint16_t)); |
| 2257 |
for ( j=0; j<ls_cnt; ++j ) { |
| 2258 |
ls_names[j] = getlong(ttf); |
| 2259 |
ls_offsets[j] = getushort(ttf); |
| 2260 |
printf( "\t Language System '%c%c%c%c' Offset=%d\n", |
| 2261 |
(char)((ls_names[j]>>24)&0xff), |
| 2262 |
(char)((ls_names[j]>>16)&0xff), |
| 2263 |
(char)((ls_names[j]>>8)&0xff), |
| 2264 |
(char)(ls_names[j]&0xff), |
| 2265 |
ls_offsets[j] ); |
| 2266 |
} |
| 2267 |
if ( dlo!=0 ) |
| 2268 |
showlangsys(ttf,script_start+script_table_offsets[i],dlo,0); |
| 2269 |
for ( j=0; j<ls_cnt; ++j ) |
| 2270 |
showlangsys(ttf,script_start+script_table_offsets[i],ls_offsets[j],ls_names[j]); |
| 2271 |
free(ls_names); free(ls_offsets); |
| 2272 |
} |
| 2273 |
free(script_table_offsets); |
| 2274 |
free(script_table_names); |
| 2275 |
} |
| 2276 |
|
| 2277 |
static void showfeaturelist(FILE *ttf,int feature_start ) { |
| 2278 |
int cnt,i, j, lu_cnt; |
| 2279 |
uint32_t *feature_record_names; |
| 2280 |
uint16_t *feature_record_offsets; |
| 2281 |
uint16_t *lu_offsets; |
| 2282 |
|
| 2283 |
fseek(ttf,feature_start,SEEK_SET); |
| 2284 |
printf( "\tFeature List\n" ); |
| 2285 |
printf( "\t feature count=%d\n", cnt=getushort(ttf)); |
| 2286 |
feature_record_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2287 |
feature_record_names = malloc(cnt*sizeof(uint32_t)); |
| 2288 |
for ( i=0; i<cnt; ++i ) { |
| 2289 |
feature_record_names[i] = getlong(ttf); |
| 2290 |
feature_record_offsets[i] = getushort(ttf); |
| 2291 |
printf( "\t Feature[%d] '%c%c%c%c' Offset=%d\n", i, |
| 2292 |
(char)((feature_record_names[i]>>24)&0xff), |
| 2293 |
(char)((feature_record_names[i]>>16)&0xff), |
| 2294 |
(char)((feature_record_names[i]>>8)&0xff), |
| 2295 |
(char)(feature_record_names[i]&0xff), |
| 2296 |
feature_record_offsets[i] ); |
| 2297 |
} |
| 2298 |
printf( "\t--\n" ); |
| 2299 |
for ( i=0; i<cnt; ++i ) { |
| 2300 |
fseek(ttf,feature_start+feature_record_offsets[i],SEEK_SET); |
| 2301 |
printf( "\t Feature Table[%d] '%c%c%c%c'\n", i, |
| 2302 |
(char)((feature_record_names[i]>>24)&0xff), |
| 2303 |
(char)((feature_record_names[i]>>16)&0xff), |
| 2304 |
(char)((feature_record_names[i]>>8)&0xff), |
| 2305 |
(char)(feature_record_names[i]&0xff) ); |
| 2306 |
printf( "\t Feature Parameters Offset=%d\n", getushort(ttf)); |
| 2307 |
printf( "\t Lookup Count = %d\n", lu_cnt = getushort(ttf)); |
| 2308 |
if ( i+1<cnt && feature_record_offsets[i]<feature_record_offsets[i+1] && |
| 2309 |
feature_record_offsets[i]+4+2*lu_cnt>feature_record_offsets[i+1] ) |
| 2310 |
printf( "!!!! Bad lookup count. More lookups than there is space for!!!!\n" ); |
| 2311 |
lu_offsets = malloc(lu_cnt*sizeof(uint16_t)); |
| 2312 |
for ( j=0; j<lu_cnt; ++j ) { |
| 2313 |
printf( "\t Lookup List Offset[%d] = %d\n", j, |
| 2314 |
lu_offsets[j] = getushort(ttf)); |
| 2315 |
} |
| 2316 |
free(lu_offsets); |
| 2317 |
} |
| 2318 |
free( feature_record_offsets ); |
| 2319 |
free( feature_record_names ); |
| 2320 |
} |
| 2321 |
|
| 2322 |
static uint16_t *showCoverageTable(FILE *ttf, int coverage_offset, int specified_cnt) { |
| 2323 |
int format, cnt, i,j, rcnt; |
| 2324 |
uint16_t *glyphs=NULL; |
| 2325 |
int start, end, ind, max; |
| 2326 |
|
| 2327 |
fseek(ttf,coverage_offset,SEEK_SET); |
| 2328 |
printf( "\t Coverage Table\n" ); |
| 2329 |
printf( "\t Format=%d\n", format = getushort(ttf)); |
| 2330 |
if ( format==1 ) { |
| 2331 |
printf("\t Glyph Count=%d\n\t ", cnt = getushort(ttf)); |
| 2332 |
glyphs = malloc((cnt+1)*sizeof(uint16_t)); |
| 2333 |
for ( i=0; i<cnt; ++i ) |
| 2334 |
printf( "%d ", glyphs[i] = getushort(ttf)); |
| 2335 |
glyphs[i] = 0xffff; |
| 2336 |
putchar('\n'); |
| 2337 |
} else if ( format==2 ) { |
| 2338 |
glyphs = malloc((max=256)*sizeof(uint16_t)); |
| 2339 |
printf("\t Range Count=%d\n\t ", rcnt = getushort(ttf)); |
| 2340 |
cnt = 0; |
| 2341 |
for ( i=0; i<rcnt; ++i ) { |
| 2342 |
printf( "\t Range [%d] Start=%d ", i, start = getushort(ttf)); |
| 2343 |
printf( "End=%d ", end = getushort(ttf)); |
| 2344 |
printf( "Index=%d\n", ind = getushort(ttf)); |
| 2345 |
if ( ind+end-start+2 >= max ) { |
| 2346 |
max = ind+end-start+2; |
| 2347 |
glyphs = realloc(glyphs,max*sizeof(uint16_t)); |
| 2348 |
} |
| 2349 |
for ( j=start; j<=end; ++j ) |
| 2350 |
glyphs[j-start+ind] = j; |
| 2351 |
if ( end-start+1+ind>cnt ) { |
| 2352 |
glyphs[end-start+1+ind] = 0xffff; |
| 2353 |
cnt = end-start+1+ind; |
| 2354 |
} |
| 2355 |
} |
| 2356 |
} |
| 2357 |
if ( specified_cnt>=0 && cnt!=specified_cnt ) |
| 2358 |
fprintf(stderr, "! > Bad coverage table: Calculated Count(%d) does not match specified (%d)\n", |
| 2359 |
cnt, specified_cnt ); |
| 2360 |
return( glyphs ); |
| 2361 |
} |
| 2362 |
|
| 2363 |
static uint16_t *getClassDefTable(FILE *ttf, int classdef_offset, int cnt) { |
| 2364 |
int format, i, j; |
| 2365 |
uint16_t start, glyphcnt, rangecnt, end, class; |
| 2366 |
uint16_t *glist=NULL; |
| 2367 |
|
| 2368 |
fseek(ttf, classdef_offset, SEEK_SET); |
| 2369 |
glist = malloc(cnt*sizeof(uint16_t)); |
| 2370 |
for ( i=0; i<cnt; ++i ) |
| 2371 |
glist[i] = 0; |
| 2372 |
format = getushort(ttf); |
| 2373 |
if ( format==1 ) { |
| 2374 |
start = getushort(ttf); |
| 2375 |
glyphcnt = getushort(ttf); |
| 2376 |
if ( start+glyphcnt>cnt ) { |
| 2377 |
fprintf( stderr, "Bad class def table. start=%d cnt=%d, max glyph=%d\n", start, glyphcnt, cnt ); |
| 2378 |
glyphcnt = cnt-start; |
| 2379 |
} |
| 2380 |
for ( i=0; i<glyphcnt; ++i ) |
| 2381 |
glist[start+i] = getushort(ttf); |
| 2382 |
} else if ( format==2 ) { |
| 2383 |
rangecnt = getushort(ttf); |
| 2384 |
for ( i=0; i<rangecnt; ++i ) { |
| 2385 |
start = getushort(ttf); |
| 2386 |
end = getushort(ttf); |
| 2387 |
if ( start>end || end>=cnt ) |
| 2388 |
fprintf( stderr, "Bad class def table. Glyph range %d-%d out of range [0,%d)\n", start, end, cnt ); |
| 2389 |
class = getushort(ttf); |
| 2390 |
for ( j=start; j<=end; ++j ) |
| 2391 |
glist[j] = class; |
| 2392 |
} |
| 2393 |
} |
| 2394 |
return glist; |
| 2395 |
} |
| 2396 |
|
| 2397 |
static void readvaluerecord(int vf,FILE *ttf,const char *label) { |
| 2398 |
printf( "\t\t %s: ", label ); |
| 2399 |
if ( vf&1 ) |
| 2400 |
printf( "XPlacement: %d ", (short) getushort(ttf)); |
| 2401 |
if ( vf&2 ) |
| 2402 |
printf( "YPlacement: %d ", (short) getushort(ttf)); |
| 2403 |
if ( vf&4 ) |
| 2404 |
printf( "XAdvance: %d ", (short) getushort(ttf)); |
| 2405 |
if ( vf&8 ) |
| 2406 |
printf( "YAdvance: %d ", (short) getushort(ttf)); |
| 2407 |
if ( vf&0x10 ) |
| 2408 |
printf( "XPlacementDevOff: %d ", getushort(ttf)); |
| 2409 |
if ( vf&0x20 ) |
| 2410 |
printf( "YPlacementDevOff: %d ", getushort(ttf)); |
| 2411 |
if ( vf&0x40 ) |
| 2412 |
printf( "XAdvanceDevOff: %d ", getushort(ttf)); |
| 2413 |
if ( vf&0x80 ) |
| 2414 |
printf( "YAdvanceDevOff: %d ", getushort(ttf)); |
| 2415 |
printf( "\n" ); |
| 2416 |
} |
| 2417 |
|
| 2418 |
static void PrintGlyphs(uint16_t *glyphs, struct ttfinfo *info) { |
| 2419 |
if ( glyphs==NULL ) |
| 2420 |
printf( "<Empty>\n" ); |
| 2421 |
else if ( info->glyph_names!=NULL ) { |
| 2422 |
int i; |
| 2423 |
printf( " " ); |
| 2424 |
for ( i=0; glyphs[i]!=0xffff; ++i ) { |
| 2425 |
printf( "%s ", info->glyph_names[glyphs[i]]); |
| 2426 |
} |
| 2427 |
printf("\n" ); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
static void gposPairSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2432 |
int coverage, cnt, i, subformat, vf1, vf2, j, pair_cnt; |
| 2433 |
uint16_t *glyphs = NULL; |
| 2434 |
uint16_t *ps_offsets; |
| 2435 |
|
| 2436 |
printf( "\t Pair Sub Table[%d]\n", which ); |
| 2437 |
printf( "\t SubFormat=%d\n", subformat = getushort(ttf)); |
| 2438 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2439 |
printf( "\t ValueFormat1=0x%x ", (unsigned int)((vf1 = getushort(ttf))) ); |
| 2440 |
printf( "%s%s%s%s%s%s%s%s\n", |
| 2441 |
(vf1&1) ? "XPlacement|":"", |
| 2442 |
(vf1&2) ? "YPlacement|":"", |
| 2443 |
(vf1&4) ? "XAdvance|":"", |
| 2444 |
(vf1&8) ? "YAdvance|":"", |
| 2445 |
(vf1&0x10) ? "XDevPlacement|":"", |
| 2446 |
(vf1&0x20) ? "YDevPlacement|":"", |
| 2447 |
(vf1&0x40) ? "XDevAdvance|":"", |
| 2448 |
(vf1&0x80) ? "YDevAdvance|":"" ); |
| 2449 |
printf( "\t ValueFormat2=0x%x ", (unsigned int)(vf2 = getushort(ttf)) ); |
| 2450 |
printf( "%s%s%s%s%s%s%s%s\n", |
| 2451 |
(vf2&1) ? "XPlacement|":"", |
| 2452 |
(vf2&2) ? "YPlacement|":"", |
| 2453 |
(vf2&4) ? "XAdvance|":"", |
| 2454 |
(vf2&8) ? "YAdvance|":"", |
| 2455 |
(vf2&0x10) ? "XDevPlacement|":"", |
| 2456 |
(vf2&0x20) ? "YDevPlacement|":"", |
| 2457 |
(vf2&0x40) ? "XDevAdvance|":"", |
| 2458 |
(vf2&0x80) ? "YDevAdvance|":"" ); |
| 2459 |
if ( subformat==1 ) { |
| 2460 |
printf( "\t PairSetCnt=%d\n", cnt = getushort(ttf)); |
| 2461 |
ps_offsets = calloc(cnt,sizeof(short)); |
| 2462 |
for ( i=0; i<cnt; ++i ) |
| 2463 |
ps_offsets[i] = getushort(ttf); |
| 2464 |
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt); |
| 2465 |
for ( i=0; i<cnt; ++i ) { |
| 2466 |
fseek(ttf,stoffset+ps_offsets[i],SEEK_SET); |
| 2467 |
printf( "\t PairCnt=%d\n", pair_cnt = getushort(ttf)); |
| 2468 |
for ( j=0; j<pair_cnt; ++j ) { |
| 2469 |
int glyph2 = getushort(ttf); |
| 2470 |
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i], |
| 2471 |
glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names==NULL? "" : info->glyph_names[glyphs[i]], |
| 2472 |
glyph2, |
| 2473 |
glyph2>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyph2]); |
| 2474 |
readvaluerecord(vf1,ttf,"First"); |
| 2475 |
readvaluerecord(vf2,ttf,"Second"); |
| 2476 |
} |
| 2477 |
} |
| 2478 |
free(ps_offsets); |
| 2479 |
} else if ( subformat==2 ) { |
| 2480 |
printf( "\t Class based kerning (not displayed)\n" ); |
| 2481 |
glyphs = showCoverageTable(ttf,stoffset+coverage,-1); |
| 2482 |
PrintGlyphs(glyphs,info); |
| 2483 |
} else { |
| 2484 |
printf( "\t !!! unknown sub-table format !!!!\n" ); |
| 2485 |
} |
| 2486 |
free(glyphs); |
| 2487 |
} |
| 2488 |
|
| 2489 |
static void ShowAttach(FILE *ttf) { |
| 2490 |
int format = getushort(ttf); |
| 2491 |
int x = getushort(ttf); |
| 2492 |
int y = getushort(ttf); |
| 2493 |
|
| 2494 |
if ( format==1 ) |
| 2495 |
printf( "Attach at (%d,%d)\n", x, y ); |
| 2496 |
else if ( format==2 ) |
| 2497 |
printf( "Attach at (%d,%d pt=%d)\n", x, y, getushort(ttf) ); |
| 2498 |
else if ( format==3 ) { |
| 2499 |
printf( "Attach at (%d,%d XDeviceOff=%d", x, y, getushort(ttf) ); |
| 2500 |
printf( " YDeviceOff=%d)\n", getushort(ttf) ); |
| 2501 |
} else |
| 2502 |
printf( "Unknown attachment format %d\n", format ); |
| 2503 |
} |
| 2504 |
|
| 2505 |
static void gposMarkToBaseSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info, int m2b) { |
| 2506 |
int mcoverage, bcoverage, classcnt, markoff, baseoff; |
| 2507 |
uint16_t *mglyphs, *bglyphs; |
| 2508 |
int i, j; |
| 2509 |
uint16_t *offsets; |
| 2510 |
uint32_t pos; |
| 2511 |
|
| 2512 |
printf( m2b ? "\t Mark To Base Sub Table[%d]\n" : "\t Mark To Mark Sub Table[%d]\n", which ); |
| 2513 |
printf( "\t SubFormat=%d\n", getushort(ttf)); |
| 2514 |
printf( "\t Mark Coverage Offset=%d\n", mcoverage = getushort(ttf)); |
| 2515 |
printf( "\t Base Coverage Offset=%d\n", bcoverage = getushort(ttf)); |
| 2516 |
printf( "\t Class Count=%d\n", classcnt = getushort(ttf)); |
| 2517 |
printf( "\t Mark Offset=%d\n", markoff = getushort(ttf)); |
| 2518 |
printf( "\t Base Offset=%d\n", baseoff = getushort(ttf)); |
| 2519 |
printf( "\t Mark Glyphs\n" ); |
| 2520 |
mglyphs = showCoverageTable(ttf,stoffset+mcoverage, -1); |
| 2521 |
printf( "\t Base Glyphs\n" ); |
| 2522 |
bglyphs = showCoverageTable(ttf,stoffset+bcoverage, -1); |
| 2523 |
fseek(ttf,stoffset+baseoff,SEEK_SET); |
| 2524 |
printf( "\t Base Glyph Count=%d\n", getushort(ttf)); |
| 2525 |
offsets = malloc(classcnt*sizeof(uint16_t)); |
| 2526 |
for ( i=0; bglyphs[i]!=0xffff; ++i ) { |
| 2527 |
printf( "\t\tBase Glyph %d (%s)\n", bglyphs[i], |
| 2528 |
bglyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : |
| 2529 |
info->glyph_names == NULL ? "" : info->glyph_names[bglyphs[i]]); |
| 2530 |
for ( j=0; j<classcnt; ++j ) |
| 2531 |
offsets[j] = getushort(ttf); |
| 2532 |
pos = ftell(ttf); |
| 2533 |
for ( j=0; j<classcnt; ++j ) { |
| 2534 |
if ( offsets[j]!=0 ) { |
| 2535 |
printf( "\t\t\tClass=%d Offset=%d ", j, offsets[j]); |
| 2536 |
fseek(ttf,stoffset+baseoff+offsets[j],SEEK_SET); |
| 2537 |
ShowAttach(ttf); |
| 2538 |
} |
| 2539 |
} |
| 2540 |
fseek(ttf,pos,SEEK_SET); |
| 2541 |
} |
| 2542 |
fseek(ttf,stoffset+markoff,SEEK_SET); |
| 2543 |
printf( "\t Mark Glyph Count=%d\n", getushort(ttf)); |
| 2544 |
for ( i=0; mglyphs[i]!=0xffff; ++i ) { |
| 2545 |
printf( "\t\tMark Glyph %d (%s)\n", mglyphs[i], |
| 2546 |
mglyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : |
| 2547 |
info->glyph_names == NULL ? "" : info->glyph_names[mglyphs[i]]); |
| 2548 |
printf( "\t\t\tClass=%d ", getushort(ttf)); |
| 2549 |
offsets[0] = getushort(ttf); |
| 2550 |
pos = ftell(ttf); |
| 2551 |
if ( offsets[0]!=0 ) { |
| 2552 |
printf( "Offset=%d ", offsets[0]); |
| 2553 |
fseek(ttf,stoffset+markoff+offsets[0],SEEK_SET); |
| 2554 |
ShowAttach(ttf); |
| 2555 |
} |
| 2556 |
fseek(ttf,pos,SEEK_SET); |
| 2557 |
} |
| 2558 |
free(offsets); |
| 2559 |
free(mglyphs); |
| 2560 |
free(bglyphs); |
| 2561 |
} |
| 2562 |
|
| 2563 |
static void gsubSingleSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2564 |
int coverage, cnt, i, type; |
| 2565 |
uint16_t *glyphs = NULL; |
| 2566 |
|
| 2567 |
printf( "\t Single Sub Table[%d] (variant forms)\n", which ); |
| 2568 |
printf( "\t Type=%d\n", type = getushort(ttf)); |
| 2569 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2570 |
if ( type==1 ) { |
| 2571 |
uint16_t delta = getushort(ttf); |
| 2572 |
printf( "\t Delta=%d\n", delta); |
| 2573 |
glyphs = showCoverageTable(ttf,stoffset+coverage, -1); |
| 2574 |
printf( "\t Which means ...\n" ); |
| 2575 |
for ( i=0; glyphs[i]!=0xffff; ++i ) |
| 2576 |
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i], |
| 2577 |
glyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]], |
| 2578 |
(uint16_t) (glyphs[i]+delta), |
| 2579 |
(uint16_t) (glyphs[i]+delta)>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[(uint16_t) (glyphs[i]+delta)]); |
| 2580 |
} else { |
| 2581 |
int here; |
| 2582 |
printf( "\t Count=%d\n", cnt = getushort(ttf)); |
| 2583 |
here = ftell(ttf); |
| 2584 |
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt); |
| 2585 |
fseek(ttf,here,SEEK_SET); |
| 2586 |
for ( i=0; i<cnt; ++i ) { |
| 2587 |
int val = getushort(ttf); |
| 2588 |
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i], |
| 2589 |
glyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]], |
| 2590 |
val, |
| 2591 |
val >= info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[val]); |
| 2592 |
} |
| 2593 |
} |
| 2594 |
free(glyphs); |
| 2595 |
} |
| 2596 |
|
| 2597 |
static void gsubMultipleSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2598 |
int coverage, cnt, i, j, glyph_cnt; |
| 2599 |
uint16_t *seq_offsets; |
| 2600 |
uint16_t *glyphs; |
| 2601 |
|
| 2602 |
printf( "\t Multiple Sub Table[%d] (ligature decomposition)\n", which ); |
| 2603 |
printf( "\t Type=%d\n", getushort(ttf)); |
| 2604 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2605 |
printf( "\t Count=%d\n", cnt = getushort(ttf)); |
| 2606 |
seq_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2607 |
for ( i=0; i<cnt; ++i ) |
| 2608 |
printf( "\t Sequence Offsets[%d]=%d\n", i, seq_offsets[i]=getushort(ttf)); |
| 2609 |
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt); |
| 2610 |
for ( i=0; i<cnt; ++i ) { |
| 2611 |
fseek(ttf,stoffset+seq_offsets[i],SEEK_SET); |
| 2612 |
printf( "\t Glyph sequence[%d] for glyph %d (%s)\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]); |
| 2613 |
printf( "\t Count=%d\n", glyph_cnt = getushort(ttf)); |
| 2614 |
printf( "\t Glyph %d (%s) -> ", glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]] ); |
| 2615 |
for ( j=0; j<glyph_cnt; ++j ) { |
| 2616 |
int de = getushort(ttf); |
| 2617 |
printf( "%d (%s) ", de, de>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[de]); |
| 2618 |
} |
| 2619 |
putchar('\n'); |
| 2620 |
} |
| 2621 |
free(glyphs); |
| 2622 |
free(seq_offsets); |
| 2623 |
} |
| 2624 |
|
| 2625 |
static void gsubAlternateSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2626 |
int coverage, cnt, i, j, glyph_cnt; |
| 2627 |
uint16_t *seq_offsets; |
| 2628 |
uint16_t *glyphs; |
| 2629 |
|
| 2630 |
printf( "\t Alternate Sub Table[%d] (variant forms)\n", which ); |
| 2631 |
printf( "\t Type=%d\n", getushort(ttf)); |
| 2632 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2633 |
printf( "\t Count=%d\n", cnt = getushort(ttf)); |
| 2634 |
seq_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2635 |
for ( i=0; i<cnt; ++i ) |
| 2636 |
printf( "\t Alternate Set Offsets[%d]=%d\n", i, seq_offsets[i]=getushort(ttf)); |
| 2637 |
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt); |
| 2638 |
for ( i=0; i<cnt; ++i ) { |
| 2639 |
fseek(ttf,stoffset+seq_offsets[i],SEEK_SET); |
| 2640 |
printf( "\t Glyph alternates[%d] for glyph %d (%s)\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]); |
| 2641 |
printf( "\t Count=%d\n", glyph_cnt = getushort(ttf)); |
| 2642 |
printf( "\t Glyph %d (%s) -> ", glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]] ); |
| 2643 |
for ( j=0; j<glyph_cnt; ++j ) { |
| 2644 |
int de = getushort(ttf); |
| 2645 |
printf( "%d (%s) | ", de, de>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[de]); |
| 2646 |
} |
| 2647 |
putchar('\n'); |
| 2648 |
} |
| 2649 |
free(glyphs); |
| 2650 |
free(seq_offsets); |
| 2651 |
} |
| 2652 |
|
| 2653 |
static void gsubLigatureSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2654 |
int coverage, cnt, i, j, k, lig_cnt, cc, gl; |
| 2655 |
uint16_t *ls_offsets, *lig_offsets; |
| 2656 |
uint16_t *glyphs; |
| 2657 |
|
| 2658 |
printf( "\t Ligature Sub Table[%d]\n", which ); |
| 2659 |
printf( "\t Type=%d\n", getushort(ttf)); |
| 2660 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2661 |
printf( "\t Lig Set Count=%d\n", cnt = getushort(ttf)); |
| 2662 |
ls_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2663 |
for ( i=0; i<cnt; ++i ) |
| 2664 |
printf( "\t Lig Set Offsets[%d]=%d\n", i, ls_offsets[i]=getushort(ttf)); |
| 2665 |
glyphs = showCoverageTable(ttf,stoffset+coverage,cnt); |
| 2666 |
for ( i=0; i<cnt; ++i ) { |
| 2667 |
fseek(ttf,stoffset+ls_offsets[i],SEEK_SET); |
| 2668 |
printf( "\t Ligature Set[%d] for glyph %d %s\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]); |
| 2669 |
printf( "\t Count=%d\n", lig_cnt = getushort(ttf)); |
| 2670 |
lig_offsets = malloc(lig_cnt*sizeof(uint16_t)); |
| 2671 |
for ( j=0; j<lig_cnt; ++j ) |
| 2672 |
printf("\t Offsets[%d]=%d\n", j, lig_offsets[j] = getushort(ttf)); |
| 2673 |
for ( j=0; j<lig_cnt; ++j ) { |
| 2674 |
fseek(ttf,stoffset+ls_offsets[i]+lig_offsets[j],SEEK_SET); |
| 2675 |
gl = getushort(ttf); |
| 2676 |
printf( "\t Ligature glyph %d (%s) <- %d (%s) ", |
| 2677 |
gl, gl>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[gl], glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]); |
| 2678 |
cc = getushort(ttf); |
| 2679 |
for ( k=1; k<cc; ++k ) { |
| 2680 |
gl = getushort(ttf); |
| 2681 |
printf( "%d (%s) ", gl, gl>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[gl]); |
| 2682 |
} |
| 2683 |
putchar('\n'); |
| 2684 |
} |
| 2685 |
free(lig_offsets); |
| 2686 |
} |
| 2687 |
free(ls_offsets); free(glyphs); |
| 2688 |
} |
| 2689 |
|
| 2690 |
static void gsubContextSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2691 |
} |
| 2692 |
|
| 2693 |
static void gsubChainingContextSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) { |
| 2694 |
} |
| 2695 |
|
| 2696 |
static void showgpossublookup(FILE *ttf,int base, int lkoffset, |
| 2697 |
struct ttfinfo *info, int gpos ) { |
| 2698 |
int lu_type, flags, cnt, j, st, is_exten_lu; |
| 2699 |
uint16_t *st_offsets; |
| 2700 |
|
| 2701 |
fseek(ttf,base+lkoffset,SEEK_SET); |
| 2702 |
lu_type = getushort(ttf); |
| 2703 |
flags = getushort(ttf); |
| 2704 |
cnt = getushort(ttf); |
| 2705 |
if ( gpos ) { |
| 2706 |
printf( "\t Type=%d %s\n", lu_type, |
| 2707 |
lu_type==1?"Single adjustment": |
| 2708 |
lu_type==2?"Pair adjustment": |
| 2709 |
lu_type==3?"Cursive attachment": |
| 2710 |
lu_type==4?"MarkToBase attachment": |
| 2711 |
lu_type==5?"MarkToLigature attachment": |
| 2712 |
lu_type==6?"MarkToMark attachment": |
| 2713 |
lu_type==7?"Context positioning": |
| 2714 |
lu_type==8?"Chained Context positioning": |
| 2715 |
lu_type==9?"Extension positioning": |
| 2716 |
"Reserved"); |
| 2717 |
is_exten_lu = lu_type==9; |
| 2718 |
} else { |
| 2719 |
printf( "\t Type=%d %s\n", lu_type, |
| 2720 |
lu_type==1?"Single": |
| 2721 |
lu_type==2?"Multiple": |
| 2722 |
lu_type==3?"Alternate": |
| 2723 |
lu_type==4?"Ligature": |
| 2724 |
lu_type==5?"Context": |
| 2725 |
lu_type==6?"Chaining Context": |
| 2726 |
lu_type==7?"Extension": |
| 2727 |
lu_type==8?"Reverse chaining": |
| 2728 |
"Reserved"); |
| 2729 |
is_exten_lu = lu_type==7; |
| 2730 |
} |
| 2731 |
printf( "\t Flags=0x%x %s|%s|%s|%s\n", (unsigned int)(flags), |
| 2732 |
(flags&0x1)?"RightToLeft":"LeftToRight", |
| 2733 |
(flags&0x2)?"IgnoreBaseGlyphs":"", |
| 2734 |
(flags&0x4)?"IgnoreLigatures":"", |
| 2735 |
(flags&0x8)?"IgnoreCombiningMarks":""); |
| 2736 |
printf( "\t Sub Table Count=%d\n", cnt); |
| 2737 |
st_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2738 |
for ( j=0; j<cnt; ++j ) |
| 2739 |
printf( "\t Sub Table Offsets[%d]=%d\n", j, st_offsets[j] = getushort(ttf)); |
| 2740 |
for ( j=0; j<cnt; ++j ) { |
| 2741 |
fseek(ttf,st = base+lkoffset+st_offsets[j],SEEK_SET); |
| 2742 |
if ( gpos ) { |
| 2743 |
if ( is_exten_lu ) { |
| 2744 |
int format = getushort(ttf); |
| 2745 |
int subtype = getushort(ttf); |
| 2746 |
int offset = getlong(ttf); |
| 2747 |
printf( "\t (extension format)=%d\n", format ); |
| 2748 |
lu_type = subtype; |
| 2749 |
printf( "\t (extension type)=%d %s\n", lu_type, |
| 2750 |
lu_type==1?"Single adjustment": |
| 2751 |
lu_type==2?"Pair adjustment": |
| 2752 |
lu_type==3?"Cursive attachment": |
| 2753 |
lu_type==4?"MarkToBase attachment": |
| 2754 |
lu_type==5?"MarkToLigature attachment": |
| 2755 |
lu_type==6?"MarkToMark attachment": |
| 2756 |
lu_type==7?"Context positioning": |
| 2757 |
lu_type==8?"Chained Context positioning": |
| 2758 |
lu_type==9?"Extension !!! Illegal here !!!": |
| 2759 |
"Reserved"); |
| 2760 |
printf( "\t (extension offset)=%d\n", offset ); |
| 2761 |
st += offset; |
| 2762 |
fseek(ttf,st,SEEK_SET); |
| 2763 |
} |
| 2764 |
switch ( lu_type ) { |
| 2765 |
case 2: gposPairSubTable(ttf,j,st,info); break; |
| 2766 |
case 4: gposMarkToBaseSubTable(ttf,j,st,info,true); break; |
| 2767 |
case 6: gposMarkToBaseSubTable(ttf,j,st,info,false); break; |
| 2768 |
} |
| 2769 |
} else { |
| 2770 |
if ( is_exten_lu ) { |
| 2771 |
int format = getushort(ttf); |
| 2772 |
int subtype = getushort(ttf); |
| 2773 |
int offset = getlong(ttf); |
| 2774 |
printf( "\t (extension format)=%d\n", format ); |
| 2775 |
lu_type = subtype; |
| 2776 |
printf( "\t (extension type)=%d %s\n", lu_type, |
| 2777 |
lu_type==1?"Single": |
| 2778 |
lu_type==2?"Multiple": |
| 2779 |
lu_type==3?"Alternate": |
| 2780 |
lu_type==4?"Ligature": |
| 2781 |
lu_type==5?"Context": |
| 2782 |
lu_type==6?"Chaining Context": |
| 2783 |
lu_type==7?"Extension !!! Illegal here !!!": |
| 2784 |
lu_type==8?"Reverse chaining": |
| 2785 |
"Reserved"); |
| 2786 |
st += offset; |
| 2787 |
fseek(ttf,st,SEEK_SET); |
| 2788 |
} |
| 2789 |
switch ( lu_type ) { |
| 2790 |
case 1: gsubSingleSubTable(ttf,j,st,info); break; |
| 2791 |
case 2: gsubMultipleSubTable(ttf,j,st,info); break; |
| 2792 |
case 3: gsubAlternateSubTable(ttf,j,st,info); break; |
| 2793 |
case 4: gsubLigatureSubTable(ttf,j,st,info); break; |
| 2794 |
case 5: gsubContextSubTable(ttf,j,st,info); break; |
| 2795 |
case 6: gsubChainingContextSubTable(ttf,j,st,info); break; |
| 2796 |
} |
| 2797 |
} |
| 2798 |
} |
| 2799 |
free(st_offsets); |
| 2800 |
} |
| 2801 |
|
| 2802 |
static void showgpossublookups(FILE *ttf,int lookup_start, struct ttfinfo *info, int gpos ) { |
| 2803 |
int i, lu_cnt; |
| 2804 |
uint16_t *lu_offsets; |
| 2805 |
|
| 2806 |
fseek(ttf,lookup_start,SEEK_SET); |
| 2807 |
printf( "\t%s Lookup List Table\n", gpos?"GPOS":"GSUB" ); |
| 2808 |
printf( "\t Lookup Count=%d\n", lu_cnt = getushort(ttf)); |
| 2809 |
lu_offsets = malloc(lu_cnt*sizeof(uint16_t)); |
| 2810 |
for ( i=0; i<lu_cnt; ++i ) |
| 2811 |
printf( "\t Lookup Offset[%d]=%d\n", i, lu_offsets[i] = getushort(ttf)); |
| 2812 |
printf( "\t--\n"); |
| 2813 |
for ( i=0; i<lu_cnt; ++i ) { |
| 2814 |
printf( "\t Lookup Table[%d]\n", i ); |
| 2815 |
showgpossublookup(ttf,lookup_start, lu_offsets[i], info, gpos); |
| 2816 |
} |
| 2817 |
free(lu_offsets); |
| 2818 |
} |
| 2819 |
|
| 2820 |
static void readttfgsub(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 2821 |
int slo, flo, llo; |
| 2822 |
|
| 2823 |
fseek(ttf,info->gsub_start,SEEK_SET); |
| 2824 |
printf( "\nGSUB table (at %d) (Glyph substitution)\n", info->gsub_start ); |
| 2825 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 2826 |
printf( "\t Script List Offset=%d\n", slo = getushort(ttf)); |
| 2827 |
printf( "\t Feature List Offset=%d\n", flo = getushort(ttf)); |
| 2828 |
printf( "\t Lookup List Offset=%d\n", llo = getushort(ttf)); |
| 2829 |
showscriptlist(ttf,info->gsub_start+slo ); |
| 2830 |
showfeaturelist(ttf,info->gsub_start+flo ); |
| 2831 |
showgpossublookups(ttf,info->gsub_start+llo,info,false ); |
| 2832 |
} |
| 2833 |
|
| 2834 |
static void readttfgpos(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 2835 |
int slo, flo, llo; |
| 2836 |
|
| 2837 |
fseek(ttf,info->gpos_start,SEEK_SET); |
| 2838 |
printf( "\nGPOS table (at %d) (Glyph positioning)\n", info->gpos_start ); |
| 2839 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 2840 |
printf( "\t Script List Offset=%d\n", slo = getushort(ttf)); |
| 2841 |
printf( "\t Feature List Offset=%d\n", flo = getushort(ttf)); |
| 2842 |
printf( "\t Lookup List Offset=%d\n", llo = getushort(ttf)); |
| 2843 |
showscriptlist(ttf,info->gpos_start+slo ); |
| 2844 |
showfeaturelist(ttf,info->gpos_start+flo ); |
| 2845 |
showgpossublookups(ttf,info->gpos_start+llo,info,true ); |
| 2846 |
} |
| 2847 |
|
| 2848 |
static void gdefshowglyphclassdef(FILE *ttf,int offset,struct ttfinfo *info) { |
| 2849 |
uint16_t *glist=NULL; |
| 2850 |
int i; |
| 2851 |
static const char * const classes[] = { "Unspecified", "Base", "Ligature", "Mark", "Component" }; |
| 2852 |
const int max_class = sizeof(classes)/sizeof(classes[0]); |
| 2853 |
|
| 2854 |
printf( " Glyph Class Definitions\n" ); |
| 2855 |
glist = getClassDefTable(ttf,offset,info->glyph_cnt); |
| 2856 |
for ( i=0; i<info->glyph_cnt; ++i ) if ( glist[i]>0 && glist[i]<max_class ) { |
| 2857 |
printf( "\t Glyph %d (%s) is a %s\n", i, |
| 2858 |
i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? info->glyph_names[i] : "", |
| 2859 |
classes[glist[i]]); |
| 2860 |
} |
| 2861 |
free(glist); |
| 2862 |
} |
| 2863 |
|
| 2864 |
static void gdefshowligcaretlist(FILE *ttf,int offset,struct ttfinfo *info) { |
| 2865 |
int coverage, cnt, i, j, cc, format; |
| 2866 |
uint16_t *lc_offsets, *glyphs, *offsets; |
| 2867 |
uint32_t caret_base; |
| 2868 |
|
| 2869 |
fseek(ttf,offset,SEEK_SET); |
| 2870 |
printf( " Ligature Caret List\n" ); |
| 2871 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 2872 |
printf( "\t Ligature Count=%d\n", cnt = getushort(ttf)); |
| 2873 |
lc_offsets = malloc(cnt*sizeof(uint16_t)); |
| 2874 |
for ( i=0; i<cnt; ++i ) |
| 2875 |
printf( "\t Lig Caret Offsets[%d]=%d\n", i, lc_offsets[i]=getushort(ttf)); |
| 2876 |
glyphs = showCoverageTable(ttf,offset+coverage,cnt); |
| 2877 |
for ( i=0; i<cnt; ++i ) { |
| 2878 |
fseek(ttf,offset+lc_offsets[i],SEEK_SET); |
| 2879 |
printf("\t Carets for glyph %d (%s)\n", glyphs[i], |
| 2880 |
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]]); |
| 2881 |
caret_base = ftell(ttf); |
| 2882 |
printf("\t Count = %d\n", cc = getushort(ttf)); |
| 2883 |
offsets = malloc(cc*sizeof(uint16_t)); |
| 2884 |
for ( j=0; j<cc; ++j ) |
| 2885 |
offsets[j] = getushort(ttf); |
| 2886 |
for ( j=0; j<cc; ++j ) { |
| 2887 |
fseek(ttf,caret_base+offsets[j],SEEK_SET); |
| 2888 |
format=getushort(ttf); |
| 2889 |
if ( format==1 ) { |
| 2890 |
printf("\t\tCaret[%d] at %d\n", j, (short) getushort(ttf)); |
| 2891 |
} else if ( format==2 ) { |
| 2892 |
printf("\t\tCaret[%d] at point #%d\n", j, getushort(ttf)); |
| 2893 |
} else if ( format==3 ) { |
| 2894 |
printf("\t\tCaret[%d] at %d ", j, (short) getushort(ttf)); |
| 2895 |
printf(" in device table at offset %d\n", getushort(ttf)); |
| 2896 |
} else { |
| 2897 |
printf( "!!!! Unknown caret format %d !!!!\n", format ); |
| 2898 |
} |
| 2899 |
} |
| 2900 |
free(offsets); |
| 2901 |
} |
| 2902 |
free(lc_offsets); |
| 2903 |
free(glyphs); |
| 2904 |
} |
| 2905 |
|
| 2906 |
static void readttfgdef(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 2907 |
int gco, alo, lco, maco; |
| 2908 |
|
| 2909 |
fseek(ttf,info->gdef_start,SEEK_SET); |
| 2910 |
printf( "\nGDEF table (at %d) (Glyph definitions)\n", info->gdef_start ); |
| 2911 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 2912 |
printf( "\t Glyph class Def Offset=%d\n", gco = getushort(ttf)); |
| 2913 |
printf( "\t Attach List Offset=%d\n", alo = getushort(ttf)); |
| 2914 |
printf( "\t Ligature Caret List Offset=%d\n", lco = getushort(ttf)); |
| 2915 |
printf( "\t Mark Attach Class Def Offset=%d\n", maco = getushort(ttf)); |
| 2916 |
if ( gco!=0 ) gdefshowglyphclassdef(ttf,info->gdef_start+gco,info); |
| 2917 |
if ( lco!=0 ) gdefshowligcaretlist(ttf,info->gdef_start+lco,info); |
| 2918 |
} |
| 2919 |
|
| 2920 |
static void readttfkern_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len); |
| 2921 |
static void readttfkern(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 2922 |
int version, ntables; |
| 2923 |
int header_size, len, coverage, i, j; |
| 2924 |
uint32_t begin; |
| 2925 |
int left, right, val, array, n, sr, es, rs; |
| 2926 |
|
| 2927 |
fseek(ttf,info->kern_start,SEEK_SET); |
| 2928 |
printf( "\nkern table (at %d)\n", info->kern_start ); |
| 2929 |
version = getushort(ttf); |
| 2930 |
if ( version!=0 ) { |
| 2931 |
fseek(ttf,info->kern_start,SEEK_SET); |
| 2932 |
version = getlong(ttf); |
| 2933 |
ntables = getlong(ttf); |
| 2934 |
printf( "\t version=%g (Apple format)\n\t num_tables=%d\n", ((double) version)/65536., ntables); |
| 2935 |
header_size = 8; |
| 2936 |
} else { |
| 2937 |
ntables = getushort(ttf); |
| 2938 |
printf( "\t version=%d (Old style)\n\t num_tables=%d\n", version, ntables); |
| 2939 |
header_size = 6; |
| 2940 |
} |
| 2941 |
for ( i=0; i<ntables; ++i ) { |
| 2942 |
begin = ftell(ttf); |
| 2943 |
if ( version==0 ) { |
| 2944 |
printf( "\t Sub-table %d, version=%d\n", i, getushort(ttf)); |
| 2945 |
len = getushort(ttf); |
| 2946 |
coverage = getushort(ttf); |
| 2947 |
printf( "\t len=%d coverage=%x %s%s%s%s sub table format=%d\n", |
| 2948 |
len, (unsigned int)(coverage), |
| 2949 |
( coverage&1 ) ? "Horizontal": "Vertical", |
| 2950 |
( coverage&2 ) ? " Minimum" : "", |
| 2951 |
( coverage&4 ) ? " cross-stream" : "", |
| 2952 |
( coverage&8 ) ? " override" : "", |
| 2953 |
( coverage>>8 )); |
| 2954 |
if ( (coverage>>8)==0 ) { |
| 2955 |
|
| 2956 |
n = getushort(ttf); |
| 2957 |
sr = getushort(ttf); |
| 2958 |
es = getushort(ttf); |
| 2959 |
rs = getushort(ttf); |
| 2960 |
printf( "\t npairs=%d searchRange=%d entrySelector=%d rangeShift=%d\n", |
| 2961 |
n, sr, es, rs ); |
| 2962 |
for ( i=0; i<n; ++i ) { |
| 2963 |
left = getushort(ttf); |
| 2964 |
right = getushort(ttf); |
| 2965 |
val = (short) getushort(ttf); |
| 2966 |
if ( info->glyph_names!=NULL && left<info->glyph_cnt && right<info->glyph_cnt ) { |
| 2967 |
printf( "\t\t%s %s %d\n", info->glyph_names[left], |
| 2968 |
info->glyph_names[right], val ); |
| 2969 |
} else { |
| 2970 |
printf( "\t\t%d %d %d\n", left, right, val ); |
| 2971 |
} |
| 2972 |
} |
| 2973 |
} |
| 2974 |
fseek(ttf,begin+header_size,SEEK_SET); |
| 2975 |
} else { |
| 2976 |
len = getlong(ttf); |
| 2977 |
coverage = getushort(ttf); |
| 2978 |
printf( "\t len=%d coverage=%x %s%s%s sub table format=%d\n", |
| 2979 |
len, (unsigned int)(coverage), |
| 2980 |
( coverage&0x8000 ) ? "Vertical": "Horizontal", |
| 2981 |
( coverage&0x4000 ) ? " cross-stream" : "", |
| 2982 |
( coverage&0x2000 ) ? " kern-variation" : "", |
| 2983 |
( coverage&0xff )); |
| 2984 |
printf( "\t tuple index=%d\n", getushort(ttf)); |
| 2985 |
switch ( (coverage&0xff) ) { |
| 2986 |
case 1: |
| 2987 |
readttfkern_context(ttf,util, info, len-6); |
| 2988 |
break; |
| 2989 |
case 2: |
| 2990 |
printf( "\t row Width=%d\n", getushort(ttf)); |
| 2991 |
printf( "\t left class offset=%d\n", left =getushort(ttf)); |
| 2992 |
printf( "\t right class offset=%d\n", right = getushort(ttf)); |
| 2993 |
printf( "\t array offset=%d\n", array = getushort(ttf)); |
| 2994 |
fseek(ttf,begin+left,SEEK_SET); |
| 2995 |
printf( "\t left class table\n" ); |
| 2996 |
printf( "\t first Glyph=%d\n", getushort(ttf) ); |
| 2997 |
printf( "\t number of glyphs=%d\n", n = getushort(ttf) ); |
| 2998 |
printf( "\t " ); |
| 2999 |
for ( j=0; j<n; ++j ) |
| 3000 |
printf( " %d", getushort(ttf)); |
| 3001 |
printf( "\n" ); |
| 3002 |
fseek(ttf,begin+right,SEEK_SET); |
| 3003 |
printf( "\t right class table\n" ); |
| 3004 |
printf( "\t first Glyph=%d\n", getushort(ttf) ); |
| 3005 |
printf( "\t number of glyphs=%d\n", n = getushort(ttf) ); |
| 3006 |
printf( "\t " ); |
| 3007 |
for ( j=0; j<n; ++j ) |
| 3008 |
printf( " %d", getushort(ttf)); |
| 3009 |
printf( "\n" ); |
| 3010 |
break; |
| 3011 |
} |
| 3012 |
fseek(ttf,begin+header_size,SEEK_SET); |
| 3013 |
} |
| 3014 |
fseek(ttf,len-header_size,SEEK_CUR); |
| 3015 |
} |
| 3016 |
} |
| 3017 |
|
| 3018 |
static void readttffontdescription(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 3019 |
int n, i; |
| 3020 |
uint32_t tag, lval; |
| 3021 |
double val; |
| 3022 |
|
| 3023 |
fseek(ttf,info->fdsc_start,SEEK_SET); |
| 3024 |
printf( "\nfdsc table (at %d) (font description)\n", info->fdsc_start ); |
| 3025 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 3026 |
n = getushort(ttf); |
| 3027 |
printf( "\t number of descriptions=%d\n", n); |
| 3028 |
for ( i=0; i<n; ++i ) { |
| 3029 |
tag = getlong(ttf); |
| 3030 |
val = getfixed(ttf); |
| 3031 |
fseek(ttf,-4,SEEK_CUR); |
| 3032 |
lval = getlong(ttf); |
| 3033 |
printf("\t %c%c%c%c %s %08lx ", |
| 3034 |
(char)((tag>>24)&0xff), (char)((tag>>16)&0xff), |
| 3035 |
(char)((tag>>8)&0xff), (char)(tag&0xff), |
| 3036 |
tag==CHR('w','g','h','t')? "Weight" : |
| 3037 |
tag==CHR('w','d','t','h')? "Width" : |
| 3038 |
tag==CHR('s','l','n','t')? "Slant" : |
| 3039 |
tag==CHR('o','p','s','z')? "Optical Size" : |
| 3040 |
tag==CHR('n','a','l','f')? "Non-alphabetic" : |
| 3041 |
"Unknown", |
| 3042 |
(long unsigned int)(lval) ); |
| 3043 |
switch ( tag ) { |
| 3044 |
case CHR('w','g','h','t'): |
| 3045 |
case CHR('w','d','t','h'): |
| 3046 |
case CHR('s','l','n','t'): |
| 3047 |
case CHR('o','p','s','z'): |
| 3048 |
default: |
| 3049 |
printf( "%g\n", val ); |
| 3050 |
break; |
| 3051 |
case CHR('n','a','l','f'): |
| 3052 |
printf( lval==0 ? "Alphabetic\n" : |
| 3053 |
lval==1 ? "Dingbats\n" : |
| 3054 |
lval==2 ? "Pi characters\n" : |
| 3055 |
lval==3 ? "Fleurons\n" : |
| 3056 |
lval==4 ? "Decorative borders\n" : |
| 3057 |
lval==5 ? "International symbols\n" : |
| 3058 |
lval==6 ? "Math symbols\n" : |
| 3059 |
"Unknown" ); |
| 3060 |
break; |
| 3061 |
} |
| 3062 |
} |
| 3063 |
} |
| 3064 |
|
| 3065 |
static void readttffeatures(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 3066 |
int n, i, j, nameid; |
| 3067 |
uint32_t setting_offset; |
| 3068 |
|
| 3069 |
fseek(ttf,info->feat_start,SEEK_SET); |
| 3070 |
printf( "\nfeat table (at %d) (feature names)\n", info->feat_start ); |
| 3071 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 3072 |
n = getushort(ttf); |
| 3073 |
printf( "\t number of features=%d\n", n); |
| 3074 |
printf( "\t must be zero: %x\n", (unsigned int)(getushort(ttf)) ); |
| 3075 |
printf( "\t must be zero: %x\n", (unsigned int)(getlong(ttf)) ); |
| 3076 |
info->features = calloc(n+1,sizeof(struct features)); |
| 3077 |
info->features[n].feature = -1; |
| 3078 |
for ( i=0; i<n; ++i ) { |
| 3079 |
info->features[i].feature = getushort(ttf); |
| 3080 |
info->features[i].nsettings = getushort(ttf); |
| 3081 |
info->features[i].settings = calloc(info->features[i].nsettings,sizeof(struct settings)); |
| 3082 |
setting_offset = getlong(ttf); |
| 3083 |
info->features[i].featureflags = getushort(ttf); |
| 3084 |
nameid = getushort(ttf); |
| 3085 |
info->features[i].name = getttfname(util,info,nameid); |
| 3086 |
printf( "\t Feature %d\n", i ); |
| 3087 |
printf( "\t Feature Id %d\n", info->features[i].feature ); |
| 3088 |
printf( "\t number Settings %d\n", info->features[i].nsettings ); |
| 3089 |
printf( "\t setting offset %d\n", (int)(setting_offset) ); |
| 3090 |
printf( "\t feature flags %d ", info->features[i].featureflags ); |
| 3091 |
if ( !(info->features[i].featureflags&0x8000) ) |
| 3092 |
printf( "Non-Exclusive settings\n" ); |
| 3093 |
else if ( !(info->features[i].featureflags&0x4000) ) |
| 3094 |
printf( "Exclusive Settings, Default=0\n" ); |
| 3095 |
else |
| 3096 |
printf( "Exclusive Settings, Default=%d\n", info->features[i].featureflags&0xff); |
| 3097 |
printf( "\t name index %d (%s)\n", nameid, info->features[i].name==NULL?"Not found":info->features[i].name ); |
| 3098 |
fseek(util,info->feat_start+setting_offset,SEEK_SET); |
| 3099 |
for ( j=0; j<info->features[i].nsettings; ++j ) { |
| 3100 |
info->features[i].settings[j].setting = getushort(util); |
| 3101 |
info->features[i].settings[j].nameid = getushort(util); |
| 3102 |
} |
| 3103 |
for ( j=0; j<info->features[i].nsettings; ++j ) |
| 3104 |
info->features[i].settings[j].name = getttfname(util,info,info->features[i].settings[j].nameid); |
| 3105 |
for ( j=0; j<info->features[i].nsettings; ++j ) |
| 3106 |
printf( "\t Setting %d nameid=%d name=%s\n", |
| 3107 |
info->features[i].settings[j].setting, |
| 3108 |
info->features[i].settings[j].nameid, |
| 3109 |
info->features[i].settings[j].name==NULL ? "Not found" : |
| 3110 |
info->features[i].settings[j].name ); |
| 3111 |
} |
| 3112 |
} |
| 3113 |
|
| 3114 |
static char *getfeaturename(struct ttfinfo *info, int type) { |
| 3115 |
int k; |
| 3116 |
char *name; |
| 3117 |
|
| 3118 |
name = NULL; |
| 3119 |
if ( info->features!=NULL ) { |
| 3120 |
for ( k=0; info->features[k].feature!=-1 && info->features[k].feature!=type; ++k ); |
| 3121 |
name = info->features[k].name; |
| 3122 |
} |
| 3123 |
if ( name!=NULL ) |
| 3124 |
return( name ); |
| 3125 |
|
| 3126 |
return( (char *)(( |
| 3127 |
type==0 ? "All typographic features" : |
| 3128 |
type==1 ? "Ligature" : |
| 3129 |
type==2 ? "Cursive connection" : |
| 3130 |
type==3 ? "Letter case" : |
| 3131 |
type==4 ? "Vertical substitution" : |
| 3132 |
type==5 ? "Linguistic rearrangement" : |
| 3133 |
type==6 ? "Number spacing" : |
| 3134 |
type==7 ? "apple, reserved" : |
| 3135 |
type==8 ? "Smart swashes" : |
| 3136 |
type==9 ? "Diacritics" : |
| 3137 |
type==10 ? "Vertical Position" : |
| 3138 |
type==11 ? "Fractions" : |
| 3139 |
type==13 ? "Overlapping characters" : |
| 3140 |
type==14 ? "Typographic extras" : |
| 3141 |
type==15 ? "Mathematical extras" : |
| 3142 |
type==16 ? "Ornament sets" : |
| 3143 |
type==17 ? "Character alternatives" : |
| 3144 |
type==18 ? "Design complexity" : |
| 3145 |
type==19 ? "Style options" : |
| 3146 |
type==20 ? "Character shape" : |
| 3147 |
type==21 ? "Number case" : |
| 3148 |
type==22 ? "Text/Letter spacing" : |
| 3149 |
type==23 ? "Transliteration" : |
| 3150 |
type==24 ? "Annotation" : |
| 3151 |
type==25 ? "Kana Spacing" : |
| 3152 |
type==26 ? "Ideographic Spacing" : |
| 3153 |
type==27 ? "Unicode Decomposition" : |
| 3154 |
type==28 ? "Ruby Kana" : |
| 3155 |
type==29 ? "CJK Symbol Alternatives" : |
| 3156 |
type==30 ? "Ideographic Alternatives" : |
| 3157 |
type==31 ? "CJK Vertical Roman Placement" : |
| 3158 |
type==32 ? "Italic CJK Roman" : |
| 3159 |
type==33 ? "Case Sensitive Layout" : |
| 3160 |
type==34 ? "Alternate Kana" : |
| 3161 |
type==35 ? "Stylistic Alternatives" : |
| 3162 |
type==36 ? "Contextual Alternates" : |
| 3163 |
type==37 ? "Lower Case" : |
| 3164 |
type==38 ? "Upper Case" : |
| 3165 |
type==39 ? "Language Tag" : |
| 3166 |
type==103 ? "CJK Roman spacing" : |
| 3167 |
|
| 3168 |
type==100 ? "(Adobe) Character Spacing" : |
| 3169 |
type==101 ? "(Adobe) Kana Spacing" : |
| 3170 |
type==102 ? "(Adobe) Kanji Spacing" : |
| 3171 |
type==104 ? "(Adobe) Square Ligatures" : |
| 3172 |
|
| 3173 |
type==16000 ? "?Decompose Unicode (undocumented)?" : |
| 3174 |
type==16001 ? "?Combining character (undocumented)?" : |
| 3175 |
"Unknown feature type")) ); |
| 3176 |
} |
| 3177 |
|
| 3178 |
static char *getsettingname(struct ttfinfo *info, int type, int setting) { |
| 3179 |
int k,l; |
| 3180 |
char *name; |
| 3181 |
|
| 3182 |
name = NULL; |
| 3183 |
if ( info->features!=NULL ) { |
| 3184 |
for ( k=0; info->features[k].feature!=-1 && info->features[k].feature!=type; ++k ); |
| 3185 |
if ( info->features[k].feature!=-1 ) { |
| 3186 |
|
| 3187 |
for ( l=0 ; l<info->features[k].nsettings && info->features[k].settings[l].setting!=setting; ++l ); |
| 3188 |
if ( l<info->features[k].nsettings ) |
| 3189 |
name = info->features[k].settings[l].name; |
| 3190 |
} |
| 3191 |
} |
| 3192 |
if ( name ) |
| 3193 |
return( name ); |
| 3194 |
|
| 3195 |
|
| 3196 |
else switch ( type ) { |
| 3197 |
case 0: |
| 3198 |
return( (char *)(( |
| 3199 |
setting==0 ? "On" : |
| 3200 |
setting==1 ? "Off" : |
| 3201 |
"Unknown")) ); |
| 3202 |
break; |
| 3203 |
case 1: |
| 3204 |
return( (char *)(( |
| 3205 |
setting==0 ? "Required ligatures On" : |
| 3206 |
setting==1 ? "Required ligatures Off" : |
| 3207 |
setting==2 ? "Common Ligatures On" : |
| 3208 |
setting==3 ? "Common Ligatures Off" : |
| 3209 |
setting==4 ? "Rare Ligatures On" : |
| 3210 |
setting==5 ? "Rare Ligatures Off" : |
| 3211 |
setting==6 ? "Logos On" : |
| 3212 |
setting==7 ? "Logos Off" : |
| 3213 |
setting==8 ? "Rebus pictures On" : |
| 3214 |
setting==9 ? "Rebus pictures Off" : |
| 3215 |
setting==10 ? "Diphthong ligatures On" : |
| 3216 |
setting==11 ? "Diphthong ligatures Off" : |
| 3217 |
setting==12 ? "Squared ligatures On" : |
| 3218 |
setting==13 ? "Squared ligatures Off" : |
| 3219 |
setting==14 ? "Squared ligatures, abbreviated On" : |
| 3220 |
setting==15 ? "Squared ligatures, abbreviated Off" : |
| 3221 |
setting==16 ? "Symbol ligatures On" : |
| 3222 |
setting==17 ? "Symbol ligatures Off" : |
| 3223 |
setting==18 ? "Contextual ligatures On" : |
| 3224 |
setting==19 ? "Contextual ligatures Off" : |
| 3225 |
setting==20 ? "Historical ligatures On" : |
| 3226 |
setting==21 ? "Historical ligatures Off" : |
| 3227 |
"Unknown")) ); |
| 3228 |
break; |
| 3229 |
case 2: |
| 3230 |
return( (char *)(( |
| 3231 |
setting==0 ? "Unconnected" : |
| 3232 |
setting==1 ? "Partially connected" : |
| 3233 |
setting==2 ? "Cursive" : |
| 3234 |
"Unknown")) ); |
| 3235 |
break; |
| 3236 |
case 3: |
| 3237 |
return( (char *)(( |
| 3238 |
setting==0 ? "Upper & Lower case" : |
| 3239 |
setting==1 ? "All Caps" : |
| 3240 |
setting==2 ? "All Lower Case" : |
| 3241 |
setting==3 ? "Small Caps" : |
| 3242 |
setting==4 ? "Initial Caps" : |
| 3243 |
setting==5 ? "Initial Caps & Small Caps" : |
| 3244 |
"Unknown")) ); |
| 3245 |
break; |
| 3246 |
case 4: |
| 3247 |
return( (char *)(( |
| 3248 |
setting==0 ? "On" : |
| 3249 |
setting==1 ? "Off" : |
| 3250 |
"Unknown")) ); |
| 3251 |
break; |
| 3252 |
case 5: |
| 3253 |
return( (char *)(( |
| 3254 |
setting==0 ? "On" : |
| 3255 |
setting==1 ? "Off" : |
| 3256 |
"Unknown")) ); |
| 3257 |
break; |
| 3258 |
case 6: |
| 3259 |
return( (char *)(( |
| 3260 |
setting==0 ? "Monospaced Numbers" : |
| 3261 |
setting==1 ? "Proportional Numbers" : |
| 3262 |
setting==2 ? "Third-width Numerals" : |
| 3263 |
setting==3 ? "Quarter-width Numerals" : |
| 3264 |
"Unknown")) ); |
| 3265 |
break; |
| 3266 |
case 8: |
| 3267 |
return( (char *)(( |
| 3268 |
setting==0 ? "Initial swashes On" : |
| 3269 |
setting==1 ? "Initial swashes Off" : |
| 3270 |
setting==2 ? "Final swashes On" : |
| 3271 |
setting==3 ? "Final swashes Off" : |
| 3272 |
setting==4 ? "line initial swashes On" : |
| 3273 |
setting==5 ? "line initial swashes Off" : |
| 3274 |
setting==6 ? "line final swashes On" : |
| 3275 |
setting==7 ? "line final swashes Off" : |
| 3276 |
setting==8 ? "non-final swashes On" : |
| 3277 |
setting==9 ? "non-final swashes Off" : |
| 3278 |
"Unknown")) ); |
| 3279 |
break; |
| 3280 |
case 9: |
| 3281 |
return( (char *)(( |
| 3282 |
setting==0 ? "show Diacritics" : |
| 3283 |
setting==1 ? "hide Diacritics" : |
| 3284 |
setting==2 ? "decompose Diacritics" : |
| 3285 |
"Unknown")) ); |
| 3286 |
break; |
| 3287 |
case 10: |
| 3288 |
return( (char *)(( |
| 3289 |
setting==0 ? "normal position" : |
| 3290 |
setting==1 ? "superiors" : |
| 3291 |
setting==2 ? "inferiors" : |
| 3292 |
setting==3 ? "ordinals" : |
| 3293 |
setting==4 ? "scientific inferiors" : |
| 3294 |
"Unknown")) ); |
| 3295 |
break; |
| 3296 |
case 11: |
| 3297 |
return( (char *)(( |
| 3298 |
setting==0 ? "no fractions" : |
| 3299 |
setting==1 ? "vertical fractions" : |
| 3300 |
setting==2 ? "diagonal fractions" : |
| 3301 |
"Unknown")) ); |
| 3302 |
break; |
| 3303 |
case 13: |
| 3304 |
return( (char *)(( |
| 3305 |
setting==0 ? "prevent Overlap On" : |
| 3306 |
setting==1 ? "prevent Overlap Off" : |
| 3307 |
"Unknown")) ); |
| 3308 |
break; |
| 3309 |
case 14: |
| 3310 |
return( (char *)(( |
| 3311 |
setting==0 ? "hyphens to Em dashes On" : |
| 3312 |
setting==1 ? "hyphens to Em dashes Off" : |
| 3313 |
setting==2 ? "hyphens to En dashes On" : |
| 3314 |
setting==3 ? "hyphens to En dashes Off" : |
| 3315 |
setting==4 ? "unslashed Zero On" : |
| 3316 |
setting==5 ? "unslashed Zero Off" : |
| 3317 |
setting==6 ? "form Interrobang On" : |
| 3318 |
setting==7 ? "form Interrobang Off" : |
| 3319 |
setting==8 ? "smart Quotes On" : |
| 3320 |
setting==9 ? "smart Quotes Off" : |
| 3321 |
setting==10 ? "periods to ellipsis On" : |
| 3322 |
setting==11 ? "periods to ellipsis Off" : |
| 3323 |
"Unknown")) ); |
| 3324 |
break; |
| 3325 |
case 15: |
| 3326 |
return( (char *)(( |
| 3327 |
setting==0 ? "hyphen to minus On" : |
| 3328 |
setting==1 ? "hyphen to minus Off" : |
| 3329 |
setting==2 ? "asterisk to multiply On" : |
| 3330 |
setting==3 ? "asterisk to multiply Off" : |
| 3331 |
setting==4 ? "slash to divide On" : |
| 3332 |
setting==5 ? "slash to divide Off" : |
| 3333 |
setting==6 ? "inequality ligatures On" : |
| 3334 |
setting==7 ? "inequality ligatures Off" : |
| 3335 |
setting==8 ? "exponents On" : |
| 3336 |
setting==9 ? "exponents Off" : |
| 3337 |
setting==10 ? "mathematical Greek Off" : |
| 3338 |
setting==11 ? "mathematical Greek Off" : |
| 3339 |
"Unknown")) ); |
| 3340 |
break; |
| 3341 |
case 16: |
| 3342 |
return( (char *)(( |
| 3343 |
setting==0 ? "no ornaments" : |
| 3344 |
setting==1 ? "dingbats" : |
| 3345 |
setting==2 ? "pi Characters" : |
| 3346 |
setting==3 ? "fleurons" : |
| 3347 |
setting==4 ? "decorative borders" : |
| 3348 |
setting==5 ? "international symbols" : |
| 3349 |
setting==6 ? "math symbols" : |
| 3350 |
"Unknown")) ); |
| 3351 |
break; |
| 3352 |
case 17: |
| 3353 |
return( (char *)(( |
| 3354 |
setting==0 ? "no alternates" : |
| 3355 |
"Unknown")) ); |
| 3356 |
break; |
| 3357 |
case 18: |
| 3358 |
return( (char *)(( |
| 3359 |
setting==0 ? "design level 1" : |
| 3360 |
setting==1 ? "design level 2" : |
| 3361 |
setting==2 ? "design level 3" : |
| 3362 |
setting==3 ? "design level 4" : |
| 3363 |
setting==4 ? "design level 5" : |
| 3364 |
"Unknown")) ); |
| 3365 |
break; |
| 3366 |
case 19: |
| 3367 |
return( (char *)(( |
| 3368 |
setting==0 ? "no style options" : |
| 3369 |
setting==1 ? "display text" : |
| 3370 |
setting==2 ? "engraved text" : |
| 3371 |
setting==3 ? "illuminated Caps" : |
| 3372 |
setting==4 ? "titling caps" : |
| 3373 |
setting==5 ? "tall caps" : |
| 3374 |
"Unknown")) ); |
| 3375 |
break; |
| 3376 |
case 20: |
| 3377 |
return( (char *)(( |
| 3378 |
setting==0 ? "traditional characters" : |
| 3379 |
setting==1 ? "simplified characters" : |
| 3380 |
setting==2 ? "JIS1978 characters" : |
| 3381 |
setting==3 ? "JIS1983 characters" : |
| 3382 |
setting==4 ? "JIS1990 characters" : |
| 3383 |
setting==5 ? "traditional alt 1" : |
| 3384 |
setting==6 ? "traditional alt 2" : |
| 3385 |
setting==7 ? "traditional alt 3" : |
| 3386 |
setting==8 ? "traditional alt 4" : |
| 3387 |
setting==9 ? "traditional alt 5" : |
| 3388 |
setting==10 ? "expert characters" : |
| 3389 |
setting==11 ? "JIS2004 characters" : |
| 3390 |
setting==12 ? "hojo characters" : |
| 3391 |
setting==13 ? "NLC characters" : |
| 3392 |
setting==14 ? "traditional name characters" : |
| 3393 |
"Unknown")) ); |
| 3394 |
break; |
| 3395 |
case 21: |
| 3396 |
return( (char *)(( |
| 3397 |
setting==0 ? "lower case numbers" : |
| 3398 |
setting==1 ? "upper case numbers" : |
| 3399 |
"Unknown")) ); |
| 3400 |
break; |
| 3401 |
case 22: |
| 3402 |
return( (char *)(( |
| 3403 |
setting==0 ? "proportional" : |
| 3404 |
setting==1 ? "monospace" : |
| 3405 |
setting==2 ? "halfwidth" : |
| 3406 |
setting==3 ? "third-width" : |
| 3407 |
setting==4 ? "quarter-width" : |
| 3408 |
setting==5 ? "alternate proportional" : |
| 3409 |
setting==6 ? "alternate halfwidth" : |
| 3410 |
"Unknown")) ); |
| 3411 |
break; |
| 3412 |
case 23: |
| 3413 |
return( (char *)(( |
| 3414 |
setting==0 ? "no transliteration" : |
| 3415 |
setting==1 ? "hanja to hangul" : |
| 3416 |
setting==2 ? "hiragana to katakana" : |
| 3417 |
setting==3 ? "katakana to hiragana" : |
| 3418 |
setting==4 ? "kana to Romanization" : |
| 3419 |
setting==5 ? "romanization to Hiragana" : |
| 3420 |
setting==6 ? "romanization to Katakana" : |
| 3421 |
setting==7 ? "hanja to hangul alt 1" : |
| 3422 |
setting==8 ? "hanja to hangul alt 2" : |
| 3423 |
setting==9 ? "hanja to hangul alt 3" : |
| 3424 |
"Unknown")) ); |
| 3425 |
break; |
| 3426 |
case 24: |
| 3427 |
return( (char *)(( |
| 3428 |
setting==0 ? "no annotation" : |
| 3429 |
setting==1 ? "box annotation" : |
| 3430 |
setting==2 ? "rounded box annotation" : |
| 3431 |
setting==3 ? "circle annotation" : |
| 3432 |
setting==4 ? "inverted circle annotation" : |
| 3433 |
setting==5 ? "parenthesis Annotation" : |
| 3434 |
setting==6 ? "period annotation" : |
| 3435 |
setting==7 ? "roman numeral annotation" : |
| 3436 |
setting==8 ? "diamond annotation" : |
| 3437 |
setting==9 ? "inverted box annotation" : |
| 3438 |
setting==10 ? "inverted rounded box annotation" : |
| 3439 |
"Unknown")) ); |
| 3440 |
break; |
| 3441 |
case 25: |
| 3442 |
return( (char *)(( |
| 3443 |
setting==0 ? "full width kana" : |
| 3444 |
setting==1 ? "proportional kana" : |
| 3445 |
"Unknown")) ); |
| 3446 |
break; |
| 3447 |
case 26: |
| 3448 |
return( (char *)(( |
| 3449 |
setting==0 ? "full width ideograph" : |
| 3450 |
setting==1 ? "proportional ideograph" : |
| 3451 |
setting==2 ? "half width ideograph" : |
| 3452 |
"Unknown")) ); |
| 3453 |
break; |
| 3454 |
case 27: |
| 3455 |
return( (char *)(( |
| 3456 |
setting==0 ? "Canonical Composition On" : |
| 3457 |
setting==1 ? "Canonical Composition Off" : |
| 3458 |
setting==2 ? "Compatibility Composition On" : |
| 3459 |
setting==3 ? "Compatibility Composition Off" : |
| 3460 |
setting==4 ? "Transcoding Composition On" : |
| 3461 |
setting==5 ? "Transcoding Composition Off" : |
| 3462 |
"Unknown")) ); |
| 3463 |
break; |
| 3464 |
case 28: |
| 3465 |
return( (char *)(( |
| 3466 |
setting==0 ? "No Ruby Kana" : |
| 3467 |
setting==1 ? "Ruby Kana" : |
| 3468 |
setting==2 ? "Ruby Kana On" : |
| 3469 |
setting==3 ? "Ruby Kana Off" : |
| 3470 |
"Unknown")) ); |
| 3471 |
break; |
| 3472 |
case 29: |
| 3473 |
return( (char *)(( |
| 3474 |
setting==0 ? "No CJK Symbol Alternatives" : |
| 3475 |
setting==1 ? "CJK Symbol Alt One" : |
| 3476 |
setting==2 ? "CJK Symbol Alt Two" : |
| 3477 |
setting==3 ? "CJK Symbol Alt Three" : |
| 3478 |
setting==4 ? "CJK Symbol Alt Four" : |
| 3479 |
setting==5 ? "CJK Symbol Alt Five" : |
| 3480 |
"Unknown")) ); |
| 3481 |
break; |
| 3482 |
case 30: |
| 3483 |
return( (char *)(( |
| 3484 |
setting==0 ? "No Ideographic Alternatives" : |
| 3485 |
setting==1 ? "Ideographic Alt One" : |
| 3486 |
setting==2 ? "Ideographic Alt Two" : |
| 3487 |
setting==3 ? "Ideographic Alt Three" : |
| 3488 |
setting==4 ? "Ideographic Alt Four" : |
| 3489 |
setting==5 ? "Ideographic Alt Five" : |
| 3490 |
"Unknown")) ); |
| 3491 |
break; |
| 3492 |
case 31: |
| 3493 |
return( (char *)(( |
| 3494 |
setting==0 ? "CJK Vertical Roman Centered" : |
| 3495 |
setting==1 ? "CJK Vertical Roman H Baseline" : |
| 3496 |
"Unknown")) ); |
| 3497 |
break; |
| 3498 |
case 32: |
| 3499 |
return( (char *)(( |
| 3500 |
setting==0 ? "No Italic CJK Roman" : |
| 3501 |
setting==1 ? "Italic CJK Roman" : |
| 3502 |
setting==2 ? "Italic CJK Roman On" : |
| 3503 |
setting==3 ? "Italic CJK Roman Off" : |
| 3504 |
"Unknown")) ); |
| 3505 |
break; |
| 3506 |
case 33: |
| 3507 |
return( (char *)(( |
| 3508 |
setting==0 ? "Case Sensitive Layout On" : |
| 3509 |
setting==1 ? "Case Sensitive Layout Off" : |
| 3510 |
setting==2 ? "Case Sensitive Spacing On" : |
| 3511 |
setting==3 ? "Case Sensitive Spacing Off" : |
| 3512 |
"Unknown")) ); |
| 3513 |
break; |
| 3514 |
case 34: |
| 3515 |
return( (char *)(( |
| 3516 |
setting==0 ? "Alternate Horiz Kana On" : |
| 3517 |
setting==1 ? "Alternate Horiz Kana Off" : |
| 3518 |
setting==2 ? "Alternate Vert Kana On" : |
| 3519 |
setting==3 ? "Alternate Vert Kana Off" : |
| 3520 |
"Unknown")) ); |
| 3521 |
break; |
| 3522 |
case 35: |
| 3523 |
return( (char *)(( |
| 3524 |
setting==0 ? "No Stylistic Alternates" : |
| 3525 |
setting==1 ? "Stylistic Alt One" : |
| 3526 |
setting==2 ? "Stylistic Alt Two" : |
| 3527 |
setting==3 ? "Stylistic Alt Three" : |
| 3528 |
setting==4 ? "Stylistic Alt Four" : |
| 3529 |
setting==5 ? "Stylistic Alt Five" : |
| 3530 |
setting==6 ? "Stylistic Alt Six" : |
| 3531 |
setting==7 ? "Stylistic Alt Seven" : |
| 3532 |
setting==8 ? "Stylistic Alt Eight" : |
| 3533 |
setting==9 ? "Stylistic Alt Nine" : |
| 3534 |
setting==10 ? "Stylistic Alt Ten" : |
| 3535 |
setting==11 ? "Stylistic Alt Eleven" : |
| 3536 |
setting==12 ? "Stylistic Alt Twelve" : |
| 3537 |
setting==13 ? "Stylistic Alt Thirteen" : |
| 3538 |
setting==14 ? "Stylistic Alt Fourteen" : |
| 3539 |
setting==15 ? "Stylistic Alt Fifteen" : |
| 3540 |
setting==16 ? "Stylistic Alt Sixteen" : |
| 3541 |
setting==17 ? "Stylistic Alt Seventeen" : |
| 3542 |
setting==18 ? "Stylistic Alt Eighteen" : |
| 3543 |
setting==19 ? "Stylistic Alt Nineteen" : |
| 3544 |
setting==20 ? "Stylistic Alt Twenty" : |
| 3545 |
"Unknown")) ); |
| 3546 |
break; |
| 3547 |
case 36: |
| 3548 |
return( (char *)(( |
| 3549 |
setting==0 ? "Contextual Alternates On" : |
| 3550 |
setting==1 ? "Contextual Alternates Off" : |
| 3551 |
setting==2 ? "Swash Alternates On" : |
| 3552 |
setting==3 ? "Swash Alternates Off" : |
| 3553 |
setting==4 ? "Contextual Swash Alternates On" : |
| 3554 |
setting==5 ? "Contextual Swash Alternates Off" : |
| 3555 |
"Unknown")) ); |
| 3556 |
break; |
| 3557 |
case 37: |
| 3558 |
return( (char *)(( |
| 3559 |
setting==0 ? "Default Lower Case" : |
| 3560 |
setting==1 ? "Lower Case Small Caps" : |
| 3561 |
setting==2 ? "Lower Case Petite Caps" : |
| 3562 |
"Unknown")) ); |
| 3563 |
break; |
| 3564 |
case 38: |
| 3565 |
return( (char *)(( |
| 3566 |
setting==0 ? "Default Upper Case" : |
| 3567 |
setting==1 ? "Upper Case Small Caps" : |
| 3568 |
setting==2 ? "Upper Case Petite Caps" : |
| 3569 |
"Unknown")) ); |
| 3570 |
break; |
| 3571 |
case 103: |
| 3572 |
return( (char *)(( |
| 3573 |
setting==0 ? "halfwidth CJK Roman" : |
| 3574 |
setting==1 ? "proportional CJK Roman" : |
| 3575 |
setting==2 ? "default CJK Roman" : |
| 3576 |
setting==3 ? "fullwidth CJK Roman" : |
| 3577 |
"Unknown")) ); |
| 3578 |
break; |
| 3579 |
case 16000: |
| 3580 |
return( (char *)(( |
| 3581 |
setting==0 ? "Compose" : |
| 3582 |
setting==1 ? "Off" : |
| 3583 |
"Unknown")) ); |
| 3584 |
break; |
| 3585 |
case 16001: |
| 3586 |
return( (char *)(( |
| 3587 |
setting==0 ? "Combine" : |
| 3588 |
setting==1 ? "Off" : |
| 3589 |
"Unknown")) ); |
| 3590 |
break; |
| 3591 |
default: |
| 3592 |
return( (char *)(( |
| 3593 |
setting==0 ? "Unknown (?On?)" : |
| 3594 |
setting==1 ? "Unknown (?Off?)" : |
| 3595 |
"Unknown")) ); |
| 3596 |
break; |
| 3597 |
} |
| 3598 |
return( (char *)("Unknown") ); |
| 3599 |
} |
| 3600 |
|
| 3601 |
static int showbinsearchheader(FILE *ttf) { |
| 3602 |
int size, cnt; |
| 3603 |
|
| 3604 |
printf( "\t Binary search header\n" ); |
| 3605 |
printf( "\t Entry size=%d\n", size = getushort(ttf)); |
| 3606 |
printf( "\t Number of entries=%d\n", cnt = getushort(ttf)); |
| 3607 |
printf( "\t Search range=%d\n", getushort(ttf)); |
| 3608 |
printf( "\t Log2(nUnits)=%d\n", getushort(ttf)); |
| 3609 |
printf( "\t Range Shift=%d\n", getushort(ttf)); |
| 3610 |
return( cnt ); |
| 3611 |
} |
| 3612 |
|
| 3613 |
static void show_applelookuptable(FILE *ttf,struct ttfinfo *info,void (*show)(FILE *,struct ttfinfo *)) { |
| 3614 |
int i, j; |
| 3615 |
int format; |
| 3616 |
int first, last, cnt, glyph, data_offset; |
| 3617 |
uint32_t here; |
| 3618 |
uint32_t base = ftell(ttf); |
| 3619 |
|
| 3620 |
printf( "\t Lookup table format=%d ", format = getushort(ttf)); |
| 3621 |
switch ( format ) { |
| 3622 |
case 0: |
| 3623 |
printf( "Simple array\n" ); |
| 3624 |
for ( i=0; i<info->glyph_cnt; ++i ) { |
| 3625 |
printf( "Glyph %d (%s)=", i, i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? info->glyph_names[i]: "" ); |
| 3626 |
show( ttf,info ); |
| 3627 |
} |
| 3628 |
break; |
| 3629 |
case 2: |
| 3630 |
printf( "Segment Single\n" ); |
| 3631 |
cnt = showbinsearchheader(ttf); |
| 3632 |
for ( i=0; i<cnt; ++i ) { |
| 3633 |
last = getushort(ttf); |
| 3634 |
first = getushort(ttf); |
| 3635 |
printf( "All glyphs between %d (%s) and %d (%s)=", |
| 3636 |
first, |
| 3637 |
first>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 3638 |
info->glyph_names[first]: "", |
| 3639 |
last, |
| 3640 |
last>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 3641 |
info->glyph_names[last]: "" ); |
| 3642 |
show( ttf,info ); |
| 3643 |
} |
| 3644 |
break; |
| 3645 |
case 4: |
| 3646 |
printf( "Segment Array\n" ); |
| 3647 |
cnt = showbinsearchheader(ttf); |
| 3648 |
for ( i=0; i<cnt; ++i ) { |
| 3649 |
last = getushort(ttf); |
| 3650 |
first = getushort(ttf); |
| 3651 |
data_offset = getushort(ttf); |
| 3652 |
here = ftell(ttf); |
| 3653 |
fseek(ttf,base+data_offset,SEEK_SET); |
| 3654 |
printf( "\t\tSegment %d, from glyph %d to glyph %d. Data offset=%d\n", |
| 3655 |
i, first, last, data_offset ); |
| 3656 |
for ( j=first; j<=last; ++j ) { |
| 3657 |
printf( "Glyph %d (%s)=", j, |
| 3658 |
j>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 3659 |
info->glyph_names[j]: "" ); |
| 3660 |
show( ttf,info ); |
| 3661 |
} |
| 3662 |
fseek(ttf,here,SEEK_SET); |
| 3663 |
} |
| 3664 |
break; |
| 3665 |
case 6: |
| 3666 |
printf( "Single table\n" ); |
| 3667 |
cnt = showbinsearchheader(ttf); |
| 3668 |
for ( i=0; i<cnt; ++i ) { |
| 3669 |
glyph = getushort(ttf); |
| 3670 |
printf( "Glyph %d (%s)=", glyph, |
| 3671 |
glyph>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 3672 |
info->glyph_names[glyph]: "" ); |
| 3673 |
show( ttf,info ); |
| 3674 |
} |
| 3675 |
break; |
| 3676 |
case 8: |
| 3677 |
printf( "Trimmed array\n" ); |
| 3678 |
first = getushort(ttf); |
| 3679 |
cnt = getushort(ttf); |
| 3680 |
for ( i=0; i<cnt; ++i ) { |
| 3681 |
printf( "Glyph %d (%s)=", i+first, |
| 3682 |
i+first>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 3683 |
info->glyph_names[i+first]: "" ); |
| 3684 |
show( ttf,info ); |
| 3685 |
} |
| 3686 |
break; |
| 3687 |
default: |
| 3688 |
printf( "Unknown format for lookup table %d\n", format ); |
| 3689 |
} |
| 3690 |
} |
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
struct classes { |
| 3700 |
}; |
| 3701 |
|
| 3702 |
struct statetable { |
| 3703 |
uint32_t state_start; |
| 3704 |
int nclasses; |
| 3705 |
int nstates; |
| 3706 |
int nentries; |
| 3707 |
int state_offset; |
| 3708 |
int entry_size; |
| 3709 |
int entry_extras; |
| 3710 |
int first_glyph; |
| 3711 |
int nglyphs; |
| 3712 |
uint8_t *classes; |
| 3713 |
uint8_t *state_table; |
| 3714 |
|
| 3715 |
uint16_t *state_table2; |
| 3716 |
uint16_t *classes2; |
| 3717 |
uint8_t *transitions; |
| 3718 |
uint32_t extra_offsets[3]; |
| 3719 |
int len; |
| 3720 |
}; |
| 3721 |
|
| 3722 |
static void show_statetable(struct statetable *st, struct ttfinfo *info, FILE *ttf, |
| 3723 |
void (*entry_print)(uint8_t *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf)) { |
| 3724 |
int i, j; |
| 3725 |
uint8_t *pt; |
| 3726 |
|
| 3727 |
printf( "\t State table\n" ); |
| 3728 |
printf( "\t num classes = %d\n", st->nclasses ); |
| 3729 |
printf( "\t num states = %d (derived)\n", st->nstates ); |
| 3730 |
printf( "\t num entries = %d (derived)\n", st->nentries ); |
| 3731 |
printf( "\t entry size = %d (derived)\n", st->entry_size ); |
| 3732 |
printf( "\t first classified glyph = %d (%s), glyph_cnt=%d\n", st->first_glyph, |
| 3733 |
st->first_glyph>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL?info->glyph_names[st->first_glyph]:"", |
| 3734 |
st->nglyphs); |
| 3735 |
if ( info->glyph_names!=NULL ) { |
| 3736 |
for ( i=0; i<st->nglyphs; ++i ) |
| 3737 |
printf( "\t Glyph %4d -> Class %d (%s)\n", |
| 3738 |
st->first_glyph+i, st->classes[i], |
| 3739 |
st->first_glyph+i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names[st->first_glyph+i]); |
| 3740 |
} else { |
| 3741 |
for ( i=0; i<st->nglyphs; ++i ) |
| 3742 |
printf( "\t Glyph %4d -> Class %d\n", |
| 3743 |
st->first_glyph+i, st->classes[i] ); |
| 3744 |
} |
| 3745 |
|
| 3746 |
|
| 3747 |
printf( "Classes: " ); |
| 3748 |
for ( j=0; j<st->nclasses; ++j ) |
| 3749 |
printf( "%4d", j ); |
| 3750 |
printf( "\n" ); |
| 3751 |
for ( i=0; i<st->nstates; ++i ) { |
| 3752 |
printf( "State %2d: ", i ); |
| 3753 |
for ( j=0; j<st->nclasses; ++j ) |
| 3754 |
printf( "%4d", st->state_table[i*st->nclasses+j]); |
| 3755 |
printf( "\n" ); |
| 3756 |
} |
| 3757 |
|
| 3758 |
|
| 3759 |
for ( i=0; i<st->nentries; ++i ) { |
| 3760 |
pt = st->transitions + i*st->entry_size; |
| 3761 |
printf( "\t Transition Entry %d\n", i ); |
| 3762 |
printf( "\t New State %d\n", (((pt[0]<<8)|pt[1])-st->state_offset)/st->nclasses ); |
| 3763 |
if ( entry_print!=NULL ) |
| 3764 |
entry_print(pt,st,info,ttf); |
| 3765 |
else { |
| 3766 |
printf( "\t Flags %04x\n", (unsigned int)(((pt[2]<<8)|pt[3])) ); |
| 3767 |
for ( j=0; j<st->entry_extras; ++j ) |
| 3768 |
printf( "\t GlyphOffset[%d] = %d\n", j, (pt[2*j+4]<<8)|pt[2*j+5]); |
| 3769 |
} |
| 3770 |
} |
| 3771 |
printf( "\n" ); |
| 3772 |
} |
| 3773 |
|
| 3774 |
static void show_statetablex(struct statetable *st, struct ttfinfo *info, FILE *ttf, |
| 3775 |
void (*entry_print)(uint8_t *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf)) { |
| 3776 |
int i, j; |
| 3777 |
uint8_t *pt; |
| 3778 |
|
| 3779 |
printf( "\t State table\n" ); |
| 3780 |
printf( "\t num classes = %d\n", st->nclasses ); |
| 3781 |
printf( "\t num states = %d (derived)\n", st->nstates ); |
| 3782 |
printf( "\t num entries = %d (derived)\n", st->nentries ); |
| 3783 |
printf( "\t entry size = %d (derived)\n", st->entry_size ); |
| 3784 |
for ( i=0; i<info->glyph_cnt ; ++i ) if ( st->classes2[i]!=1 ) { |
| 3785 |
if ( info->glyph_names!=NULL ) { |
| 3786 |
printf( "\t Glyph %4d -> Class %d (%s)\n", |
| 3787 |
i, st->classes2[i], |
| 3788 |
i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names[i]); |
| 3789 |
} else { |
| 3790 |
printf( "\t Glyph %4d -> Class %d\n", |
| 3791 |
i, st->classes2[i] ); |
| 3792 |
} |
| 3793 |
} |
| 3794 |
|
| 3795 |
|
| 3796 |
printf( "Classes: " ); |
| 3797 |
for ( j=0; j<st->nclasses; ++j ) |
| 3798 |
printf( "%4d", j ); |
| 3799 |
printf( "\n" ); |
| 3800 |
for ( i=0; i<st->nstates; ++i ) { |
| 3801 |
printf( "State %2d: ", i ); |
| 3802 |
for ( j=0; j<st->nclasses; ++j ) |
| 3803 |
printf( "%4d", st->state_table2[i*st->nclasses+j]); |
| 3804 |
printf( "\n" ); |
| 3805 |
} |
| 3806 |
|
| 3807 |
|
| 3808 |
for ( i=0; i<st->nentries; ++i ) { |
| 3809 |
pt = st->transitions + i*st->entry_size; |
| 3810 |
printf( "\t Transition Entry %d\n", i ); |
| 3811 |
printf( "\t New State %d\n", ((pt[0]<<8)|pt[1]) ); |
| 3812 |
if ( entry_print!=NULL ) |
| 3813 |
entry_print(pt,st,info,ttf); |
| 3814 |
else { |
| 3815 |
printf( "\t Flags %04x\n", (unsigned int)(((pt[2]<<8)|pt[3])) ); |
| 3816 |
for ( j=0; j<st->entry_extras; ++j ) |
| 3817 |
printf( "\t GlyphOffset[%d] = %d\n", j, (pt[2*j+4]<<8)|pt[2*j+5]); |
| 3818 |
} |
| 3819 |
} |
| 3820 |
printf( "\n" ); |
| 3821 |
} |
| 3822 |
|
| 3823 |
static void readttf_applelookup(FILE *ttf,struct ttfinfo *info, |
| 3824 |
void (*apply_values)(struct ttfinfo *info, int gfirst, int glast,FILE *ttf), |
| 3825 |
void (*apply_value)(struct ttfinfo *info, int gfirst, int glast,FILE *ttf), |
| 3826 |
void (*apply_default)(struct ttfinfo *info, int gfirst, int glast,void *def), |
| 3827 |
void *def) { |
| 3828 |
int format, i, first, last, data_off, cnt, prev; |
| 3829 |
uint32_t here; |
| 3830 |
uint32_t base = ftell(ttf); |
| 3831 |
|
| 3832 |
switch ( format = getushort(ttf)) { |
| 3833 |
case 0: |
| 3834 |
apply_values(info,0,info->glyph_cnt-1,ttf); |
| 3835 |
break; |
| 3836 |
case 2: |
| 3837 |
getushort(ttf); |
| 3838 |
cnt = getushort(ttf); |
| 3839 |
getushort(ttf); |
| 3840 |
getushort(ttf); |
| 3841 |
getushort(ttf); |
| 3842 |
prev = 0; |
| 3843 |
for ( i=0; i<cnt; ++i ) { |
| 3844 |
last = getushort(ttf); |
| 3845 |
first = getushort(ttf); |
| 3846 |
if ( apply_default!=NULL ) |
| 3847 |
apply_default(info,prev,first-1,def); |
| 3848 |
apply_value(info,first,last,ttf); |
| 3849 |
prev = last+1; |
| 3850 |
} |
| 3851 |
break; |
| 3852 |
case 4: |
| 3853 |
getushort(ttf); |
| 3854 |
cnt = getushort(ttf); |
| 3855 |
getushort(ttf); |
| 3856 |
getushort(ttf); |
| 3857 |
getushort(ttf); |
| 3858 |
prev = 0; |
| 3859 |
for ( i=0; i<cnt; ++i ) { |
| 3860 |
last = getushort(ttf); |
| 3861 |
first = getushort(ttf); |
| 3862 |
data_off = getushort(ttf); |
| 3863 |
here = ftell(ttf); |
| 3864 |
if ( apply_default!=NULL ) |
| 3865 |
apply_default(info,prev,first-1,def); |
| 3866 |
fseek(ttf,base+data_off,SEEK_SET); |
| 3867 |
apply_values(info,first,last,ttf); |
| 3868 |
fseek(ttf,here,SEEK_SET); |
| 3869 |
prev = last+1; |
| 3870 |
} |
| 3871 |
break; |
| 3872 |
case 6: |
| 3873 |
getushort(ttf); |
| 3874 |
cnt = getushort(ttf); |
| 3875 |
getushort(ttf); |
| 3876 |
getushort(ttf); |
| 3877 |
getushort(ttf); |
| 3878 |
prev = 0; |
| 3879 |
for ( i=0; i<cnt; ++i ) { |
| 3880 |
first = getushort(ttf); |
| 3881 |
if ( apply_default!=NULL ) |
| 3882 |
apply_default(info,prev,first-1,def); |
| 3883 |
apply_value(info,first,first,ttf); |
| 3884 |
prev = first+1; |
| 3885 |
} |
| 3886 |
break; |
| 3887 |
case 8: |
| 3888 |
first = getushort(ttf); |
| 3889 |
cnt = getushort(ttf); |
| 3890 |
if ( apply_default!=NULL ) { |
| 3891 |
apply_default(info,0,first-1,def); |
| 3892 |
apply_default(info,first+cnt,info->glyph_cnt-1,def); |
| 3893 |
} |
| 3894 |
apply_values(info,first,first+cnt-1,ttf); |
| 3895 |
break; |
| 3896 |
default: |
| 3897 |
fprintf( stderr, "Invalid lookup table format. %d\n", format ); |
| 3898 |
break; |
| 3899 |
} |
| 3900 |
} |
| 3901 |
|
| 3902 |
static void mortclass_apply_values(struct ttfinfo *info, int gfirst, int glast,FILE *ttf) { |
| 3903 |
int i; |
| 3904 |
|
| 3905 |
for ( i=gfirst; i<=glast; ++i ) |
| 3906 |
info->morx_classes[i] = getushort(ttf); |
| 3907 |
} |
| 3908 |
|
| 3909 |
static void mortclass_apply_value(struct ttfinfo *info, int gfirst, int glast,FILE *ttf) { |
| 3910 |
uint16_t class; |
| 3911 |
int i; |
| 3912 |
|
| 3913 |
class = getushort(ttf); |
| 3914 |
|
| 3915 |
for ( i=gfirst; i<=glast; ++i ) |
| 3916 |
info->morx_classes[i] = class; |
| 3917 |
} |
| 3918 |
|
| 3919 |
static struct statetable *read_statetable(FILE *ttf, int ent_extras, int ismorx, struct ttfinfo *info) { |
| 3920 |
struct statetable *st = calloc(1,sizeof(struct statetable)); |
| 3921 |
uint32_t here = ftell(ttf); |
| 3922 |
int nclasses, class_off, state_off, entry_off; |
| 3923 |
int state_max, ent_max, old_state_max, old_ent_max; |
| 3924 |
int i, j, ent, new_state, ent_size; |
| 3925 |
|
| 3926 |
st->state_start = here; |
| 3927 |
|
| 3928 |
if ( ismorx ) { |
| 3929 |
nclasses = getlong(ttf); |
| 3930 |
class_off = getlong(ttf); |
| 3931 |
state_off = getlong(ttf); |
| 3932 |
entry_off = getlong(ttf); |
| 3933 |
st->extra_offsets[0] = getlong(ttf); |
| 3934 |
st->extra_offsets[1] = getlong(ttf); |
| 3935 |
st->extra_offsets[2] = getlong(ttf); |
| 3936 |
} else { |
| 3937 |
nclasses = getushort(ttf); |
| 3938 |
class_off = getushort(ttf); |
| 3939 |
state_off = getushort(ttf); |
| 3940 |
entry_off = getushort(ttf); |
| 3941 |
st->extra_offsets[0] = getushort(ttf); |
| 3942 |
st->extra_offsets[1] = getushort(ttf); |
| 3943 |
st->extra_offsets[2] = getushort(ttf); |
| 3944 |
} |
| 3945 |
st->nclasses = nclasses; |
| 3946 |
st->state_offset = state_off; |
| 3947 |
|
| 3948 |
|
| 3949 |
fseek(ttf,here+class_off,SEEK_SET); |
| 3950 |
if ( ismorx ) { |
| 3951 |
st->classes2 = info->morx_classes = malloc(info->glyph_cnt*sizeof(uint16_t)); |
| 3952 |
for ( i=0; i<info->glyph_cnt; ++i ) |
| 3953 |
st->classes2[i] = 1; |
| 3954 |
readttf_applelookup(ttf,info, |
| 3955 |
mortclass_apply_values,mortclass_apply_value,NULL,NULL); |
| 3956 |
} else { |
| 3957 |
st->first_glyph = getushort(ttf); |
| 3958 |
st->nglyphs = getushort(ttf); |
| 3959 |
st->classes = malloc(st->nglyphs); |
| 3960 |
fread(st->classes,1,st->nglyphs,ttf); |
| 3961 |
} |
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
ent_size = 4 + 2*ent_extras; |
| 3967 |
st->entry_size = ent_size; |
| 3968 |
st->entry_extras = ent_extras; |
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
old_state_max = 0; old_ent_max = 0; |
| 3978 |
state_max = 2; ent_max = 0; |
| 3979 |
while ( old_state_max!=state_max ) { |
| 3980 |
i = old_state_max*nclasses; |
| 3981 |
fseek(ttf,here+state_off+(ismorx?i*sizeof(uint16_t):i),SEEK_SET); |
| 3982 |
old_state_max = state_max; |
| 3983 |
for ( ; i<state_max*nclasses; ++i ) { |
| 3984 |
ent = ismorx ? getushort(ttf) : getc(ttf); |
| 3985 |
if ( ent+1 > ent_max ) |
| 3986 |
ent_max = ent+1; |
| 3987 |
} |
| 3988 |
if ( ent_max==old_ent_max ) |
| 3989 |
break; |
| 3990 |
if ( ent_max>1000 ) { |
| 3991 |
fprintf( stderr, "It looks to me as though there's a morx sub-table with more than 1000\n transitions. Which makes me think there's probably an error\n" ); |
| 3992 |
free(st); |
| 3993 |
return( NULL ); |
| 3994 |
} |
| 3995 |
fseek(ttf,here+entry_off+old_ent_max*ent_size,SEEK_SET); |
| 3996 |
i = old_ent_max; |
| 3997 |
old_ent_max = ent_max; |
| 3998 |
for ( ; i<ent_max; ++i ) { |
| 3999 |
new_state = getushort(ttf); |
| 4000 |
if ( !ismorx ) |
| 4001 |
new_state = (new_state-state_off)/nclasses; |
| 4002 |
getushort(ttf); |
| 4003 |
for ( j=0; j<ent_extras; ++j ) |
| 4004 |
getushort(ttf); |
| 4005 |
if ( new_state+1>state_max ) |
| 4006 |
state_max = new_state+1; |
| 4007 |
} |
| 4008 |
if ( state_max>1000 ) { |
| 4009 |
fprintf( stderr, "It looks to me as though there's a morx sub-table with more than 1000\n states. Which makes me think there's probably an error\n" ); |
| 4010 |
free(st); |
| 4011 |
return( NULL ); |
| 4012 |
} |
| 4013 |
} |
| 4014 |
|
| 4015 |
st->nstates = state_max; |
| 4016 |
st->nentries = ent_max; |
| 4017 |
|
| 4018 |
fseek(ttf,here+state_off,SEEK_SET); |
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
if ( ismorx ) { |
| 4025 |
st->state_table2 = malloc(st->nstates*st->nclasses*sizeof(uint16_t)); |
| 4026 |
for ( i=0; i<st->nstates*st->nclasses; ++i ) |
| 4027 |
st->state_table2[i] = getushort(ttf); |
| 4028 |
} else { |
| 4029 |
st->state_table = malloc(st->nstates*st->nclasses); |
| 4030 |
fread(st->state_table,1,st->nstates*st->nclasses,ttf); |
| 4031 |
} |
| 4032 |
|
| 4033 |
|
| 4034 |
fseek(ttf,here+entry_off,SEEK_SET); |
| 4035 |
st->transitions = malloc(st->nentries*st->entry_size); |
| 4036 |
fread(st->transitions,1,st->nentries*st->entry_size,ttf); |
| 4037 |
return( st ); |
| 4038 |
} |
| 4039 |
|
| 4040 |
static void free_statetable(struct statetable *st) { |
| 4041 |
if ( st==NULL ) |
| 4042 |
return; |
| 4043 |
free( st->state_table ); |
| 4044 |
free( st->state_table2 ); |
| 4045 |
free( st->transitions ); |
| 4046 |
free( st->classes ); |
| 4047 |
free( st->classes2 ); |
| 4048 |
free( st ); |
| 4049 |
} |
| 4050 |
|
| 4051 |
static void show_contextkerndata(uint8_t *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) { |
| 4052 |
int flags = (entry[2]<<8)|entry[3]; |
| 4053 |
int offset = flags&0x3fff; |
| 4054 |
int i, k; |
| 4055 |
|
| 4056 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4057 |
if ( flags&0x8000 ) |
| 4058 |
printf( "Add to Kern Stack | "); |
| 4059 |
if ( flags&0x4000 ) |
| 4060 |
printf( "Don't Advance Glyph" ); |
| 4061 |
else |
| 4062 |
printf( "Advance Glyph" ); |
| 4063 |
printf( ", ValueOffset = %d\n", offset ); |
| 4064 |
if ( offset!=0 ) { |
| 4065 |
printf( "Offset=%d, len=%d\n", offset, st->len ); |
| 4066 |
fseek(ttf,offset+st->state_start,SEEK_SET); |
| 4067 |
printf( "Kerns: " ); |
| 4068 |
for ( i=0; i<8; ++i ) { |
| 4069 |
printf( "%d ", (k = (short) getushort(ttf)) & ~1 ); |
| 4070 |
if ( k&1 ) |
| 4071 |
break; |
| 4072 |
} |
| 4073 |
printf( "\n" ); |
| 4074 |
} |
| 4075 |
} |
| 4076 |
|
| 4077 |
static void readttfkern_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4078 |
struct statetable *st; |
| 4079 |
|
| 4080 |
st = read_statetable(ttf,0,false,info); |
| 4081 |
st->len = stab_len; |
| 4082 |
show_statetable(st, info, ttf, show_contextkerndata); |
| 4083 |
free_statetable(st); |
| 4084 |
} |
| 4085 |
|
| 4086 |
static void show_indicflags(uint8_t *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf) { |
| 4087 |
int flags = (entry[2]<<8)|entry[3]; |
| 4088 |
|
| 4089 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4090 |
if ( flags&0x8000 ) |
| 4091 |
printf( "Mark First | "); |
| 4092 |
if ( flags&0x2000 ) |
| 4093 |
printf( "Mark Last | " ); |
| 4094 |
if ( flags&0x4000 ) |
| 4095 |
printf( "Don't Advance Glyph " ); |
| 4096 |
else |
| 4097 |
printf( "Advance Glyph " ); |
| 4098 |
switch( flags&0xf ) { |
| 4099 |
case 0 : |
| 4100 |
printf( "No action\n" ); |
| 4101 |
break; |
| 4102 |
case 1 : |
| 4103 |
printf( "Ax => xA\n" ); |
| 4104 |
break; |
| 4105 |
case 2 : |
| 4106 |
printf( "xD => Dx\n" ); |
| 4107 |
break; |
| 4108 |
case 3 : |
| 4109 |
printf( "AxD => DxA\n" ); |
| 4110 |
break; |
| 4111 |
case 4 : |
| 4112 |
printf( "ABx => xAB\n" ); |
| 4113 |
break; |
| 4114 |
case 5 : |
| 4115 |
printf( "ABx => xBA\n" ); |
| 4116 |
break; |
| 4117 |
case 6 : |
| 4118 |
printf( "xCD => CDx\n" ); |
| 4119 |
break; |
| 4120 |
case 7 : |
| 4121 |
printf( "xCD => DCx\n" ); |
| 4122 |
break; |
| 4123 |
case 8 : |
| 4124 |
printf( "AxCD => CDxA\n" ); |
| 4125 |
break; |
| 4126 |
case 9 : |
| 4127 |
printf( "AxCD => DCxA\n" ); |
| 4128 |
break; |
| 4129 |
case 10 : |
| 4130 |
printf( "ABxD => DxAB\n" ); |
| 4131 |
break; |
| 4132 |
case 11 : |
| 4133 |
printf( "ABxD => DxBA\n" ); |
| 4134 |
break; |
| 4135 |
case 12 : |
| 4136 |
printf( "ABxCD => CDxAB\n" ); |
| 4137 |
break; |
| 4138 |
case 13 : |
| 4139 |
printf( "ABxCD => CDxBA\n" ); |
| 4140 |
break; |
| 4141 |
case 14 : |
| 4142 |
printf( "ABxCD => DCxAB\n" ); |
| 4143 |
break; |
| 4144 |
case 15 : |
| 4145 |
printf( "ABxCD => DCxBA\n" ); |
| 4146 |
break; |
| 4147 |
} |
| 4148 |
} |
| 4149 |
|
| 4150 |
static void readttfmort_indic(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4151 |
struct statetable *st; |
| 4152 |
|
| 4153 |
st = read_statetable(ttf,0,false,info); |
| 4154 |
show_statetable(st, info, ttf, show_indicflags); |
| 4155 |
free_statetable(st); |
| 4156 |
} |
| 4157 |
|
| 4158 |
static void readttfmorx_indic(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4159 |
struct statetable *st; |
| 4160 |
|
| 4161 |
st = read_statetable(ttf,2,true,info); |
| 4162 |
show_statetablex(st, info, ttf, show_indicflags); |
| 4163 |
free_statetable(st); |
| 4164 |
} |
| 4165 |
|
| 4166 |
static void show_contextflags(uint8_t *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) { |
| 4167 |
int flags = (entry[2]<<8)|entry[3]; |
| 4168 |
|
| 4169 |
int mark_offset = (int16_t) ((entry[4]<<8)|entry[5]); |
| 4170 |
int cur_offset = (int16_t) ((entry[6]<<8)|entry[7]); |
| 4171 |
int i, sub; |
| 4172 |
|
| 4173 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4174 |
if ( flags&0x8000 ) |
| 4175 |
printf( "Set Mark | "); |
| 4176 |
if ( flags&0x4000 ) |
| 4177 |
printf( "Don't Advance Glyph\n" ); |
| 4178 |
else |
| 4179 |
printf( "Advance Glyph\n" ); |
| 4180 |
|
| 4181 |
|
| 4182 |
|
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
if ( mark_offset!=0 || cur_offset!=0 ) { |
| 4191 |
printf( "!!!! Caveat !!!! I am printing out entries that look as though they might\n" ); |
| 4192 |
printf( "!!!! be meaningful, but that is no guarantee. Examine them carefully to\n" ); |
| 4193 |
printf( "!!!! find those sections which are actually used.\n" ); |
| 4194 |
} |
| 4195 |
printf( "\t Offset to substitution table for marked glyph: %d\n", mark_offset ); |
| 4196 |
if ( mark_offset!=0 ) { |
| 4197 |
fseek(ttf,2*(mark_offset+st->first_glyph)+st->state_start,SEEK_SET); |
| 4198 |
for ( i=0; i<st->nglyphs; ++i ) { |
| 4199 |
sub = getushort(ttf); |
| 4200 |
if ( sub==0 || (sub>=info->glyph_cnt && sub!=0xffff) ) |
| 4201 |
continue; |
| 4202 |
printf( "\t Glyph %d ", st->first_glyph+i ); |
| 4203 |
if ( st->first_glyph+i>=info->glyph_cnt ) |
| 4204 |
printf( "!!! Bad Glyph !!! " ); |
| 4205 |
else if ( info->glyph_names!=NULL ) |
| 4206 |
printf( "%s ", info->glyph_names[st->first_glyph+i]); |
| 4207 |
if ( sub==0xffff ) |
| 4208 |
printf( "-> Deleted" ); |
| 4209 |
else { |
| 4210 |
printf( "-> Glyph %d ", sub ); |
| 4211 |
if ( sub>=info->glyph_cnt ) |
| 4212 |
printf( "!!! Bad Glyph !!! " ); |
| 4213 |
else if ( info->glyph_names!=NULL ) |
| 4214 |
printf( "%s", info->glyph_names[sub]); |
| 4215 |
} |
| 4216 |
putchar('\n'); |
| 4217 |
} |
| 4218 |
} |
| 4219 |
printf( "\t Offset to substitution table for current glyph: %d\n", cur_offset ); |
| 4220 |
if ( cur_offset!=0 ) { |
| 4221 |
fseek(ttf,2*(cur_offset+st->first_glyph)+st->state_start,SEEK_SET); |
| 4222 |
for ( i=0; i<st->nglyphs; ++i ) { |
| 4223 |
sub = getushort(ttf); |
| 4224 |
if ( sub==0 || (sub>=info->glyph_cnt && sub!=0xffff) ) |
| 4225 |
continue; |
| 4226 |
printf( "\t Glyph %d ", st->first_glyph+i ); |
| 4227 |
if ( st->first_glyph+i>=info->glyph_cnt ) |
| 4228 |
printf( "!!! Bad Glyph !!! " ); |
| 4229 |
else if ( info->glyph_names!=NULL ) |
| 4230 |
printf( "%s ", info->glyph_names[st->first_glyph+i]); |
| 4231 |
if ( sub==0xffff ) |
| 4232 |
printf( "-> Deleted" ); |
| 4233 |
else { |
| 4234 |
printf( "-> Glyph %d ", sub ); |
| 4235 |
if ( sub>=info->glyph_cnt ) |
| 4236 |
printf( "!!! Bad Glyph !!! " ); |
| 4237 |
else if ( info->glyph_names!=NULL ) |
| 4238 |
printf( "%s", info->glyph_names[sub]); |
| 4239 |
} |
| 4240 |
putchar('\n'); |
| 4241 |
} |
| 4242 |
} |
| 4243 |
} |
| 4244 |
|
| 4245 |
static void readttfmort_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4246 |
struct statetable *st; |
| 4247 |
|
| 4248 |
st = read_statetable(ttf,2,false,info); |
| 4249 |
show_statetable(st, info, ttf, show_contextflags); |
| 4250 |
free_statetable(st); |
| 4251 |
} |
| 4252 |
|
| 4253 |
static void mort_noncontextualsubs_glyph( FILE *ttf, struct ttfinfo *info ) { |
| 4254 |
int gnum = getushort(ttf); |
| 4255 |
|
| 4256 |
printf( " Glyph %d (%s)\n", gnum, |
| 4257 |
gnum>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? |
| 4258 |
info->glyph_names[gnum]: "" ); |
| 4259 |
} |
| 4260 |
|
| 4261 |
static void show_contextflagsx(uint8_t *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) { |
| 4262 |
int flags = (entry[2]<<8)|entry[3]; |
| 4263 |
int mark_index = ((entry[4]<<8)|entry[5]); |
| 4264 |
int cur_index = ((entry[6]<<8)|entry[7]); |
| 4265 |
|
| 4266 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4267 |
if ( flags&0x8000 ) |
| 4268 |
printf( "Set Mark | "); |
| 4269 |
if ( flags&0x4000 ) |
| 4270 |
printf( "Don't Advance Glyph\n" ); |
| 4271 |
else |
| 4272 |
printf( "Advance Glyph\n" ); |
| 4273 |
printf( "\t Index to substitution table for marked glyph: %d\n", mark_index ); |
| 4274 |
if ( mark_index!=0xffff ) { |
| 4275 |
fseek(ttf,st->state_start+st->extra_offsets[0]+4*mark_index,SEEK_SET); |
| 4276 |
fseek(ttf,st->state_start+st->extra_offsets[0]+getlong(ttf),SEEK_SET); |
| 4277 |
show_applelookuptable(ttf,info, |
| 4278 |
mort_noncontextualsubs_glyph); |
| 4279 |
} |
| 4280 |
printf( "\t Offset to substitution table for current glyph: %d\n", cur_index ); |
| 4281 |
if ( cur_index!=0xffff ) { |
| 4282 |
fseek(ttf,st->state_start+st->extra_offsets[0]+4*cur_index,SEEK_SET); |
| 4283 |
fseek(ttf,st->state_start+st->extra_offsets[0]+getlong(ttf),SEEK_SET); |
| 4284 |
show_applelookuptable(ttf,info, |
| 4285 |
mort_noncontextualsubs_glyph); |
| 4286 |
} |
| 4287 |
} |
| 4288 |
|
| 4289 |
static void readttfmorx_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4290 |
struct statetable *st; |
| 4291 |
|
| 4292 |
st = read_statetable(ttf,2,true,info); |
| 4293 |
show_statetablex(st, info, ttf, show_contextflagsx); |
| 4294 |
free_statetable(st); |
| 4295 |
} |
| 4296 |
|
| 4297 |
static void show_ligflags(uint8_t *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) { |
| 4298 |
int flags = (entry[2]<<8)|entry[3]; |
| 4299 |
uint32_t val; |
| 4300 |
|
| 4301 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4302 |
if ( flags&0x8000 ) |
| 4303 |
printf( "Set Component | "); |
| 4304 |
if ( flags&0x4000 ) |
| 4305 |
printf( "Don't Advance Glyph " ); |
| 4306 |
else |
| 4307 |
printf( "Advance Glyph " ); |
| 4308 |
printf( "Offset=%d\n", flags&0x3fff ); |
| 4309 |
if ( (flags&0x3fff)==0 ) |
| 4310 |
return; |
| 4311 |
|
| 4312 |
fseek(ttf,st->state_start+(flags&0x3fff),SEEK_SET); |
| 4313 |
do { |
| 4314 |
val = getlong(ttf); |
| 4315 |
printf( "\t lig action %08x %s offset=%d\n", val, |
| 4316 |
(val&0x80000000)?"last (& store)": |
| 4317 |
(val&0x40000000)?"store": "delete", |
| 4318 |
(((int32_t)val)<<2)>>2 ); |
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
} while ( !(val&0x80000000) ); |
| 4326 |
} |
| 4327 |
|
| 4328 |
static void readttfmort_lig(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4329 |
struct statetable *st; |
| 4330 |
|
| 4331 |
st = read_statetable(ttf,0,false,info); |
| 4332 |
show_statetable(st, info, ttf, show_ligflags); |
| 4333 |
free_statetable(st); |
| 4334 |
} |
| 4335 |
|
| 4336 |
static void show_ligxflags(uint8_t *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) { |
| 4337 |
int flags = (entry[2]<<8)|entry[3]; |
| 4338 |
int index = (entry[4]<<8)|entry[5]; |
| 4339 |
uint32_t val; |
| 4340 |
|
| 4341 |
printf( "\t Flags %04x ", (unsigned int)(flags) ); |
| 4342 |
if ( flags&0x8000 ) |
| 4343 |
printf( "Set Component | "); |
| 4344 |
if ( flags&0x2000 ) |
| 4345 |
printf( "Perform | "); |
| 4346 |
if ( flags&0x4000 ) |
| 4347 |
printf( "Don't Advance Glyph " ); |
| 4348 |
else |
| 4349 |
printf( "Advance Glyph " ); |
| 4350 |
if ( flags&0x2000 ) |
| 4351 |
printf( "Index=%d\n", index ); |
| 4352 |
else |
| 4353 |
printf( "\n"); |
| 4354 |
if ( (flags&0x2000)==0 ) |
| 4355 |
return; |
| 4356 |
|
| 4357 |
fseek(ttf,st->state_start+st->extra_offsets[0]+4*index,SEEK_SET); |
| 4358 |
do { |
| 4359 |
val = getlong(ttf); |
| 4360 |
printf( "\t lig action %08x %s offset=%d\n", val, |
| 4361 |
(val&0x80000000)?"last (& store)": |
| 4362 |
(val&0x40000000)?"store": "delete", |
| 4363 |
(((int32_t)val)<<2)>>2 ); |
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
} while ( !(val&0x80000000) ); |
| 4371 |
} |
| 4372 |
|
| 4373 |
static void readttfmorx_lig(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) { |
| 4374 |
struct statetable *st; |
| 4375 |
|
| 4376 |
st = read_statetable(ttf,1,true,info); |
| 4377 |
show_statetablex(st, info, ttf, show_ligxflags); |
| 4378 |
free_statetable(st); |
| 4379 |
} |
| 4380 |
|
| 4381 |
static int32_t memlong(uint8_t *data,int offset) { |
| 4382 |
int ch1 = data[offset], ch2 = data[offset+1], ch3 = data[offset+2], ch4 = data[offset+3]; |
| 4383 |
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 ); |
| 4384 |
} |
| 4385 |
|
| 4386 |
static int memushort(uint8_t *data,int offset) { |
| 4387 |
int ch1 = data[offset], ch2 = data[offset+1]; |
| 4388 |
return( (ch1<<8)|ch2 ); |
| 4389 |
} |
| 4390 |
|
| 4391 |
#define MAX_LIG_COMP 16 |
| 4392 |
struct statemachine { |
| 4393 |
uint8_t *data; |
| 4394 |
int length; |
| 4395 |
uint32_t nClasses; |
| 4396 |
uint32_t classOffset, stateOffset, entryOffset, ligActOff, compOff, ligOff; |
| 4397 |
uint16_t *classes; |
| 4398 |
uint16_t lig_comp_classes[MAX_LIG_COMP]; |
| 4399 |
uint16_t lig_comp_glyphs[MAX_LIG_COMP]; |
| 4400 |
int lcp; |
| 4401 |
uint8_t *states_in_use; |
| 4402 |
int smax; |
| 4403 |
struct ttfinfo *info; |
| 4404 |
int cnt; |
| 4405 |
}; |
| 4406 |
|
| 4407 |
static void mort_figure_ligatures(struct statemachine *sm, int lcp, int off, int32_t lig_offset) { |
| 4408 |
uint32_t lig; |
| 4409 |
int i, j, lig_glyph; |
| 4410 |
|
| 4411 |
if ( lcp<0 || off+3>sm->length ) |
| 4412 |
return; |
| 4413 |
|
| 4414 |
lig = memlong(sm->data,off); |
| 4415 |
off += sizeof(long); |
| 4416 |
|
| 4417 |
for ( i=0; i<sm->info->glyph_cnt; ++i ) if ( sm->classes[i]==sm->lig_comp_classes[lcp] ) { |
| 4418 |
sm->lig_comp_glyphs[lcp] = i; |
| 4419 |
lig_offset += memushort(sm->data,2*( ((((int32_t) lig)<<2)>>2) + i ) ); |
| 4420 |
if ( lig&0xc0000000 ) { |
| 4421 |
if ( lig_offset+1 > sm->length ) { |
| 4422 |
fprintf( stderr, "Invalid ligature offset\n" ); |
| 4423 |
break; |
| 4424 |
} |
| 4425 |
lig_glyph = memushort(sm->data,lig_offset); |
| 4426 |
if ( lig_glyph>=sm->info->glyph_cnt ) { |
| 4427 |
fprintf(stderr, "Attempt to make a ligature for glyph %d out of ", lig_glyph ); |
| 4428 |
for ( j=lcp; j<sm->lcp; ++j ) |
| 4429 |
fprintf(stderr,"%d ",sm->lig_comp_glyphs[j]); |
| 4430 |
fprintf(stderr,"\n"); |
| 4431 |
} else { |
| 4432 |
printf( "\t\tGlyph %d (%s) is a ligature of:\n", |
| 4433 |
lig_glyph, lig_glyph>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[lig_glyph] : "" ); |
| 4434 |
for ( j=lcp; j<sm->lcp; ++j ) |
| 4435 |
printf( "\t\t\t%d (%s)\n", sm->lig_comp_glyphs[j], |
| 4436 |
sm->lig_comp_glyphs[j]>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[sm->lig_comp_glyphs[j]] : "" ); |
| 4437 |
} |
| 4438 |
} else |
| 4439 |
mort_figure_ligatures(sm,lcp-1,off,lig_offset); |
| 4440 |
lig_offset -= memushort(sm->data,2*( ((((int32_t) lig)<<2)>>2) + i ) ); |
| 4441 |
} |
| 4442 |
} |
| 4443 |
|
| 4444 |
static void follow_mort_state(struct statemachine *sm,int offset,int class) { |
| 4445 |
int state = (offset-sm->stateOffset)/sm->nClasses; |
| 4446 |
int class_top, class_bottom; |
| 4447 |
|
| 4448 |
if ( state<0 || state>=sm->smax || sm->states_in_use[state] || sm->lcp>=MAX_LIG_COMP ) |
| 4449 |
return; |
| 4450 |
++ sm->cnt; |
| 4451 |
if ( sm->cnt>=max_lig_nest ) { |
| 4452 |
if ( sm->cnt==max_lig_nest ) |
| 4453 |
fprintf( stderr, "ligature state machine too complex, giving up\n" ); |
| 4454 |
return; |
| 4455 |
} |
| 4456 |
|
| 4457 |
sm->states_in_use[state] = true; |
| 4458 |
|
| 4459 |
if ( class==-1 ) { class_bottom = 0; class_top = sm->nClasses; } |
| 4460 |
else { class_bottom = class; class_top = class+1; } |
| 4461 |
for ( class=class_bottom; class<class_top; ++class ) { |
| 4462 |
int ent = sm->data[offset+class]; |
| 4463 |
int newState = memushort(sm->data,sm->entryOffset+4*ent); |
| 4464 |
int flags = memushort(sm->data,sm->entryOffset+4*ent+2); |
| 4465 |
if (( state!=0 && sm->data[sm->stateOffset+class] == ent ) || |
| 4466 |
(state>1 && sm->data[sm->stateOffset+sm->nClasses+class]==ent )) |
| 4467 |
continue; |
| 4468 |
if ( flags&0x8000 ) |
| 4469 |
sm->lig_comp_classes[sm->lcp++] = class; |
| 4470 |
if ( flags&0x3fff ) { |
| 4471 |
mort_figure_ligatures(sm, sm->lcp-1, flags & 0x3fff, 0); |
| 4472 |
} else if ( flags&0x8000 ) |
| 4473 |
follow_mort_state(sm,newState,(flags&0x4000)?class:-1); |
| 4474 |
if ( flags&0x8000 ) |
| 4475 |
--sm->lcp; |
| 4476 |
} |
| 4477 |
sm->states_in_use[state] = false; |
| 4478 |
} |
| 4479 |
|
| 4480 |
static void morx_figure_ligatures(struct statemachine *sm, int lcp, int ligindex, int32_t lig_offset) { |
| 4481 |
uint32_t lig; |
| 4482 |
int i, j, lig_glyph; |
| 4483 |
|
| 4484 |
if ( lcp<0 || sm->ligActOff+4*ligindex+3>sm->length ) |
| 4485 |
return; |
| 4486 |
|
| 4487 |
lig = memlong(sm->data,sm->ligActOff+4*ligindex); |
| 4488 |
++ligindex; |
| 4489 |
|
| 4490 |
for ( i=0; i<sm->info->glyph_cnt; ++i ) if ( sm->classes[i]==sm->lig_comp_classes[lcp] ) { |
| 4491 |
sm->lig_comp_glyphs[lcp] = i; |
| 4492 |
lig_offset += memushort(sm->data,sm->compOff + 2*( ((((int32_t) lig)<<2)>>2) + i ) ); |
| 4493 |
if ( lig&0xc0000000 ) { |
| 4494 |
if ( sm->ligOff+2*lig_offset+1 > sm->length ) { |
| 4495 |
fprintf( stderr, "Invalid ligature offset\n" ); |
| 4496 |
break; |
| 4497 |
} |
| 4498 |
lig_glyph = memushort(sm->data,sm->ligOff+2*lig_offset); |
| 4499 |
if ( lig_glyph>=sm->info->glyph_cnt ) { |
| 4500 |
fprintf(stderr, "Attempt to make a ligature for glyph %d out of ", lig_glyph ); |
| 4501 |
for ( j=lcp; j<sm->lcp; ++j ) |
| 4502 |
fprintf(stderr,"%d ",sm->lig_comp_glyphs[j]); |
| 4503 |
fprintf(stderr,"\n"); |
| 4504 |
} else { |
| 4505 |
printf( "\t\tGlyph %d (%s) is a ligature of:\n", |
| 4506 |
lig_glyph, lig_glyph>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[lig_glyph] : "" ); |
| 4507 |
for ( j=lcp; j<sm->lcp; ++j ) |
| 4508 |
printf( "\t\t\t%d (%s)\n", sm->lig_comp_glyphs[j], |
| 4509 |
sm->lig_comp_glyphs[j]>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[sm->lig_comp_glyphs[j]] : "" ); |
| 4510 |
} |
| 4511 |
} else |
| 4512 |
morx_figure_ligatures(sm,lcp-1,ligindex,lig_offset); |
| 4513 |
lig_offset -= memushort(sm->data,sm->compOff + 2*( ((((int32_t) lig)<<2)>>2) + i ) ); |
| 4514 |
} |
| 4515 |
} |
| 4516 |
|
| 4517 |
static void follow_morx_state(struct statemachine *sm,int state,int class) { |
| 4518 |
int class_top, class_bottom; |
| 4519 |
|
| 4520 |
if ( state<0 || state>=sm->smax || sm->states_in_use[state] || sm->lcp>=MAX_LIG_COMP ) |
| 4521 |
return; |
| 4522 |
++ sm->cnt; |
| 4523 |
if ( sm->cnt>=max_lig_nest ) { |
| 4524 |
if ( sm->cnt==max_lig_nest ) |
| 4525 |
fprintf( stderr, "ligature state machine too complex, giving up\n" ); |
| 4526 |
return; |
| 4527 |
} |
| 4528 |
|
| 4529 |
sm->states_in_use[state] = true; |
| 4530 |
|
| 4531 |
if ( class==-1 ) { class_bottom = 0; class_top = sm->nClasses; } |
| 4532 |
else { class_bottom = class; class_top = class+1; } |
| 4533 |
for ( class=class_bottom; class<class_top; ++class ) { |
| 4534 |
int ent = memushort(sm->data, sm->stateOffset + 2*(state*sm->nClasses+class) ); |
| 4535 |
int newState = memushort(sm->data,sm->entryOffset+6*ent); |
| 4536 |
int flags = memushort(sm->data,sm->entryOffset+6*ent+2); |
| 4537 |
int ligindex = memushort(sm->data,sm->entryOffset+6*ent+4); |
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
if (( state!=0 && memushort(sm->data, sm->stateOffset + 2*class) == ent ) || |
| 4542 |
(state>1 && memushort(sm->data, sm->stateOffset + 2*(sm->nClasses+class))==ent )) |
| 4543 |
continue; |
| 4544 |
if ( flags&0x8000 ) |
| 4545 |
sm->lig_comp_classes[sm->lcp++] = class; |
| 4546 |
if ( flags&0x2000 ) { |
| 4547 |
morx_figure_ligatures(sm, sm->lcp-1, ligindex, 0); |
| 4548 |
} else if ( flags&0x8000 ) |
| 4549 |
follow_morx_state(sm,newState,(flags&0x4000)?class:-1); |
| 4550 |
if ( flags&0x8000 ) |
| 4551 |
--sm->lcp; |
| 4552 |
} |
| 4553 |
sm->states_in_use[state] = false; |
| 4554 |
} |
| 4555 |
|
| 4556 |
static void readttf_mortx_lig(FILE *ttf,struct ttfinfo *info,int ismorx,uint32_t base,uint32_t length) { |
| 4557 |
uint32_t here; |
| 4558 |
struct statemachine sm; |
| 4559 |
int first, cnt, i; |
| 4560 |
|
| 4561 |
memset(&sm,0,sizeof(sm)); |
| 4562 |
sm.info = info; |
| 4563 |
here = ftell(ttf); |
| 4564 |
length -= here-base; |
| 4565 |
sm.data = malloc(length); |
| 4566 |
sm.length = length; |
| 4567 |
if ( fread(sm.data,1,length,ttf)!=length ) { |
| 4568 |
free(sm.data); |
| 4569 |
fprintf( stderr, "Bad mort/morx ligature table. Not long enough\n"); |
| 4570 |
return; |
| 4571 |
} |
| 4572 |
fseek(ttf,here,SEEK_SET); |
| 4573 |
if ( ismorx ) { |
| 4574 |
sm.nClasses = memlong(sm.data,0); |
| 4575 |
sm.classOffset = memlong(sm.data,sizeof(long)); |
| 4576 |
sm.stateOffset = memlong(sm.data,2*sizeof(long)); |
| 4577 |
sm.entryOffset = memlong(sm.data,3*sizeof(long)); |
| 4578 |
sm.ligActOff = memlong(sm.data,4*sizeof(long)); |
| 4579 |
sm.compOff = memlong(sm.data,5*sizeof(long)); |
| 4580 |
sm.ligOff = memlong(sm.data,6*sizeof(long)); |
| 4581 |
fseek(ttf,here+sm.classOffset,SEEK_SET); |
| 4582 |
sm.classes = info->morx_classes = malloc(info->glyph_cnt*sizeof(uint16_t)); |
| 4583 |
for ( i=0; i<info->glyph_cnt; ++i ) |
| 4584 |
sm.classes[i] = 1; |
| 4585 |
readttf_applelookup(ttf,info, |
| 4586 |
mortclass_apply_values,mortclass_apply_value,NULL,NULL); |
| 4587 |
sm.smax = length/(2*sm.nClasses); |
| 4588 |
sm.states_in_use = calloc(sm.smax,sizeof(uint8_t)); |
| 4589 |
follow_morx_state(&sm,0,-1); |
| 4590 |
} else { |
| 4591 |
sm.nClasses = memushort(sm.data,0); |
| 4592 |
sm.classOffset = memushort(sm.data,sizeof(uint16_t)); |
| 4593 |
sm.stateOffset = memushort(sm.data,2*sizeof(uint16_t)); |
| 4594 |
sm.entryOffset = memushort(sm.data,3*sizeof(uint16_t)); |
| 4595 |
sm.ligActOff = memushort(sm.data,4*sizeof(uint16_t)); |
| 4596 |
sm.compOff = memushort(sm.data,5*sizeof(uint16_t)); |
| 4597 |
sm.ligOff = memushort(sm.data,6*sizeof(uint16_t)); |
| 4598 |
sm.classes = malloc(info->glyph_cnt*sizeof(uint16_t)); |
| 4599 |
for ( i=0; i<info->glyph_cnt; ++i ) |
| 4600 |
sm.classes[i] = 1; |
| 4601 |
first = memushort(sm.data,sm.classOffset); |
| 4602 |
cnt = memushort(sm.data,sm.classOffset+sizeof(uint16_t)); |
| 4603 |
for ( i=0; i<cnt; ++i ) |
| 4604 |
sm.classes[first+i] = sm.data[sm.classOffset+2*sizeof(uint16_t)+i]; |
| 4605 |
sm.smax = length/sm.nClasses; |
| 4606 |
sm.states_in_use = calloc(sm.smax,sizeof(uint8_t)); |
| 4607 |
follow_mort_state(&sm,sm.stateOffset,-1); |
| 4608 |
} |
| 4609 |
free(sm.data); |
| 4610 |
free(sm.states_in_use); |
| 4611 |
free(sm.classes); |
| 4612 |
} |
| 4613 |
|
| 4614 |
static void readttfmetamorph(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4615 |
int n, i, j, k, l, nf, ns, type, setting, stab_len, coverage; |
| 4616 |
uint32_t chain_start, len, temp, stab_start, flags, here; |
| 4617 |
int features[32], settings[32], masks[32]; |
| 4618 |
int ismorx = false; |
| 4619 |
|
| 4620 |
if ( info->morx_start!=0 ) { |
| 4621 |
fseek(ttf,info->morx_start,SEEK_SET); |
| 4622 |
printf( "\nmorx table (at %d) (Glyph metamorphosis extended)\n", info->morx_start ); |
| 4623 |
ismorx = true; |
| 4624 |
} else { |
| 4625 |
fseek(ttf,info->mort_start,SEEK_SET); |
| 4626 |
printf( "\nmort table (at %d) (Glyph metamorphosis)\n", info->mort_start ); |
| 4627 |
} |
| 4628 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4629 |
n = getlong(ttf); |
| 4630 |
printf( "\t number of chains=%d\n", n); |
| 4631 |
for ( i=0; i<n; ++i ) { |
| 4632 |
printf( "\t For Chain %d\n", i ); |
| 4633 |
chain_start = ftell(ttf); |
| 4634 |
printf( "\t default flags=%lx\n", (long unsigned int)(getlong(ttf)) ); |
| 4635 |
printf( "\t chain length=%ld\n", (long)((len = getlong(ttf))) ); |
| 4636 |
printf( "\t number Feature Entries=%d\n", nf = ismorx ? getlong(ttf) : getushort(ttf)); |
| 4637 |
printf( "\t number Subtables=%d\n", ns = ismorx ? (int) getlong(ttf) : getushort(ttf)); |
| 4638 |
for ( j=k=0; j<nf; ++j ) { |
| 4639 |
printf( "\t For Feature %d of Chain %d\n", j, i ); |
| 4640 |
printf( "\t Feature Type=%d ", type = getushort(ttf)); |
| 4641 |
printf( "%s\n", getfeaturename(info,type)); |
| 4642 |
printf( "\t Feature Setting=%d ", setting=getushort(ttf)); |
| 4643 |
printf( "%s\n", getsettingname(info,type, setting)); |
| 4644 |
printf( "\t Enable Flags=%08lx\n", (long unsigned int)((flags = getlong(ttf))) ); |
| 4645 |
printf( "\t Disable Flags=%08lx ", (long unsigned int)((temp=getlong(ttf))) ); |
| 4646 |
printf( "(Complement=%08lx)\n", (long unsigned int)(~temp) ); |
| 4647 |
|
| 4648 |
for ( l=0; l<k; ++l ) |
| 4649 |
flags &= ~masks[l]; |
| 4650 |
if ( k<32 && flags!=0 ) { |
| 4651 |
features[k] = type; |
| 4652 |
settings[k] = setting; |
| 4653 |
masks[k++] = flags; |
| 4654 |
} |
| 4655 |
} |
| 4656 |
for ( j=0; j<ns; ++j ) { |
| 4657 |
stab_start = ftell(ttf); |
| 4658 |
if ( ismorx ) { |
| 4659 |
stab_len = getlong(ttf); |
| 4660 |
coverage = getlong(ttf); |
| 4661 |
} else { |
| 4662 |
stab_len = getushort(ttf); |
| 4663 |
coverage = getushort(ttf); |
| 4664 |
coverage = ((coverage&0xe000)<<16) | (coverage&7); |
| 4665 |
} |
| 4666 |
flags = getlong(ttf); |
| 4667 |
for ( l=0; l<k; ++l ) |
| 4668 |
if ( masks[l]==flags ) |
| 4669 |
break; |
| 4670 |
printf( "\t Subtable %d ", j); |
| 4671 |
if ( l!=k ) |
| 4672 |
printf( "Probably for feature=%d (%s)\n\t\t setting=%d (%s)\n", |
| 4673 |
features[l], getfeaturename(info,features[l]), |
| 4674 |
settings[l], getsettingname(info,features[l],settings[l])); |
| 4675 |
else |
| 4676 |
printf( "\n" ); |
| 4677 |
printf( "\t Length = %d\n", stab_len ); |
| 4678 |
printf( "\t Coverage = %08x, Apply=%s Search=%s\n\t\tType=%s\n", |
| 4679 |
(unsigned int)(coverage), |
| 4680 |
(coverage&0x20000000) ? "Always" : (coverage&0x80000000) ? "Vertical" : "Horizontal", |
| 4681 |
(coverage&0x40000000) ? "Descending (?Right2Left?)" : "Ascending (?Left2Right?)", |
| 4682 |
(coverage&0xff)==0 ? "Indic rearrangement" : |
| 4683 |
(coverage&0xff)==1 ? "contextual glyph substitution" : |
| 4684 |
(coverage&0xff)==2 ? "Ligature substitution" : |
| 4685 |
(coverage&0xff)==4 ? "non-contextual glyph substitution" : |
| 4686 |
(coverage&0xff)==5 ? "contextual glyph insertion" : |
| 4687 |
"Unknown" ); |
| 4688 |
printf( "\t Flags=%08lx\n", (long unsigned int)(flags) ); |
| 4689 |
switch( (coverage&0x7) ) { |
| 4690 |
case 0: |
| 4691 |
if ( !ismorx ) |
| 4692 |
readttfmort_indic(ttf,util,info,stab_len); |
| 4693 |
else |
| 4694 |
readttfmorx_indic(ttf,util,info,stab_len); |
| 4695 |
break; |
| 4696 |
case 1: |
| 4697 |
if ( !ismorx ) |
| 4698 |
readttfmort_context(ttf,util,info,stab_len); |
| 4699 |
else |
| 4700 |
readttfmorx_context(ttf,util,info,stab_len); |
| 4701 |
break; |
| 4702 |
case 2: |
| 4703 |
here = ftell(ttf); |
| 4704 |
readttf_mortx_lig(ttf,info,ismorx,stab_start,stab_len); |
| 4705 |
if ( verbose ) { |
| 4706 |
fseek(ttf,here,SEEK_SET); |
| 4707 |
if ( !ismorx ) |
| 4708 |
readttfmort_lig(ttf,util,info,stab_len); |
| 4709 |
else |
| 4710 |
readttfmorx_lig(ttf,util,info,stab_len); |
| 4711 |
} |
| 4712 |
break; |
| 4713 |
case 4: |
| 4714 |
show_applelookuptable(ttf,info, |
| 4715 |
mort_noncontextualsubs_glyph); |
| 4716 |
break; |
| 4717 |
case 5: |
| 4718 |
break; |
| 4719 |
} |
| 4720 |
fseek(ttf,stab_start+stab_len,SEEK_SET); |
| 4721 |
} |
| 4722 |
len = ((len+3)>>2)<<2; |
| 4723 |
fseek(ttf,chain_start+len,SEEK_SET); |
| 4724 |
} |
| 4725 |
} |
| 4726 |
|
| 4727 |
static void showagproperties( uint16_t props ) { |
| 4728 |
|
| 4729 |
printf( "%04x=", props ); |
| 4730 |
if ( props&0x8000 ) printf( "Floater|" ); |
| 4731 |
if ( props&0x4000 ) printf( "HangLeft|" ); |
| 4732 |
if ( props&0x2000 ) printf( "HangRight|" ); |
| 4733 |
if ( props&0x1000 ) printf( "Mirror += %d|", (((int32_t) props)<<20)>>28 ); |
| 4734 |
if ( props&0x0080 ) printf( "AttachRight|" ); |
| 4735 |
switch (props&0x1f ) { |
| 4736 |
case 0: printf( "Strong L2R" ); break; |
| 4737 |
case 1: printf( "Strong Hebrew" ); break; |
| 4738 |
case 2: printf( "Strong Arabic" ); break; |
| 4739 |
case 3: printf( "Euro Digit" ); break; |
| 4740 |
case 4: printf( "Euro Num Sep" ); break; |
| 4741 |
case 5: printf( "Euro Num Term" ); break; |
| 4742 |
case 6: printf( "Arabic Digit" ); break; |
| 4743 |
case 7: printf( "Common Num Sep" ); break; |
| 4744 |
case 8: printf( "Block Sep" ); break; |
| 4745 |
case 9: printf( "Segment Sep" ); break; |
| 4746 |
case 10: printf( "White Space" ); break; |
| 4747 |
case 11: printf( "Other Neutral" ); break; |
| 4748 |
default: printf( "Undocumented Unicode 3 direction %d", props&0x1f ); break; |
| 4749 |
} |
| 4750 |
putchar('\n'); |
| 4751 |
} |
| 4752 |
|
| 4753 |
static void prop_show( FILE *ttf, struct ttfinfo *info ) { |
| 4754 |
showagproperties( getushort(ttf)); |
| 4755 |
} |
| 4756 |
|
| 4757 |
static void readttfappleprop(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4758 |
|
| 4759 |
fseek(ttf,info->prop_start,SEEK_SET); |
| 4760 |
printf( "\nprop table (at %d) (Glyph properties)\n", info->prop_start ); |
| 4761 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4762 |
printf( "\t has lookup data=%d\n", getushort(ttf)); |
| 4763 |
printf( "\t default properties=" ); |
| 4764 |
showagproperties( getushort(ttf)); |
| 4765 |
show_applelookuptable(ttf,info,prop_show); |
| 4766 |
} |
| 4767 |
|
| 4768 |
static void lcar_show( FILE *ttf, struct ttfinfo *info ) { |
| 4769 |
uint32_t here; |
| 4770 |
int cnt,i,off; |
| 4771 |
|
| 4772 |
off = getushort(ttf); |
| 4773 |
here = ftell(ttf); |
| 4774 |
fseek(ttf, info->lcar_start+off,SEEK_SET ); |
| 4775 |
printf( " caret cnt=%d\n", cnt = getushort(ttf)); |
| 4776 |
for ( i=0; i<cnt; ++i ) |
| 4777 |
printf( "\t\tcaret %d at %d\n", i, getushort(ttf)); |
| 4778 |
fseek(ttf,here,SEEK_SET); |
| 4779 |
} |
| 4780 |
|
| 4781 |
static void readttfapplelcar(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4782 |
|
| 4783 |
fseek(ttf,info->lcar_start,SEEK_SET); |
| 4784 |
printf( "\nlcar table (at %d) (Ligature carets)\n", info->lcar_start ); |
| 4785 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4786 |
printf( "\t data are points=%d\n", getushort(ttf)); |
| 4787 |
show_applelookuptable(ttf,info,lcar_show); |
| 4788 |
} |
| 4789 |
|
| 4790 |
static void opbd_show( FILE *ttf, struct ttfinfo *info ) { |
| 4791 |
uint32_t here; |
| 4792 |
int off; |
| 4793 |
|
| 4794 |
off = getushort(ttf); |
| 4795 |
here = ftell(ttf); |
| 4796 |
fseek(ttf, info->opbd_start+off,SEEK_SET ); |
| 4797 |
printf( " optical left=%d\n", (short) getushort(ttf)); |
| 4798 |
printf( " optical top=%d\n", (short) getushort(ttf)); |
| 4799 |
printf( " optical right=%d\n", (short) getushort(ttf)); |
| 4800 |
printf( " optical bottom=%d\n", (short) getushort(ttf)); |
| 4801 |
fseek(ttf,here,SEEK_SET); |
| 4802 |
} |
| 4803 |
|
| 4804 |
static void readttfappleopbd(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4805 |
|
| 4806 |
fseek(ttf,info->opbd_start,SEEK_SET); |
| 4807 |
printf( "\nopbd table (at %d) (Optical Bounds)\n", info->opbd_start ); |
| 4808 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4809 |
printf( "\t data are points=%d\n", getushort(ttf)); |
| 4810 |
show_applelookuptable(ttf,info,opbd_show); |
| 4811 |
} |
| 4812 |
|
| 4813 |
static void readttfapplefvar(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4814 |
int dataoff, countsizepairs, axiscount, instancecount, instancesize, nameid; |
| 4815 |
uint32_t tag; |
| 4816 |
char *name; |
| 4817 |
int i,j; |
| 4818 |
|
| 4819 |
fseek(ttf,info->fvar_start,SEEK_SET); |
| 4820 |
printf( "\nfvar table (at %d) (Font Variations)\n", info->fvar_start ); |
| 4821 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4822 |
printf( "\t offset to data=%d\n", dataoff = getushort(ttf)); |
| 4823 |
printf( "\t # size pairs=%d\n", countsizepairs = getushort(ttf)); |
| 4824 |
printf( "\t Axis count=%d\n", axiscount = getushort(ttf)); |
| 4825 |
info->fvar_axiscount = axiscount; |
| 4826 |
printf( "\t Axis size=%d\n", getushort(ttf)); |
| 4827 |
printf( "\t Instance count=%d\n", instancecount = getushort(ttf)); |
| 4828 |
printf( "\t Instance size=%d\n", instancesize = getushort(ttf)); |
| 4829 |
for ( i=0; i<axiscount; ++i ) { |
| 4830 |
printf( "\t Axis %d\n", i ); |
| 4831 |
tag = getlong(ttf); |
| 4832 |
printf( "\t Axis Tag '%c%c%c%c'\n", |
| 4833 |
(char)((tag>>24)&0xff), (char)((tag>>16)&0xff), |
| 4834 |
(char)((tag>>8)&0xff), (char)(tag&0xff) ); |
| 4835 |
printf( "\t minValue=%g\n", getfixed(ttf)); |
| 4836 |
printf( "\t defaultValue=%g\n", getfixed(ttf)); |
| 4837 |
printf( "\t maxValue=%g\n", getfixed(ttf)); |
| 4838 |
printf( "\t flags=%x\n", (unsigned int)(getushort(ttf)) ); |
| 4839 |
nameid = getushort(ttf); |
| 4840 |
name = getttfname(util,info,nameid); |
| 4841 |
printf( "\t nameid=%d (%s)\n", nameid, name==NULL ? "Not Found" : name ); |
| 4842 |
free(name); |
| 4843 |
} |
| 4844 |
for ( i=0; i<instancecount; ++i ) { |
| 4845 |
printf( "\t Instance %d\n", i ); |
| 4846 |
nameid = getushort(ttf); |
| 4847 |
name = getttfname(util,info,nameid); |
| 4848 |
printf( "\t nameid=%d (%s)\n", nameid, name==NULL ? "Not Found" : name ); |
| 4849 |
printf( "\t flags=%x\n", (unsigned int)(getushort(ttf)) ); |
| 4850 |
printf( "\t Blend coefficients: "); |
| 4851 |
for ( j=0; j<axiscount; ++j ) |
| 4852 |
printf( "%g, ", getfixed(ttf)); |
| 4853 |
printf( "\n" ); |
| 4854 |
free(name); |
| 4855 |
} |
| 4856 |
printf( "\n" ); |
| 4857 |
} |
| 4858 |
|
| 4859 |
static void readttfapplegvar(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4860 |
int axiscount, gcc, glyphCount, flags; |
| 4861 |
uint32_t *offsets, offset2Coord, offset2Data; |
| 4862 |
int tupleCount, offset; |
| 4863 |
int i, j, k, index; |
| 4864 |
|
| 4865 |
fseek(ttf,info->gvar_start,SEEK_SET); |
| 4866 |
printf( "\ngvar table (at %d) (Glyph Variations)\n", info->gvar_start ); |
| 4867 |
printf( "\t version=%g\n", getfixed(ttf)); |
| 4868 |
printf( "\t Axis count=%d\n", axiscount = getushort(ttf)); |
| 4869 |
if ( axiscount!=info->fvar_axiscount ) |
| 4870 |
fprintf( stderr, "The axis count in the gvar table differs from that in the fvar table.\n 'gvar' axes=%d, 'fvar' axes=%d\n", axiscount, info->fvar_axiscount ); |
| 4871 |
printf( "\t global coord count=%d\n", gcc = getushort(ttf)); |
| 4872 |
printf( "\t offset to coord=%d\n", (int)((offset2Coord = getlong(ttf))) ); |
| 4873 |
printf( "\t glyph count=%d\n", glyphCount = getushort(ttf)); |
| 4874 |
printf( "\t flags=%x\n", (unsigned int)((flags = getushort(ttf))) ); |
| 4875 |
printf( "\t offset to data=%x\n", offset2Data = getlong(ttf)); |
| 4876 |
offsets = malloc(glyphCount*sizeof(uint32_t)); |
| 4877 |
if ( flags&1 ) { |
| 4878 |
for ( i=0; i<glyphCount; ++i ) |
| 4879 |
offsets[i] = getlong(ttf) + offset2Data + info->gvar_start; |
| 4880 |
} else { |
| 4881 |
for ( i=0; i<glyphCount; ++i ) |
| 4882 |
offsets[i] = getushort(ttf)*2 + offset2Data + info->gvar_start; |
| 4883 |
} |
| 4884 |
for ( i=0; i<glyphCount; ++i ) if ( offsets[i]!=offsets[i+1] ) { |
| 4885 |
fseek(ttf,offsets[i],SEEK_SET); |
| 4886 |
printf( "\t Glyph %d %s\n", i, info->glyph_names!=NULL? info->glyph_names[i]: "" ); |
| 4887 |
tupleCount = getushort(ttf); |
| 4888 |
offset = getushort(ttf); |
| 4889 |
printf( "\t Tuple count=%x, (count=%d) tuples %sshare points\n", |
| 4890 |
(unsigned int)(tupleCount), tupleCount&0xfff, |
| 4891 |
(tupleCount&0x8000)? "" : "do not " ); |
| 4892 |
printf( "\t Offset=%d\n", offset ); |
| 4893 |
for ( j=0; j<(tupleCount&0xfff); ++j ) { |
| 4894 |
printf( "\t Tuple %d\n", j ); |
| 4895 |
printf( "\t Size %d\n", getushort(ttf) ); |
| 4896 |
index = getushort(ttf); |
| 4897 |
printf( "\t Index %d%s%s%s\n", index&0xfff, |
| 4898 |
index&0x8000 ? ", Embedded tuple" : "", |
| 4899 |
index&0x4000 ? ", Intermediate tuple" : "", |
| 4900 |
index&0x2000 ? ", Private points" : "" ); |
| 4901 |
if ( index&0x8000 ) { |
| 4902 |
printf( "\t Coords[%g", ((short) getushort(ttf))/16384.0 ); |
| 4903 |
for ( k=1; k<axiscount; ++k ) |
| 4904 |
printf( ",%g", ((short) getushort(ttf))/16384.0 ); |
| 4905 |
printf( "]\n" ); |
| 4906 |
} |
| 4907 |
if ( index&0x4000 ) { |
| 4908 |
printf( "\t Intermediate[%g-%g", ((short) getushort(ttf)/16384.0), |
| 4909 |
((short) getushort(ttf)/16384.0)); |
| 4910 |
for ( k=1; k<axiscount; ++k ) |
| 4911 |
printf( ",%g-%g", ((short) getushort(ttf)/16384.0), |
| 4912 |
((short) getushort(ttf)/16384.0)); |
| 4913 |
printf( "]\n" ); |
| 4914 |
} |
| 4915 |
if ( !(index&0xc000) ) { |
| 4916 |
int here = ftell(ttf); |
| 4917 |
fseek(ttf,info->gvar_start+offset2Coord+(index&0xfff)*axiscount*2,SEEK_SET); |
| 4918 |
printf( "\t Global Coords[%g", ((short) getushort(ttf))/16384.0 ); |
| 4919 |
for ( k=1; k<axiscount; ++k ) |
| 4920 |
printf( ",%g", ((short) getushort(ttf))/16384.0 ); |
| 4921 |
printf( "]\n" ); |
| 4922 |
fseek(ttf,here,SEEK_SET); |
| 4923 |
} |
| 4924 |
} |
| 4925 |
} |
| 4926 |
|
| 4927 |
printf( "\n" ); |
| 4928 |
free(offsets); |
| 4929 |
} |
| 4930 |
|
| 4931 |
static void readttfgasp(FILE *ttf, FILE *util, struct ttfinfo *info) { |
| 4932 |
int n, i, ppem, flags, last=0; |
| 4933 |
|
| 4934 |
fseek(ttf,info->gasp_start,SEEK_SET); |
| 4935 |
printf( "\ngasp table (at %d) (grid fitting and scan conversion table)\n", info->gasp_start ); |
| 4936 |
printf( "\t version=%d\n", getushort(ttf)); |
| 4937 |
printf( "\t Number of gasp entries=%d\n", n = getushort(ttf)); |
| 4938 |
for ( i=0; i<n; ++i ) { |
| 4939 |
ppem = getushort(ttf); |
| 4940 |
flags = getushort(ttf); |
| 4941 |
if ( i==0 && ppem==0xffff ) |
| 4942 |
printf( "\t All sizes: " ); |
| 4943 |
else if ( i==0 ) |
| 4944 |
printf( "\t Sizes below %d: \t", ppem ); |
| 4945 |
else if ( ppem!=0xffff ) |
| 4946 |
printf( "\t Sizes >= %d and <%d:\t", last, ppem ); |
| 4947 |
else |
| 4948 |
printf( "\t All sizes >= %d: \t", last ); |
| 4949 |
last = ppem; |
| 4950 |
if ( flags==0 ) |
| 4951 |
printf( "Nothing (No gridfitting, no anti-aliasing)\n" ); |
| 4952 |
else if ( flags==1 ) |
| 4953 |
printf( "Grid Fit (no anti-aliasing)\n" ); |
| 4954 |
else if ( flags==2 ) |
| 4955 |
printf( "Anti-alias (no grid fitting)\n" ); |
| 4956 |
else |
| 4957 |
printf( "Both Grid Fitting and Anti-Aliasing\n" ); |
| 4958 |
} |
| 4959 |
} |
| 4960 |
|
| 4961 |
static void readtableinstr(FILE *ttf, int start, int len, const char *string) { |
| 4962 |
int i, j, ch, n, ch1, ch2; |
| 4963 |
|
| 4964 |
if ( start==0 ) |
| 4965 |
return; |
| 4966 |
|
| 4967 |
fseek(ttf,start,SEEK_SET); |
| 4968 |
printf( "\n%s table (at %d for %d bytes)\n\t", string, start, len ); |
| 4969 |
for ( i=0; i<len; ++i ) { |
| 4970 |
printf( "%s ", instrs[ch = getc(ttf)]); |
| 4971 |
if ( ch==0x40 ) { |
| 4972 |
printf( "(%d) ", n = getc(ttf)); ++i; |
| 4973 |
for ( j=0; j<n; ++j, ++i ) |
| 4974 |
printf( "%d ", getc(ttf)); |
| 4975 |
printf( "\n" ); |
| 4976 |
} else if ( ch==0x41 ) { |
| 4977 |
printf( "(%d) ", n = getc(ttf)); ++i; |
| 4978 |
for ( j=0; j<n; ++j, i += 2 ) { |
| 4979 |
ch1=getc(ttf); ch2 = getc(ttf); |
| 4980 |
printf( "%d ", (short) ((ch1<<8)|ch2) ); |
| 4981 |
} |
| 4982 |
printf( "\n" ); |
| 4983 |
} else if ( ch>=0xb0 && ch<=0xb7 ) { |
| 4984 |
n = (ch-0xb0)+1; |
| 4985 |
for ( j=0; j<n; ++j, ++i ) |
| 4986 |
printf( "%d ", getc(ttf)); |
| 4987 |
printf( "\n" ); |
| 4988 |
} else if ( ch>=0xb8 && ch<=0xbf ) { |
| 4989 |
n = (ch-0xb8)+1; |
| 4990 |
for ( j=0; j<n; ++j, i += 2 ) { |
| 4991 |
ch1=getc(ttf); ch2 = getc(ttf); |
| 4992 |
printf( "%d ", (short) ((ch1<<8)|ch2) ); |
| 4993 |
} |
| 4994 |
printf( "\n" ); |
| 4995 |
} |
| 4996 |
} |
| 4997 |
printf("\n"); |
| 4998 |
} |
| 4999 |
|
| 5000 |
static char **readcfffontnames(FILE *ttf, int ltype) { |
| 5001 |
uint16_t count = getushort(ttf); |
| 5002 |
int offsize; |
| 5003 |
uint32_t *offsets; |
| 5004 |
char **names; |
| 5005 |
int i,j; |
| 5006 |
const char *labels[] = { "Font Name", "String", NULL }; |
| 5007 |
const char *lab2[] = { "fontnames", "strings", NULL }; |
| 5008 |
|
| 5009 |
printf( "\nThere %s %d %s in this cff\n", count==1?"is":"are", count, lab2[ltype] ); |
| 5010 |
if ( count==0 ) |
| 5011 |
return( NULL ); |
| 5012 |
offsets = malloc((count+1)*sizeof(uint32_t)); |
| 5013 |
offsize = getc(ttf); |
| 5014 |
printf( " Name Index Offset Size: %d\n Offsets: ", offsize ); |
| 5015 |
for ( i=0; i<=count; ++i ) { |
| 5016 |
offsets[i] = getoffset(ttf,offsize); |
| 5017 |
if ( i==0 && offsets[0]!=1 ) |
| 5018 |
fprintf(stderr, "!! Initial offset must be one in %s\n", labels[ltype]); |
| 5019 |
printf( "%d ", (int)(offsets[i]) ); |
| 5020 |
} |
| 5021 |
putchar('\n'); |
| 5022 |
names = malloc((count+1)*sizeof(char *)); |
| 5023 |
for ( i=0; i<count; ++i ) { |
| 5024 |
names[i] = malloc(offsets[i+1]-offsets[i]+1); |
| 5025 |
for ( j=0; j<offsets[i+1]-offsets[i]; ++j ) |
| 5026 |
names[i][j] = getc(ttf); |
| 5027 |
names[i][j] = '\0'; |
| 5028 |
printf( " %s %2d: %s\n", labels[ltype], i, names[i]); |
| 5029 |
} |
| 5030 |
names[i] = NULL; |
| 5031 |
free(offsets); |
| 5032 |
return( names ); |
| 5033 |
} |
| 5034 |
|
| 5035 |
static char *addnibble(char *pt, int nib) { |
| 5036 |
if ( nib<=9 ) |
| 5037 |
*pt++ = nib+'0'; |
| 5038 |
else if ( nib==10 ) |
| 5039 |
*pt++ = '.'; |
| 5040 |
else if ( nib==11 ) |
| 5041 |
*pt++ = 'E'; |
| 5042 |
else if ( nib==12 ) { |
| 5043 |
*pt++ = 'E'; |
| 5044 |
*pt++ = '-'; |
| 5045 |
} else if ( nib==14 ) |
| 5046 |
*pt++ = '-'; |
| 5047 |
else if ( nib==15 ) |
| 5048 |
*pt++ = '\0'; |
| 5049 |
return( pt ); |
| 5050 |
} |
| 5051 |
|
| 5052 |
static int readcffthing(FILE *ttf,int *_ival,double *dval,int *operand) { |
| 5053 |
char buffer[50], *pt; |
| 5054 |
int ch, ival; |
| 5055 |
|
| 5056 |
ch = getc(ttf); |
| 5057 |
if ( ch==12 ) { |
| 5058 |
*operand = (12<<8) | getc(ttf); |
| 5059 |
return( 3 ); |
| 5060 |
} else if ( ch<=21 ) { |
| 5061 |
*operand = ch; |
| 5062 |
return( 3 ); |
| 5063 |
} else if ( ch==30 ) { |
| 5064 |
pt = buffer; |
| 5065 |
do { |
| 5066 |
ch = getc(ttf); |
| 5067 |
pt = addnibble(pt,ch>>4); |
| 5068 |
pt = addnibble(pt,ch&0xf); |
| 5069 |
} while ( pt[-1]!='\0' ); |
| 5070 |
*dval = strtod(buffer,NULL); |
| 5071 |
return( 2 ); |
| 5072 |
} else if ( ch>=32 && ch<=246 ) { |
| 5073 |
*_ival = ch-139; |
| 5074 |
return( 1 ); |
| 5075 |
} else if ( ch>=247 && ch<=250 ) { |
| 5076 |
*_ival = ((ch-247)<<8) + getc(ttf)+108; |
| 5077 |
return( 1 ); |
| 5078 |
} else if ( ch>=251 && ch<=254 ) { |
| 5079 |
*_ival = -((ch-251)<<8) - getc(ttf)-108; |
| 5080 |
return( 1 ); |
| 5081 |
} else if ( ch==28 ) { |
| 5082 |
ival = getc(ttf)<<8; |
| 5083 |
*_ival = (short) (ival | getc(ttf)); |
| 5084 |
return( 1 ); |
| 5085 |
} else if ( ch==29 ) { |
| 5086 |
ival = getc(ttf)<<24; |
| 5087 |
ival = ival | getc(ttf)<<16; |
| 5088 |
ival = ival | getc(ttf)<<8; |
| 5089 |
*_ival = (int) (ival | getc(ttf)); |
| 5090 |
return( 1 ); |
| 5091 |
} |
| 5092 |
printf( "Unexpected value in dictionary %d\n", ch ); |
| 5093 |
*_ival = 0; |
| 5094 |
return( 0 ); |
| 5095 |
} |
| 5096 |
|
| 5097 |
struct pschars { |
| 5098 |
int cnt, next; |
| 5099 |
char **keys; |
| 5100 |
uint8_t **values; |
| 5101 |
int *lens; |
| 5102 |
int bias; |
| 5103 |
}; |
| 5104 |
|
| 5105 |
struct topdicts { |
| 5106 |
int32_t cff_start; |
| 5107 |
|
| 5108 |
char *fontname; |
| 5109 |
|
| 5110 |
int version; |
| 5111 |
int notice; |
| 5112 |
int copyright; |
| 5113 |
int fullname; |
| 5114 |
int familyname; |
| 5115 |
int weight; |
| 5116 |
int isfixedpitch; |
| 5117 |
double italicangle; |
| 5118 |
double underlinepos; |
| 5119 |
double underlinewidth; |
| 5120 |
int painttype; |
| 5121 |
int charstringtype; |
| 5122 |
double fontmatrix[6]; |
| 5123 |
int uniqueid; |
| 5124 |
double fontbb[4]; |
| 5125 |
double strokewidth; |
| 5126 |
int xuid[20]; |
| 5127 |
int charsetoff; |
| 5128 |
int encodingoff; |
| 5129 |
int charstringsoff; |
| 5130 |
int private_size; |
| 5131 |
int private_offset; |
| 5132 |
int synthetic_base; |
| 5133 |
int postscript_code; |
| 5134 |
|
| 5135 |
int basefontname; |
| 5136 |
int basefontblend[16]; |
| 5137 |
|
| 5138 |
int ros_registry; |
| 5139 |
int ros_ordering; |
| 5140 |
int ros_supplement; |
| 5141 |
int cidfontversion; |
| 5142 |
int cidfontrevision; |
| 5143 |
int cidfonttype; |
| 5144 |
int cidcount; |
| 5145 |
int uidbase; |
| 5146 |
int fdarrayoff; |
| 5147 |
int fdselectoff; |
| 5148 |
int sid_fontname; |
| 5149 |
|
| 5150 |
double bluevalues[14]; |
| 5151 |
double otherblues[10]; |
| 5152 |
double familyblues[14]; |
| 5153 |
double familyotherblues[10]; |
| 5154 |
double bluescale; |
| 5155 |
double blueshift; |
| 5156 |
double bluefuzz; |
| 5157 |
int stdhw; |
| 5158 |
int stdvw; |
| 5159 |
double stemsnaph[10]; |
| 5160 |
double stemsnapv[10]; |
| 5161 |
int forcebold; |
| 5162 |
int languagegroup; |
| 5163 |
double expansionfactor; |
| 5164 |
int initialRandomSeed; |
| 5165 |
int subrsoff; |
| 5166 |
int defaultwidthx; |
| 5167 |
int nominalwidthx; |
| 5168 |
|
| 5169 |
struct pschars glyphs; |
| 5170 |
struct pschars local_subrs; |
| 5171 |
uint16_t *charset; |
| 5172 |
}; |
| 5173 |
|
| 5174 |
static void ShowCharString(uint8_t *str,int len,int type) { |
| 5175 |
int v; |
| 5176 |
int val; |
| 5177 |
|
| 5178 |
|
| 5179 |
|
| 5180 |
|
| 5181 |
do { |
| 5182 |
if ( (v = *str++)>=32 ) { |
| 5183 |
if ( v<=246) { |
| 5184 |
val = v - 139; |
| 5185 |
} else if ( v<=250 ) { |
| 5186 |
val = (v-247)*256 + *str++ + 108; |
| 5187 |
--len; |
| 5188 |
} else if ( v<=254 ) { |
| 5189 |
val = -(v-251)*256 - *str++ - 108; |
| 5190 |
--len; |
| 5191 |
} else { |
| 5192 |
val = (*str<<24) | (str[1]<<16) | (str[2]<<8) | str[3]; |
| 5193 |
str += 4; |
| 5194 |
len -= 4; |
| 5195 |
} |
| 5196 |
if ( v==0xff && type==2 ) |
| 5197 |
printf( "%g ", val/65536. ); |
| 5198 |
else |
| 5199 |
printf( "%d ", val ); |
| 5200 |
} else if ( v==28 ) { |
| 5201 |
val = (short) ((str[0]<<8) | str[1]); |
| 5202 |
str += 2; |
| 5203 |
len -= 2; |
| 5204 |
printf( "%d ", val ); |
| 5205 |
} else if ( v==12 ) { |
| 5206 |
v = *str++; |
| 5207 |
--len; |
| 5208 |
switch ( v ) { |
| 5209 |
case 3: printf( "and " ); break; |
| 5210 |
case 4: printf( "or " ); break; |
| 5211 |
case 5: printf( "not " ); break; |
| 5212 |
case 9: printf( "abs " ); break; |
| 5213 |
case 10: printf( "add " ); break; |
| 5214 |
case 11: printf( "sub " ); break; |
| 5215 |
case 12: printf( "div " ); break; |
| 5216 |
case 14: printf( "neg " ); break; |
| 5217 |
case 15: printf( "eq " ); break; |
| 5218 |
case 18: printf( "drop " ); break; |
| 5219 |
case 20: printf( "put " ); break; |
| 5220 |
case 21: printf( "get " ); break; |
| 5221 |
case 22: printf( "ifelse " ); break; |
| 5222 |
case 23: printf( "random " ); break; |
| 5223 |
case 24: printf( "mul " ); break; |
| 5224 |
case 26: printf( "sqrt " ); break; |
| 5225 |
case 27: printf( "dup " ); break; |
| 5226 |
case 28: printf( "exch " ); break; |
| 5227 |
case 29: printf( "index " ); break; |
| 5228 |
case 30: printf( "roll " ); break; |
| 5229 |
case 34: printf( "hflex " ); break; |
| 5230 |
case 35: printf( "flex " ); break; |
| 5231 |
case 36: printf( "hflex1 " ); break; |
| 5232 |
case 37: printf( "flex1 " ); break; |
| 5233 |
|
| 5234 |
case 0: printf( "dotsection " ); break; |
| 5235 |
case 1: printf( "vstem3 " ); break; |
| 5236 |
case 2: printf( "hstem3 " ); break; |
| 5237 |
case 6: printf( "seac " ); break; |
| 5238 |
case 7: printf( "sbw " ); break; |
| 5239 |
case 16: printf( "callothersubr " ); break; |
| 5240 |
case 17: printf( "pop " ); break; |
| 5241 |
case 33: printf( "setcurrentpoint " ); break; |
| 5242 |
|
| 5243 |
default: printf( "?\?\?-12-%d-??? ", v ); break; |
| 5244 |
} |
| 5245 |
} else switch ( v ) { |
| 5246 |
case 1: printf( "hstem " ); break; |
| 5247 |
case 3: printf( "vstem " ); break; |
| 5248 |
case 4: printf( "vmoveto " ); break; |
| 5249 |
case 5: printf( "rlineto " ); break; |
| 5250 |
case 6: printf( "hlineto " ); break; |
| 5251 |
case 7: printf( "vlineto " ); break; |
| 5252 |
case 8: printf( "rrcurveto " ); break; |
| 5253 |
case 10: printf( "callsubr " ); break; |
| 5254 |
case 11: printf( "return " ); break; |
| 5255 |
case 14: printf( "endchar " ); break; |
| 5256 |
case 18: printf( "hstemhm " ); break; |
| 5257 |
case 19: printf( "hintmask " ); break; |
| 5258 |
case 20: printf( "cntrmask " ); break; |
| 5259 |
case 21: printf( "rmoveto " ); break; |
| 5260 |
case 22: printf( "hmoveto " ); break; |
| 5261 |
case 23: printf( "vstemhm " ); break; |
| 5262 |
case 24: printf( "rcurveline " ); break; |
| 5263 |
case 25: printf( "rlinecurve " ); break; |
| 5264 |
case 26: printf( "vvcurveto " ); break; |
| 5265 |
case 27: printf( "hhcurveto " ); break; |
| 5266 |
case 29: printf( "callgsubr " ); break; |
| 5267 |
case 30: printf( "vhcurveto " ); break; |
| 5268 |
case 31: printf( "hvcurveto " ); break; |
| 5269 |
|
| 5270 |
case 9: printf( "closepath " ); break; |
| 5271 |
case 13: printf( "hsbw " ); break; |
| 5272 |
|
| 5273 |
default: printf( "?\?\?-%d-??? ", v ); |
| 5274 |
} |
| 5275 |
--len; |
| 5276 |
if ( v==19 || v==20 ) { |
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
|
| 5281 |
printf( "0x%02x ", *str++ ); |
| 5282 |
--len; |
| 5283 |
} |
| 5284 |
} while ( len>0 ); |
| 5285 |
printf( "\n" ); |
| 5286 |
} |
| 5287 |
|
| 5288 |
static void readcffsubrs(FILE *ttf,struct topdicts *dict,struct pschars *subs, |
| 5289 |
int type, const char *label) { |
| 5290 |
uint16_t count = getushort(ttf); |
| 5291 |
int offsize; |
| 5292 |
uint32_t *offsets; |
| 5293 |
int i,j; |
| 5294 |
const char *text[] = { "char strings", "subrs", NULL }; |
| 5295 |
uint8_t *temp; |
| 5296 |
|
| 5297 |
printf( "\nThere are %d %s in the index associated with %s\n", |
| 5298 |
count, text[type], label ); |
| 5299 |
memset(subs,'\0',sizeof(struct pschars)); |
| 5300 |
if ( count==0 ) |
| 5301 |
return; |
| 5302 |
subs->cnt = count; |
| 5303 |
|
| 5304 |
|
| 5305 |
subs->bias = dict->charstringtype==1 ? 0 : |
| 5306 |
count<1240 ? 107 : |
| 5307 |
count<33900 ? 1131 : 32768; |
| 5308 |
if ( type==1 ) |
| 5309 |
printf( " Bias = %d\n", subs->bias ); |
| 5310 |
offsets = malloc((count+1)*sizeof(uint32_t)); |
| 5311 |
offsize = getc(ttf); |
| 5312 |
printf( " Subr Index Offset Size: %d\n Offsets: ", offsize ); |
| 5313 |
for ( i=0; i<=count; ++i ) { |
| 5314 |
offsets[i] = getoffset(ttf,offsize); |
| 5315 |
if ( i==0 && offsets[0]!=1 ) |
| 5316 |
fprintf( stderr, "!!! Initial offset must be 1 in %s in %s\n", text[type], label); |
| 5317 |
else if ( i!=0 && offsets[i]<offsets[i-1] ) |
| 5318 |
fprintf( stderr, "!!! bad length for %d, %d in %s in %s\n", |
| 5319 |
i-1, (int)((offsets[i]-offsets[i-1])), text[type], label); |
| 5320 |
printf( "%d ", (int)(offsets[i]) ); |
| 5321 |
} |
| 5322 |
putchar('\n'); |
| 5323 |
for ( i=0; i<count; ++i ) { |
| 5324 |
|
| 5325 |
|
| 5326 |
temp = malloc(offsets[i+1]-offsets[i]+1); |
| 5327 |
for ( j=0; j<offsets[i+1]-offsets[i]; ++j ) |
| 5328 |
temp[j] = getc(ttf); |
| 5329 |
temp[j] = '\0'; |
| 5330 |
printf( " %s %d: ", text[type], i ); |
| 5331 |
ShowCharString(temp,offsets[i+1]-offsets[i],dict->charstringtype); |
| 5332 |
free(temp); |
| 5333 |
} |
| 5334 |
free(offsets); |
| 5335 |
} |
| 5336 |
|
| 5337 |
static struct topdicts *readcfftopdict(FILE *ttf, char *fontname, int len) { |
| 5338 |
struct topdicts *td = calloc(1,sizeof(struct topdicts)); |
| 5339 |
long base = ftell(ttf); |
| 5340 |
int ival, oval, sp, ret, i; |
| 5341 |
double stack[50]; |
| 5342 |
|
| 5343 |
td->fontname = fontname; |
| 5344 |
td->underlinepos = -100; |
| 5345 |
td->underlinewidth = 50; |
| 5346 |
td->charstringtype = 2; |
| 5347 |
td->fontmatrix[0] = td->fontmatrix[3] = .001; |
| 5348 |
td->cidcount = 8720; |
| 5349 |
|
| 5350 |
td->notice = td->copyright = td->fullname = td->familyname = td->weight = -1; |
| 5351 |
td->postscript_code = td->basefontname = -1; |
| 5352 |
td->synthetic_base = -1; |
| 5353 |
td->ros_registry = td->ros_ordering = td->fdarrayoff = td->fdselectoff = -1; |
| 5354 |
td->sid_fontname = -1; |
| 5355 |
|
| 5356 |
if ( fontname!=NULL ) printf( " Top Dict for %s\n", fontname ); |
| 5357 |
while ( ftell(ttf)<base+len ) { |
| 5358 |
sp = 0; |
| 5359 |
while ( (ret=readcffthing(ttf,&ival,&stack[sp],&oval))!=3 && ftell(ttf)<base+len ) { |
| 5360 |
if ( sp==0 ) putchar(' '); |
| 5361 |
if ( ret==1 ) printf( " %d", ival ); |
| 5362 |
else printf( " %g", stack[sp] ); |
| 5363 |
if ( ret==1 ) |
| 5364 |
stack[sp]=ival; |
| 5365 |
if ( ret!=0 && sp<45 ) |
| 5366 |
++sp; |
| 5367 |
} |
| 5368 |
if ( sp==0 ) |
| 5369 |
fprintf( stderr, "No argument to operator\n" ); |
| 5370 |
else if ( ret==3 ) switch( oval ) { |
| 5371 |
case 0: |
| 5372 |
printf( " Version\n" ); |
| 5373 |
td->version = stack[sp-1]; |
| 5374 |
break; |
| 5375 |
case 1: |
| 5376 |
printf( " notice\n" ); |
| 5377 |
td->notice = stack[sp-1]; |
| 5378 |
break; |
| 5379 |
case (12<<8)+0: |
| 5380 |
printf( " copyright\n" ); |
| 5381 |
td->copyright = stack[sp-1]; |
| 5382 |
break; |
| 5383 |
case 2: |
| 5384 |
printf( " fullname\n" ); |
| 5385 |
td->fullname = stack[sp-1]; |
| 5386 |
break; |
| 5387 |
case 3: |
| 5388 |
printf( " familyname\n" ); |
| 5389 |
td->familyname = stack[sp-1]; |
| 5390 |
break; |
| 5391 |
case 4: |
| 5392 |
printf( " weight\n" ); |
| 5393 |
td->weight = stack[sp-1]; |
| 5394 |
break; |
| 5395 |
case (12<<8)+1: |
| 5396 |
printf( " isfixedpitch\n" ); |
| 5397 |
td->isfixedpitch = stack[sp-1]; |
| 5398 |
break; |
| 5399 |
case (12<<8)+2: |
| 5400 |
printf( " italicangle\n" ); |
| 5401 |
td->italicangle = stack[sp-1]; |
| 5402 |
break; |
| 5403 |
case (12<<8)+3: |
| 5404 |
printf( " underlinepos\n" ); |
| 5405 |
td->underlinepos = stack[sp-1]; |
| 5406 |
break; |
| 5407 |
case (12<<8)+4: |
| 5408 |
printf( " underlinewidth\n" ); |
| 5409 |
td->underlinewidth = stack[sp-1]; |
| 5410 |
break; |
| 5411 |
case (12<<8)+5: |
| 5412 |
printf( " painttype\n" ); |
| 5413 |
td->painttype = stack[sp-1]; |
| 5414 |
break; |
| 5415 |
case (12<<8)+6: |
| 5416 |
printf( " charstringtype\n" ); |
| 5417 |
td->charstringtype = stack[sp-1]; |
| 5418 |
break; |
| 5419 |
case (12<<8)+7: |
| 5420 |
printf( " fontmatrix\n" ); |
| 5421 |
memcpy(td->fontmatrix,stack,(sp>=6?6:sp)*sizeof(double)); |
| 5422 |
break; |
| 5423 |
case 13: |
| 5424 |
printf( " uniqueid\n" ); |
| 5425 |
td->uniqueid = stack[sp-1]; |
| 5426 |
break; |
| 5427 |
case 5: |
| 5428 |
printf( " fontbb\n" ); |
| 5429 |
memcpy(td->fontbb,stack,(sp>=4?4:sp)*sizeof(double)); |
| 5430 |
break; |
| 5431 |
case (12<<8)+8: |
| 5432 |
printf( " strokewidth\n" ); |
| 5433 |
td->strokewidth = stack[sp-1]; |
| 5434 |
break; |
| 5435 |
case 14: |
| 5436 |
printf( " xuid\n" ); |
| 5437 |
for ( i=0; i<sp && i<20; ++i ) |
| 5438 |
td->xuid[i] = stack[i]; |
| 5439 |
break; |
| 5440 |
case 15: |
| 5441 |
printf( " charsetoff\n" ); |
| 5442 |
td->charsetoff = stack[sp-1]; |
| 5443 |
break; |
| 5444 |
case 16: |
| 5445 |
printf( " encodingoff\n" ); |
| 5446 |
td->encodingoff = stack[sp-1]; |
| 5447 |
break; |
| 5448 |
case 17: |
| 5449 |
printf( " charstringsoff\n" ); |
| 5450 |
td->charstringsoff = stack[sp-1]; |
| 5451 |
break; |
| 5452 |
case 18: |
| 5453 |
printf( " private\n" ); |
| 5454 |
td->private_size = stack[0]; |
| 5455 |
td->private_offset = stack[1]; |
| 5456 |
break; |
| 5457 |
case (12<<8)+20: |
| 5458 |
printf( " synthetic_base\n" ); |
| 5459 |
td->synthetic_base = stack[sp-1]; |
| 5460 |
break; |
| 5461 |
case (12<<8)+21: |
| 5462 |
printf( " postscript_code\n" ); |
| 5463 |
td->postscript_code = stack[sp-1]; |
| 5464 |
break; |
| 5465 |
case (12<<8)+22: |
| 5466 |
printf( " basefontname\n" ); |
| 5467 |
td->basefontname = stack[sp-1]; |
| 5468 |
break; |
| 5469 |
case (12<<8)+23: |
| 5470 |
printf( " basefontblend\n" ); |
| 5471 |
for ( i=0; i<sp && i<16; ++i ) |
| 5472 |
td->basefontblend[i] = stack[i]; |
| 5473 |
break; |
| 5474 |
case (12<<8)+30: |
| 5475 |
printf( " ROS\n" ); |
| 5476 |
td->ros_registry = stack[0]; |
| 5477 |
td->ros_ordering = stack[1]; |
| 5478 |
td->ros_supplement = stack[2]; |
| 5479 |
break; |
| 5480 |
case (12<<8)+31: |
| 5481 |
printf( " CIDFontVersion\n" ); |
| 5482 |
td->cidfontversion = stack[sp-1]; |
| 5483 |
break; |
| 5484 |
case (12<<8)+32: |
| 5485 |
printf( " CIDFontRevision\n" ); |
| 5486 |
td->cidfontrevision = stack[sp-1]; |
| 5487 |
break; |
| 5488 |
case (12<<8)+33: |
| 5489 |
printf( " CIDFontType\n" ); |
| 5490 |
td->cidfonttype = stack[sp-1]; |
| 5491 |
break; |
| 5492 |
case (12<<8)+34: |
| 5493 |
printf( " CIDCount\n" ); |
| 5494 |
td->cidcount = stack[sp-1]; |
| 5495 |
break; |
| 5496 |
case (12<<8)+35: |
| 5497 |
printf( " UIDBase\n" ); |
| 5498 |
td->uidbase = stack[sp-1]; |
| 5499 |
break; |
| 5500 |
case (12<<8)+36: |
| 5501 |
printf( " FDArray Off\n" ); |
| 5502 |
td->fdarrayoff = stack[sp-1]; |
| 5503 |
break; |
| 5504 |
case (12<<8)+37: |
| 5505 |
printf( " FDSelect Off\n" ); |
| 5506 |
td->fdselectoff = stack[sp-1]; |
| 5507 |
break; |
| 5508 |
case (12<<8)+38: |
| 5509 |
printf( " Fontname\n" ); |
| 5510 |
td->sid_fontname = stack[sp-1]; |
| 5511 |
break; |
| 5512 |
default: |
| 5513 |
fprintf(stderr,"Unknown operator in %s: %x\n", fontname, (unsigned int)(oval) ); |
| 5514 |
break; |
| 5515 |
} |
| 5516 |
} |
| 5517 |
return( td ); |
| 5518 |
} |
| 5519 |
|
| 5520 |
static void dumpsid(const char *label, int sid, char **strings, int smax ) { |
| 5521 |
if ( sid==-1 ) |
| 5522 |
return; |
| 5523 |
|
| 5524 |
if ( sid<nStdStrings ) |
| 5525 |
printf( "%s%d %s\n", label, sid, cffnames[sid]); |
| 5526 |
else if ( sid<nStdStrings+smax ) |
| 5527 |
printf( "%s%d %s\n", label, sid, strings[sid-nStdStrings]); |
| 5528 |
else |
| 5529 |
printf( "%s%d >> Bad SID (max=%d) <<\n", label, sid, smax ); |
| 5530 |
} |
| 5531 |
|
| 5532 |
static char *getsid(int sid, char **strings,int smax ) { |
| 5533 |
if ( sid==-1 ) |
| 5534 |
return(NULL); |
| 5535 |
|
| 5536 |
if ( sid<nStdStrings ) |
| 5537 |
return( strdup(cffnames[sid])); |
| 5538 |
else if ( sid<nStdStrings+smax ) |
| 5539 |
return( strdup(strings[sid-nStdStrings])); |
| 5540 |
else |
| 5541 |
return( strdup(">> Bad SID <<")); |
| 5542 |
} |
| 5543 |
|
| 5544 |
static void readcffprivate(FILE *ttf, struct topdicts *td, char **strings, int smax) { |
| 5545 |
int ival, oval, sp, ret, i; |
| 5546 |
double stack[50]; |
| 5547 |
int32_t end = td->cff_start+td->private_offset+td->private_size; |
| 5548 |
char *name = NULL; |
| 5549 |
|
| 5550 |
char *nameless_str = "<Nameless>"; |
| 5551 |
|
| 5552 |
fseek(ttf,td->cff_start+td->private_offset,SEEK_SET); |
| 5553 |
|
| 5554 |
td->subrsoff = -1; |
| 5555 |
td->expansionfactor = .06; |
| 5556 |
td->bluefuzz = 1; |
| 5557 |
td->blueshift = 7; |
| 5558 |
td->bluescale = .039625; |
| 5559 |
|
| 5560 |
name = td->fontname?td->fontname: |
| 5561 |
td->sid_fontname?getsid(td->sid_fontname,strings,smax):nameless_str; |
| 5562 |
|
| 5563 |
printf( "\n Private Dict for %s\n", name ); |
| 5564 |
while ( ftell(ttf)<end ) { |
| 5565 |
sp = 0; |
| 5566 |
while ( (ret=readcffthing(ttf,&ival,&stack[sp],&oval))!=3 && ftell(ttf)<end ) { |
| 5567 |
if ( sp==0 ) putchar(' '); |
| 5568 |
if ( ret==1 ) printf( " %d", ival ); |
| 5569 |
else printf( " %g", stack[sp] ); |
| 5570 |
if ( ret==1 ) |
| 5571 |
stack[sp]=ival; |
| 5572 |
if ( ret!=0 && sp<45 ) |
| 5573 |
++sp; |
| 5574 |
} |
| 5575 |
if ( sp==0 ) |
| 5576 |
fprintf( stderr, "No argument to operator\n" ); |
| 5577 |
else if ( ret==3 ) switch( oval ) { |
| 5578 |
case 6: |
| 5579 |
printf( " BlueValues\n" ); |
| 5580 |
for ( i=0; i<sp && i<14; ++i ) { |
| 5581 |
td->bluevalues[i] = stack[i]; |
| 5582 |
if ( i!=0 ) |
| 5583 |
td->bluevalues[i] += td->bluevalues[i-1]; |
| 5584 |
} |
| 5585 |
break; |
| 5586 |
case 7: |
| 5587 |
printf( " OtherBlues\n" ); |
| 5588 |
for ( i=0; i<sp && i<10; ++i ) { |
| 5589 |
td->otherblues[i] = stack[i]; |
| 5590 |
if ( i!=0 ) |
| 5591 |
td->otherblues[i] += td->otherblues[i-1]; |
| 5592 |
} |
| 5593 |
break; |
| 5594 |
case 8: |
| 5595 |
printf( " FamilyBlues\n" ); |
| 5596 |
for ( i=0; i<sp && i<14; ++i ) { |
| 5597 |
td->familyblues[i] = stack[i]; |
| 5598 |
if ( i!=0 ) |
| 5599 |
td->familyblues[i] += td->familyblues[i-1]; |
| 5600 |
} |
| 5601 |
break; |
| 5602 |
case 9: |
| 5603 |
printf( " FamilyOtherBlues\n" ); |
| 5604 |
for ( i=0; i<sp && i<10; ++i ) { |
| 5605 |
td->familyotherblues[i] = stack[i]; |
| 5606 |
if ( i!=0 ) |
| 5607 |
td->familyotherblues[i] += td->familyotherblues[i-1]; |
| 5608 |
} |
| 5609 |
break; |
| 5610 |
case (12<<8)+9: |
| 5611 |
printf( " BlueScale\n" ); |
| 5612 |
td->bluescale = stack[sp-1]; |
| 5613 |
break; |
| 5614 |
case (12<<8)+10: |
| 5615 |
printf( " BlueShift\n" ); |
| 5616 |
td->blueshift = stack[sp-1]; |
| 5617 |
break; |
| 5618 |
case (12<<8)+11: |
| 5619 |
printf( " BlueFuzz\n" ); |
| 5620 |
td->bluefuzz = stack[sp-1]; |
| 5621 |
break; |
| 5622 |
case 10: |
| 5623 |
printf( " StdHW\n" ); |
| 5624 |
td->stdhw = stack[sp-1]; |
| 5625 |
break; |
| 5626 |
case 11: |
| 5627 |
printf( " StdVW\n" ); |
| 5628 |
td->stdvw = stack[sp-1]; |
| 5629 |
break; |
| 5630 |
case (12<<8)+12: |
| 5631 |
printf( " StemSnapH\n" ); |
| 5632 |
for ( i=0; i<sp && i<10; ++i ) { |
| 5633 |
td->stemsnaph[i] = stack[i]; |
| 5634 |
if ( i!=0 ) |
| 5635 |
td->stemsnaph[i] += td->stemsnaph[i-1]; |
| 5636 |
} |
| 5637 |
break; |
| 5638 |
case (12<<8)+13: |
| 5639 |
printf( " StemSnapV\n" ); |
| 5640 |
for ( i=0; i<sp && i<10; ++i ) { |
| 5641 |
td->stemsnapv[i] = stack[i]; |
| 5642 |
if ( i!=0 ) |
| 5643 |
td->stemsnapv[i] += td->stemsnapv[i-1]; |
| 5644 |
} |
| 5645 |
break; |
| 5646 |
case (12<<8)+14: |
| 5647 |
printf( " ForceBold\n" ); |
| 5648 |
td->forcebold = stack[sp-1]; |
| 5649 |
break; |
| 5650 |
case (12<<8)+17: |
| 5651 |
printf( " LanguageGroup\n" ); |
| 5652 |
td->languagegroup = stack[sp-1]; |
| 5653 |
break; |
| 5654 |
case (12<<8)+18: |
| 5655 |
printf( " ExpansionFactor\n" ); |
| 5656 |
td->expansionfactor = stack[sp-1]; |
| 5657 |
break; |
| 5658 |
case (12<<8)+19: |
| 5659 |
printf( " InitialRandomSeed\n" ); |
| 5660 |
td->initialRandomSeed = stack[sp-1]; |
| 5661 |
break; |
| 5662 |
case 19: |
| 5663 |
printf( " Subrs\n" ); |
| 5664 |
td->subrsoff = stack[sp-1]; |
| 5665 |
break; |
| 5666 |
case 20: |
| 5667 |
printf( " DefaultWidthX\n" ); |
| 5668 |
td->defaultwidthx = stack[sp-1]; |
| 5669 |
break; |
| 5670 |
case 21: |
| 5671 |
printf( " NominalWidthX\n" ); |
| 5672 |
td->nominalwidthx = stack[sp-1]; |
| 5673 |
break; |
| 5674 |
default: |
| 5675 |
fprintf(stderr,"Unknown operator in %s: %x\n", td->fontname, (unsigned int)(oval) ); |
| 5676 |
break; |
| 5677 |
} |
| 5678 |
} |
| 5679 |
|
| 5680 |
if ( td->subrsoff!=-1 ) { |
| 5681 |
fseek(ttf,td->cff_start+td->private_offset+td->subrsoff,SEEK_SET); |
| 5682 |
readcffsubrs(ttf,td,&td->local_subrs, 1, name ); |
| 5683 |
} |
| 5684 |
if (name != nameless_str) free(name); |
| 5685 |
} |
| 5686 |
|
| 5687 |
static struct topdicts **readcfftopdicts(FILE *ttf, char **fontnames, int cff_start) { |
| 5688 |
uint16_t count = getushort(ttf); |
| 5689 |
int offsize; |
| 5690 |
uint32_t *offsets; |
| 5691 |
struct topdicts **dicts; |
| 5692 |
int i; |
| 5693 |
|
| 5694 |
if ( fontnames!=NULL ) |
| 5695 |
printf( "There %s %d top dictionar%s in this cff\n", count==1?"is":"are",count, count==1?"y":"ies" ); |
| 5696 |
else |
| 5697 |
printf( "There %s %d subdictionary dictionar%s in this font\n", count==1?"is":"are",count, count==1?"y":"ies" ); |
| 5698 |
if ( count==0 ) |
| 5699 |
return( NULL ); |
| 5700 |
offsets = malloc((count+1)*sizeof(uint32_t)); |
| 5701 |
offsize = getc(ttf); |
| 5702 |
printf( " %s Dict Index Offset Size: %d\n Offsets: ", |
| 5703 |
fontnames!=NULL?"Top":"Sub", offsize ); |
| 5704 |
for ( i=0; i<=count; ++i ) { |
| 5705 |
offsets[i] = getoffset(ttf,offsize); |
| 5706 |
if ( i==0 && offsets[0]!=1 ) |
| 5707 |
fprintf(stderr, "!! Initial offset must be one in Top Dict Index\n" ); |
| 5708 |
printf( "%d ", (int)(offsets[i]) ); |
| 5709 |
} |
| 5710 |
putchar('\n'); |
| 5711 |
dicts = malloc((count+1)*sizeof(struct topdicts *)); |
| 5712 |
for ( i=0; i<count; ++i ) { |
| 5713 |
dicts[i] = readcfftopdict(ttf,fontnames!=NULL?fontnames[i]:NULL, |
| 5714 |
offsets[i+1]-offsets[i]); |
| 5715 |
dicts[i]->cff_start = cff_start; |
| 5716 |
} |
| 5717 |
dicts[i] = NULL; |
| 5718 |
free(offsets); |
| 5719 |
return( dicts ); |
| 5720 |
} |
| 5721 |
|
| 5722 |
static void showdict(struct topdicts *dict, char **strings, int smax) { |
| 5723 |
int i, j; |
| 5724 |
|
| 5725 |
if ( dict->sid_fontname==-1 ) |
| 5726 |
printf( "\nDump of top dictionary for %s\n", dict->fontname); |
| 5727 |
else |
| 5728 |
dumpsid("\nDump of sub dictionary ", dict->sid_fontname, strings, smax ); |
| 5729 |
dumpsid(" Version=", dict->version, strings, smax ); |
| 5730 |
dumpsid(" Notice=", dict->notice, strings, smax ); |
| 5731 |
dumpsid(" copyright=", dict->copyright, strings, smax ); |
| 5732 |
dumpsid(" fullname=", dict->fullname, strings, smax ); |
| 5733 |
dumpsid(" familyname=", dict->familyname, strings, smax ); |
| 5734 |
dumpsid(" weight=", dict->weight, strings, smax ); |
| 5735 |
printf( " fixedpitch=%d\n", dict->isfixedpitch); |
| 5736 |
printf( " ItalicAngle=%g\n", dict->italicangle); |
| 5737 |
printf( " underlinepos=%g\n", dict->underlinepos); |
| 5738 |
printf( " underlinewidth=%g\n", dict->underlinewidth); |
| 5739 |
printf( " painttype=%d\n", dict->painttype); |
| 5740 |
printf( " charstringtype=%d\n", dict->charstringtype); |
| 5741 |
printf( " fontmatrix=[%g %g %g %g %g %g]\n", |
| 5742 |
dict->fontmatrix[0], dict->fontmatrix[1], |
| 5743 |
dict->fontmatrix[2], dict->fontmatrix[3], |
| 5744 |
dict->fontmatrix[4], dict->fontmatrix[5]); |
| 5745 |
printf( " uniqueid=%d\n", dict->uniqueid); |
| 5746 |
printf( " fontbb=[%g %g %g %g]\n", |
| 5747 |
dict->fontbb[0], dict->fontbb[1], |
| 5748 |
dict->fontbb[2], dict->fontbb[3]); |
| 5749 |
printf( " strokewidth=%g\n", dict->strokewidth); |
| 5750 |
for ( i=19; i>=0; --i ) |
| 5751 |
if ( dict->xuid[i]!=0 ) |
| 5752 |
break; |
| 5753 |
if ( i>=0 ) { |
| 5754 |
printf( " XUID=[" ); |
| 5755 |
for ( j=0; j<=i; ++j ) |
| 5756 |
printf("%d ", dict->xuid[j]); |
| 5757 |
printf("]\n"); |
| 5758 |
} |
| 5759 |
printf( " charsetoff=%d\n", dict->charsetoff); |
| 5760 |
printf( " encodingoff=%d\n", dict->encodingoff); |
| 5761 |
printf( " charstringsoff=%d\n", dict->charstringsoff); |
| 5762 |
printf( " private size=%d off=%d\n", dict->private_size, dict->private_offset); |
| 5763 |
if ( dict->synthetic_base!=-1 ) |
| 5764 |
printf( " synthetic_base=%d\n", dict->synthetic_base ); |
| 5765 |
dumpsid(" postscript_code=", dict->postscript_code, strings, smax ); |
| 5766 |
dumpsid(" basefontname=", dict->basefontname, strings, smax ); |
| 5767 |
for ( i=15; i>=0; --i ) |
| 5768 |
if ( dict->basefontblend[i]!=0 ) |
| 5769 |
break; |
| 5770 |
if ( i>=0 ) { |
| 5771 |
printf( " basefontblend=[" ); |
| 5772 |
for ( j=0; j<=i; ++j ) |
| 5773 |
printf("%d ", dict->basefontblend[i]); |
| 5774 |
printf("]\n"); |
| 5775 |
} |
| 5776 |
if ( dict->ros_registry!=-1 ) { |
| 5777 |
dumpsid(" ros (Registry)=", dict->ros_registry, strings, smax ); |
| 5778 |
dumpsid(" (Ordering)=", dict->ros_ordering, strings, smax ); |
| 5779 |
printf(" (Supplement)=%d\n", dict->ros_supplement ); |
| 5780 |
printf( " cidfontversion=%d\n", dict->cidfontversion); |
| 5781 |
printf( " cidfontrevision=%d\n", dict->cidfontrevision); |
| 5782 |
printf( " cidfonttype=%d\n", dict->cidfonttype); |
| 5783 |
printf( " cidcount=%d\n", dict->cidcount); |
| 5784 |
printf( " uidbase=%d\n", dict->uidbase); |
| 5785 |
printf( " FDArray off=%d\n", dict->fdarrayoff ); |
| 5786 |
} |
| 5787 |
if ( dict->fdselectoff!=-1 ) |
| 5788 |
printf( " FDSelect off=%d\n", dict->fdselectoff ); |
| 5789 |
printf( "\n" ); |
| 5790 |
} |
| 5791 |
|
| 5792 |
|
| 5793 |
static void readcffenc(FILE *ttf,struct topdicts *dict,char **strings,int smax) { |
| 5794 |
int format, cnt, i; |
| 5795 |
|
| 5796 |
if ( dict->encodingoff==0 ) { |
| 5797 |
printf( "\nAdobe Standard Encoding\n" ); |
| 5798 |
return; |
| 5799 |
} else if ( dict->encodingoff==1 ) { |
| 5800 |
printf( "\nExpert Encoding\n" ); |
| 5801 |
return; |
| 5802 |
} |
| 5803 |
fseek(ttf,dict->cff_start+dict->encodingoff,SEEK_SET); |
| 5804 |
format = getc(ttf); |
| 5805 |
printf( "\nCFF Encoding format=%x\n", (unsigned int)(format) ); |
| 5806 |
if ( (format&0x7f)==0 ) { |
| 5807 |
cnt = getc(ttf); |
| 5808 |
printf( " Enc cnt=%d\n Enc: ", cnt ); |
| 5809 |
for ( i=0; i<cnt; ++i ) |
| 5810 |
printf( "%02x ", (unsigned int)(getc(ttf)) ); |
| 5811 |
printf("\n"); |
| 5812 |
} else if ( (format&0x7f)==1 ) { |
| 5813 |
cnt = getc(ttf); |
| 5814 |
printf( " Enc range cnt=%d\n", cnt ); |
| 5815 |
for ( i=0; i<cnt; ++i ) { |
| 5816 |
printf( " Enc Range %d: First=%02x ", i, (unsigned int)(getc(ttf)) ); |
| 5817 |
printf( "nLeft=%d\n", getc(ttf)); |
| 5818 |
} |
| 5819 |
} |
| 5820 |
if ( format&0x80 ) { |
| 5821 |
cnt = getc(ttf); |
| 5822 |
printf( " Supplemental entries[%d]\n", cnt ); |
| 5823 |
for ( i=0; i<cnt; ++i ) { |
| 5824 |
printf( " Supplement[%d]: Encoding %d -> ", i, getc(ttf)); |
| 5825 |
dumpsid("",getushort(ttf),strings, smax); |
| 5826 |
} |
| 5827 |
} |
| 5828 |
} |
| 5829 |
|
| 5830 |
static void readcffset(FILE *ttf,struct topdicts *dict,char **strings,int smax, |
| 5831 |
struct ttfinfo *info) { |
| 5832 |
int len = dict->glyphs.cnt; |
| 5833 |
int i=0; |
| 5834 |
int format, cnt, j, first; |
| 5835 |
|
| 5836 |
if ( dict->charsetoff==0 ) { |
| 5837 |
|
| 5838 |
printf( "\nISOAdobe charset\n" ); |
| 5839 |
dict->charset = malloc(len*sizeof(uint16_t)); |
| 5840 |
for ( i=0; i<len && i<=228; ++i ) |
| 5841 |
dict->charset[i] = i; |
| 5842 |
} else if ( dict->charsetoff==1 ) { |
| 5843 |
printf( "\nExpert charset\n" ); |
| 5844 |
|
| 5845 |
dict->charset = malloc((len<162?162:len)*sizeof(uint16_t)); |
| 5846 |
dict->charset[0] = 0; |
| 5847 |
dict->charset[1] = 1; |
| 5848 |
for ( i=2; i<len && i<=238-227; ++i ) |
| 5849 |
dict->charset[i] = i+227; |
| 5850 |
dict->charset[12] = 13; |
| 5851 |
dict->charset[13] = 14; |
| 5852 |
dict->charset[14] = 15; |
| 5853 |
dict->charset[15] = 99; |
| 5854 |
for ( i=16; i<len && i<=248-223; ++i ) |
| 5855 |
dict->charset[i] = i+223; |
| 5856 |
dict->charset[25] = 27; |
| 5857 |
dict->charset[26] = 28; |
| 5858 |
for ( i=27; i<len && i<=266-222; ++i ) |
| 5859 |
dict->charset[i] = i+222; |
| 5860 |
dict->charset[44] = 109; |
| 5861 |
dict->charset[45] = 110; |
| 5862 |
for ( i=46; i<len && i<=318-221; ++i ) |
| 5863 |
dict->charset[i] = i+221; |
| 5864 |
dict->charset[96] = 158; |
| 5865 |
dict->charset[97] = 155; |
| 5866 |
dict->charset[98] = 163; |
| 5867 |
for ( i=99; i<len && i<=326-220; ++i ) |
| 5868 |
dict->charset[i] = i+220; |
| 5869 |
dict->charset[107] = 150; |
| 5870 |
dict->charset[108] = 164; |
| 5871 |
dict->charset[109] = 169; |
| 5872 |
for ( i=110; i<len && i<=378-217; ++i ) |
| 5873 |
dict->charset[i] = i+217; |
| 5874 |
} else if ( dict->charsetoff==2 ) { |
| 5875 |
printf( "\nExpert subset charset\n" ); |
| 5876 |
|
| 5877 |
dict->charset = malloc((len<130?130:len)*sizeof(uint16_t)); |
| 5878 |
dict->charset[0] = 0; |
| 5879 |
dict->charset[1] = 1; |
| 5880 |
for ( i=2; i<len && i<=238-227; ++i ) |
| 5881 |
dict->charset[i] = i+227; |
| 5882 |
dict->charset[12] = 13; |
| 5883 |
dict->charset[13] = 14; |
| 5884 |
dict->charset[14] = 15; |
| 5885 |
dict->charset[15] = 99; |
| 5886 |
for ( i=16; i<len && i<=248-223; ++i ) |
| 5887 |
dict->charset[i] = i+223; |
| 5888 |
dict->charset[25] = 27; |
| 5889 |
dict->charset[26] = 28; |
| 5890 |
for ( i=27; i<len && i<=266-222; ++i ) |
| 5891 |
dict->charset[i] = i+222; |
| 5892 |
dict->charset[44] = 109; |
| 5893 |
dict->charset[45] = 110; |
| 5894 |
for ( i=46; i<len && i<=272-221; ++i ) |
| 5895 |
dict->charset[i] = i+221; |
| 5896 |
dict->charset[51] = 300; |
| 5897 |
dict->charset[52] = 301; |
| 5898 |
dict->charset[53] = 302; |
| 5899 |
dict->charset[54] = 305; |
| 5900 |
dict->charset[55] = 314; |
| 5901 |
dict->charset[56] = 315; |
| 5902 |
dict->charset[57] = 158; |
| 5903 |
dict->charset[58] = 155; |
| 5904 |
dict->charset[59] = 163; |
| 5905 |
for ( i=60; i<len && i<=326-260; ++i ) |
| 5906 |
dict->charset[i] = i+260; |
| 5907 |
dict->charset[67] = 150; |
| 5908 |
dict->charset[68] = 164; |
| 5909 |
dict->charset[69] = 169; |
| 5910 |
for ( i=110; i<len && i<=346-217; ++i ) |
| 5911 |
dict->charset[i] = i+217; |
| 5912 |
} else { |
| 5913 |
dict->charset = malloc(len*sizeof(uint16_t)); |
| 5914 |
dict->charset[0] = 0; |
| 5915 |
fseek(ttf,dict->cff_start+dict->charsetoff,SEEK_SET); |
| 5916 |
format = getc(ttf); |
| 5917 |
printf( "\nCharset format=%d\n", format ); |
| 5918 |
if ( format==0 ) { |
| 5919 |
for ( i=1; i<len; ++i ) |
| 5920 |
dict->charset[i] = getushort(ttf); |
| 5921 |
} else if ( format==1 ) { |
| 5922 |
for ( i = 1; i<len; ) { |
| 5923 |
first = dict->charset[i++] = getushort(ttf); |
| 5924 |
cnt = getc(ttf); |
| 5925 |
for ( j=0; j<cnt; ++j ) |
| 5926 |
dict->charset[i++] = ++first; |
| 5927 |
} |
| 5928 |
} else if ( format==2 ) { |
| 5929 |
for ( i = 1; i<len; ) { |
| 5930 |
first = dict->charset[i++] = getushort(ttf); |
| 5931 |
cnt = getushort(ttf); |
| 5932 |
for ( j=0; j<cnt; ++j ) |
| 5933 |
dict->charset[i++] = ++first; |
| 5934 |
} |
| 5935 |
} |
| 5936 |
} |
| 5937 |
while ( i<len ) dict->charset[i++] = 0; |
| 5938 |
printf( " Which means...\n" ); |
| 5939 |
if ( dict->ros_registry==-1 ) { |
| 5940 |
info->glyph_names = calloc(len,sizeof(char *)); |
| 5941 |
for ( i=0; i<len; ++i ) { |
| 5942 |
printf( "Glyph %d is named ", i ); |
| 5943 |
dumpsid("", dict->charset[i], strings, smax); |
| 5944 |
info->glyph_names[i] = getsid(dict->charset[i], strings,smax); |
| 5945 |
} |
| 5946 |
} else |
| 5947 |
for ( i=0; i<len; ++i ) |
| 5948 |
printf( "Glyph %d -> CID %d\n", i, dict->charset[i]); |
| 5949 |
} |
| 5950 |
|
| 5951 |
static int readcff(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 5952 |
int offsize; |
| 5953 |
int hdrsize; |
| 5954 |
char **fontnames; |
| 5955 |
char **strings; |
| 5956 |
struct topdicts **dicts, **subdicts; |
| 5957 |
int i, j, smax; |
| 5958 |
struct pschars gsubs; |
| 5959 |
|
| 5960 |
fseek(ttf,info->cff_start,SEEK_SET); |
| 5961 |
printf( "\nPostscript CFF table (at %d for %d bytes)\n", info->cff_start, info->cff_length); |
| 5962 |
printf( "\tMajor Version: %d\n", getc(ttf)); |
| 5963 |
printf( "\tMinor Version: %d\n", getc(ttf)); |
| 5964 |
printf( "\tTable Header size: %d\n", hdrsize = getc(ttf)); |
| 5965 |
printf( "\tOffset size: %d\n", offsize = getc(ttf)); |
| 5966 |
if ( hdrsize!=4 ) |
| 5967 |
fseek(ttf,info->cff_start+hdrsize,SEEK_SET); |
| 5968 |
fontnames = readcfffontnames(ttf,0); |
| 5969 |
dicts = readcfftopdicts(ttf,fontnames,info->cff_start); |
| 5970 |
|
| 5971 |
strings = readcfffontnames(ttf,1); |
| 5972 |
for ( smax=0; strings[smax]!=NULL; ++smax ); |
| 5973 |
for ( i=0; fontnames[i]!=NULL; ++i ) |
| 5974 |
showdict(dicts[i],strings,smax); |
| 5975 |
readcffsubrs(ttf,dicts[0],&gsubs, 1, "Global" ); |
| 5976 |
for ( i=0; fontnames[i]!=NULL; ++i ) { |
| 5977 |
if ( dicts[i]->charstringsoff!=-1 ) { |
| 5978 |
fseek(ttf,info->cff_start+dicts[i]->charstringsoff,SEEK_SET); |
| 5979 |
readcffsubrs(ttf,dicts[i],&dicts[i]->glyphs, 0, fontnames[i]); |
| 5980 |
} |
| 5981 |
if ( dicts[i]->private_offset!=-1 ) |
| 5982 |
readcffprivate(ttf,dicts[i],strings,smax); |
| 5983 |
if ( dicts[i]->charsetoff!=-1 ) |
| 5984 |
readcffset(ttf,dicts[i],strings,smax,info); |
| 5985 |
if ( dicts[i]->ros_registry==-1 ) |
| 5986 |
readcffenc(ttf,dicts[i],strings,smax); |
| 5987 |
if ( dicts[i]->fdarrayoff!=-1 ) { |
| 5988 |
fseek(ttf,info->cff_start+dicts[i]->fdarrayoff,SEEK_SET); |
| 5989 |
subdicts = readcfftopdicts(ttf,NULL,info->cff_start); |
| 5990 |
for ( j=0; subdicts[j]!=NULL; ++j ) { |
| 5991 |
showdict(subdicts[j],strings,smax); |
| 5992 |
if ( subdicts[j]->private_offset!=-1 ) |
| 5993 |
readcffprivate(ttf,subdicts[j],strings,smax); |
| 5994 |
} |
| 5995 |
} |
| 5996 |
} |
| 5997 |
for ( i = 0; strings[i] != NULL; ++i) |
| 5998 |
free(strings[i]); |
| 5999 |
free(strings); |
| 6000 |
|
| 6001 |
for ( i = 0; dicts[i] != NULL; ++i) |
| 6002 |
free(dicts[i]); |
| 6003 |
free(dicts); |
| 6004 |
|
| 6005 |
for ( i = 0; fontnames[i] != NULL; ++i) |
| 6006 |
free(fontnames[i]); |
| 6007 |
free(fontnames); |
| 6008 |
return( 1 ); |
| 6009 |
} |
| 6010 |
|
| 6011 |
static void readttfBigGlyphMetrics(FILE *ttf,const char *indent) { |
| 6012 |
printf( "%sBitmap rows=%d\n", indent, getc(ttf)); |
| 6013 |
printf( "%sBitmap columns=%d\n", indent, getc(ttf)); |
| 6014 |
printf( "%shoriBearingX=%d\n", indent, (signed char) getc(ttf)); |
| 6015 |
printf( "%shoriBearingY=%d\n", indent, (signed char) getc(ttf)); |
| 6016 |
printf( "%shoriAdvance=%d\n", indent, getc(ttf)); |
| 6017 |
printf( "%svertBearingX=%d\n", indent, (signed char) getc(ttf)); |
| 6018 |
printf( "%svertBearingY=%d\n", indent, (signed char) getc(ttf)); |
| 6019 |
printf( "%svertAdvance=%d\n", indent, getc(ttf)); |
| 6020 |
} |
| 6021 |
|
| 6022 |
static void ShowGlyph(FILE *ttf,long offset,long len,int imageFormat, struct ttfinfo *info) { |
| 6023 |
int h,w,sbX,sbY,advance; |
| 6024 |
int i,j,k,ch; |
| 6025 |
long here; |
| 6026 |
|
| 6027 |
if ( imageFormat!=1 && imageFormat!=2 ) |
| 6028 |
return; |
| 6029 |
here = ftell(ttf); |
| 6030 |
fseek(ttf,info->bitmapdata_start+offset,SEEK_SET); |
| 6031 |
|
| 6032 |
h = getc(ttf); |
| 6033 |
w = getc(ttf); |
| 6034 |
sbX = (signed char) getc(ttf); |
| 6035 |
sbY = (signed char) getc(ttf); |
| 6036 |
advance = getc(ttf); |
| 6037 |
printf( "\t\theight=%d width=%d sbX=%d sbY=%d advance=%d %s aligned\n", |
| 6038 |
h,w,sbX,sbY,advance,imageFormat==1?"Byte":"Bit"); |
| 6039 |
len -= 5; ch = 0; |
| 6040 |
if ( imageFormat==1 ) { |
| 6041 |
|
| 6042 |
for ( i=0; i<h; ++i ) { |
| 6043 |
putchar('\t'); |
| 6044 |
for ( j=0; j<(w+7)/8; ++j ) { |
| 6045 |
ch = getc(ttf); --len; |
| 6046 |
for ( k=0; k<8 && j*8+k<w; ++k ) { |
| 6047 |
if ( ch&(0x80>>k)) |
| 6048 |
putchar('*'); |
| 6049 |
else |
| 6050 |
putchar('.'); |
| 6051 |
} |
| 6052 |
} |
| 6053 |
putchar('\n'); |
| 6054 |
} |
| 6055 |
} else { |
| 6056 |
k=8; |
| 6057 |
for ( i=0; i<h; ++i ) { |
| 6058 |
putchar('\t'); |
| 6059 |
for ( j=0; j<w; ++j ) { |
| 6060 |
if ( ++k>=8 ) { |
| 6061 |
ch = getc(ttf); --len; |
| 6062 |
k=0; |
| 6063 |
} |
| 6064 |
if ( ch&(0x80>>k)) |
| 6065 |
putchar('*'); |
| 6066 |
else |
| 6067 |
putchar('.'); |
| 6068 |
} |
| 6069 |
putchar('\n'); |
| 6070 |
} |
| 6071 |
} |
| 6072 |
if ( len!=0 ) |
| 6073 |
printf("!!!\tLength field wrong. %d left\n", (int) len ); |
| 6074 |
fseek(ttf,here,SEEK_SET); |
| 6075 |
} |
| 6076 |
|
| 6077 |
static void readttfIndexSubTab(FILE *ttf,long offset, int first, int last, |
| 6078 |
struct ttfinfo *info) { |
| 6079 |
int i, indexFormat, imageFormat, bdatOff; |
| 6080 |
long curstart, nextstart; |
| 6081 |
|
| 6082 |
fseek(ttf,offset,SEEK_SET); |
| 6083 |
printf( "\t index Format=%d ", indexFormat=getushort(ttf)); |
| 6084 |
if ( indexFormat==1 || indexFormat==3 ) printf( "Proportional\n" ); |
| 6085 |
else if ( indexFormat==2 ) printf( "Monospace\n" ); |
| 6086 |
else printf( "Unknown\n" ); |
| 6087 |
printf( "\t image Format=%d\n", imageFormat=getushort(ttf)); |
| 6088 |
printf( "\t Offset in bitmap data table=%d\n", bdatOff=getlong(ttf)); |
| 6089 |
if ( indexFormat==1 || indexFormat==3 ) { |
| 6090 |
curstart = (indexFormat==1?getlong(ttf):getushort(ttf)); |
| 6091 |
for ( i=first; i<=last; ++i ) { |
| 6092 |
nextstart = (indexFormat==1?getlong(ttf):getushort(ttf)); |
| 6093 |
if ( info->glyph_names==NULL ) |
| 6094 |
printf( "\t Glyph %d starts at %5d length=%d\n", i, (int) curstart, (int) (nextstart-curstart) ); |
| 6095 |
else if ( i<info->glyph_cnt && info->glyph_names[i]!=NULL ) |
| 6096 |
printf( "\t Glyph %d (%10s) starts at %5d length=%d\n", i, |
| 6097 |
info->glyph_names[i], (int) curstart, (int) (nextstart-curstart) ); |
| 6098 |
else |
| 6099 |
printf( "\t Glyph %d ( ) starts at %5d length=%d\n", i, |
| 6100 |
(int) curstart, (int) (nextstart-curstart) ); |
| 6101 |
ShowGlyph(ttf,bdatOff+curstart,nextstart-curstart,imageFormat,info); |
| 6102 |
curstart = nextstart; |
| 6103 |
} |
| 6104 |
} else if ( indexFormat==2 ) { |
| 6105 |
printf( "\t Bitmap Image Size=%d\n", (int) getlong(ttf)); |
| 6106 |
printf( "\t big Metrics for any glyph\n" ); |
| 6107 |
readttfBigGlyphMetrics(ttf,"\t "); |
| 6108 |
} |
| 6109 |
} |
| 6110 |
|
| 6111 |
static void readttfIndexSizeSubTab(FILE *ttf,long offset, long size, long num, |
| 6112 |
struct ttfinfo *info) { |
| 6113 |
int i, first, last; |
| 6114 |
long here, moreoff; |
| 6115 |
|
| 6116 |
fseek(ttf,offset,SEEK_SET); |
| 6117 |
for ( i=0; i<num; ++i ) { |
| 6118 |
printf( "\t indexSubTable[%d]\n", i ); |
| 6119 |
printf( "\t first glyph=%d\n", first = getushort(ttf)); |
| 6120 |
printf( "\t last glyph=%d\n", last = getushort(ttf)); |
| 6121 |
printf( "\t additional offset=%d\n", (int) (moreoff = getlong(ttf))); |
| 6122 |
here = ftell(ttf); |
| 6123 |
readttfIndexSubTab(ttf,offset+moreoff,first,last,info); |
| 6124 |
fseek(ttf,here,SEEK_SET); |
| 6125 |
} |
| 6126 |
} |
| 6127 |
|
| 6128 |
static void sbitLineMetrics(FILE *ttf) { |
| 6129 |
|
| 6130 |
printf( "\t ascender: %d\n", (signed char) getc(ttf)); |
| 6131 |
printf( "\t descender: %d\n", (signed char) getc(ttf)); |
| 6132 |
printf( "\t widthMax: %d\n", getc(ttf)); |
| 6133 |
printf( "\t caretSlopeNumerator: %d\n", (signed char) getc(ttf)); |
| 6134 |
printf( "\t caretSlopeDenominator: %d\n", (signed char) getc(ttf)); |
| 6135 |
printf( "\t caretOffset: %d\n", (signed char) getc(ttf)); |
| 6136 |
printf( "\t minOriginSB: %d\n", (signed char) getc(ttf)); |
| 6137 |
printf( "\t minAdvanceSB: %d\n", (signed char) getc(ttf)); |
| 6138 |
printf( "\t maxBeforeBL: %d\n", (signed char) getc(ttf)); |
| 6139 |
printf( "\t maxAfterBL: %d\n", (signed char) getc(ttf)); |
| 6140 |
getushort(ttf); |
| 6141 |
} |
| 6142 |
|
| 6143 |
static int readttfbitmapscale(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6144 |
int cnt,i; |
| 6145 |
int newx, newy, oldx, oldy; |
| 6146 |
|
| 6147 |
fseek(ttf,info->bitmapscale_start,SEEK_SET); |
| 6148 |
printf( "\nBitmap scaling data (at %d)\n", info->bitmapscale_start); |
| 6149 |
printf( "\tVersion: 0x%08x\n", (unsigned int)(getlong(ttf)) ); |
| 6150 |
printf( "\tnum Sizes: %d\n", cnt = (int) getlong(ttf)); |
| 6151 |
for ( i=0; i<cnt; ++i ) { |
| 6152 |
printf( " Scaling Info %d\n", i ); |
| 6153 |
printf( " Horizontal metrics\n" ); |
| 6154 |
sbitLineMetrics(ttf); |
| 6155 |
printf( " Vertical metrics\n" ); |
| 6156 |
sbitLineMetrics(ttf); |
| 6157 |
newx = getc(ttf); |
| 6158 |
newy = getc(ttf); |
| 6159 |
oldx = getc(ttf); |
| 6160 |
oldy = getc(ttf); |
| 6161 |
printf( " Scale original bitmap (xppem=%d,yppem=%d) to (xppem=%d,yppem=%d)\n", |
| 6162 |
oldx, oldy, newx, newy ); |
| 6163 |
} |
| 6164 |
return( 1 ); |
| 6165 |
} |
| 6166 |
|
| 6167 |
static int readttfbitmaps(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6168 |
int cnt,i, num; |
| 6169 |
long here, offset, size; |
| 6170 |
|
| 6171 |
fseek(ttf,info->bitmaploc_start,SEEK_SET); |
| 6172 |
printf( "\nBitmap location data (at %d for %d bytes)\n", info->bitmaploc_start, info->bitmaploc_length); |
| 6173 |
printf( "\tVersion: 0x%08x\n", (unsigned int)(getlong(ttf)) ); |
| 6174 |
printf( "\tnumStrikes: %d\n", (int)((cnt = getlong(ttf))) ); |
| 6175 |
for ( i=0; i<cnt; ++i ) { |
| 6176 |
printf( "\t indexSubTableArrayOffset: %d\n", (int)((offset = getlong(ttf))) ); |
| 6177 |
printf( "\t indexTableSize: %d\n", (int)((size = getlong(ttf))) ); |
| 6178 |
printf( "\t numberOfIndexSubTables: %d\n", (int)((num = getlong(ttf))) ); |
| 6179 |
printf( "\t colorRef: %d\n", (int)(getlong(ttf)) ); |
| 6180 |
printf( "\t horizontal metrics\n" ); |
| 6181 |
sbitLineMetrics(ttf); |
| 6182 |
printf( "\t vertical metrics\n" ); |
| 6183 |
sbitLineMetrics(ttf); |
| 6184 |
printf( "\t startGlyph: %d\n", getushort(ttf)); |
| 6185 |
printf( "\t endGlyph: %d\n", getushort(ttf)); |
| 6186 |
printf( "\t ppemX: %d\n", getc(ttf)); |
| 6187 |
printf( "\t ppemY: %d\n", getc(ttf)); |
| 6188 |
printf( "\t bitDepth: %d\n", getc(ttf)); |
| 6189 |
printf( "\t flags: 0x%x\n\n", (unsigned int)(getc(ttf)) ); |
| 6190 |
here = ftell(ttf); |
| 6191 |
readttfIndexSizeSubTab(ttf,info->bitmaploc_start+offset,size,num,info); |
| 6192 |
fseek(ttf,here,SEEK_SET); |
| 6193 |
} |
| 6194 |
return( 1 ); |
| 6195 |
} |
| 6196 |
|
| 6197 |
static int readttfhdmx(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6198 |
int cnt,size,i; |
| 6199 |
int gid; |
| 6200 |
int pos; |
| 6201 |
|
| 6202 |
fseek(ttf,info->hdmx_start,SEEK_SET); |
| 6203 |
printf( "\nHorizontal device metrics (at %d)\n", info->hdmx_start); |
| 6204 |
printf( "\tVersion: 0x%08x\n", (unsigned int)(getushort(ttf)) ); |
| 6205 |
printf( "\tnum Records: %d\n", cnt = getushort(ttf)); |
| 6206 |
printf( "\trecord Size: %d\n", size = (int) getlong(ttf)); |
| 6207 |
pos = ftell(ttf); |
| 6208 |
for ( i=0; i<cnt; ++i ) { |
| 6209 |
fseek(ttf,pos+i*size,SEEK_SET); |
| 6210 |
printf( " Device widths at %dppem\n", getc(ttf)); |
| 6211 |
printf( " Max Width %d\n", getc(ttf)); |
| 6212 |
for ( gid=0; gid<info->glyph_cnt; ++gid ) { |
| 6213 |
if ( info->glyph_names!=NULL && info->glyph_names[gid]!=NULL ) |
| 6214 |
printf("\t\t%s:\t%d\n", info->glyph_names[gid], getc(ttf)); |
| 6215 |
} |
| 6216 |
} |
| 6217 |
return( 1 ); |
| 6218 |
} |
| 6219 |
|
| 6220 |
static void PrintDeviceTable(FILE *ttf, uint32_t start) { |
| 6221 |
uint32_t here = ftell(ttf); |
| 6222 |
int first, last, type; |
| 6223 |
signed char *corrections; |
| 6224 |
int i,b,c, w; |
| 6225 |
int any; |
| 6226 |
|
| 6227 |
fseek(ttf,start,SEEK_SET); |
| 6228 |
first = getushort(ttf); |
| 6229 |
last = getushort(ttf); |
| 6230 |
type = getushort(ttf); |
| 6231 |
if ( type!=1 && type!=2 && type!=3 ) |
| 6232 |
fprintf( stderr, "! > Bad device table type: %d (must be 1,2, or 3)\n", |
| 6233 |
type ); |
| 6234 |
if ( first>last ) |
| 6235 |
fprintf( stderr, "! > Bad device table first>last (first=%d last=%d)\n", |
| 6236 |
first, last ); |
| 6237 |
else { |
| 6238 |
c = last-first+1; |
| 6239 |
corrections = malloc(c); |
| 6240 |
if ( type==1 ) { |
| 6241 |
for ( i=0; i<c; i+=8 ) { |
| 6242 |
w = getushort(ttf); |
| 6243 |
for ( b=0; b<8 && i+b<c; ++b ) |
| 6244 |
corrections[i+b] = ((int16_t) ((w<<(b*2))&0xc000))>>14; |
| 6245 |
} |
| 6246 |
} else if ( type==2 ) { |
| 6247 |
for ( i=0; i<c; i+=4 ) { |
| 6248 |
w = getushort(ttf); |
| 6249 |
for ( b=0; b<4 && i+b<c; ++b ) |
| 6250 |
corrections[i+b] = ((int16_t) ((w<<(b*4))&0xf000))>>12; |
| 6251 |
} |
| 6252 |
} else { |
| 6253 |
for ( i=0; i<c; ++i ) |
| 6254 |
corrections[i] = (int8_t) getc(ttf); |
| 6255 |
} |
| 6256 |
putchar('{'); |
| 6257 |
any = false; |
| 6258 |
for ( i=0; i<c; ++i ) { |
| 6259 |
if ( corrections[i]!=0 ) { |
| 6260 |
if ( any ) putchar(' '); |
| 6261 |
any = true; |
| 6262 |
printf( "%d:%d", first+i, corrections[i]); |
| 6263 |
} |
| 6264 |
} |
| 6265 |
free( corrections ); |
| 6266 |
printf( "}[%d-%d sized %d]", first,last, type ); |
| 6267 |
} |
| 6268 |
fseek( ttf, here, SEEK_SET ); |
| 6269 |
} |
| 6270 |
|
| 6271 |
static void PrintMathValueRecord(FILE *ttf, uint32_t start) { |
| 6272 |
int val; |
| 6273 |
uint32_t devtaboffset; |
| 6274 |
|
| 6275 |
val = (short) getushort(ttf); |
| 6276 |
devtaboffset = getushort(ttf); |
| 6277 |
printf( "%d", val ); |
| 6278 |
if ( devtaboffset!=0 ) |
| 6279 |
PrintDeviceTable(ttf,start+devtaboffset); |
| 6280 |
} |
| 6281 |
|
| 6282 |
static void readttfmathConstants(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6283 |
int i; |
| 6284 |
|
| 6285 |
fseek(ttf,start,SEEK_SET); |
| 6286 |
printf( "\n MATH Constants sub-table (at %d)\n", (int)(start) ); |
| 6287 |
for ( i=0; i<4; ++i ) |
| 6288 |
printf( "\t Constant %d: %d\n", i, getushort(ttf)); |
| 6289 |
for ( ; i<4+51; ++i ) { |
| 6290 |
printf( "\t Constant %d: ", i ); |
| 6291 |
PrintMathValueRecord(ttf,start); |
| 6292 |
printf( "\n"); |
| 6293 |
} |
| 6294 |
|
| 6295 |
printf( "\t Constant %d: %d\n", i, getushort(ttf)); |
| 6296 |
printf( "\n"); |
| 6297 |
if ( feof(ttf) ) { |
| 6298 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6299 |
return; |
| 6300 |
} |
| 6301 |
} |
| 6302 |
|
| 6303 |
static void readttfmathICTA(FILE *ttf,uint32_t start, struct ttfinfo *info, int is_ic) { |
| 6304 |
int coverage, cnt, i; |
| 6305 |
uint16_t *glyphs; |
| 6306 |
uint32_t here; |
| 6307 |
|
| 6308 |
fseek(ttf,start,SEEK_SET); |
| 6309 |
if ( is_ic ) |
| 6310 |
printf( "\n MATH Italics Correction sub-table (at %d)\n", (int)(start) ); |
| 6311 |
else |
| 6312 |
printf( "\n MATH Top Accent Attachment sub-table (at %d)\n", (int)(start) ); |
| 6313 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 6314 |
printf( "\t Count=%d\n", cnt = getushort(ttf)); |
| 6315 |
if ( feof(ttf) ) { |
| 6316 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6317 |
return; |
| 6318 |
} |
| 6319 |
here = ftell(ttf); |
| 6320 |
glyphs = showCoverageTable(ttf,start+coverage,cnt); |
| 6321 |
fseek(ttf,here,SEEK_SET); |
| 6322 |
for ( i=0; i<cnt; ++i ) { |
| 6323 |
printf( "\t\tGlyph %s(%d): ", |
| 6324 |
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]], |
| 6325 |
glyphs[i]); |
| 6326 |
PrintMathValueRecord(ttf,start); |
| 6327 |
printf( "\n"); |
| 6328 |
} |
| 6329 |
free(glyphs); |
| 6330 |
printf( "\n"); |
| 6331 |
} |
| 6332 |
|
| 6333 |
static void PrintMathKernTable(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6334 |
int cnt, i; |
| 6335 |
uint32_t here = ftell(ttf); |
| 6336 |
|
| 6337 |
fseek(ttf,start,SEEK_SET); |
| 6338 |
cnt = getushort(ttf); |
| 6339 |
for ( i=0; i<cnt; ++i ) { |
| 6340 |
printf( "\t\t\tHeights %d: ", i ); |
| 6341 |
PrintMathValueRecord(ttf,start); |
| 6342 |
printf( "\n"); |
| 6343 |
} |
| 6344 |
for ( i=0; i<=cnt; ++i ) { |
| 6345 |
printf( "\t\t\tKerns %d: ", i ); |
| 6346 |
PrintMathValueRecord(ttf,start); |
| 6347 |
printf( "\n"); |
| 6348 |
} |
| 6349 |
fseek(ttf,here,SEEK_SET); |
| 6350 |
} |
| 6351 |
|
| 6352 |
static void readttfmathKern(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6353 |
int coverage, cnt, i, j; |
| 6354 |
uint16_t *glyphs; |
| 6355 |
uint32_t here; |
| 6356 |
const char *cornernames[] = { "TopRight:", "TopLeft:", "BottomRight:", "BottomLeft:" }; |
| 6357 |
|
| 6358 |
fseek(ttf,start,SEEK_SET); |
| 6359 |
printf( "\n MATH Kerning sub-table (at %d)\n", (int)(start) ); |
| 6360 |
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf)); |
| 6361 |
printf( "\t Count=%d\n", cnt = getushort(ttf)); |
| 6362 |
if ( feof(ttf) ) { |
| 6363 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6364 |
return; |
| 6365 |
} |
| 6366 |
here = ftell(ttf); |
| 6367 |
glyphs = showCoverageTable(ttf,start+coverage,cnt); |
| 6368 |
fseek(ttf,here,SEEK_SET); |
| 6369 |
for ( i=0; i<cnt; ++i ) { |
| 6370 |
printf( "\t\tGlyph %s(%d):\n", |
| 6371 |
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]], |
| 6372 |
glyphs[i]); |
| 6373 |
for ( j=0; j<4; ++j ) { |
| 6374 |
int offset = getushort(ttf); |
| 6375 |
if ( offset!=0 ) { |
| 6376 |
printf( "\t\t %s\n", cornernames[j]); |
| 6377 |
PrintMathKernTable(ttf,start+offset,info); |
| 6378 |
} |
| 6379 |
} |
| 6380 |
} |
| 6381 |
free(glyphs); |
| 6382 |
printf( "\n"); |
| 6383 |
} |
| 6384 |
|
| 6385 |
static void readttfmathGlyphInfo(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6386 |
uint32_t ic, ta, es, mk; |
| 6387 |
|
| 6388 |
fseek(ttf,start,SEEK_SET); |
| 6389 |
printf( "\n MATH Glyph Info sub-table (at %d)\n", (int)(start) ); |
| 6390 |
printf( "\tOffset to Italic Correction: %d\n", (int)((ic = getushort(ttf))) ); |
| 6391 |
printf( "\tOffset to Top Accent: %d\n", (int)((ta = getushort(ttf))) ); |
| 6392 |
printf( "\tOffset to Extended Shape: %d\n", (int)((es = getushort(ttf))) ); |
| 6393 |
printf( "\tOffset to Math Kern: %d\n", (int)((mk = getushort(ttf))) ); |
| 6394 |
if ( feof(ttf) ) { |
| 6395 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6396 |
return; |
| 6397 |
} |
| 6398 |
|
| 6399 |
if ( ic!=0 ) |
| 6400 |
readttfmathICTA(ttf,start+ic,info,1); |
| 6401 |
if ( ta!=0 ) |
| 6402 |
readttfmathICTA(ttf,start+ta,info,0); |
| 6403 |
if ( es!=0 ) { |
| 6404 |
printf( "\n MATH Extended Shape sub-table (at %d)\n", (int)((start+es)) ); |
| 6405 |
free( showCoverageTable(ttf,start+es,-1)); |
| 6406 |
} |
| 6407 |
if ( mk!=0 ) |
| 6408 |
readttfmathKern(ttf,start+mk,info); |
| 6409 |
} |
| 6410 |
|
| 6411 |
static void PrintMathGlyphConstruction(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6412 |
uint32_t here = ftell(ttf); |
| 6413 |
int offset, variant_cnt, part_cnt; |
| 6414 |
int i; |
| 6415 |
|
| 6416 |
fseek(ttf,start,SEEK_SET); |
| 6417 |
printf( "\t\t Glyph Assembly Offset=%d\n", offset = getushort(ttf)); |
| 6418 |
printf( "\t\t Variant Count=%d\n", variant_cnt = getushort(ttf)); |
| 6419 |
if ( feof(ttf) ) { |
| 6420 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6421 |
return; |
| 6422 |
} |
| 6423 |
if ( variant_cnt!=0 ) { |
| 6424 |
printf("\t\t Variants: " ); |
| 6425 |
for ( i=0; i<variant_cnt; ++i ) { |
| 6426 |
int gid, adv; |
| 6427 |
gid = getushort(ttf); |
| 6428 |
adv = getushort(ttf); |
| 6429 |
printf( " %s:%d", |
| 6430 |
gid>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[gid], |
| 6431 |
adv); |
| 6432 |
} |
| 6433 |
printf( "\n" ); |
| 6434 |
} |
| 6435 |
if ( offset!=0 ) { |
| 6436 |
fseek(ttf,start+offset,SEEK_SET); |
| 6437 |
printf( "\t\t Glyph Assembly Italic Correction: " ); |
| 6438 |
PrintMathValueRecord(ttf,start+offset); |
| 6439 |
printf( "\n\t\t Part Count=%d\n", part_cnt = getushort(ttf)); |
| 6440 |
for ( i=0; i<part_cnt; ++i ) { |
| 6441 |
int gid = getushort(ttf), flags; |
| 6442 |
printf( "\t\t %s", |
| 6443 |
gid>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[gid]); |
| 6444 |
printf( " start=%d", getushort(ttf)); |
| 6445 |
printf( " end=%d", getushort(ttf)); |
| 6446 |
printf( " full=%d", getushort(ttf)); |
| 6447 |
flags = getushort(ttf); |
| 6448 |
printf( " flags=%04x(%s%s)\n", (unsigned int)(flags), (flags&1)?"Extender":"Required", |
| 6449 |
(flags&0xfffe)?",Unknown flags!!!!":""); |
| 6450 |
} |
| 6451 |
} |
| 6452 |
fseek(ttf,here,SEEK_SET); |
| 6453 |
} |
| 6454 |
|
| 6455 |
static void readttfmathVariants(FILE *ttf,uint32_t start, struct ttfinfo *info) { |
| 6456 |
int vcoverage, vcnt, hcoverage, hcnt, i, offset; |
| 6457 |
uint16_t *vglyphs=NULL, *hglyphs=NULL; |
| 6458 |
uint32_t here; |
| 6459 |
|
| 6460 |
fseek(ttf,start,SEEK_SET); |
| 6461 |
printf( "\n MATH Variants sub-table (at %d)\n", (int)(start) ); |
| 6462 |
printf( "\t MinConnectorOverlap=%d\n", getushort(ttf)); |
| 6463 |
printf( "\t VCoverage Offset=%d\n", vcoverage = getushort(ttf)); |
| 6464 |
printf( "\t HCoverage Offset=%d\n", hcoverage = getushort(ttf)); |
| 6465 |
printf( "\t VCount=%d\n", vcnt = getushort(ttf)); |
| 6466 |
printf( "\t HCount=%d\n", hcnt = getushort(ttf)); |
| 6467 |
if ( feof(ttf) ) { |
| 6468 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6469 |
return; |
| 6470 |
} |
| 6471 |
here = ftell(ttf); |
| 6472 |
if ( vcoverage!=0 ) |
| 6473 |
vglyphs = showCoverageTable(ttf,start+vcoverage,vcnt); |
| 6474 |
else { |
| 6475 |
vglyphs = NULL; |
| 6476 |
if ( vcnt!=0 ) |
| 6477 |
fprintf( stderr, "! > Bad coverage table: Offset=NUL, but cnt=%d\n", vcnt ); |
| 6478 |
} |
| 6479 |
if ( hcoverage!=0 ) |
| 6480 |
hglyphs = showCoverageTable(ttf,start+hcoverage,hcnt); |
| 6481 |
else { |
| 6482 |
hglyphs = NULL; |
| 6483 |
if ( hcnt!=0 ) |
| 6484 |
fprintf( stderr, "! > Bad coverage table: Offset=NUL, but cnt=%d\n", hcnt ); |
| 6485 |
} |
| 6486 |
fseek(ttf,here,SEEK_SET); |
| 6487 |
for ( i=0; i<vcnt; ++i ) { |
| 6488 |
printf( "\t\tV Glyph %s(%d):\n", |
| 6489 |
vglyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[vglyphs[i]], |
| 6490 |
vglyphs[i]); |
| 6491 |
offset = getushort(ttf); |
| 6492 |
PrintMathGlyphConstruction(ttf,start+offset,info); |
| 6493 |
} |
| 6494 |
free(vglyphs); |
| 6495 |
for ( i=0; i<hcnt; ++i ) { |
| 6496 |
printf( "\t\tH Glyph %s(%d):\n", |
| 6497 |
hglyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[hglyphs[i]], |
| 6498 |
hglyphs[i]); |
| 6499 |
offset = getushort(ttf); |
| 6500 |
PrintMathGlyphConstruction(ttf,start+offset,info); |
| 6501 |
} |
| 6502 |
free(hglyphs); |
| 6503 |
printf( "\n"); |
| 6504 |
} |
| 6505 |
|
| 6506 |
static int readttfmath(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6507 |
int version; |
| 6508 |
uint32_t constants, glyphinfo, variants; |
| 6509 |
|
| 6510 |
fseek(ttf,info->math_start,SEEK_SET); |
| 6511 |
printf( "\nMATH table (at %d)\n", info->math_start); |
| 6512 |
printf( "\tVersion: 0x%08x\n", (unsigned int)((version = (int) getlong(ttf))) ); |
| 6513 |
if ( version!=0x00010000 ) |
| 6514 |
fprintf( stderr, "!> Bad version number for math table.\n" ); |
| 6515 |
printf( "\tOffset to Constants: %d\n", (int)((constants = getushort(ttf))) ); |
| 6516 |
printf( "\tOffset to GlyphInfo: %d\n", (int)((glyphinfo = getushort(ttf))) ); |
| 6517 |
printf( "\tOffset to Variants: %d\n", (int)((variants = getushort(ttf))) ); |
| 6518 |
if ( feof(ttf) ) { |
| 6519 |
fprintf( stderr, "!> Unexpected end of file!\n" ); |
| 6520 |
return( 0 ); |
| 6521 |
} |
| 6522 |
if ( constants!=0 ) |
| 6523 |
readttfmathConstants(ttf,info->math_start+constants,info); |
| 6524 |
else |
| 6525 |
fprintf( stderr, "!> NUL Offset not expected for math constant table.\n" ); |
| 6526 |
if ( glyphinfo!=0 ) |
| 6527 |
readttfmathGlyphInfo(ttf,info->math_start+glyphinfo,info); |
| 6528 |
else |
| 6529 |
fprintf( stderr, "!> NUL Offset not expected for math Glyph Info table.\n" ); |
| 6530 |
if ( variants!=0 ) |
| 6531 |
readttfmathVariants(ttf,info->math_start+variants,info); |
| 6532 |
else |
| 6533 |
fprintf( stderr, "!> NUL Offset not expected for math Variants table.\n" ); |
| 6534 |
return( 1 ); |
| 6535 |
} |
| 6536 |
|
| 6537 |
static void readttfbaseminmax(FILE *ttf,uint32_t offset,struct ttfinfo *info, |
| 6538 |
uint32_t script_tag,uint32_t lang_tag) { |
| 6539 |
int min, max; |
| 6540 |
int j,feat_cnt; |
| 6541 |
|
| 6542 |
fseek(ttf,offset,SEEK_SET); |
| 6543 |
min = (short) getushort(ttf); |
| 6544 |
max = (short) getushort(ttf); |
| 6545 |
if ( lang_tag == 0 ) |
| 6546 |
printf( "\t min extent=%d max extent=%d for script '%c%c%c%c'\n", |
| 6547 |
min, max, |
| 6548 |
(char)((script_tag>>24)&0xff), (char)((script_tag>>16)&0xff), |
| 6549 |
(char)((script_tag>>8)&0xff), (char)((script_tag)&0xff) ); |
| 6550 |
else |
| 6551 |
printf( "\t min extent=%d max extent=%d for language '%c%c%c%c' in script '%c%c%c%c'\n", |
| 6552 |
min, max, |
| 6553 |
(char)((lang_tag>>24)&0xff), (char)((lang_tag>>16)&0xff), |
| 6554 |
(char)((lang_tag>>8)&0xff), (char)((lang_tag)&0xff), |
| 6555 |
(char)((script_tag>>24)&0xff), (char)((script_tag>>16)&0xff), |
| 6556 |
(char)((script_tag>>8)&0xff), (char)(script_tag&0xf) ); |
| 6557 |
feat_cnt = getushort(ttf); |
| 6558 |
for ( j=0; j<feat_cnt; ++j ) { |
| 6559 |
uint32_t feat_tag = getlong(ttf); |
| 6560 |
min = (short) getushort(ttf); |
| 6561 |
max = (short) getushort(ttf); |
| 6562 |
if ( lang_tag == 0 ) |
| 6563 |
printf( "\t min extent=%d max extent=%d in feature '%c%c%c%c' of script '%c%c%c%c'\n", |
| 6564 |
min, max, |
| 6565 |
(char)((feat_tag>>24)&0xff), (char)((feat_tag>>16)&0xff), |
| 6566 |
(char)((feat_tag>>8)&0xff), (char)(feat_tag&0xff), |
| 6567 |
(char)((script_tag>>24)&0xff), (char)((script_tag>>16)&0xff), |
| 6568 |
(char)((script_tag>>8)&0xff), (char)(script_tag&0xff) ); |
| 6569 |
else |
| 6570 |
printf( "\t min extent=%d max extent=%d in feature '%c%c%c%c' of language '%c%c%c%c' in script '%c%c%c%c'\n", |
| 6571 |
min, max, |
| 6572 |
(char)((feat_tag>>24)&0xff), (char)((feat_tag>>16)&0xff), |
| 6573 |
(char)((feat_tag>>8)&0xff), (char)(feat_tag&0xff), |
| 6574 |
(char)((lang_tag>>24)&0xff), (char)((lang_tag>>16)&0xff), |
| 6575 |
(char)((lang_tag>>8)&0xff), (char)((lang_tag)&0xff), |
| 6576 |
(char)((script_tag>>24)&0xff), (char)((script_tag>>16)&0xff), |
| 6577 |
(char)((script_tag>>8)&0xff), (char)(script_tag&0xff) ); |
| 6578 |
} |
| 6579 |
} |
| 6580 |
|
| 6581 |
struct tagoff { uint32_t tag; uint32_t offset; }; |
| 6582 |
|
| 6583 |
static int readttfbase(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6584 |
int version; |
| 6585 |
uint32_t axes[2]; |
| 6586 |
uint32_t basetags, basescripts; |
| 6587 |
int basetagcnt, basescriptcnt; |
| 6588 |
uint32_t *tags; |
| 6589 |
struct tagoff *bs; |
| 6590 |
int axis,i,j; |
| 6591 |
|
| 6592 |
fseek(ttf,info->base_start,SEEK_SET); |
| 6593 |
printf( "\nBASE table (at %d)\n", info->base_start); |
| 6594 |
printf( "\tVersion: 0x%08x\n", (unsigned int)((version = getlong(ttf))) ); |
| 6595 |
if ( version!=0x00010000 ) |
| 6596 |
fprintf( stderr, "!> Bad version number for BASE table.\n" ); |
| 6597 |
axes[0] = getushort(ttf); |
| 6598 |
axes[1] = getushort(ttf); |
| 6599 |
|
| 6600 |
for ( axis=0; axis<2; ++axis ) { |
| 6601 |
if ( axes[axis]==0 ) { |
| 6602 |
printf("\tNO %s axis data\n", axis==0 ? "Horizontal": "Vertical" ); |
| 6603 |
continue; |
| 6604 |
} |
| 6605 |
printf("\t%s axis data\n", axis==0 ? "Horizontal": "Vertical" ); |
| 6606 |
fseek(ttf,info->base_start+axes[axis],SEEK_SET); |
| 6607 |
basetags = getushort(ttf); |
| 6608 |
basescripts = getushort(ttf); |
| 6609 |
if ( basetags==0 ) { |
| 6610 |
printf("\t NO %s base tags data\n", axis==0 ? "Horizontal": "Vertical" ); |
| 6611 |
basetagcnt = 0; |
| 6612 |
tags = NULL; |
| 6613 |
} else { |
| 6614 |
fseek(ttf,info->base_start+axes[axis]+basetags,SEEK_SET); |
| 6615 |
basetagcnt = getushort(ttf); |
| 6616 |
tags = calloc(basetagcnt,sizeof(uint32_t)); |
| 6617 |
for ( i=0; i<basetagcnt; ++i ) |
| 6618 |
tags[i] = getlong(ttf); |
| 6619 |
printf( "\t %d Baseline tags for %s\n", basetagcnt, axis==0 ? "Horizontal": "Vertical" ); |
| 6620 |
for ( i=0; i<basetagcnt; ++i ) |
| 6621 |
printf( "\t '%c%c%c%c'\n", |
| 6622 |
(char)((tags[i]>>24)&0xff), (char)((tags[i]>>16)&0xff), |
| 6623 |
(char)((tags[i]>>8)&0xff), (char)(tags[i]&0xff) ); |
| 6624 |
} |
| 6625 |
if ( basescripts==0 ) |
| 6626 |
printf("\t NO %s base script data\n", axis==0 ? "Horizontal": "Vertical" ); |
| 6627 |
else { |
| 6628 |
fseek(ttf,info->base_start+axes[axis]+basescripts,SEEK_SET); |
| 6629 |
basescriptcnt = getushort(ttf); |
| 6630 |
bs = calloc(basescriptcnt,sizeof(struct tagoff)); |
| 6631 |
for ( i=0; i<basescriptcnt; ++i ) { |
| 6632 |
bs[i].tag = getlong(ttf); |
| 6633 |
bs[i].offset = getushort(ttf); |
| 6634 |
if ( bs[i].offset != 0 ) |
| 6635 |
bs[i].offset += info->base_start+axes[axis]+basescripts; |
| 6636 |
} |
| 6637 |
for ( i=0; i<basescriptcnt; ++i ) if ( bs[i].offset!=0 ) { |
| 6638 |
int basevalues, defminmax; |
| 6639 |
int langsyscnt; |
| 6640 |
struct tagoff *ls; |
| 6641 |
printf("\t %s baseline data for '%c%c%c%c' script\n", |
| 6642 |
axis==0 ? "Horizontal": "Vertical", |
| 6643 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6644 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff) ); |
| 6645 |
fseek(ttf,bs[i].offset,SEEK_SET); |
| 6646 |
basevalues = getushort(ttf); |
| 6647 |
defminmax = getushort(ttf); |
| 6648 |
langsyscnt = getushort(ttf); |
| 6649 |
ls = calloc(langsyscnt,sizeof(struct tagoff)); |
| 6650 |
for ( j=0; j<langsyscnt; ++j ) { |
| 6651 |
ls[j].tag = getlong(ttf); |
| 6652 |
ls[j].offset = getushort(ttf); |
| 6653 |
} |
| 6654 |
if ( basevalues==0 ) |
| 6655 |
printf("\t No %s baseline positions for '%c%c%c%c' script\n", |
| 6656 |
axis==0 ? "Horizontal": "Vertical", |
| 6657 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6658 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff) ); |
| 6659 |
else { |
| 6660 |
int defbl, coordcnt; |
| 6661 |
int *coords; |
| 6662 |
|
| 6663 |
fseek( ttf,bs[i].offset+basevalues,SEEK_SET); |
| 6664 |
defbl = getushort(ttf); |
| 6665 |
coordcnt = getushort(ttf); |
| 6666 |
printf("\t The default baseline for '%c%c%c%c' script is '%c%c%c%c'\n", |
| 6667 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6668 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff), |
| 6669 |
(char)((tags[defbl]>>24)&0xff), (char)((tags[defbl]>>16)&0xff), |
| 6670 |
(char)((tags[defbl]>>8)&0xff), (char)(tags[defbl]&0xff) ); |
| 6671 |
if ( coordcnt!=basetagcnt ) |
| 6672 |
fprintf( stderr, "!!!!! Coord count (%d) for '%c%c%c%c' script does not match base tag count (%d) in 'BASE' table\n", |
| 6673 |
coordcnt, |
| 6674 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6675 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff), |
| 6676 |
basetagcnt ); |
| 6677 |
coords = calloc(coordcnt,sizeof(int)); |
| 6678 |
for ( j=0; j<coordcnt; ++j ) |
| 6679 |
coords[j] = getushort(ttf); |
| 6680 |
for ( j=0; j<coordcnt; ++j ) if ( coords[j]!=0 ) { |
| 6681 |
int format, coord, gid, pt; |
| 6682 |
fseek( ttf,bs[i].offset+basevalues+coords[j],SEEK_SET); |
| 6683 |
format = getushort(ttf); |
| 6684 |
coord = (short) getushort(ttf); |
| 6685 |
if ( format==3 ) { |
| 6686 |
getushort(ttf); |
| 6687 |
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d, with device table\n", |
| 6688 |
(char)((tags[j]>>24)&0xff), (char)((tags[j]>>16)&0xff), |
| 6689 |
(char)((tags[j]>>8)&0xff), (char)(tags[j]&0xff), |
| 6690 |
(char)((bs[j].tag>>24)&0xff), (char)((bs[j].tag>>16)&0xff), |
| 6691 |
(char)((bs[j].tag>>8)&0xff), (char)(bs[j].tag&0xff), |
| 6692 |
coord ); |
| 6693 |
} else if ( format==2 ) { |
| 6694 |
gid = getushort(ttf); |
| 6695 |
pt = getushort(ttf); |
| 6696 |
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d, modified by point %d in glyph %d\n", |
| 6697 |
(char)((tags[j]>>24)&0xff), (char)((tags[j]>>16)&0xff), |
| 6698 |
(char)((tags[j]>>8)&0xff), (char)(tags[j]&0xff), |
| 6699 |
(char)((bs[j].tag>>24)&0xff), (char)((bs[j].tag>>16)&0xff), |
| 6700 |
(char)((bs[j].tag>>8)&0xff), (char)(bs[j].tag&0xff), |
| 6701 |
coord, pt, gid ); |
| 6702 |
} else { |
| 6703 |
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d\n", |
| 6704 |
(char)((tags[j]>>24)&0xff), (char)((tags[j]>>16)&0xff), |
| 6705 |
(char)((tags[j]>>8)&0xff), (char)(tags[j]&0xff), |
| 6706 |
(char)((bs[j].tag>>24)&0xff), (char)((bs[j].tag>>16)&0xff), |
| 6707 |
(char)((bs[j].tag>>8)&0xff), (char)(bs[j].tag&0xff), |
| 6708 |
coord ); |
| 6709 |
if ( format!=1 ) |
| 6710 |
fprintf( stderr, "!!!!! Bad Base Coord format (%d) for '%c%c%c%c' in '%c%c%c%c' script in 'BASE' table\n", |
| 6711 |
format, |
| 6712 |
(char)((tags[j]>>24)&0xff), (char)((tags[j]>>16)&0xff), |
| 6713 |
(char)((tags[j]>>8)&0xff), (char)(tags[j]&0xff), |
| 6714 |
(char)((bs[j].tag>>24)&0xff), (char)((bs[j].tag>>16)&0xff), |
| 6715 |
(char)((bs[j].tag>>8)&0xff), (char)(bs[j].tag&0xff) ); |
| 6716 |
} |
| 6717 |
} |
| 6718 |
free(coords); |
| 6719 |
} |
| 6720 |
if ( defminmax==0 ) |
| 6721 |
printf("\t No %s min/max extents for '%c%c%c%c' script\n", |
| 6722 |
axis==0 ? "Horizontal": "Vertical", |
| 6723 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6724 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff) ); |
| 6725 |
else |
| 6726 |
readttfbaseminmax(ttf,bs[i].offset+defminmax,info,bs[i].tag,0); |
| 6727 |
if ( langsyscnt==0 ) |
| 6728 |
printf("\t No %s min/max extents for specific langs in '%c%c%c%c' script\n", |
| 6729 |
axis==0 ? "Horizontal": "Vertical", |
| 6730 |
(char)((bs[i].tag>>24)&0xff), (char)((bs[i].tag>>16)&0xff), |
| 6731 |
(char)((bs[i].tag>>8)&0xff), (char)(bs[i].tag&0xff) ); |
| 6732 |
else |
| 6733 |
for ( j=0; j<langsyscnt; ++j ) if ( ls[j].offset!=0 ) |
| 6734 |
readttfbaseminmax(ttf,bs[i].offset+ls[j].offset,info,bs[i].tag,ls[j].tag); |
| 6735 |
free(ls); |
| 6736 |
} |
| 6737 |
free(bs); |
| 6738 |
} |
| 6739 |
free(tags); |
| 6740 |
} |
| 6741 |
return( 1 ); |
| 6742 |
} |
| 6743 |
|
| 6744 |
static void readttfjustmax(const char *label,FILE *ttf,int base,int offset, struct ttfinfo *info) { |
| 6745 |
int lcnt,i; |
| 6746 |
int *offsets; |
| 6747 |
|
| 6748 |
if ( offset==0 ) { |
| 6749 |
printf( "\t No %s data\n", label ); |
| 6750 |
return; |
| 6751 |
} |
| 6752 |
base += offset; |
| 6753 |
fseek(ttf,base,SEEK_SET); |
| 6754 |
lcnt = getushort(ttf); |
| 6755 |
offsets = malloc(lcnt*sizeof(int)); |
| 6756 |
printf( "\t %d lookup%s for %s\n", lcnt, lcnt==1? "" : "s", label ); |
| 6757 |
for ( i=0; i<lcnt; ++i ) |
| 6758 |
printf( "\t\tOffset to lookup %d\n", offsets[i] = getushort(ttf)); |
| 6759 |
for ( i=0; i<lcnt; ++i ) |
| 6760 |
showgpossublookup(ttf,base, offsets[i], info, true); |
| 6761 |
free(offsets); |
| 6762 |
} |
| 6763 |
|
| 6764 |
static void readttfjustlookups(const char *label,FILE *ttf,int base,int offset) { |
| 6765 |
int lcnt,i; |
| 6766 |
|
| 6767 |
if ( offset==0 ) { |
| 6768 |
printf( "\t No %s data\n", label ); |
| 6769 |
return; |
| 6770 |
} |
| 6771 |
base += offset; |
| 6772 |
fseek(ttf,base,SEEK_SET); |
| 6773 |
lcnt = getushort(ttf); |
| 6774 |
printf( "\t %d lookup%s for %s\n", lcnt, lcnt==1? "" : "s", label ); |
| 6775 |
for ( i=0; i<lcnt; ++i ) |
| 6776 |
printf( "\t\tLookup %d\n", getushort(ttf)); |
| 6777 |
} |
| 6778 |
|
| 6779 |
static void readttfjustlangsys(FILE *ttf,int offset,uint32_t stag, uint32_t ltag, struct ttfinfo *info) { |
| 6780 |
int pcnt,j; |
| 6781 |
int *offsets; |
| 6782 |
int shrinkenablesub, shrinkenablepos, shrinkdisablesub, shrinkdisablepos; |
| 6783 |
int extendenablesub, extendenablepos, extenddisablesub, extenddisablepos; |
| 6784 |
int shrinkmax, extendmax; |
| 6785 |
|
| 6786 |
fseek(ttf,offset,SEEK_SET); |
| 6787 |
printf("\t Justification priority data for '%c%c%c%c' script, '%c%c%c%c' lang.\n", |
| 6788 |
(char)((stag>>24)&0xff), (char)((stag>>16)&0xff), |
| 6789 |
(char)((stag>>8)&0xff), (char)(stag&0xff), |
| 6790 |
(char)((ltag>>24)&0xff), (char)((ltag>>16)&0xff), |
| 6791 |
(char)((ltag>>8)&0xff), (char)(ltag&0xff) ); |
| 6792 |
pcnt = getushort(ttf); |
| 6793 |
offsets = malloc(pcnt*sizeof(int)); |
| 6794 |
for ( j=0; j<pcnt; ++j ) |
| 6795 |
offsets[j] = getushort(ttf); |
| 6796 |
printf( "\t %d Priority level%s\n", pcnt, pcnt==1 ? "" : "s" ); |
| 6797 |
for ( j=0; j<pcnt; ++j ) { |
| 6798 |
if ( offsets[j]==0 ) { |
| 6799 |
printf( "\t No data for priority level %d\n", j ); |
| 6800 |
continue; |
| 6801 |
} |
| 6802 |
printf( "\t Priority level %d\n", j ); |
| 6803 |
fseek(ttf,offset+offsets[j],SEEK_SET); |
| 6804 |
shrinkenablesub = getushort(ttf); |
| 6805 |
shrinkdisablesub = getushort(ttf); |
| 6806 |
shrinkenablepos = getushort(ttf); |
| 6807 |
shrinkdisablepos = getushort(ttf); |
| 6808 |
shrinkmax = getushort(ttf); |
| 6809 |
extendenablesub = getushort(ttf); |
| 6810 |
extenddisablesub = getushort(ttf); |
| 6811 |
extendenablepos = getushort(ttf); |
| 6812 |
extenddisablepos = getushort(ttf); |
| 6813 |
extendmax = getushort(ttf); |
| 6814 |
readttfjustlookups("ShrinkageEnableGSUB",ttf,offset+offsets[j],shrinkenablesub); |
| 6815 |
readttfjustlookups("ShrinkageDisableGSUB",ttf,offset+offsets[j],shrinkdisablesub); |
| 6816 |
readttfjustlookups("ShrinkageEnableGPOS",ttf,offset+offsets[j],shrinkenablepos); |
| 6817 |
readttfjustlookups("ShrinkageDisableGPOS",ttf,offset+offsets[j],shrinkdisablepos); |
| 6818 |
readttfjustmax("ShrinkageMax",ttf,offset+offsets[j],shrinkmax,info); |
| 6819 |
readttfjustlookups("ExtensionEnableGSUB",ttf,offset+offsets[j],extendenablesub); |
| 6820 |
readttfjustlookups("ExtensionDisableGSUB",ttf,offset+offsets[j],extenddisablesub); |
| 6821 |
readttfjustlookups("ExtensionEnableGPOS",ttf,offset+offsets[j],extendenablepos); |
| 6822 |
readttfjustlookups("ExtensionDisableGPOS",ttf,offset+offsets[j],extenddisablepos); |
| 6823 |
readttfjustmax("ExtensionMax",ttf,offset+offsets[j],extendmax,info); |
| 6824 |
} |
| 6825 |
free(offsets); |
| 6826 |
} |
| 6827 |
|
| 6828 |
static void readttfjstf(FILE *ttf,FILE *util, struct ttfinfo *info) { |
| 6829 |
int version; |
| 6830 |
int i,j,cnt, lcnt, lmax=0; |
| 6831 |
struct tagoff *scripts, *langs=NULL; |
| 6832 |
int extenderOff, defOff; |
| 6833 |
|
| 6834 |
fseek(ttf,info->JSTF_start,SEEK_SET); |
| 6835 |
printf( "\nJSTF table (at %d)\n", info->JSTF_start); |
| 6836 |
printf( "\tVersion: 0x%08x\n", (unsigned int)(version = getlong(ttf)) ); |
| 6837 |
if ( version!=0x00010000 ) |
| 6838 |
fprintf( stderr, "!> Bad version number for BASE table.\n" ); |
| 6839 |
cnt = getushort(ttf); |
| 6840 |
printf( "\t %d scripts\n", cnt ); |
| 6841 |
scripts = malloc(cnt*sizeof(struct tagoff)); |
| 6842 |
for ( i=0; i<cnt; ++i ) { |
| 6843 |
scripts[i].tag = getlong(ttf); |
| 6844 |
scripts[i].offset = getushort(ttf); |
| 6845 |
} |
| 6846 |
|
| 6847 |
for ( i=0; i<cnt; ++i ) { |
| 6848 |
printf("\t Justification data for '%c%c%c%c' script\n", \ |
| 6849 |
(char)(scripts[i].tag>>24), (char)(scripts[i].tag>>16), \ |
| 6850 |
(char)(scripts[i].tag>>8), (char)(scripts[i].tag) ); |
| 6851 |
if ( scripts[i].offset==0 ) { |
| 6852 |
printf("\t Nothing for this script\n" ); |
| 6853 |
continue; |
| 6854 |
} |
| 6855 |
fseek(ttf,info->JSTF_start+scripts[i].offset,SEEK_SET); |
| 6856 |
extenderOff = getushort(ttf); |
| 6857 |
defOff = getushort(ttf); |
| 6858 |
lcnt = getushort(ttf); |
| 6859 |
if ( lcnt>lmax ) |
| 6860 |
langs = realloc(langs,(lmax = lcnt+20)*sizeof(struct tagoff)); |
| 6861 |
for ( j=0; j<lcnt; ++j ) { |
| 6862 |
langs[j].tag = getlong(ttf); |
| 6863 |
langs[j].offset = getushort(ttf); |
| 6864 |
} |
| 6865 |
if ( extenderOff==0 ) |
| 6866 |
printf( "\t No extension glyphs.\n" ); |
| 6867 |
else { |
| 6868 |
int gcnt; |
| 6869 |
fseek(ttf,info->JSTF_start+scripts[i].offset+extenderOff,SEEK_SET); |
| 6870 |
gcnt = getushort(ttf); |
| 6871 |
printf( "\t %d extension glyph%s.\n", gcnt, gcnt==1?"":"s" ); |
| 6872 |
for ( j=0; j<gcnt; ++j ) { |
| 6873 |
int gid = getushort(ttf); |
| 6874 |
printf( "\t Extension Glyph %d (%s)\n", gid, |
| 6875 |
gid>=info->glyph_cnt ? "!!! Bad glyph !!!" : |
| 6876 |
info->glyph_names == NULL ? "" : info->glyph_names[gid]); |
| 6877 |
} |
| 6878 |
} |
| 6879 |
if ( defOff==0 ) |
| 6880 |
printf( "\t No default just language system table\n" ); |
| 6881 |
else |
| 6882 |
readttfjustlangsys(ttf,info->JSTF_start+scripts[i].offset+defOff, |
| 6883 |
scripts[i].tag, CHR('d','f','l','t'),info); |
| 6884 |
printf( "\t %d langsys table%s.\n", lcnt, lcnt==1?"":"s" ); |
| 6885 |
for ( j=0; j<lcnt; ++j ) { |
| 6886 |
readttfjustlangsys(ttf,info->JSTF_start+scripts[i].offset+langs[j].offset, |
| 6887 |
scripts[i].tag, langs[j].tag,info); |
| 6888 |
} |
| 6889 |
} |
| 6890 |
free( langs ); |
| 6891 |
free( scripts ); |
| 6892 |
} |
| 6893 |
|
| 6894 |
|
| 6895 |
static void readit(FILE *ttf, FILE *util) { |
| 6896 |
struct ttfinfo info; |
| 6897 |
int i, pos; |
| 6898 |
|
| 6899 |
memset(&info,'\0',sizeof(info)); |
| 6900 |
readttfheader(ttf,util,&info); |
| 6901 |
if ( info.ttccnt!=0 ) { |
| 6902 |
for ( i=0; i<info.ttccnt; ++i ) { |
| 6903 |
printf( "\n=============================> TTC font %d\n", i ); |
| 6904 |
fseek(ttf,info.ttcoffsets[i],SEEK_SET); |
| 6905 |
readit(ttf,util); |
| 6906 |
} |
| 6907 |
return; |
| 6908 |
} |
| 6909 |
if ( just_headers ) |
| 6910 |
return; |
| 6911 |
if ( head_check ) { |
| 6912 |
if ( info.head_start!=0 ) |
| 6913 |
readttfhead(ttf,util,&info); |
| 6914 |
return; |
| 6915 |
} |
| 6916 |
|
| 6917 |
if ( info.fftm_start!=0 ) |
| 6918 |
readttfFFTM(ttf,util,&info); |
| 6919 |
if ( info.head_start!=0 ) |
| 6920 |
readttfhead(ttf,util,&info); |
| 6921 |
if ( info.hhea_start!=0 ) |
| 6922 |
readttfhhead(ttf,util,&info); |
| 6923 |
if ( info.copyright_start!=0 ) |
| 6924 |
readttfname(ttf,util,&info); |
| 6925 |
if ( info.os2_start!=0 ) |
| 6926 |
readttfos2(ttf,util,&info); |
| 6927 |
if ( info.maxp_start!=0 ) |
| 6928 |
readttfmaxp(ttf,util,&info); |
| 6929 |
if ( info.gasp_start!=0 ) |
| 6930 |
readttfgasp(ttf,util,&info); |
| 6931 |
if ( info.encoding_start!=0 ) |
| 6932 |
readttfencodings(ttf,util,&info); |
| 6933 |
if ( info.postscript_len!= 0 ) |
| 6934 |
readttfpost(ttf,util,&info); |
| 6935 |
if ( info.cvt_length!=0 ) |
| 6936 |
readttfcvt(ttf,util,&info); |
| 6937 |
if ( info.cff_start!=0 ) |
| 6938 |
readcff(ttf,util,&info); |
| 6939 |
if ( info.gsub_start!=0 ) |
| 6940 |
readttfgsub(ttf,util,&info); |
| 6941 |
if ( info.gpos_start!=0 ) |
| 6942 |
readttfgpos(ttf,util,&info); |
| 6943 |
if ( info.kern_start!=0 ) |
| 6944 |
readttfkern(ttf,util,&info); |
| 6945 |
if ( info.gdef_start!=0 ) |
| 6946 |
readttfgdef(ttf,util,&info); |
| 6947 |
if ( info.base_start!=0 ) |
| 6948 |
readttfbase(ttf,util,&info); |
| 6949 |
if ( info.JSTF_start!=0 ) |
| 6950 |
readttfjstf(ttf,util,&info); |
| 6951 |
if ( info.bitmaploc_start!=0 && info.bitmapdata_start!=0 ) |
| 6952 |
readttfbitmaps(ttf,util,&info); |
| 6953 |
if ( info.bitmapscale_start!=0 ) |
| 6954 |
readttfbitmapscale(ttf,util,&info); |
| 6955 |
if ( info.prep_length!=0 ) |
| 6956 |
readtableinstr(ttf,info.prep_start,info.prep_length,"prep"); |
| 6957 |
if ( info.fpgm_length!=0 ) |
| 6958 |
readtableinstr(ttf,info.fpgm_start,info.fpgm_length,"fpgm"); |
| 6959 |
if ( info.fdsc_start!=0 ) |
| 6960 |
readttffontdescription(ttf,util,&info); |
| 6961 |
if ( info.feat_start!=0 ) |
| 6962 |
readttffeatures(ttf,util,&info); |
| 6963 |
if ( info.mort_start!=0 || info.morx_start!=0 ) |
| 6964 |
readttfmetamorph(ttf,util,&info); |
| 6965 |
if ( info.prop_start!=0 ) |
| 6966 |
readttfappleprop(ttf,util,&info); |
| 6967 |
if ( info.lcar_start!=0 ) |
| 6968 |
readttfapplelcar(ttf,util,&info); |
| 6969 |
if ( info.opbd_start!=0 ) |
| 6970 |
readttfappleopbd(ttf,util,&info); |
| 6971 |
if ( info.fvar_start!=0 ) |
| 6972 |
readttfapplefvar(ttf,util,&info); |
| 6973 |
if ( info.gvar_start!=0 ) |
| 6974 |
readttfapplegvar(ttf,util,&info); |
| 6975 |
if ( info.hdmx_start!=0 ) |
| 6976 |
readttfhdmx(ttf,util,&info); |
| 6977 |
if ( info.math_start!=0 ) |
| 6978 |
readttfmath(ttf,util,&info); |
| 6979 |
if ( info.glyphlocations_start!=0 ) { |
| 6980 |
fseek(ttf,info.glyphlocations_start,SEEK_SET); |
| 6981 |
if ( info.index_to_loc_is_long ) { |
| 6982 |
for ( i=0; 4*i<info.loca_length; ++i ) { |
| 6983 |
pos = getlong(ttf); |
| 6984 |
if ( pos&3 ) |
| 6985 |
fprintf( stderr, "Not aligned GID=%d, pos=0x%x\n", i, (unsigned int)(pos)); |
| 6986 |
} |
| 6987 |
} else { |
| 6988 |
for ( i=0; 2*i<info.loca_length; ++i ) { |
| 6989 |
pos = getushort(ttf); |
| 6990 |
if ( pos&1 ) |
| 6991 |
fprintf( stderr, "Not aligned GID=%d, pos=0x%x\n", i, (unsigned int)(pos<<1) ); |
| 6992 |
} |
| 6993 |
} |
| 6994 |
} |
| 6995 |
} |
| 6996 |
|
| 6997 |
int main(int argc, char **argv) { |
| 6998 |
FILE *ttf, *util; |
| 6999 |
char *filename = NULL; |
| 7000 |
int i; |
| 7001 |
char *pt; |
| 7002 |
|
| 7003 |
for ( i=1; i<argc; ++i ) { |
| 7004 |
if ( *argv[i]=='-' ) { |
| 7005 |
pt = argv[i]+1; |
| 7006 |
if ( *pt=='-' ) ++pt; |
| 7007 |
if ( strcmp(pt,"v")==0 || strcmp(pt,"verbose")==0 ) |
| 7008 |
verbose = true; |
| 7009 |
else if ( strcmp(pt,"h")==0 || strcmp(pt,"headers")==0 ) |
| 7010 |
just_headers = true; |
| 7011 |
else if ( strcmp(pt,"c")==0 || strcmp(pt,"checkhead")==0 ) |
| 7012 |
head_check = true; |
| 7013 |
else { |
| 7014 |
fprintf( stderr, "%s [-verbose] ttf-file\n", argv[0]); |
| 7015 |
exit(1); |
| 7016 |
} |
| 7017 |
} else { |
| 7018 |
if ( filename!=NULL ) |
| 7019 |
printf( "\n\n\n******************** %s *****************\n\n\n", argv[i]); |
| 7020 |
filename = argv[i]; |
| 7021 |
ttf = fopen(filename,"rb"); |
| 7022 |
if ( ttf==NULL ) { |
| 7023 |
fprintf( stderr, "Can't open %s\n", argv[1]); |
| 7024 |
return( 1 ); |
| 7025 |
} |
| 7026 |
util = fopen(filename,"rb"); |
| 7027 |
|
| 7028 |
readit(ttf,util); |
| 7029 |
fclose(ttf); |
| 7030 |
fclose(util); |
| 7031 |
} |
| 7032 |
} |
| 7033 |
if ( filename==NULL ) { |
| 7034 |
fprintf( stderr, "%s [-verbose] [-headers] ttf-file\n", argv[0]); |
| 7035 |
exit(1); |
| 7036 |
} |
| 7037 |
return( 0 ); |
| 7038 |
} |