1 /**************************************************************************** 2 * 3 * cffgload.c 4 * 5 * OpenType Glyph Loader (body). 6 * 7 * Copyright (C) 1996-2023 by 8 * David Turner, Robert Wilhelm, and Werner Lemberg. 9 * 10 * This file is part of the FreeType project, and may only be used, 11 * modified, and distributed under the terms of the FreeType project 12 * license, LICENSE.TXT. By continuing to use, modify, or distribute 13 * this file you indicate that you have read the license and 14 * understand and accept it fully. 15 * 16 */ 17 18 19 #include <freetype/internal/ftdebug.h> 20 #include <freetype/internal/ftstream.h> 21 #include <freetype/internal/sfnt.h> 22 #include <freetype/internal/ftcalc.h> 23 #include <freetype/internal/psaux.h> 24 #include <freetype/ftoutln.h> 25 #include <freetype/ftdriver.h> 26 27 #include "cffload.h" 28 #include "cffgload.h" 29 30 #include "cfferrs.h" 31 32 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 33 #define IS_DEFAULT_INSTANCE( _face ) \ 34 ( !( FT_IS_NAMED_INSTANCE( _face ) || \ 35 FT_IS_VARIATION( _face ) ) ) 36 #else 37 #define IS_DEFAULT_INSTANCE( _face ) 1 38 #endif 39 40 41 /************************************************************************** 42 * 43 * The macro FT_COMPONENT is used in trace mode. It is an implicit 44 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log 45 * messages during execution. 46 */ 47 #undef FT_COMPONENT 48 #define FT_COMPONENT cffgload 49 50 51 FT_LOCAL_DEF( FT_Error ) cff_get_glyph_data(TT_Face face,FT_UInt glyph_index,FT_Byte ** pointer,FT_ULong * length)52 cff_get_glyph_data( TT_Face face, 53 FT_UInt glyph_index, 54 FT_Byte** pointer, 55 FT_ULong* length ) 56 { 57 #ifdef FT_CONFIG_OPTION_INCREMENTAL 58 /* For incremental fonts get the character data using the */ 59 /* callback function. */ 60 if ( face->root.internal->incremental_interface ) 61 { 62 FT_Data data; 63 FT_Error error = 64 face->root.internal->incremental_interface->funcs->get_glyph_data( 65 face->root.internal->incremental_interface->object, 66 glyph_index, &data ); 67 68 69 *pointer = (FT_Byte*)data.pointer; 70 *length = data.length; 71 72 return error; 73 } 74 else 75 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ 76 77 { 78 CFF_Font cff = (CFF_Font)( face->extra.data ); 79 80 81 return cff_index_access_element( &cff->charstrings_index, glyph_index, 82 pointer, length ); 83 } 84 } 85 86 87 FT_LOCAL_DEF( void ) cff_free_glyph_data(TT_Face face,FT_Byte ** pointer,FT_ULong length)88 cff_free_glyph_data( TT_Face face, 89 FT_Byte** pointer, 90 FT_ULong length ) 91 { 92 #ifndef FT_CONFIG_OPTION_INCREMENTAL 93 FT_UNUSED( length ); 94 #endif 95 96 #ifdef FT_CONFIG_OPTION_INCREMENTAL 97 /* For incremental fonts get the character data using the */ 98 /* callback function. */ 99 if ( face->root.internal->incremental_interface ) 100 { 101 FT_Data data; 102 103 104 data.pointer = *pointer; 105 data.length = (FT_UInt)length; 106 107 face->root.internal->incremental_interface->funcs->free_glyph_data( 108 face->root.internal->incremental_interface->object, &data ); 109 } 110 else 111 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ 112 113 { 114 CFF_Font cff = (CFF_Font)( face->extra.data ); 115 116 117 cff_index_forget_element( &cff->charstrings_index, pointer ); 118 } 119 } 120 121 122 /*************************************************************************/ 123 /*************************************************************************/ 124 /*************************************************************************/ 125 /********** *********/ 126 /********** *********/ 127 /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ 128 /********** *********/ 129 /********** The following code is in charge of computing *********/ 130 /********** the maximum advance width of the font. It *********/ 131 /********** quickly processes each glyph charstring to *********/ 132 /********** extract the value from either a `sbw' or `seac' *********/ 133 /********** operator. *********/ 134 /********** *********/ 135 /*************************************************************************/ 136 /*************************************************************************/ 137 /*************************************************************************/ 138 139 140 #if 0 /* unused until we support pure CFF fonts */ 141 142 143 FT_LOCAL_DEF( FT_Error ) 144 cff_compute_max_advance( TT_Face face, 145 FT_Int* max_advance ) 146 { 147 FT_Error error = FT_Err_Ok; 148 CFF_Decoder decoder; 149 FT_Int glyph_index; 150 CFF_Font cff = (CFF_Font)face->other; 151 152 PSAux_Service psaux = (PSAux_Service)face->psaux; 153 const CFF_Decoder_Funcs decoder_funcs = psaux->cff_decoder_funcs; 154 155 156 *max_advance = 0; 157 158 /* Initialize load decoder */ 159 decoder_funcs->init( &decoder, face, 0, 0, 0, 0, 0, 0 ); 160 161 decoder.builder.metrics_only = 1; 162 decoder.builder.load_points = 0; 163 164 /* For each glyph, parse the glyph charstring and extract */ 165 /* the advance width. */ 166 for ( glyph_index = 0; glyph_index < face->root.num_glyphs; 167 glyph_index++ ) 168 { 169 FT_Byte* charstring; 170 FT_ULong charstring_len; 171 172 173 /* now get load the unscaled outline */ 174 error = cff_get_glyph_data( face, glyph_index, 175 &charstring, &charstring_len ); 176 if ( !error ) 177 { 178 error = decoder_funcs->prepare( &decoder, size, glyph_index ); 179 if ( !error ) 180 error = decoder_funcs->parse_charstrings_old( &decoder, 181 charstring, 182 charstring_len, 183 0 ); 184 185 cff_free_glyph_data( face, &charstring, &charstring_len ); 186 } 187 188 /* ignore the error if one has occurred -- skip to next glyph */ 189 error = FT_Err_Ok; 190 } 191 192 *max_advance = decoder.builder.advance.x; 193 194 return FT_Err_Ok; 195 } 196 197 198 #endif /* 0 */ 199 200 201 FT_LOCAL_DEF( FT_Error ) cff_slot_load(CFF_GlyphSlot glyph,CFF_Size size,FT_UInt glyph_index,FT_Int32 load_flags)202 cff_slot_load( CFF_GlyphSlot glyph, 203 CFF_Size size, 204 FT_UInt glyph_index, 205 FT_Int32 load_flags ) 206 { 207 FT_Error error; 208 CFF_Decoder decoder; 209 PS_Decoder psdecoder; 210 TT_Face face = (TT_Face)glyph->root.face; 211 FT_Bool hinting, scaled, force_scaling; 212 CFF_Font cff = (CFF_Font)face->extra.data; 213 214 PSAux_Service psaux = (PSAux_Service)face->psaux; 215 const CFF_Decoder_Funcs decoder_funcs = psaux->cff_decoder_funcs; 216 217 FT_Matrix font_matrix; 218 FT_Vector font_offset; 219 220 221 force_scaling = FALSE; 222 223 /* in a CID-keyed font, consider `glyph_index' as a CID and map */ 224 /* it immediately to the real glyph_index -- if it isn't a */ 225 /* subsetted font, glyph_indices and CIDs are identical, though */ 226 if ( cff->top_font.font_dict.cid_registry != 0xFFFFU && 227 cff->charset.cids ) 228 { 229 /* don't handle CID 0 (.notdef) which is directly mapped to GID 0 */ 230 if ( glyph_index != 0 ) 231 { 232 glyph_index = cff_charset_cid_to_gindex( &cff->charset, 233 glyph_index ); 234 if ( glyph_index == 0 ) 235 return FT_THROW( Invalid_Argument ); 236 } 237 } 238 else if ( glyph_index >= cff->num_glyphs ) 239 return FT_THROW( Invalid_Argument ); 240 241 if ( load_flags & FT_LOAD_NO_RECURSE ) 242 load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; 243 244 glyph->x_scale = 0x10000L; 245 glyph->y_scale = 0x10000L; 246 if ( size ) 247 { 248 glyph->x_scale = size->root.metrics.x_scale; 249 glyph->y_scale = size->root.metrics.y_scale; 250 } 251 252 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 253 254 /* try to load embedded bitmap if any */ 255 /* */ 256 /* XXX: The convention should be emphasized in */ 257 /* the documents because it can be confusing. */ 258 if ( size ) 259 { 260 CFF_Face cff_face = (CFF_Face)size->root.face; 261 SFNT_Service sfnt = (SFNT_Service)cff_face->sfnt; 262 FT_Stream stream = cff_face->root.stream; 263 264 265 if ( size->strike_index != 0xFFFFFFFFUL && 266 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 && 267 IS_DEFAULT_INSTANCE( size->root.face ) ) 268 { 269 TT_SBit_MetricsRec metrics; 270 271 272 error = sfnt->load_sbit_image( face, 273 size->strike_index, 274 glyph_index, 275 (FT_UInt)load_flags, 276 stream, 277 &glyph->root.bitmap, 278 &metrics ); 279 280 if ( !error ) 281 { 282 FT_Bool has_vertical_info; 283 FT_UShort advance; 284 FT_Short dummy; 285 286 287 glyph->root.outline.n_points = 0; 288 glyph->root.outline.n_contours = 0; 289 290 glyph->root.metrics.width = (FT_Pos)metrics.width * 64; 291 glyph->root.metrics.height = (FT_Pos)metrics.height * 64; 292 293 glyph->root.metrics.horiBearingX = (FT_Pos)metrics.horiBearingX * 64; 294 glyph->root.metrics.horiBearingY = (FT_Pos)metrics.horiBearingY * 64; 295 glyph->root.metrics.horiAdvance = (FT_Pos)metrics.horiAdvance * 64; 296 297 glyph->root.metrics.vertBearingX = (FT_Pos)metrics.vertBearingX * 64; 298 glyph->root.metrics.vertBearingY = (FT_Pos)metrics.vertBearingY * 64; 299 glyph->root.metrics.vertAdvance = (FT_Pos)metrics.vertAdvance * 64; 300 301 glyph->root.format = FT_GLYPH_FORMAT_BITMAP; 302 303 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) 304 { 305 glyph->root.bitmap_left = metrics.vertBearingX; 306 glyph->root.bitmap_top = metrics.vertBearingY; 307 } 308 else 309 { 310 glyph->root.bitmap_left = metrics.horiBearingX; 311 glyph->root.bitmap_top = metrics.horiBearingY; 312 } 313 314 /* compute linear advance widths */ 315 316 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 0, 317 glyph_index, 318 &dummy, 319 &advance ); 320 glyph->root.linearHoriAdvance = advance; 321 322 has_vertical_info = FT_BOOL( 323 face->vertical_info && 324 face->vertical.number_Of_VMetrics > 0 ); 325 326 /* get the vertical metrics from the vmtx table if we have one */ 327 if ( has_vertical_info ) 328 { 329 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1, 330 glyph_index, 331 &dummy, 332 &advance ); 333 glyph->root.linearVertAdvance = advance; 334 } 335 else 336 { 337 /* make up vertical ones */ 338 if ( face->os2.version != 0xFFFFU ) 339 glyph->root.linearVertAdvance = (FT_Pos) 340 ( face->os2.sTypoAscender - face->os2.sTypoDescender ); 341 else 342 glyph->root.linearVertAdvance = (FT_Pos) 343 ( face->horizontal.Ascender - face->horizontal.Descender ); 344 } 345 346 return error; 347 } 348 } 349 } 350 351 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 352 353 /* return immediately if we only want the embedded bitmaps */ 354 if ( load_flags & FT_LOAD_SBITS_ONLY ) 355 return FT_THROW( Invalid_Argument ); 356 357 #ifdef FT_CONFIG_OPTION_SVG 358 /* check for OT-SVG */ 359 if ( ( load_flags & FT_LOAD_COLOR ) && face->svg ) 360 { 361 /* 362 * We load the SVG document and try to grab the advances from the 363 * table. For the bearings we rely on the presetting hook to do that. 364 */ 365 366 SFNT_Service sfnt = (SFNT_Service)face->sfnt; 367 368 369 if ( size && (size->root.metrics.x_ppem < 1 || 370 size->root.metrics.y_ppem < 1 ) ) 371 { 372 error = FT_THROW( Invalid_Size_Handle ); 373 return error; 374 } 375 376 FT_TRACE3(( "Trying to load SVG glyph\n" )); 377 378 error = sfnt->load_svg_doc( (FT_GlyphSlot)glyph, glyph_index ); 379 if ( !error ) 380 { 381 FT_Fixed x_scale = size->root.metrics.x_scale; 382 FT_Fixed y_scale = size->root.metrics.y_scale; 383 384 FT_Short dummy; 385 FT_UShort advanceX; 386 FT_UShort advanceY; 387 388 389 FT_TRACE3(( "Successfully loaded SVG glyph\n" )); 390 391 glyph->root.format = FT_GLYPH_FORMAT_SVG; 392 393 /* 394 * If horizontal or vertical advances are not present in the table, 395 * this is a problem with the font since the standard requires them. 396 * However, we are graceful and calculate the values by ourselves 397 * for the vertical case. 398 */ 399 sfnt->get_metrics( face, 400 FALSE, 401 glyph_index, 402 &dummy, 403 &advanceX ); 404 sfnt->get_metrics( face, 405 TRUE, 406 glyph_index, 407 &dummy, 408 &advanceY ); 409 410 glyph->root.linearHoriAdvance = advanceX; 411 glyph->root.linearVertAdvance = advanceY; 412 413 glyph->root.metrics.horiAdvance = FT_MulFix( advanceX, x_scale ); 414 glyph->root.metrics.vertAdvance = FT_MulFix( advanceY, y_scale ); 415 416 return error; 417 } 418 419 FT_TRACE3(( "Failed to load SVG glyph\n" )); 420 } 421 422 #endif /* FT_CONFIG_OPTION_SVG */ 423 424 /* if we have a CID subfont, use its matrix (which has already */ 425 /* been multiplied with the root matrix) */ 426 427 /* this scaling is only relevant if the PS hinter isn't active */ 428 if ( cff->num_subfonts ) 429 { 430 FT_Long top_upm, sub_upm; 431 FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, 432 glyph_index ); 433 434 435 if ( fd_index >= cff->num_subfonts ) 436 fd_index = (FT_Byte)( cff->num_subfonts - 1 ); 437 438 top_upm = (FT_Long)cff->top_font.font_dict.units_per_em; 439 sub_upm = (FT_Long)cff->subfonts[fd_index]->font_dict.units_per_em; 440 441 font_matrix = cff->subfonts[fd_index]->font_dict.font_matrix; 442 font_offset = cff->subfonts[fd_index]->font_dict.font_offset; 443 444 if ( top_upm != sub_upm ) 445 { 446 glyph->x_scale = FT_MulDiv( glyph->x_scale, top_upm, sub_upm ); 447 glyph->y_scale = FT_MulDiv( glyph->y_scale, top_upm, sub_upm ); 448 449 force_scaling = TRUE; 450 } 451 } 452 else 453 { 454 font_matrix = cff->top_font.font_dict.font_matrix; 455 font_offset = cff->top_font.font_dict.font_offset; 456 } 457 458 glyph->root.outline.n_points = 0; 459 glyph->root.outline.n_contours = 0; 460 461 /* top-level code ensures that FT_LOAD_NO_HINTING is set */ 462 /* if FT_LOAD_NO_SCALE is active */ 463 hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_HINTING ) == 0 ); 464 scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ); 465 466 glyph->hint = hinting; 467 glyph->scaled = scaled; 468 glyph->root.format = FT_GLYPH_FORMAT_OUTLINE; /* by default */ 469 470 { 471 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE 472 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face ); 473 #endif 474 475 FT_Byte* charstring; 476 FT_ULong charstring_len; 477 478 479 decoder_funcs->init( &decoder, face, size, glyph, hinting, 480 FT_LOAD_TARGET_MODE( load_flags ), 481 cff_get_glyph_data, 482 cff_free_glyph_data ); 483 484 /* this is for pure CFFs */ 485 if ( load_flags & FT_LOAD_ADVANCE_ONLY ) 486 decoder.width_only = TRUE; 487 488 decoder.builder.no_recurse = 489 FT_BOOL( load_flags & FT_LOAD_NO_RECURSE ); 490 491 /* this function also checks for a valid subfont index */ 492 error = decoder_funcs->prepare( &decoder, size, glyph_index ); 493 if ( error ) 494 goto Glyph_Build_Finished; 495 496 /* now load the unscaled outline */ 497 error = cff_get_glyph_data( face, glyph_index, 498 &charstring, &charstring_len ); 499 if ( error ) 500 goto Glyph_Build_Finished; 501 502 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE 503 /* choose which CFF renderer to use */ 504 if ( driver->hinting_engine == FT_HINTING_FREETYPE ) 505 error = decoder_funcs->parse_charstrings_old( &decoder, 506 charstring, 507 charstring_len, 508 0 ); 509 else 510 #endif 511 { 512 psaux->ps_decoder_init( &psdecoder, &decoder, FALSE ); 513 514 error = decoder_funcs->parse_charstrings( &psdecoder, 515 charstring, 516 charstring_len ); 517 518 /* Adobe's engine uses 16.16 numbers everywhere; */ 519 /* as a consequence, glyphs larger than 2000ppem get rejected */ 520 if ( FT_ERR_EQ( error, Glyph_Too_Big ) ) 521 { 522 /* this time, we retry unhinted and scale up the glyph later on */ 523 /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */ 524 /* 0x400 for both `x_scale' and `y_scale' in this case) */ 525 hinting = FALSE; 526 force_scaling = TRUE; 527 glyph->hint = hinting; 528 529 error = decoder_funcs->parse_charstrings( &psdecoder, 530 charstring, 531 charstring_len ); 532 } 533 } 534 535 cff_free_glyph_data( face, &charstring, charstring_len ); 536 537 if ( error ) 538 goto Glyph_Build_Finished; 539 540 #ifdef FT_CONFIG_OPTION_INCREMENTAL 541 /* Control data and length may not be available for incremental */ 542 /* fonts. */ 543 if ( face->root.internal->incremental_interface ) 544 { 545 glyph->root.control_data = NULL; 546 glyph->root.control_len = 0; 547 } 548 else 549 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ 550 551 /* We set control_data and control_len if charstrings is loaded. */ 552 /* See how charstring loads at cff_index_access_element() in */ 553 /* cffload.c. */ 554 { 555 CFF_Index csindex = &cff->charstrings_index; 556 557 558 if ( csindex->offsets ) 559 { 560 glyph->root.control_data = csindex->bytes + 561 csindex->offsets[glyph_index] - 1; 562 glyph->root.control_len = (FT_Long)charstring_len; 563 } 564 } 565 566 Glyph_Build_Finished: 567 /* save new glyph tables, if no error */ 568 if ( !error ) 569 decoder.builder.funcs.done( &decoder.builder ); 570 /* XXX: anything to do for broken glyph entry? */ 571 } 572 573 #ifdef FT_CONFIG_OPTION_INCREMENTAL 574 575 /* Incremental fonts can optionally override the metrics. */ 576 if ( !error && 577 face->root.internal->incremental_interface && 578 face->root.internal->incremental_interface->funcs->get_glyph_metrics ) 579 { 580 FT_Incremental_MetricsRec metrics; 581 582 583 metrics.bearing_x = decoder.builder.left_bearing.x; 584 metrics.bearing_y = 0; 585 metrics.advance = decoder.builder.advance.x; 586 metrics.advance_v = decoder.builder.advance.y; 587 588 error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( 589 face->root.internal->incremental_interface->object, 590 glyph_index, FALSE, &metrics ); 591 592 decoder.builder.left_bearing.x = metrics.bearing_x; 593 decoder.builder.advance.x = metrics.advance; 594 decoder.builder.advance.y = metrics.advance_v; 595 } 596 597 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ 598 599 if ( !error ) 600 { 601 /* Now, set the metrics -- this is rather simple, as */ 602 /* the left side bearing is the xMin, and the top side */ 603 /* bearing the yMax. */ 604 605 /* For composite glyphs, return only left side bearing and */ 606 /* advance width. */ 607 if ( load_flags & FT_LOAD_NO_RECURSE ) 608 { 609 FT_Slot_Internal internal = glyph->root.internal; 610 611 612 glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x; 613 glyph->root.metrics.horiAdvance = decoder.glyph_width; 614 internal->glyph_matrix = font_matrix; 615 internal->glyph_delta = font_offset; 616 internal->glyph_transformed = 1; 617 } 618 else 619 { 620 FT_BBox cbox; 621 FT_Glyph_Metrics* metrics = &glyph->root.metrics; 622 FT_Bool has_vertical_info; 623 624 625 if ( face->horizontal.number_Of_HMetrics ) 626 { 627 FT_Short horiBearingX = 0; 628 FT_UShort horiAdvance = 0; 629 630 631 ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, 632 glyph_index, 633 &horiBearingX, 634 &horiAdvance ); 635 metrics->horiAdvance = horiAdvance; 636 metrics->horiBearingX = horiBearingX; 637 glyph->root.linearHoriAdvance = horiAdvance; 638 } 639 else 640 { 641 /* copy the _unscaled_ advance width */ 642 metrics->horiAdvance = decoder.glyph_width; 643 glyph->root.linearHoriAdvance = decoder.glyph_width; 644 } 645 646 glyph->root.internal->glyph_transformed = 0; 647 648 has_vertical_info = FT_BOOL( face->vertical_info && 649 face->vertical.number_Of_VMetrics > 0 ); 650 651 /* get the vertical metrics from the vmtx table if we have one */ 652 if ( has_vertical_info ) 653 { 654 FT_Short vertBearingY = 0; 655 FT_UShort vertAdvance = 0; 656 657 658 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, 659 glyph_index, 660 &vertBearingY, 661 &vertAdvance ); 662 metrics->vertBearingY = vertBearingY; 663 metrics->vertAdvance = vertAdvance; 664 } 665 else 666 { 667 /* make up vertical ones */ 668 if ( face->os2.version != 0xFFFFU ) 669 metrics->vertAdvance = (FT_Pos)( face->os2.sTypoAscender - 670 face->os2.sTypoDescender ); 671 else 672 metrics->vertAdvance = (FT_Pos)( face->horizontal.Ascender - 673 face->horizontal.Descender ); 674 } 675 676 glyph->root.linearVertAdvance = metrics->vertAdvance; 677 678 glyph->root.format = FT_GLYPH_FORMAT_OUTLINE; 679 680 glyph->root.outline.flags = 0; 681 if ( size && size->root.metrics.y_ppem < 24 ) 682 glyph->root.outline.flags |= FT_OUTLINE_HIGH_PRECISION; 683 684 glyph->root.outline.flags |= FT_OUTLINE_REVERSE_FILL; 685 686 /* apply the font matrix, if any */ 687 if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L || 688 font_matrix.xy != 0 || font_matrix.yx != 0 ) 689 { 690 FT_Outline_Transform( &glyph->root.outline, &font_matrix ); 691 692 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, 693 font_matrix.xx ); 694 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, 695 font_matrix.yy ); 696 } 697 698 if ( font_offset.x || font_offset.y ) 699 { 700 FT_Outline_Translate( &glyph->root.outline, 701 font_offset.x, 702 font_offset.y ); 703 704 metrics->horiAdvance += font_offset.x; 705 metrics->vertAdvance += font_offset.y; 706 } 707 708 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || force_scaling ) 709 { 710 /* scale the outline and the metrics */ 711 FT_Int n; 712 FT_Outline* cur = &glyph->root.outline; 713 FT_Vector* vec = cur->points; 714 FT_Fixed x_scale = glyph->x_scale; 715 FT_Fixed y_scale = glyph->y_scale; 716 717 718 /* First of all, scale the points */ 719 if ( !hinting || !decoder.builder.hints_funcs ) 720 for ( n = cur->n_points; n > 0; n--, vec++ ) 721 { 722 vec->x = FT_MulFix( vec->x, x_scale ); 723 vec->y = FT_MulFix( vec->y, y_scale ); 724 } 725 726 /* Then scale the metrics */ 727 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale ); 728 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale ); 729 } 730 731 /* compute the other metrics */ 732 FT_Outline_Get_CBox( &glyph->root.outline, &cbox ); 733 734 metrics->width = cbox.xMax - cbox.xMin; 735 metrics->height = cbox.yMax - cbox.yMin; 736 737 metrics->horiBearingX = cbox.xMin; 738 metrics->horiBearingY = cbox.yMax; 739 740 if ( has_vertical_info ) 741 { 742 metrics->vertBearingX = metrics->horiBearingX - 743 metrics->horiAdvance / 2; 744 metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, 745 glyph->y_scale ); 746 } 747 else 748 { 749 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) 750 ft_synthesize_vertical_metrics( metrics, 751 metrics->vertAdvance ); 752 } 753 } 754 } 755 756 return error; 757 } 758 759 760 /* END */ 761