Clean up the SFNT_Interface. In this pass, we want to treat the font directory (offset table and table directory) as a normal table like the others. This also means that TTC is no longer recognized there, but in `init_face'. * include/freetype/internal/sfnt.h (SFNT_Interface), src/sfnt/sfdriver.c: `load_sfnt_header' and `load_directory' are combined and renamed to `load_font_dir'. * src/sfnt/ttload.h, src/sfnt/ttload.c: s/sfnt_dir_check/check_table_dir/. `sfnt_init' is moved to sfobjs.c and renamed to `sfnt_open_font'. `tt_face_load_sfnt_header' and `tt_face_load_directory' are combined and renamed to `tt_face_load_font_dir'. * src/sfnt/sfobjs.c (sfnt_init_face): Recognize TTC here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
diff --git a/ChangeLog b/ChangeLog
index 3f5877f..12a5460 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2006-02-13 Chia-I Wu <b90201047@ntu.edu.tw>
+ Clean up the SFNT_Interface. In this pass, we want to treat the font
+ directory (offset table and table directory) as a normal table like
+ the others. This also means that TTC is no longer recognized there,
+ but in `init_face'.
+
+ * include/freetype/internal/sfnt.h (SFNT_Interface),
+ src/sfnt/sfdriver.c: `load_sfnt_header' and `load_directory' are
+ combined and renamed to `load_font_dir'.
+
+ * src/sfnt/ttload.h, src/sfnt/ttload.c:
+ s/sfnt_dir_check/check_table_dir/.
+ `sfnt_init' is moved to sfobjs.c and renamed to `sfnt_open_font'.
+ `tt_face_load_sfnt_header' and `tt_face_load_directory' are combined
+ and renamed to `tt_face_load_font_dir'.
+
+ * src/sfnt/sfobjs.c (sfnt_init_face): Recognize TTC here.
+
+2006-02-13 Chia-I Wu <b90201047@ntu.edu.tw>
+
Clean up the SFNT_Interface. Table loading functions are now named
after the tables' tags; `hdmx' is TrueType-specific and thus the code
is moved to the truetype module; `get_metrics' is moved here from the
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index 5753a06..4d54fb3 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -128,73 +128,6 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <FuncType> */
- /* TT_Load_SFNT_HeaderRec_Func */
- /* */
- /* <Description> */
- /* Load the header of a SFNT font file. Supports collections. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* */
- /* stream :: The input stream. */
- /* */
- /* face_index :: The index of the TrueType font, if we are opening a */
- /* collection. */
- /* */
- /* <Output> */
- /* sfnt :: The SFNT header. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <Note> */
- /* The stream cursor must be at the font file's origin. */
- /* */
- /* This function recognizes fonts embedded in a `TrueType */
- /* collection'. */
- /* */
- /* This function checks that the header is valid by looking at the */
- /* values of `search_range', `entry_selector', and `range_shift'. */
- /* */
- typedef FT_Error
- (*TT_Load_SFNT_HeaderRec_Func)( TT_Face face,
- FT_Stream stream,
- FT_Long face_index,
- SFNT_Header sfnt );
-
-
- /*************************************************************************/
- /* */
- /* <FuncType> */
- /* TT_Load_Directory_Func */
- /* */
- /* <Description> */
- /* Load the table directory into a face object. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* */
- /* stream :: The input stream. */
- /* */
- /* sfnt :: The SFNT header. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <Note> */
- /* The stream cursor must be on the first byte after the 4-byte font */
- /* format tag. This is the case just after a call to */
- /* TT_Load_Format_Tag(). */
- /* */
- typedef FT_Error
- (*TT_Load_Directory_Func)( TT_Face face,
- FT_Stream stream,
- SFNT_Header sfnt );
-
-
- /*************************************************************************/
- /* */
- /* <FuncType> */
/* TT_Load_Any_Func */
/* */
/* <Description> */
@@ -505,7 +438,7 @@ FT_BEGIN_HEADER
/* */
/* <Note> */
/* The function will use `face->goto_table' to seek the stream to */
- /* the start of the table. */
+ /* the start of the table, except in loading font directory. */
/* */
typedef FT_Error
(*TT_Load_Table_Func)( TT_Face face,
@@ -570,8 +503,10 @@ FT_BEGIN_HEADER
FT_Module_Requester get_interface;
TT_Load_Any_Func load_any;
- TT_Load_SFNT_HeaderRec_Func load_sfnt_header;
- TT_Load_Directory_Func load_directory;
+
+ /* load the font directory, i.e. the offset table and */
+ /* the table directory */
+ TT_Load_Table_Func load_font_dir;
/* these functions are called by `load_face' but they can also */
/* be called from external modules, if there is a need to do so */
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index a43ac01..f451950 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -386,8 +386,7 @@
sfnt_get_interface,
tt_face_load_any,
- tt_face_load_sfnt_header,
- tt_face_load_directory,
+ tt_face_load_font_dir,
tt_face_load_head,
tt_face_load_hhea,
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index da466ae..e16cc94 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -345,6 +345,85 @@
}
+ /* Fill in face->ttc_header. If the font is not a TTC, it is */
+ /* synthesized into a TTC with one offset table. */
+ static FT_Error
+ sfnt_open_font( FT_Stream stream,
+ TT_Face face )
+ {
+ FT_Memory memory = stream->memory;
+ FT_Error error;
+ FT_ULong tag, offset;
+
+ static const FT_Frame_Field ttc_header_fields[] =
+ {
+#undef FT_STRUCTURE
+#define FT_STRUCTURE TTC_HeaderRec
+
+ FT_FRAME_START( 8 ),
+ FT_FRAME_LONG( version ),
+ FT_FRAME_LONG( count ),
+ FT_FRAME_END
+ };
+
+
+ face->ttc_header.tag = 0;
+ face->ttc_header.version = 0;
+ face->ttc_header.count = 0;
+
+ offset = FT_STREAM_POS();
+
+ if ( FT_READ_ULONG( tag ) )
+ return error;
+
+ if ( tag != 0x00010000UL &&
+ tag != TTAG_ttcf &&
+ tag != FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) &&
+ tag != TTAG_true &&
+ tag != 0x00020000UL )
+ return SFNT_Err_Unknown_File_Format;
+
+ face->ttc_header.tag = TTAG_ttcf;
+
+ if ( tag == TTAG_ttcf )
+ {
+ FT_Int n;
+
+
+ FT_TRACE3(( "sfnt_open_font: file is a collection\n" ));
+
+ if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) )
+ return error;
+
+ /* now read the offsets of each font in the file */
+ if ( FT_NEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) )
+ return error;
+
+ if ( FT_FRAME_ENTER( face->ttc_header.count * 4L ) )
+ return error;
+
+ for ( n = 0; n < face->ttc_header.count; n++ )
+ face->ttc_header.offsets[n] = FT_GET_ULONG();
+
+ FT_FRAME_EXIT();
+ }
+ else
+ {
+ FT_TRACE3(( "sfnt_open_font: synthesize TTC\n" ));
+
+ face->ttc_header.version = 1 << 16;
+ face->ttc_header.count = 1;
+
+ if ( FT_NEW( face->ttc_header.offsets) )
+ return error;
+
+ face->ttc_header.offsets[0] = offset;
+ }
+
+ return error;
+ }
+
+
FT_LOCAL_DEF( FT_Error )
sfnt_init_face( FT_Stream stream,
TT_Face face,
@@ -355,7 +434,7 @@
FT_Error error;
FT_Library library = face->root.driver->root.library;
SFNT_Service sfnt;
- SFNT_HeaderRec sfnt_header;
+
/* for now, parameters are unused */
FT_UNUSED( num_params );
@@ -367,10 +446,7 @@
{
sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
if ( !sfnt )
- {
- error = SFNT_Err_Invalid_File_Format;
- goto Exit;
- }
+ return SFNT_Err_Invalid_File_Format;
face->sfnt = sfnt;
face->goto_table = sfnt->goto_table;
@@ -378,24 +454,28 @@
FT_FACE_FIND_GLOBAL_SERVICE( face, face->psnames, POSTSCRIPT_CMAPS );
- /* check that we have a valid TrueType file */
- error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header );
+ error = sfnt_open_font( stream, face );
if ( error )
- goto Exit;
+ return error;
+
+ FT_TRACE2(( "sfnt_init_face: %08p, %ld\n", face, face_index ));
- face->format_tag = sfnt_header.format_tag;
- face->num_tables = sfnt_header.num_tables;
+ if ( face_index < 0 )
+ face_index = 0;
- /* Load font directory */
- error = sfnt->load_directory( face, stream, &sfnt_header );
+ if ( face_index >= face->ttc_header.count )
+ return SFNT_Err_Bad_Argument;
+
+ if ( FT_STREAM_SEEK( face->ttc_header.offsets[face_index] ) )
+ return error;
+
+ /* check that we have a valid TrueType file */
+ error = sfnt->load_font_dir( face, stream );
if ( error )
- goto Exit;
+ return error;
face->root.num_faces = face->ttc_header.count;
- if ( face->root.num_faces < 1 )
- face->root.num_faces = 1;
- Exit:
return error;
}
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 9877b9e..adfb0b9 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -145,8 +145,8 @@
/* Type 42 fonts, and which are generally invalid. */
/* */
static FT_Error
- sfnt_dir_check( SFNT_Header sfnt,
- FT_Stream stream )
+ check_table_dir( SFNT_Header sfnt,
+ FT_Stream stream )
{
FT_Error error;
FT_UInt nn;
@@ -156,7 +156,7 @@
const FT_ULong glyx_tag = FT_MAKE_TAG( 'g', 'l', 'y', 'x' );
const FT_ULong locx_tag = FT_MAKE_TAG( 'l', 'o', 'c', 'x' );
- static const FT_Frame_Field sfnt_dir_entry_fields[] =
+ static const FT_Frame_Field table_dir_entry_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_TableRec
@@ -182,7 +182,7 @@
TT_TableRec table;
- if ( FT_STREAM_READ_FIELDS( sfnt_dir_entry_fields, &table ) )
+ if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields, &table ) )
return error;
if ( table.Offset + table.Length > stream->size &&
@@ -194,6 +194,7 @@
{
FT_UInt32 magic;
+
#ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
if ( table.Tag == TTAG_head )
#endif
@@ -235,101 +236,19 @@
}
- /* Fill in face->ttc_header. If the font is not a TTC, it is */
- /* synthesized into a TTC with one offset table. */
- static FT_Error
- sfnt_init( FT_Stream stream,
- TT_Face face )
- {
- FT_Memory memory = stream->memory;
- FT_Error error;
- FT_ULong tag, offset;
-
- static const FT_Frame_Field ttc_header_fields[] =
- {
-#undef FT_STRUCTURE
-#define FT_STRUCTURE TTC_HeaderRec
-
- FT_FRAME_START( 8 ),
- FT_FRAME_LONG( version ),
- FT_FRAME_LONG( count ),
- FT_FRAME_END
- };
-
-
- face->ttc_header.tag = 0;
- face->ttc_header.version = 0;
- face->ttc_header.count = 0;
-
- offset = FT_STREAM_POS();
-
- if ( FT_READ_ULONG( tag ) )
- return error;
-
- if ( tag != 0x00010000UL &&
- tag != TTAG_ttcf &&
- tag != FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) &&
- tag != TTAG_true &&
- tag != 0x00020000UL )
- return SFNT_Err_Unknown_File_Format;
-
- face->ttc_header.tag = TTAG_ttcf;
-
- if ( tag == TTAG_ttcf )
- {
- FT_Int n;
-
-
- FT_TRACE3(( "sfnt_init: file is a collection\n" ));
-
- if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) )
- return error;
-
- /* now read the offsets of each font in the file */
- if ( FT_NEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) )
- return error;
-
- if ( FT_FRAME_ENTER( face->ttc_header.count * 4L ) )
- return error;
-
- for ( n = 0; n < face->ttc_header.count; n++ )
- face->ttc_header.offsets[n] = FT_GET_ULONG();
-
- FT_FRAME_EXIT();
- }
- else
- {
- FT_TRACE3(( "sfnt_init: synthesize TTC\n" ));
-
- face->ttc_header.version = 1 << 16;
- face->ttc_header.count = 1;
-
- if ( FT_NEW( face->ttc_header.offsets) )
- return error;
-
- face->ttc_header.offsets[0] = offset;
- }
-
- return error;
- }
-
-
/*************************************************************************/
/* */
/* <Function> */
- /* tt_face_load_sfnt_header */
+ /* tt_face_load_font_dir */
/* */
/* <Description> */
- /* Loads the header of a SFNT font file. Supports collections. */
+ /* Loads the header of a SFNT font file. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
- /* face_index :: If the font is a collection, the number of the font */
- /* in the collection. Must be zero otherwise. */
- /* */
/* <Output> */
/* sfnt :: The SFNT header. */
/* */
@@ -337,22 +256,19 @@
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
- /* The stream cursor must be at the font file's origin. */
- /* */
- /* This function recognizes fonts embedded in a `TrueType collection' */
- /* */
- /* The header will be checked whether it is valid by looking at the */
- /* values of `search_range', `entry_selector', and `range_shift'. */
+ /* The stream cursor must be at the beginning of the font directory. */
/* */
FT_LOCAL_DEF( FT_Error )
- tt_face_load_sfnt_header( TT_Face face,
- FT_Stream stream,
- FT_Long face_index,
- SFNT_Header sfnt )
+ tt_face_load_font_dir( TT_Face face,
+ FT_Stream stream )
{
- FT_Error error;
+ SFNT_HeaderRec sfnt;
+ FT_Error error;
+ FT_Memory memory = stream->memory;
+ TT_TableRec* entry;
+ TT_TableRec* limit;
- static const FT_Frame_Field sfnt_header_fields[] =
+ static const FT_Frame_Field offset_table_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE SFNT_HeaderRec
@@ -366,101 +282,52 @@
};
- FT_TRACE2(( "tt_face_load_sfnt_header: %08p, %ld\n",
- face, face_index ));
-
- error = sfnt_init( stream, face );
- if ( error )
- return error;
-
- if ( face_index < 0 )
- face_index = 0;
-
- if ( face_index >= face->ttc_header.count )
- return SFNT_Err_Bad_Argument;
+ FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face ));
- sfnt->offset = face->ttc_header.offsets[face_index];
+ /* read the offset table */
- if ( FT_STREAM_SEEK( sfnt->offset ) )
- return error;
+ sfnt.offset = FT_STREAM_POS();
- /* read offset table */
- if ( FT_READ_ULONG( sfnt->format_tag ) ||
- FT_STREAM_READ_FIELDS( sfnt_header_fields, sfnt ) )
+ if ( FT_READ_ULONG( sfnt.format_tag ) ||
+ FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) )
return error;
/* many fonts don't have these fields set correctly */
#if 0
- if ( sfnt->search_range != 1 << ( sfnt->entry_selector + 4 ) ||
- sfnt->search_range + sfnt->range_shift != sfnt->num_tables << 4 )
+ if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 ) ||
+ sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 )
return SFNT_Err_Unknown_File_Format;
#endif
- return error;
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* tt_face_load_directory */
- /* */
- /* <Description> */
- /* Loads the table directory into a face object. */
- /* */
- /* <InOut> */
- /* face :: A handle to the target face object. */
- /* */
- /* <Input> */
- /* stream :: The input stream. */
- /* */
- /* sfnt :: The SFNT directory header. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <Note> */
- /* The stream cursor must be at the font file's origin. */
- /* */
- FT_LOCAL_DEF( FT_Error )
- tt_face_load_directory( TT_Face face,
- FT_Stream stream,
- SFNT_Header sfnt )
- {
- FT_Error error;
- FT_Memory memory = stream->memory;
-
- TT_TableRec *entry, *limit;
+ /* load the table directory */
-
- FT_TRACE2(( "tt_face_load_directory: %08p\n", face ));
-
- FT_TRACE2(( "-- Tables count: %12u\n", sfnt->num_tables ));
- FT_TRACE2(( "-- Format version: %08lx\n", sfnt->format_tag ));
+ FT_TRACE2(( "-- Tables count: %12u\n", sfnt.num_tables ));
+ FT_TRACE2(( "-- Format version: %08lx\n", sfnt.format_tag ));
/* check first */
- error = sfnt_dir_check( sfnt, stream );
+ error = check_table_dir( &sfnt, stream );
if ( error )
{
- FT_TRACE2(( "tt_face_load_directory: directory checking failed!\n" ));
+ FT_TRACE2(( "tt_face_load_font_dir: invalid table directory!\n" ));
return error;
}
- face->num_tables = sfnt->num_tables;
+ face->num_tables = sfnt.num_tables;
+ face->format_tag = sfnt.format_tag;
if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )
- goto Exit;
+ return error;
- if ( FT_STREAM_SEEK( sfnt->offset + 12 ) ||
+ if ( FT_STREAM_SEEK( sfnt.offset + 12 ) ||
FT_FRAME_ENTER( face->num_tables * 16L ) )
- goto Exit;
+ return error;
entry = face->dir_tables;
limit = entry + face->num_tables;
for ( ; entry < limit; entry++ )
- { /* loop through the tables and get all entries */
+ {
entry->Tag = FT_GET_TAG4();
entry->CheckSum = FT_GET_ULONG();
entry->Offset = FT_GET_LONG();
@@ -477,9 +344,8 @@
FT_FRAME_EXIT();
- FT_TRACE2(( "Directory loaded\n\n" ));
+ FT_TRACE2(( "table directory loaded\n\n" ));
- Exit:
return error;
}
diff --git a/src/sfnt/ttload.h b/src/sfnt/ttload.h
index 68b50ea..b665711 100644
--- a/src/sfnt/ttload.h
+++ b/src/sfnt/ttload.h
@@ -41,15 +41,9 @@ FT_BEGIN_HEADER
FT_LOCAL( FT_Error )
- tt_face_load_sfnt_header( TT_Face face,
- FT_Stream stream,
- FT_Long face_index,
- SFNT_Header sfnt );
+ tt_face_load_font_dir( TT_Face face,
+ FT_Stream stream );
- FT_LOCAL( FT_Error )
- tt_face_load_directory( TT_Face face,
- FT_Stream stream,
- SFNT_Header sfnt );
FT_LOCAL( FT_Error )
tt_face_load_any( TT_Face face,