1 /***************************************************************************/ 2 /* */ 3 /* afcjk.c */ 4 /* */ 5 /* Auto-fitter hinting routines for CJK writing system (body). */ 6 /* */ 7 /* Copyright 2006-2015 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 * The algorithm is based on akito's autohint patch, available here: 20 * 21 * http://www.kde.gr.jp/~akito/patch/freetype2/ 22 * 23 */ 24 25 #include <ft2build.h> 26 #include FT_ADVANCES_H 27 #include FT_INTERNAL_DEBUG_H 28 29 #include "afglobal.h" 30 #include "afpic.h" 31 #include "aflatin.h" 32 33 34 #ifdef AF_CONFIG_OPTION_CJK 35 36 #undef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT 37 38 #include "afcjk.h" 39 #include "aferrors.h" 40 41 42 #ifdef AF_CONFIG_OPTION_USE_WARPER 43 #include "afwarp.h" 44 #endif 45 46 47 /*************************************************************************/ 48 /* */ 49 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 50 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 51 /* messages during execution. */ 52 /* */ 53 #undef FT_COMPONENT 54 #define FT_COMPONENT trace_afcjk 55 56 57 /*************************************************************************/ 58 /*************************************************************************/ 59 /***** *****/ 60 /***** C J K G L O B A L M E T R I C S *****/ 61 /***** *****/ 62 /*************************************************************************/ 63 /*************************************************************************/ 64 65 66 /* Basically the Latin version with AF_CJKMetrics */ 67 /* to replace AF_LatinMetrics. */ 68 69 FT_LOCAL_DEF( void ) 70 af_cjk_metrics_init_widths( AF_CJKMetrics metrics, 71 FT_Face face ) 72 { 73 /* scan the array of segments in each direction */ 74 AF_GlyphHintsRec hints[1]; 75 76 77 FT_TRACE5(( "\n" 78 "cjk standard widths computation (style `%s')\n" 79 "===================================================\n" 80 "\n", 81 af_style_names[metrics->root.style_class->style] )); 82 83 af_glyph_hints_init( hints, face->memory ); 84 85 metrics->axis[AF_DIMENSION_HORZ].width_count = 0; 86 metrics->axis[AF_DIMENSION_VERT].width_count = 0; 87 88 { 89 FT_Error error; 90 FT_ULong glyph_index; 91 FT_Long y_offset; 92 int dim; 93 AF_CJKMetricsRec dummy[1]; 94 AF_Scaler scaler = &dummy->root.scaler; 95 96 #ifdef FT_CONFIG_OPTION_PIC 97 AF_FaceGlobals globals = metrics->root.globals; 98 #endif 99 100 AF_StyleClass style_class = metrics->root.style_class; 101 AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET 102 [style_class->script]; 103 104 FT_UInt32 standard_char; 105 106 107 standard_char = script_class->standard_char1; 108 af_get_char_index( &metrics->root, 109 standard_char, 110 &glyph_index, 111 &y_offset ); 112 if ( !glyph_index ) 113 { 114 if ( script_class->standard_char2 ) 115 { 116 standard_char = script_class->standard_char2; 117 af_get_char_index( &metrics->root, 118 standard_char, 119 &glyph_index, 120 &y_offset ); 121 if ( !glyph_index ) 122 { 123 if ( script_class->standard_char3 ) 124 { 125 standard_char = script_class->standard_char3; 126 af_get_char_index( &metrics->root, 127 standard_char, 128 &glyph_index, 129 &y_offset ); 130 if ( !glyph_index ) 131 goto Exit; 132 } 133 else 134 goto Exit; 135 } 136 } 137 else 138 goto Exit; 139 } 140 141 FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n", 142 standard_char, glyph_index )); 143 144 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); 145 if ( error || face->glyph->outline.n_points <= 0 ) 146 goto Exit; 147 148 FT_ZERO( dummy ); 149 150 dummy->units_per_em = metrics->units_per_em; 151 152 scaler->x_scale = 0x10000L; 153 scaler->y_scale = 0x10000L; 154 scaler->x_delta = 0; 155 scaler->y_delta = 0; 156 157 scaler->face = face; 158 scaler->render_mode = FT_RENDER_MODE_NORMAL; 159 scaler->flags = 0; 160 161 af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy ); 162 163 error = af_glyph_hints_reload( hints, &face->glyph->outline ); 164 if ( error ) 165 goto Exit; 166 167 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) 168 { 169 AF_CJKAxis axis = &metrics->axis[dim]; 170 AF_AxisHints axhints = &hints->axis[dim]; 171 AF_Segment seg, limit, link; 172 FT_UInt num_widths = 0; 173 174 175 error = af_latin_hints_compute_segments( hints, 176 (AF_Dimension)dim ); 177 if ( error ) 178 goto Exit; 179 180 af_latin_hints_link_segments( hints, 181 0, 182 NULL, 183 (AF_Dimension)dim ); 184 185 seg = axhints->segments; 186 limit = seg + axhints->num_segments; 187 188 for ( ; seg < limit; seg++ ) 189 { 190 link = seg->link; 191 192 /* we only consider stem segments there! */ 193 if ( link && link->link == seg && link > seg ) 194 { 195 FT_Pos dist; 196 197 198 dist = seg->pos - link->pos; 199 if ( dist < 0 ) 200 dist = -dist; 201 202 if ( num_widths < AF_CJK_MAX_WIDTHS ) 203 axis->widths[num_widths++].org = dist; 204 } 205 } 206 207 /* this also replaces multiple almost identical stem widths */ 208 /* with a single one (the value 100 is heuristic) */ 209 af_sort_and_quantize_widths( &num_widths, axis->widths, 210 dummy->units_per_em / 100 ); 211 axis->width_count = num_widths; 212 } 213 214 Exit: 215 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) 216 { 217 AF_CJKAxis axis = &metrics->axis[dim]; 218 FT_Pos stdw; 219 220 221 stdw = ( axis->width_count > 0 ) ? axis->widths[0].org 222 : AF_LATIN_CONSTANT( metrics, 50 ); 223 224 /* let's try 20% of the smallest width */ 225 axis->edge_distance_threshold = stdw / 5; 226 axis->standard_width = stdw; 227 axis->extra_light = 0; 228 229 #ifdef FT_DEBUG_LEVEL_TRACE 230 { 231 FT_UInt i; 232 233 234 FT_TRACE5(( "%s widths:\n", 235 dim == AF_DIMENSION_VERT ? "horizontal" 236 : "vertical" )); 237 238 FT_TRACE5(( " %d (standard)", axis->standard_width )); 239 for ( i = 1; i < axis->width_count; i++ ) 240 FT_TRACE5(( " %d", axis->widths[i].org )); 241 242 FT_TRACE5(( "\n" )); 243 } 244 #endif 245 } 246 } 247 248 FT_TRACE5(( "\n" )); 249 250 af_glyph_hints_done( hints ); 251 } 252 253 254 /* Find all blue zones. */ 255 256 static void 257 af_cjk_metrics_init_blues( AF_CJKMetrics metrics, 258 FT_Face face ) 259 { 260 FT_Pos fills[AF_BLUE_STRING_MAX_LEN]; 261 FT_Pos flats[AF_BLUE_STRING_MAX_LEN]; 262 263 FT_UInt num_fills; 264 FT_UInt num_flats; 265 266 FT_Bool fill; 267 268 AF_CJKBlue blue; 269 FT_Error error; 270 AF_CJKAxis axis; 271 FT_Outline outline; 272 273 AF_StyleClass sc = metrics->root.style_class; 274 275 AF_Blue_Stringset bss = sc->blue_stringset; 276 const AF_Blue_StringRec* bs = &af_blue_stringsets[bss]; 277 278 279 /* we walk over the blue character strings as specified in the */ 280 /* style's entry in the `af_blue_stringset' array, computing its */ 281 /* extremum points (depending on the string properties) */ 282 283 FT_TRACE5(( "cjk blue zones computation\n" 284 "==========================\n" 285 "\n" )); 286 287 for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ ) 288 { 289 const char* p = &af_blue_strings[bs->string]; 290 FT_Pos* blue_ref; 291 FT_Pos* blue_shoot; 292 293 294 if ( AF_CJK_IS_HORIZ_BLUE( bs ) ) 295 axis = &metrics->axis[AF_DIMENSION_HORZ]; 296 else 297 axis = &metrics->axis[AF_DIMENSION_VERT]; 298 299 #ifdef FT_DEBUG_LEVEL_TRACE 300 { 301 FT_String* cjk_blue_name[4] = 302 { 303 (FT_String*)"bottom", /* -- , -- */ 304 (FT_String*)"top", /* -- , TOP */ 305 (FT_String*)"left", /* HORIZ, -- */ 306 (FT_String*)"right" /* HORIZ, TOP */ 307 }; 308 309 310 FT_TRACE5(( "blue zone %d (%s):\n", 311 axis->blue_count, 312 cjk_blue_name[AF_CJK_IS_HORIZ_BLUE( bs ) | 313 AF_CJK_IS_TOP_BLUE( bs ) ] )); 314 } 315 #endif /* FT_DEBUG_LEVEL_TRACE */ 316 317 num_fills = 0; 318 num_flats = 0; 319 320 fill = 1; /* start with characters that define fill values */ 321 FT_TRACE5(( " [overshoot values]\n" )); 322 323 while ( *p ) 324 { 325 FT_ULong ch; 326 FT_ULong glyph_index; 327 FT_Long y_offset; 328 FT_Pos best_pos; /* same as points.y or points.x, resp. */ 329 FT_Int best_point; 330 FT_Vector* points; 331 332 333 GET_UTF8_CHAR( ch, p ); 334 335 /* switch to characters that define flat values */ 336 if ( ch == '|' ) 337 { 338 fill = 0; 339 FT_TRACE5(( " [reference values]\n" )); 340 continue; 341 } 342 343 /* load the character in the face -- skip unknown or empty ones */ 344 af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset ); 345 if ( glyph_index == 0 ) 346 { 347 FT_TRACE5(( " U+%04lX unavailable\n", ch )); 348 continue; 349 } 350 351 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); 352 outline = face->glyph->outline; 353 if ( error || outline.n_points <= 0 ) 354 { 355 FT_TRACE5(( " U+%04lX contains no outlines\n", ch )); 356 continue; 357 } 358 359 /* now compute min or max point indices and coordinates */ 360 points = outline.points; 361 best_point = -1; 362 best_pos = 0; /* make compiler happy */ 363 364 { 365 FT_Int nn; 366 FT_Int first = 0; 367 FT_Int last = -1; 368 369 370 for ( nn = 0; nn < outline.n_contours; first = last + 1, nn++ ) 371 { 372 FT_Int pp; 373 374 375 last = outline.contours[nn]; 376 377 /* Avoid single-point contours since they are never rasterized. */ 378 /* In some fonts, they correspond to mark attachment points */ 379 /* which are way outside of the glyph's real outline. */ 380 if ( last <= first ) 381 continue; 382 383 if ( AF_CJK_IS_HORIZ_BLUE( bs ) ) 384 { 385 if ( AF_CJK_IS_RIGHT_BLUE( bs ) ) 386 { 387 for ( pp = first; pp <= last; pp++ ) 388 if ( best_point < 0 || points[pp].x > best_pos ) 389 { 390 best_point = pp; 391 best_pos = points[pp].x; 392 } 393 } 394 else 395 { 396 for ( pp = first; pp <= last; pp++ ) 397 if ( best_point < 0 || points[pp].x < best_pos ) 398 { 399 best_point = pp; 400 best_pos = points[pp].x; 401 } 402 } 403 } 404 else 405 { 406 if ( AF_CJK_IS_TOP_BLUE( bs ) ) 407 { 408 for ( pp = first; pp <= last; pp++ ) 409 if ( best_point < 0 || points[pp].y > best_pos ) 410 { 411 best_point = pp; 412 best_pos = points[pp].y; 413 } 414 } 415 else 416 { 417 for ( pp = first; pp <= last; pp++ ) 418 if ( best_point < 0 || points[pp].y < best_pos ) 419 { 420 best_point = pp; 421 best_pos = points[pp].y; 422 } 423 } 424 } 425 } 426 427 FT_TRACE5(( " U+%04lX: best_pos = %5ld\n", ch, best_pos )); 428 } 429 430 if ( fill ) 431 fills[num_fills++] = best_pos; 432 else 433 flats[num_flats++] = best_pos; 434 } 435 436 if ( num_flats == 0 && num_fills == 0 ) 437 { 438 /* 439 * we couldn't find a single glyph to compute this blue zone, 440 * we will simply ignore it then 441 */ 442 FT_TRACE5(( " empty\n" )); 443 continue; 444 } 445 446 /* we have computed the contents of the `fill' and `flats' tables, */ 447 /* now determine the reference and overshoot position of the blue -- */ 448 /* we simply take the median value after a simple sort */ 449 af_sort_pos( num_fills, fills ); 450 af_sort_pos( num_flats, flats ); 451 452 blue = &axis->blues[axis->blue_count]; 453 blue_ref = &blue->ref.org; 454 blue_shoot = &blue->shoot.org; 455 456 axis->blue_count++; 457 458 if ( num_flats == 0 ) 459 { 460 *blue_ref = 461 *blue_shoot = fills[num_fills / 2]; 462 } 463 else if ( num_fills == 0 ) 464 { 465 *blue_ref = 466 *blue_shoot = flats[num_flats / 2]; 467 } 468 else 469 { 470 *blue_ref = fills[num_fills / 2]; 471 *blue_shoot = flats[num_flats / 2]; 472 } 473 474 /* make sure blue_ref >= blue_shoot for top/right or */ 475 /* vice versa for bottom/left */ 476 if ( *blue_shoot != *blue_ref ) 477 { 478 FT_Pos ref = *blue_ref; 479 FT_Pos shoot = *blue_shoot; 480 FT_Bool under_ref = FT_BOOL( shoot < ref ); 481 482 483 /* AF_CJK_IS_TOP_BLUE covers `right' and `top' */ 484 if ( AF_CJK_IS_TOP_BLUE( bs ) ^ under_ref ) 485 { 486 *blue_ref = 487 *blue_shoot = ( shoot + ref ) / 2; 488 489 FT_TRACE5(( " [reference smaller than overshoot," 490 " taking mean value]\n" )); 491 } 492 } 493 494 blue->flags = 0; 495 if ( AF_CJK_IS_TOP_BLUE( bs ) ) 496 blue->flags |= AF_CJK_BLUE_TOP; 497 498 FT_TRACE5(( " -> reference = %ld\n" 499 " overshoot = %ld\n", 500 *blue_ref, *blue_shoot )); 501 } 502 503 FT_TRACE5(( "\n" )); 504 505 return; 506 } 507 508 509 /* Basically the Latin version with type AF_CJKMetrics for metrics. */ 510 511 FT_LOCAL_DEF( void ) 512 af_cjk_metrics_check_digits( AF_CJKMetrics metrics, 513 FT_Face face ) 514 { 515 FT_UInt i; 516 FT_Bool started = 0, same_width = 1; 517 FT_Fixed advance, old_advance = 0; 518 519 520 /* digit `0' is 0x30 in all supported charmaps */ 521 for ( i = 0x30; i <= 0x39; i++ ) 522 { 523 FT_ULong glyph_index; 524 FT_Long y_offset; 525 526 527 af_get_char_index( &metrics->root, i, &glyph_index, &y_offset ); 528 if ( glyph_index == 0 ) 529 continue; 530 531 if ( FT_Get_Advance( face, glyph_index, 532 FT_LOAD_NO_SCALE | 533 FT_LOAD_NO_HINTING | 534 FT_LOAD_IGNORE_TRANSFORM, 535 &advance ) ) 536 continue; 537 538 if ( started ) 539 { 540 if ( advance != old_advance ) 541 { 542 same_width = 0; 543 break; 544 } 545 } 546 else 547 { 548 old_advance = advance; 549 started = 1; 550 } 551 } 552 553 metrics->root.digits_have_same_width = same_width; 554 } 555 556 557 /* Initialize global metrics. */ 558 559 FT_LOCAL_DEF( FT_Error ) 560 af_cjk_metrics_init( AF_CJKMetrics metrics, 561 FT_Face face ) 562 { 563 FT_CharMap oldmap = face->charmap; 564 565 566 metrics->units_per_em = face->units_per_EM; 567 568 if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) ) 569 { 570 af_cjk_metrics_init_widths( metrics, face ); 571 af_cjk_metrics_init_blues( metrics, face ); 572 af_cjk_metrics_check_digits( metrics, face ); 573 } 574 575 FT_Set_Charmap( face, oldmap ); 576 return FT_Err_Ok; 577 } 578 579 580 /* Adjust scaling value, then scale and shift widths */ 581 /* and blue zones (if applicable) for given dimension. */ 582 583 static void 584 af_cjk_metrics_scale_dim( AF_CJKMetrics metrics, 585 AF_Scaler scaler, 586 AF_Dimension dim ) 587 { 588 FT_Fixed scale; 589 FT_Pos delta; 590 AF_CJKAxis axis; 591 FT_UInt nn; 592 593 594 if ( dim == AF_DIMENSION_HORZ ) 595 { 596 scale = scaler->x_scale; 597 delta = scaler->x_delta; 598 } 599 else 600 { 601 scale = scaler->y_scale; 602 delta = scaler->y_delta; 603 } 604 605 axis = &metrics->axis[dim]; 606 607 if ( axis->org_scale == scale && axis->org_delta == delta ) 608 return; 609 610 axis->org_scale = scale; 611 axis->org_delta = delta; 612 613 axis->scale = scale; 614 axis->delta = delta; 615 616 /* scale the blue zones */ 617 for ( nn = 0; nn < axis->blue_count; nn++ ) 618 { 619 AF_CJKBlue blue = &axis->blues[nn]; 620 FT_Pos dist; 621 622 623 blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta; 624 blue->ref.fit = blue->ref.cur; 625 blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta; 626 blue->shoot.fit = blue->shoot.cur; 627 blue->flags &= ~AF_CJK_BLUE_ACTIVE; 628 629 /* a blue zone is only active if it is less than 3/4 pixels tall */ 630 dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale ); 631 if ( dist <= 48 && dist >= -48 ) 632 { 633 FT_Pos delta1, delta2; 634 635 636 blue->ref.fit = FT_PIX_ROUND( blue->ref.cur ); 637 638 /* shoot is under shoot for cjk */ 639 delta1 = FT_DivFix( blue->ref.fit, scale ) - blue->shoot.org; 640 delta2 = delta1; 641 if ( delta1 < 0 ) 642 delta2 = -delta2; 643 644 delta2 = FT_MulFix( delta2, scale ); 645 646 FT_TRACE5(( "delta: %d", delta1 )); 647 if ( delta2 < 32 ) 648 delta2 = 0; 649 #if 0 650 else if ( delta2 < 64 ) 651 delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 ); 652 #endif 653 else 654 delta2 = FT_PIX_ROUND( delta2 ); 655 FT_TRACE5(( "/%d\n", delta2 )); 656 657 if ( delta1 < 0 ) 658 delta2 = -delta2; 659 660 blue->shoot.fit = blue->ref.fit - delta2; 661 662 FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]:\n" 663 " ref: cur=%.2f fit=%.2f\n" 664 " shoot: cur=%.2f fit=%.2f\n", 665 ( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V', 666 nn, blue->ref.org, blue->shoot.org, 667 blue->ref.cur / 64.0, blue->ref.fit / 64.0, 668 blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 )); 669 670 blue->flags |= AF_CJK_BLUE_ACTIVE; 671 } 672 } 673 } 674 675 676 /* Scale global values in both directions. */ 677 678 FT_LOCAL_DEF( void ) 679 af_cjk_metrics_scale( AF_CJKMetrics metrics, 680 AF_Scaler scaler ) 681 { 682 /* we copy the whole structure since the x and y scaling values */ 683 /* are not modified, contrary to e.g. the `latin' auto-hinter */ 684 metrics->root.scaler = *scaler; 685 686 af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ ); 687 af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT ); 688 } 689 690 691 /* Extract standard_width from writing system/script specific */ 692 /* metrics class. */ 693 694 FT_LOCAL_DEF( void ) 695 af_cjk_get_standard_widths( AF_CJKMetrics metrics, 696 FT_Pos* stdHW, 697 FT_Pos* stdVW ) 698 { 699 if ( stdHW ) 700 *stdHW = metrics->axis[AF_DIMENSION_VERT].standard_width; 701 702 if ( stdVW ) 703 *stdVW = metrics->axis[AF_DIMENSION_HORZ].standard_width; 704 } 705 706 707 /*************************************************************************/ 708 /*************************************************************************/ 709 /***** *****/ 710 /***** C J K G L Y P H A N A L Y S I S *****/ 711 /***** *****/ 712 /*************************************************************************/ 713 /*************************************************************************/ 714 715 716 /* Walk over all contours and compute its segments. */ 717 718 static FT_Error 719 af_cjk_hints_compute_segments( AF_GlyphHints hints, 720 AF_Dimension dim ) 721 { 722 AF_AxisHints axis = &hints->axis[dim]; 723 AF_Segment segments = axis->segments; 724 AF_Segment segment_limit = segments + axis->num_segments; 725 FT_Error error; 726 AF_Segment seg; 727 728 729 error = af_latin_hints_compute_segments( hints, dim ); 730 if ( error ) 731 return error; 732 733 /* a segment is round if it doesn't have successive */ 734 /* on-curve points. */ 735 for ( seg = segments; seg < segment_limit; seg++ ) 736 { 737 AF_Point pt = seg->first; 738 AF_Point last = seg->last; 739 FT_UInt f0 = pt->flags & AF_FLAG_CONTROL; 740 FT_UInt f1; 741 742 743 seg->flags &= ~AF_EDGE_ROUND; 744 745 for ( ; pt != last; f0 = f1 ) 746 { 747 pt = pt->next; 748 f1 = pt->flags & AF_FLAG_CONTROL; 749 750 if ( !f0 && !f1 ) 751 break; 752 753 if ( pt == last ) 754 seg->flags |= AF_EDGE_ROUND; 755 } 756 } 757 758 return FT_Err_Ok; 759 } 760 761 762 static void 763 af_cjk_hints_link_segments( AF_GlyphHints hints, 764 AF_Dimension dim ) 765 { 766 AF_AxisHints axis = &hints->axis[dim]; 767 AF_Segment segments = axis->segments; 768 AF_Segment segment_limit = segments + axis->num_segments; 769 AF_Direction major_dir = axis->major_dir; 770 AF_Segment seg1, seg2; 771 FT_Pos len_threshold; 772 FT_Pos dist_threshold; 773 774 775 len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 ); 776 777 dist_threshold = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale 778 : hints->y_scale; 779 dist_threshold = FT_DivFix( 64 * 3, dist_threshold ); 780 781 /* now compare each segment to the others */ 782 for ( seg1 = segments; seg1 < segment_limit; seg1++ ) 783 { 784 if ( seg1->dir != major_dir ) 785 continue; 786 787 for ( seg2 = segments; seg2 < segment_limit; seg2++ ) 788 if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 ) 789 { 790 FT_Pos dist = seg2->pos - seg1->pos; 791 792 793 if ( dist < 0 ) 794 continue; 795 796 { 797 FT_Pos min = seg1->min_coord; 798 FT_Pos max = seg1->max_coord; 799 FT_Pos len; 800 801 802 if ( min < seg2->min_coord ) 803 min = seg2->min_coord; 804 805 if ( max > seg2->max_coord ) 806 max = seg2->max_coord; 807 808 len = max - min; 809 if ( len >= len_threshold ) 810 { 811 if ( dist * 8 < seg1->score * 9 && 812 ( dist * 8 < seg1->score * 7 || seg1->len < len ) ) 813 { 814 seg1->score = dist; 815 seg1->len = len; 816 seg1->link = seg2; 817 } 818 819 if ( dist * 8 < seg2->score * 9 && 820 ( dist * 8 < seg2->score * 7 || seg2->len < len ) ) 821 { 822 seg2->score = dist; 823 seg2->len = len; 824 seg2->link = seg1; 825 } 826 } 827 } 828 } 829 } 830 831 /* 832 * now compute the `serif' segments 833 * 834 * In Hanzi, some strokes are wider on one or both of the ends. 835 * We either identify the stems on the ends as serifs or remove 836 * the linkage, depending on the length of the stems. 837 * 838 */ 839 840 { 841 AF_Segment link1, link2; 842 843 844 for ( seg1 = segments; seg1 < segment_limit; seg1++ ) 845 { 846 link1 = seg1->link; 847 if ( !link1 || link1->link != seg1 || link1->pos <= seg1->pos ) 848 continue; 849 850 if ( seg1->score >= dist_threshold ) 851 continue; 852 853 for ( seg2 = segments; seg2 < segment_limit; seg2++ ) 854 { 855 if ( seg2->pos > seg1->pos || seg1 == seg2 ) 856 continue; 857 858 link2 = seg2->link; 859 if ( !link2 || link2->link != seg2 || link2->pos < link1->pos ) 860 continue; 861 862 if ( seg1->pos == seg2->pos && link1->pos == link2->pos ) 863 continue; 864 865 if ( seg2->score <= seg1->score || seg1->score * 4 <= seg2->score ) 866 continue; 867 868 /* seg2 < seg1 < link1 < link2 */ 869 870 if ( seg1->len >= seg2->len * 3 ) 871 { 872 AF_Segment seg; 873 874 875 for ( seg = segments; seg < segment_limit; seg++ ) 876 { 877 AF_Segment link = seg->link; 878 879 880 if ( link == seg2 ) 881 { 882 seg->link = NULL; 883 seg->serif = link1; 884 } 885 else if ( link == link2 ) 886 { 887 seg->link = NULL; 888 seg->serif = seg1; 889 } 890 } 891 } 892 else 893 { 894 seg1->link = link1->link = NULL; 895 896 break; 897 } 898 } 899 } 900 } 901 902 for ( seg1 = segments; seg1 < segment_limit; seg1++ ) 903 { 904 seg2 = seg1->link; 905 906 if ( seg2 ) 907 { 908 seg2->num_linked++; 909 if ( seg2->link != seg1 ) 910 { 911 seg1->link = NULL; 912 913 if ( seg2->score < dist_threshold || seg1->score < seg2->score * 4 ) 914 seg1->serif = seg2->link; 915 else 916 seg2->num_linked--; 917 } 918 } 919 } 920 } 921 922 923 static FT_Error 924 af_cjk_hints_compute_edges( AF_GlyphHints hints, 925 AF_Dimension dim ) 926 { 927 AF_AxisHints axis = &hints->axis[dim]; 928 FT_Error error = FT_Err_Ok; 929 FT_Memory memory = hints->memory; 930 AF_CJKAxis laxis = &((AF_CJKMetrics)hints->metrics)->axis[dim]; 931 932 AF_Segment segments = axis->segments; 933 AF_Segment segment_limit = segments + axis->num_segments; 934 AF_Segment seg; 935 936 FT_Fixed scale; 937 FT_Pos edge_distance_threshold; 938 939 940 axis->num_edges = 0; 941 942 scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale 943 : hints->y_scale; 944 945 /*********************************************************************/ 946 /* */ 947 /* We begin by generating a sorted table of edges for the current */ 948 /* direction. To do so, we simply scan each segment and try to find */ 949 /* an edge in our table that corresponds to its position. */ 950 /* */ 951 /* If no edge is found, we create and insert a new edge in the */ 952 /* sorted table. Otherwise, we simply add the segment to the edge's */ 953 /* list which is then processed in the second step to compute the */ 954 /* edge's properties. */ 955 /* */ 956 /* Note that the edges table is sorted along the segment/edge */ 957 /* position. */ 958 /* */ 959 /*********************************************************************/ 960 961 edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold, 962 scale ); 963 if ( edge_distance_threshold > 64 / 4 ) 964 edge_distance_threshold = FT_DivFix( 64 / 4, scale ); 965 else 966 edge_distance_threshold = laxis->edge_distance_threshold; 967 968 for ( seg = segments; seg < segment_limit; seg++ ) 969 { 970 AF_Edge found = NULL; 971 FT_Pos best = 0xFFFFU; 972 FT_Int ee; 973 974 975 /* look for an edge corresponding to the segment */ 976 for ( ee = 0; ee < axis->num_edges; ee++ ) 977 { 978 AF_Edge edge = axis->edges + ee; 979 FT_Pos dist; 980 981 982 if ( edge->dir != seg->dir ) 983 continue; 984 985 dist = seg->pos - edge->fpos; 986 if ( dist < 0 ) 987 dist = -dist; 988 989 if ( dist < edge_distance_threshold && dist < best ) 990 { 991 AF_Segment link = seg->link; 992 993 994 /* check whether all linked segments of the candidate edge */ 995 /* can make a single edge. */ 996 if ( link ) 997 { 998 AF_Segment seg1 = edge->first; 999 FT_Pos dist2 = 0; 1000 1001 1002 do 1003 { 1004 AF_Segment link1 = seg1->link; 1005 1006 1007 if ( link1 ) 1008 { 1009 dist2 = AF_SEGMENT_DIST( link, link1 ); 1010 if ( dist2 >= edge_distance_threshold ) 1011 break; 1012 } 1013 1014 } while ( ( seg1 = seg1->edge_next ) != edge->first ); 1015 1016 if ( dist2 >= edge_distance_threshold ) 1017 continue; 1018 } 1019 1020 best = dist; 1021 found = edge; 1022 } 1023 } 1024 1025 if ( !found ) 1026 { 1027 AF_Edge edge; 1028 1029 1030 /* insert a new edge in the list and */ 1031 /* sort according to the position */ 1032 error = af_axis_hints_new_edge( axis, seg->pos, 1033 (AF_Direction)seg->dir, 1034 memory, &edge ); 1035 if ( error ) 1036 goto Exit; 1037 1038 /* add the segment to the new edge's list */ 1039 FT_ZERO( edge ); 1040 1041 edge->first = seg; 1042 edge->last = seg; 1043 edge->dir = seg->dir; 1044 edge->fpos = seg->pos; 1045 edge->opos = FT_MulFix( seg->pos, scale ); 1046 edge->pos = edge->opos; 1047 seg->edge_next = seg; 1048 } 1049 else 1050 { 1051 /* if an edge was found, simply add the segment to the edge's */ 1052 /* list */ 1053 seg->edge_next = found->first; 1054 found->last->edge_next = seg; 1055 found->last = seg; 1056 } 1057 } 1058 1059 /******************************************************************/ 1060 /* */ 1061 /* Good, we now compute each edge's properties according to the */ 1062 /* segments found on its position. Basically, these are */ 1063 /* */ 1064 /* - the edge's main direction */ 1065 /* - stem edge, serif edge or both (which defaults to stem then) */ 1066 /* - rounded edge, straight or both (which defaults to straight) */ 1067 /* - link for edge */ 1068 /* */ 1069 /******************************************************************/ 1070 1071 /* first of all, set the `edge' field in each segment -- this is */ 1072 /* required in order to compute edge links */ 1073 1074 /* 1075 * Note that removing this loop and setting the `edge' field of each 1076 * segment directly in the code above slows down execution speed for 1077 * some reasons on platforms like the Sun. 1078 */ 1079 { 1080 AF_Edge edges = axis->edges; 1081 AF_Edge edge_limit = edges + axis->num_edges; 1082 AF_Edge edge; 1083 1084 1085 for ( edge = edges; edge < edge_limit; edge++ ) 1086 { 1087 seg = edge->first; 1088 if ( seg ) 1089 do 1090 { 1091 seg->edge = edge; 1092 seg = seg->edge_next; 1093 1094 } while ( seg != edge->first ); 1095 } 1096 1097 /* now compute each edge properties */ 1098 for ( edge = edges; edge < edge_limit; edge++ ) 1099 { 1100 FT_Int is_round = 0; /* does it contain round segments? */ 1101 FT_Int is_straight = 0; /* does it contain straight segments? */ 1102 1103 1104 seg = edge->first; 1105 1106 do 1107 { 1108 FT_Bool is_serif; 1109 1110 1111 /* check for roundness of segment */ 1112 if ( seg->flags & AF_EDGE_ROUND ) 1113 is_round++; 1114 else 1115 is_straight++; 1116 1117 /* check for links -- if seg->serif is set, then seg->link must */ 1118 /* be ignored */ 1119 is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge ); 1120 1121 if ( seg->link || is_serif ) 1122 { 1123 AF_Edge edge2; 1124 AF_Segment seg2; 1125 1126 1127 edge2 = edge->link; 1128 seg2 = seg->link; 1129 1130 if ( is_serif ) 1131 { 1132 seg2 = seg->serif; 1133 edge2 = edge->serif; 1134 } 1135 1136 if ( edge2 ) 1137 { 1138 FT_Pos edge_delta; 1139 FT_Pos seg_delta; 1140 1141 1142 edge_delta = edge->fpos - edge2->fpos; 1143 if ( edge_delta < 0 ) 1144 edge_delta = -edge_delta; 1145 1146 seg_delta = AF_SEGMENT_DIST( seg, seg2 ); 1147 1148 if ( seg_delta < edge_delta ) 1149 edge2 = seg2->edge; 1150 } 1151 else 1152 edge2 = seg2->edge; 1153 1154 if ( is_serif ) 1155 { 1156 edge->serif = edge2; 1157 edge2->flags |= AF_EDGE_SERIF; 1158 } 1159 else 1160 edge->link = edge2; 1161 } 1162 1163 seg = seg->edge_next; 1164 1165 } while ( seg != edge->first ); 1166 1167 /* set the round/straight flags */ 1168 edge->flags = AF_EDGE_NORMAL; 1169 1170 if ( is_round > 0 && is_round >= is_straight ) 1171 edge->flags |= AF_EDGE_ROUND; 1172 1173 /* get rid of serifs if link is set */ 1174 /* XXX: This gets rid of many unpleasant artefacts! */ 1175 /* Example: the `c' in cour.pfa at size 13 */ 1176 1177 if ( edge->serif && edge->link ) 1178 edge->serif = NULL; 1179 } 1180 } 1181 1182 Exit: 1183 return error; 1184 } 1185 1186 1187 /* Detect segments and edges for given dimension. */ 1188 1189 static FT_Error 1190 af_cjk_hints_detect_features( AF_GlyphHints hints, 1191 AF_Dimension dim ) 1192 { 1193 FT_Error error; 1194 1195 1196 error = af_cjk_hints_compute_segments( hints, dim ); 1197 if ( !error ) 1198 { 1199 af_cjk_hints_link_segments( hints, dim ); 1200 1201 error = af_cjk_hints_compute_edges( hints, dim ); 1202 } 1203 return error; 1204 } 1205 1206 1207 /* Compute all edges which lie within blue zones. */ 1208 1209 static void 1210 af_cjk_hints_compute_blue_edges( AF_GlyphHints hints, 1211 AF_CJKMetrics metrics, 1212 AF_Dimension dim ) 1213 { 1214 AF_AxisHints axis = &hints->axis[dim]; 1215 AF_Edge edge = axis->edges; 1216 AF_Edge edge_limit = edge + axis->num_edges; 1217 AF_CJKAxis cjk = &metrics->axis[dim]; 1218 FT_Fixed scale = cjk->scale; 1219 FT_Pos best_dist0; /* initial threshold */ 1220 1221 1222 /* compute the initial threshold as a fraction of the EM size */ 1223 best_dist0 = FT_MulFix( metrics->units_per_em / 40, scale ); 1224 1225 if ( best_dist0 > 64 / 2 ) /* maximum 1/2 pixel */ 1226 best_dist0 = 64 / 2; 1227 1228 /* compute which blue zones are active, i.e. have their scaled */ 1229 /* size < 3/4 pixels */ 1230 1231 /* If the distant between an edge and a blue zone is shorter than */ 1232 /* best_dist0, set the blue zone for the edge. Then search for */ 1233 /* the blue zone with the smallest best_dist to the edge. */ 1234 1235 for ( ; edge < edge_limit; edge++ ) 1236 { 1237 FT_UInt bb; 1238 AF_Width best_blue = NULL; 1239 FT_Pos best_dist = best_dist0; 1240 1241 1242 for ( bb = 0; bb < cjk->blue_count; bb++ ) 1243 { 1244 AF_CJKBlue blue = cjk->blues + bb; 1245 FT_Bool is_top_right_blue, is_major_dir; 1246 1247 1248 /* skip inactive blue zones (i.e., those that are too small) */ 1249 if ( !( blue->flags & AF_CJK_BLUE_ACTIVE ) ) 1250 continue; 1251 1252 /* if it is a top zone, check for right edges -- if it is a bottom */ 1253 /* zone, check for left edges */ 1254 /* */ 1255 /* of course, that's for TrueType */ 1256 is_top_right_blue = 1257 (FT_Byte)( ( blue->flags & AF_CJK_BLUE_TOP ) != 0 ); 1258 is_major_dir = 1259 FT_BOOL( edge->dir == axis->major_dir ); 1260 1261 /* if it is a top zone, the edge must be against the major */ 1262 /* direction; if it is a bottom zone, it must be in the major */ 1263 /* direction */ 1264 if ( is_top_right_blue ^ is_major_dir ) 1265 { 1266 FT_Pos dist; 1267 AF_Width compare; 1268 1269 1270 /* Compare the edge to the closest blue zone type */ 1271 if ( FT_ABS( edge->fpos - blue->ref.org ) > 1272 FT_ABS( edge->fpos - blue->shoot.org ) ) 1273 compare = &blue->shoot; 1274 else 1275 compare = &blue->ref; 1276 1277 dist = edge->fpos - compare->org; 1278 if ( dist < 0 ) 1279 dist = -dist; 1280 1281 dist = FT_MulFix( dist, scale ); 1282 if ( dist < best_dist ) 1283 { 1284 best_dist = dist; 1285 best_blue = compare; 1286 } 1287 } 1288 } 1289 1290 if ( best_blue ) 1291 edge->blue_edge = best_blue; 1292 } 1293 } 1294 1295 1296 /* Initalize hinting engine. */ 1297 1298 FT_LOCAL_DEF( FT_Error ) 1299 af_cjk_hints_init( AF_GlyphHints hints, 1300 AF_CJKMetrics metrics ) 1301 { 1302 FT_Render_Mode mode; 1303 FT_UInt32 scaler_flags, other_flags; 1304 1305 1306 af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics ); 1307 1308 /* 1309 * correct x_scale and y_scale when needed, since they may have 1310 * been modified af_cjk_scale_dim above 1311 */ 1312 hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale; 1313 hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta; 1314 hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale; 1315 hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta; 1316 1317 /* compute flags depending on render mode, etc. */ 1318 mode = metrics->root.scaler.render_mode; 1319 1320 #if 0 /* AF_CONFIG_OPTION_USE_WARPER */ 1321 if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V ) 1322 metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL; 1323 #endif 1324 1325 scaler_flags = hints->scaler_flags; 1326 other_flags = 0; 1327 1328 /* 1329 * We snap the width of vertical stems for the monochrome and 1330 * horizontal LCD rendering targets only. 1331 */ 1332 if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD ) 1333 other_flags |= AF_LATIN_HINTS_HORZ_SNAP; 1334 1335 /* 1336 * We snap the width of horizontal stems for the monochrome and 1337 * vertical LCD rendering targets only. 1338 */ 1339 if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V ) 1340 other_flags |= AF_LATIN_HINTS_VERT_SNAP; 1341 1342 /* 1343 * We adjust stems to full pixels only if we don't use the `light' mode. 1344 */ 1345 if ( mode != FT_RENDER_MODE_LIGHT ) 1346 other_flags |= AF_LATIN_HINTS_STEM_ADJUST; 1347 1348 if ( mode == FT_RENDER_MODE_MONO ) 1349 other_flags |= AF_LATIN_HINTS_MONO; 1350 1351 scaler_flags |= AF_SCALER_FLAG_NO_ADVANCE; 1352 1353 #ifdef AF_CONFIG_OPTION_USE_WARPER 1354 /* get (global) warper flag */ 1355 if ( !metrics->root.globals->module->warping ) 1356 scaler_flags |= AF_SCALER_FLAG_NO_WARPER; 1357 #endif 1358 1359 hints->scaler_flags = scaler_flags; 1360 hints->other_flags = other_flags; 1361 1362 return FT_Err_Ok; 1363 } 1364 1365 1366 /*************************************************************************/ 1367 /*************************************************************************/ 1368 /***** *****/ 1369 /***** C J K G L Y P H G R I D - F I T T I N G *****/ 1370 /***** *****/ 1371 /*************************************************************************/ 1372 /*************************************************************************/ 1373 1374 /* Snap a given width in scaled coordinates to one of the */ 1375 /* current standard widths. */ 1376 1377 static FT_Pos 1378 af_cjk_snap_width( AF_Width widths, 1379 FT_UInt count, 1380 FT_Pos width ) 1381 { 1382 FT_UInt n; 1383 FT_Pos best = 64 + 32 + 2; 1384 FT_Pos reference = width; 1385 FT_Pos scaled; 1386 1387 1388 for ( n = 0; n < count; n++ ) 1389 { 1390 FT_Pos w; 1391 FT_Pos dist; 1392 1393 1394 w = widths[n].cur; 1395 dist = width - w; 1396 if ( dist < 0 ) 1397 dist = -dist; 1398 if ( dist < best ) 1399 { 1400 best = dist; 1401 reference = w; 1402 } 1403 } 1404 1405 scaled = FT_PIX_ROUND( reference ); 1406 1407 if ( width >= reference ) 1408 { 1409 if ( width < scaled + 48 ) 1410 width = reference; 1411 } 1412 else 1413 { 1414 if ( width > scaled - 48 ) 1415 width = reference; 1416 } 1417 1418 return width; 1419 } 1420 1421 1422 /* Compute the snapped width of a given stem. */ 1423 /* There is a lot of voodoo in this function; changing the hard-coded */ 1424 /* parameters influence the whole hinting process. */ 1425 1426 static FT_Pos 1427 af_cjk_compute_stem_width( AF_GlyphHints hints, 1428 AF_Dimension dim, 1429 FT_Pos width, 1430 FT_UInt base_flags, 1431 FT_UInt stem_flags ) 1432 { 1433 AF_CJKMetrics metrics = (AF_CJKMetrics)hints->metrics; 1434 AF_CJKAxis axis = &metrics->axis[dim]; 1435 FT_Pos dist = width; 1436 FT_Int sign = 0; 1437 FT_Bool vertical = FT_BOOL( dim == AF_DIMENSION_VERT ); 1438 1439 FT_UNUSED( base_flags ); 1440 FT_UNUSED( stem_flags ); 1441 1442 1443 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ) 1444 return width; 1445 1446 if ( dist < 0 ) 1447 { 1448 dist = -width; 1449 sign = 1; 1450 } 1451 1452 if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) || 1453 ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ) 1454 { 1455 /* smooth hinting process: very lightly quantize the stem width */ 1456 1457 if ( axis->width_count > 0 ) 1458 { 1459 if ( FT_ABS( dist - axis->widths[0].cur ) < 40 ) 1460 { 1461 dist = axis->widths[0].cur; 1462 if ( dist < 48 ) 1463 dist = 48; 1464 1465 goto Done_Width; 1466 } 1467 } 1468 1469 if ( dist < 54 ) 1470 dist += ( 54 - dist ) / 2 ; 1471 else if ( dist < 3 * 64 ) 1472 { 1473 FT_Pos delta; 1474 1475 1476 delta = dist & 63; 1477 dist &= -64; 1478 1479 if ( delta < 10 ) 1480 dist += delta; 1481 else if ( delta < 22 ) 1482 dist += 10; 1483 else if ( delta < 42 ) 1484 dist += delta; 1485 else if ( delta < 54 ) 1486 dist += 54; 1487 else 1488 dist += delta; 1489 } 1490 } 1491 else 1492 { 1493 /* strong hinting process: snap the stem width to integer pixels */ 1494 1495 dist = af_cjk_snap_width( axis->widths, axis->width_count, dist ); 1496 1497 if ( vertical ) 1498 { 1499 /* in the case of vertical hinting, always round */ 1500 /* the stem heights to integer pixels */ 1501 1502 if ( dist >= 64 ) 1503 dist = ( dist + 16 ) & ~63; 1504 else 1505 dist = 64; 1506 } 1507 else 1508 { 1509 if ( AF_LATIN_HINTS_DO_MONO( hints ) ) 1510 { 1511 /* monochrome horizontal hinting: snap widths to integer pixels */ 1512 /* with a different threshold */ 1513 1514 if ( dist < 64 ) 1515 dist = 64; 1516 else 1517 dist = ( dist + 32 ) & ~63; 1518 } 1519 else 1520 { 1521 /* for horizontal anti-aliased hinting, we adopt a more subtle */ 1522 /* approach: we strengthen small stems, round stems whose size */ 1523 /* is between 1 and 2 pixels to an integer, otherwise nothing */ 1524 1525 if ( dist < 48 ) 1526 dist = ( dist + 64 ) >> 1; 1527 1528 else if ( dist < 128 ) 1529 dist = ( dist + 22 ) & ~63; 1530 else 1531 /* round otherwise to prevent color fringes in LCD mode */ 1532 dist = ( dist + 32 ) & ~63; 1533 } 1534 } 1535 } 1536 1537 Done_Width: 1538 if ( sign ) 1539 dist = -dist; 1540 1541 return dist; 1542 } 1543 1544 1545 /* Align one stem edge relative to the previous stem edge. */ 1546 1547 static void 1548 af_cjk_align_linked_edge( AF_GlyphHints hints, 1549 AF_Dimension dim, 1550 AF_Edge base_edge, 1551 AF_Edge stem_edge ) 1552 { 1553 FT_Pos dist = stem_edge->opos - base_edge->opos; 1554 1555 FT_Pos fitted_width = af_cjk_compute_stem_width( hints, dim, dist, 1556 base_edge->flags, 1557 stem_edge->flags ); 1558 1559 1560 stem_edge->pos = base_edge->pos + fitted_width; 1561 1562 FT_TRACE5(( " CJKLINK: edge %d @%d (opos=%.2f) linked to %.2f," 1563 " dist was %.2f, now %.2f\n", 1564 stem_edge - hints->axis[dim].edges, stem_edge->fpos, 1565 stem_edge->opos / 64.0, stem_edge->pos / 64.0, 1566 dist / 64.0, fitted_width / 64.0 )); 1567 } 1568 1569 1570 /* Shift the coordinates of the `serif' edge by the same amount */ 1571 /* as the corresponding `base' edge has been moved already. */ 1572 1573 static void 1574 af_cjk_align_serif_edge( AF_GlyphHints hints, 1575 AF_Edge base, 1576 AF_Edge serif ) 1577 { 1578 FT_UNUSED( hints ); 1579 1580 serif->pos = base->pos + ( serif->opos - base->opos ); 1581 } 1582 1583 1584 /*************************************************************************/ 1585 /*************************************************************************/ 1586 /*************************************************************************/ 1587 /**** ****/ 1588 /**** E D G E H I N T I N G ****/ 1589 /**** ****/ 1590 /*************************************************************************/ 1591 /*************************************************************************/ 1592 /*************************************************************************/ 1593 1594 1595 #define AF_LIGHT_MODE_MAX_HORZ_GAP 9 1596 #define AF_LIGHT_MODE_MAX_VERT_GAP 15 1597 #define AF_LIGHT_MODE_MAX_DELTA_ABS 14 1598 1599 1600 static FT_Pos 1601 af_hint_normal_stem( AF_GlyphHints hints, 1602 AF_Edge edge, 1603 AF_Edge edge2, 1604 FT_Pos anchor, 1605 AF_Dimension dim ) 1606 { 1607 FT_Pos org_len, cur_len, org_center; 1608 FT_Pos cur_pos1, cur_pos2; 1609 FT_Pos d_off1, u_off1, d_off2, u_off2, delta; 1610 FT_Pos offset; 1611 FT_Pos threshold = 64; 1612 1613 1614 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ) 1615 { 1616 if ( ( edge->flags & AF_EDGE_ROUND ) && 1617 ( edge2->flags & AF_EDGE_ROUND ) ) 1618 { 1619 if ( dim == AF_DIMENSION_VERT ) 1620 threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP; 1621 else 1622 threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP; 1623 } 1624 else 1625 { 1626 if ( dim == AF_DIMENSION_VERT ) 1627 threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP / 3; 1628 else 1629 threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP / 3; 1630 } 1631 } 1632 1633 org_len = edge2->opos - edge->opos; 1634 cur_len = af_cjk_compute_stem_width( hints, dim, org_len, 1635 edge->flags, 1636 edge2->flags ); 1637 1638 org_center = ( edge->opos + edge2->opos ) / 2 + anchor; 1639 cur_pos1 = org_center - cur_len / 2; 1640 cur_pos2 = cur_pos1 + cur_len; 1641 d_off1 = cur_pos1 - FT_PIX_FLOOR( cur_pos1 ); 1642 d_off2 = cur_pos2 - FT_PIX_FLOOR( cur_pos2 ); 1643 u_off1 = 64 - d_off1; 1644 u_off2 = 64 - d_off2; 1645 delta = 0; 1646 1647 1648 if ( d_off1 == 0 || d_off2 == 0 ) 1649 goto Exit; 1650 1651 if ( cur_len <= threshold ) 1652 { 1653 if ( d_off2 < cur_len ) 1654 { 1655 if ( u_off1 <= d_off2 ) 1656 delta = u_off1; 1657 else 1658 delta = -d_off2; 1659 } 1660 1661 goto Exit; 1662 } 1663 1664 if ( threshold < 64 ) 1665 { 1666 if ( d_off1 >= threshold || u_off1 >= threshold || 1667 d_off2 >= threshold || u_off2 >= threshold ) 1668 goto Exit; 1669 } 1670 1671 offset = cur_len & 63; 1672 1673 if ( offset < 32 ) 1674 { 1675 if ( u_off1 <= offset || d_off2 <= offset ) 1676 goto Exit; 1677 } 1678 else 1679 offset = 64 - threshold; 1680 1681 d_off1 = threshold - u_off1; 1682 u_off1 = u_off1 - offset; 1683 u_off2 = threshold - d_off2; 1684 d_off2 = d_off2 - offset; 1685 1686 if ( d_off1 <= u_off1 ) 1687 u_off1 = -d_off1; 1688 1689 if ( d_off2 <= u_off2 ) 1690 u_off2 = -d_off2; 1691 1692 if ( FT_ABS( u_off1 ) <= FT_ABS( u_off2 ) ) 1693 delta = u_off1; 1694 else 1695 delta = u_off2; 1696 1697 Exit: 1698 1699 #if 1 1700 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ) 1701 { 1702 if ( delta > AF_LIGHT_MODE_MAX_DELTA_ABS ) 1703 delta = AF_LIGHT_MODE_MAX_DELTA_ABS; 1704 else if ( delta < -AF_LIGHT_MODE_MAX_DELTA_ABS ) 1705 delta = -AF_LIGHT_MODE_MAX_DELTA_ABS; 1706 } 1707 #endif 1708 1709 cur_pos1 += delta; 1710 1711 if ( edge->opos < edge2->opos ) 1712 { 1713 edge->pos = cur_pos1; 1714 edge2->pos = cur_pos1 + cur_len; 1715 } 1716 else 1717 { 1718 edge->pos = cur_pos1 + cur_len; 1719 edge2->pos = cur_pos1; 1720 } 1721 1722 return delta; 1723 } 1724 1725 1726 /* The main grid-fitting routine. */ 1727 1728 static void 1729 af_cjk_hint_edges( AF_GlyphHints hints, 1730 AF_Dimension dim ) 1731 { 1732 AF_AxisHints axis = &hints->axis[dim]; 1733 AF_Edge edges = axis->edges; 1734 AF_Edge edge_limit = edges + axis->num_edges; 1735 FT_PtrDist n_edges; 1736 AF_Edge edge; 1737 AF_Edge anchor = NULL; 1738 FT_Pos delta = 0; 1739 FT_Int skipped = 0; 1740 FT_Bool has_last_stem = FALSE; 1741 FT_Pos last_stem_pos = 0; 1742 1743 #ifdef FT_DEBUG_LEVEL_TRACE 1744 FT_UInt num_actions = 0; 1745 #endif 1746 1747 1748 FT_TRACE5(( "cjk %s edge hinting (style `%s')\n", 1749 dim == AF_DIMENSION_VERT ? "horizontal" : "vertical", 1750 af_style_names[hints->metrics->style_class->style] )); 1751 1752 /* we begin by aligning all stems relative to the blue zone */ 1753 1754 if ( AF_HINTS_DO_BLUES( hints ) ) 1755 { 1756 for ( edge = edges; edge < edge_limit; edge++ ) 1757 { 1758 AF_Width blue; 1759 AF_Edge edge1, edge2; 1760 1761 1762 if ( edge->flags & AF_EDGE_DONE ) 1763 continue; 1764 1765 blue = edge->blue_edge; 1766 edge1 = NULL; 1767 edge2 = edge->link; 1768 1769 if ( blue ) 1770 { 1771 edge1 = edge; 1772 } 1773 else if ( edge2 && edge2->blue_edge ) 1774 { 1775 blue = edge2->blue_edge; 1776 edge1 = edge2; 1777 edge2 = edge; 1778 } 1779 1780 if ( !edge1 ) 1781 continue; 1782 1783 #ifdef FT_DEBUG_LEVEL_TRACE 1784 FT_TRACE5(( " CJKBLUE: edge %d @%d (opos=%.2f) snapped to %.2f," 1785 " was %.2f\n", 1786 edge1 - edges, edge1->fpos, edge1->opos / 64.0, 1787 blue->fit / 64.0, edge1->pos / 64.0 )); 1788 1789 num_actions++; 1790 #endif 1791 1792 edge1->pos = blue->fit; 1793 edge1->flags |= AF_EDGE_DONE; 1794 1795 if ( edge2 && !edge2->blue_edge ) 1796 { 1797 af_cjk_align_linked_edge( hints, dim, edge1, edge2 ); 1798 edge2->flags |= AF_EDGE_DONE; 1799 1800 #ifdef FT_DEBUG_LEVEL_TRACE 1801 num_actions++; 1802 #endif 1803 } 1804 1805 if ( !anchor ) 1806 anchor = edge; 1807 } 1808 } 1809 1810 /* now we align all stem edges. */ 1811 for ( edge = edges; edge < edge_limit; edge++ ) 1812 { 1813 AF_Edge edge2; 1814 1815 1816 if ( edge->flags & AF_EDGE_DONE ) 1817 continue; 1818 1819 /* skip all non-stem edges */ 1820 edge2 = edge->link; 1821 if ( !edge2 ) 1822 { 1823 skipped++; 1824 continue; 1825 } 1826 1827 /* Some CJK characters have so many stems that 1828 * the hinter is likely to merge two adjacent ones. 1829 * To solve this problem, if either edge of a stem 1830 * is too close to the previous one, we avoid 1831 * aligning the two edges, but rather interpolate 1832 * their locations at the end of this function in 1833 * order to preserve the space between the stems. 1834 */ 1835 if ( has_last_stem && 1836 ( edge->pos < last_stem_pos + 64 || 1837 edge2->pos < last_stem_pos + 64 ) ) 1838 { 1839 skipped++; 1840 continue; 1841 } 1842 1843 /* now align the stem */ 1844 1845 /* this should not happen, but it's better to be safe */ 1846 if ( edge2->blue_edge ) 1847 { 1848 FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges )); 1849 1850 af_cjk_align_linked_edge( hints, dim, edge2, edge ); 1851 edge->flags |= AF_EDGE_DONE; 1852 1853 #ifdef FT_DEBUG_LEVEL_TRACE 1854 num_actions++; 1855 #endif 1856 1857 continue; 1858 } 1859 1860 if ( edge2 < edge ) 1861 { 1862 af_cjk_align_linked_edge( hints, dim, edge2, edge ); 1863 edge->flags |= AF_EDGE_DONE; 1864 1865 #ifdef FT_DEBUG_LEVEL_TRACE 1866 num_actions++; 1867 #endif 1868 1869 /* We rarely reaches here it seems; 1870 * usually the two edges belonging 1871 * to one stem are marked as DONE together 1872 */ 1873 has_last_stem = TRUE; 1874 last_stem_pos = edge->pos; 1875 continue; 1876 } 1877 1878 if ( dim != AF_DIMENSION_VERT && !anchor ) 1879 { 1880 1881 #if 0 1882 if ( fixedpitch ) 1883 { 1884 AF_Edge left = edge; 1885 AF_Edge right = edge_limit - 1; 1886 AF_EdgeRec left1, left2, right1, right2; 1887 FT_Pos target, center1, center2; 1888 FT_Pos delta1, delta2, d1, d2; 1889 1890 1891 while ( right > left && !right->link ) 1892 right--; 1893 1894 left1 = *left; 1895 left2 = *left->link; 1896 right1 = *right->link; 1897 right2 = *right; 1898 1899 delta = ( ( ( hinter->pp2.x + 32 ) & -64 ) - hinter->pp2.x ) / 2; 1900 target = left->opos + ( right->opos - left->opos ) / 2 + delta - 16; 1901 1902 delta1 = delta; 1903 delta1 += af_hint_normal_stem( hints, left, left->link, 1904 delta1, 0 ); 1905 1906 if ( left->link != right ) 1907 af_hint_normal_stem( hints, right->link, right, delta1, 0 ); 1908 1909 center1 = left->pos + ( right->pos - left->pos ) / 2; 1910 1911 if ( center1 >= target ) 1912 delta2 = delta - 32; 1913 else 1914 delta2 = delta + 32; 1915 1916 delta2 += af_hint_normal_stem( hints, &left1, &left2, delta2, 0 ); 1917 1918 if ( delta1 != delta2 ) 1919 { 1920 if ( left->link != right ) 1921 af_hint_normal_stem( hints, &right1, &right2, delta2, 0 ); 1922 1923 center2 = left1.pos + ( right2.pos - left1.pos ) / 2; 1924 1925 d1 = center1 - target; 1926 d2 = center2 - target; 1927 1928 if ( FT_ABS( d2 ) < FT_ABS( d1 ) ) 1929 { 1930 left->pos = left1.pos; 1931 left->link->pos = left2.pos; 1932 1933 if ( left->link != right ) 1934 { 1935 right->link->pos = right1.pos; 1936 right->pos = right2.pos; 1937 } 1938 1939 delta1 = delta2; 1940 } 1941 } 1942 1943 delta = delta1; 1944 right->link->flags |= AF_EDGE_DONE; 1945 right->flags |= AF_EDGE_DONE; 1946 } 1947 else 1948 1949 #endif /* 0 */ 1950 1951 delta = af_hint_normal_stem( hints, edge, edge2, 0, 1952 AF_DIMENSION_HORZ ); 1953 } 1954 else 1955 af_hint_normal_stem( hints, edge, edge2, delta, dim ); 1956 1957 #if 0 1958 printf( "stem (%d,%d) adjusted (%.1f,%.1f)\n", 1959 edge - edges, edge2 - edges, 1960 ( edge->pos - edge->opos ) / 64.0, 1961 ( edge2->pos - edge2->opos ) / 64.0 ); 1962 #endif 1963 1964 anchor = edge; 1965 edge->flags |= AF_EDGE_DONE; 1966 edge2->flags |= AF_EDGE_DONE; 1967 has_last_stem = TRUE; 1968 last_stem_pos = edge2->pos; 1969 } 1970 1971 /* make sure that lowercase m's maintain their symmetry */ 1972 1973 /* In general, lowercase m's have six vertical edges if they are sans */ 1974 /* serif, or twelve if they are with serifs. This implementation is */ 1975 /* based on that assumption, and seems to work very well with most */ 1976 /* faces. However, if for a certain face this assumption is not */ 1977 /* true, the m is just rendered like before. In addition, any stem */ 1978 /* correction will only be applied to symmetrical glyphs (even if the */ 1979 /* glyph is not an m), so the potential for unwanted distortion is */ 1980 /* relatively low. */ 1981 1982 /* We don't handle horizontal edges since we can't easily assure that */ 1983 /* the third (lowest) stem aligns with the base line; it might end up */ 1984 /* one pixel higher or lower. */ 1985 1986 n_edges = edge_limit - edges; 1987 if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) ) 1988 { 1989 AF_Edge edge1, edge2, edge3; 1990 FT_Pos dist1, dist2, span; 1991 1992 1993 if ( n_edges == 6 ) 1994 { 1995 edge1 = edges; 1996 edge2 = edges + 2; 1997 edge3 = edges + 4; 1998 } 1999 else 2000 { 2001 edge1 = edges + 1; 2002 edge2 = edges + 5; 2003 edge3 = edges + 9; 2004 } 2005 2006 dist1 = edge2->opos - edge1->opos; 2007 dist2 = edge3->opos - edge2->opos; 2008 2009 span = dist1 - dist2; 2010 if ( span < 0 ) 2011 span = -span; 2012 2013 if ( edge1->link == edge1 + 1 && 2014 edge2->link == edge2 + 1 && 2015 edge3->link == edge3 + 1 && span < 8 ) 2016 { 2017 delta = edge3->pos - ( 2 * edge2->pos - edge1->pos ); 2018 edge3->pos -= delta; 2019 if ( edge3->link ) 2020 edge3->link->pos -= delta; 2021 2022 /* move the serifs along with the stem */ 2023 if ( n_edges == 12 ) 2024 { 2025 ( edges + 8 )->pos -= delta; 2026 ( edges + 11 )->pos -= delta; 2027 } 2028 2029 edge3->flags |= AF_EDGE_DONE; 2030 if ( edge3->link ) 2031 edge3->link->flags |= AF_EDGE_DONE; 2032 } 2033 } 2034 2035 if ( !skipped ) 2036 goto Exit; 2037 2038 /* 2039 * now hint the remaining edges (serifs and single) in order 2040 * to complete our processing 2041 */ 2042 for ( edge = edges; edge < edge_limit; edge++ ) 2043 { 2044 if ( edge->flags & AF_EDGE_DONE ) 2045 continue; 2046 2047 if ( edge->serif ) 2048 { 2049 af_cjk_align_serif_edge( hints, edge->serif, edge ); 2050 edge->flags |= AF_EDGE_DONE; 2051 skipped--; 2052 } 2053 } 2054 2055 if ( !skipped ) 2056 goto Exit; 2057 2058 for ( edge = edges; edge < edge_limit; edge++ ) 2059 { 2060 AF_Edge before, after; 2061 2062 2063 if ( edge->flags & AF_EDGE_DONE ) 2064 continue; 2065 2066 before = after = edge; 2067 2068 while ( --before >= edges ) 2069 if ( before->flags & AF_EDGE_DONE ) 2070 break; 2071 2072 while ( ++after < edge_limit ) 2073 if ( after->flags & AF_EDGE_DONE ) 2074 break; 2075 2076 if ( before >= edges || after < edge_limit ) 2077 { 2078 if ( before < edges ) 2079 af_cjk_align_serif_edge( hints, after, edge ); 2080 else if ( after >= edge_limit ) 2081 af_cjk_align_serif_edge( hints, before, edge ); 2082 else 2083 { 2084 if ( after->fpos == before->fpos ) 2085 edge->pos = before->pos; 2086 else 2087 edge->pos = before->pos + 2088 FT_MulDiv( edge->fpos - before->fpos, 2089 after->pos - before->pos, 2090 after->fpos - before->fpos ); 2091 } 2092 } 2093 } 2094 2095 Exit: 2096 2097 #ifdef FT_DEBUG_LEVEL_TRACE 2098 if ( !num_actions ) 2099 FT_TRACE5(( " (none)\n" )); 2100 FT_TRACE5(( "\n" )); 2101 #endif 2102 2103 return; 2104 } 2105 2106 2107 static void 2108 af_cjk_align_edge_points( AF_GlyphHints hints, 2109 AF_Dimension dim ) 2110 { 2111 AF_AxisHints axis = & hints->axis[dim]; 2112 AF_Edge edges = axis->edges; 2113 AF_Edge edge_limit = edges + axis->num_edges; 2114 AF_Edge edge; 2115 FT_Bool snapping; 2116 2117 2118 snapping = FT_BOOL( ( dim == AF_DIMENSION_HORZ && 2119 AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) || 2120 ( dim == AF_DIMENSION_VERT && 2121 AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ); 2122 2123 for ( edge = edges; edge < edge_limit; edge++ ) 2124 { 2125 /* move the points of each segment */ 2126 /* in each edge to the edge's position */ 2127 AF_Segment seg = edge->first; 2128 2129 2130 if ( snapping ) 2131 { 2132 do 2133 { 2134 AF_Point point = seg->first; 2135 2136 2137 for (;;) 2138 { 2139 if ( dim == AF_DIMENSION_HORZ ) 2140 { 2141 point->x = edge->pos; 2142 point->flags |= AF_FLAG_TOUCH_X; 2143 } 2144 else 2145 { 2146 point->y = edge->pos; 2147 point->flags |= AF_FLAG_TOUCH_Y; 2148 } 2149 2150 if ( point == seg->last ) 2151 break; 2152 2153 point = point->next; 2154 } 2155 2156 seg = seg->edge_next; 2157 2158 } while ( seg != edge->first ); 2159 } 2160 else 2161 { 2162 FT_Pos delta = edge->pos - edge->opos; 2163 2164 2165 do 2166 { 2167 AF_Point point = seg->first; 2168 2169 2170 for (;;) 2171 { 2172 if ( dim == AF_DIMENSION_HORZ ) 2173 { 2174 point->x += delta; 2175 point->flags |= AF_FLAG_TOUCH_X; 2176 } 2177 else 2178 { 2179 point->y += delta; 2180 point->flags |= AF_FLAG_TOUCH_Y; 2181 } 2182 2183 if ( point == seg->last ) 2184 break; 2185 2186 point = point->next; 2187 } 2188 2189 seg = seg->edge_next; 2190 2191 } while ( seg != edge->first ); 2192 } 2193 } 2194 } 2195 2196 2197 /* Apply the complete hinting algorithm to a CJK glyph. */ 2198 2199 FT_LOCAL_DEF( FT_Error ) 2200 af_cjk_hints_apply( FT_UInt glyph_index, 2201 AF_GlyphHints hints, 2202 FT_Outline* outline, 2203 AF_CJKMetrics metrics ) 2204 { 2205 FT_Error error; 2206 int dim; 2207 2208 FT_UNUSED( metrics ); 2209 FT_UNUSED( glyph_index ); 2210 2211 2212 error = af_glyph_hints_reload( hints, outline ); 2213 if ( error ) 2214 goto Exit; 2215 2216 /* analyze glyph outline */ 2217 #ifdef AF_CONFIG_OPTION_USE_WARPER 2218 if ( ( metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT && 2219 AF_HINTS_DO_WARP( hints ) ) || 2220 AF_HINTS_DO_HORIZONTAL( hints ) ) 2221 #else 2222 if ( AF_HINTS_DO_HORIZONTAL( hints ) ) 2223 #endif 2224 { 2225 error = af_cjk_hints_detect_features( hints, AF_DIMENSION_HORZ ); 2226 if ( error ) 2227 goto Exit; 2228 2229 af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_HORZ ); 2230 } 2231 2232 if ( AF_HINTS_DO_VERTICAL( hints ) ) 2233 { 2234 error = af_cjk_hints_detect_features( hints, AF_DIMENSION_VERT ); 2235 if ( error ) 2236 goto Exit; 2237 2238 af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_VERT ); 2239 } 2240 2241 /* grid-fit the outline */ 2242 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) 2243 { 2244 if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) || 2245 ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) ) 2246 { 2247 2248 #ifdef AF_CONFIG_OPTION_USE_WARPER 2249 if ( dim == AF_DIMENSION_HORZ && 2250 metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT && 2251 AF_HINTS_DO_WARP( hints ) ) 2252 { 2253 AF_WarperRec warper; 2254 FT_Fixed scale; 2255 FT_Pos delta; 2256 2257 2258 af_warper_compute( &warper, hints, (AF_Dimension)dim, 2259 &scale, &delta ); 2260 af_glyph_hints_scale_dim( hints, (AF_Dimension)dim, 2261 scale, delta ); 2262 continue; 2263 } 2264 #endif /* AF_CONFIG_OPTION_USE_WARPER */ 2265 2266 af_cjk_hint_edges( hints, (AF_Dimension)dim ); 2267 af_cjk_align_edge_points( hints, (AF_Dimension)dim ); 2268 af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim ); 2269 af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim ); 2270 } 2271 } 2272 2273 af_glyph_hints_save( hints, outline ); 2274 2275 Exit: 2276 return error; 2277 } 2278 2279 2280 /*************************************************************************/ 2281 /*************************************************************************/ 2282 /***** *****/ 2283 /***** C J K S C R I P T C L A S S *****/ 2284 /***** *****/ 2285 /*************************************************************************/ 2286 /*************************************************************************/ 2287 2288 2289 AF_DEFINE_WRITING_SYSTEM_CLASS( 2290 af_cjk_writing_system_class, 2291 2292 AF_WRITING_SYSTEM_CJK, 2293 2294 sizeof ( AF_CJKMetricsRec ), 2295 2296 (AF_WritingSystem_InitMetricsFunc) af_cjk_metrics_init, 2297 (AF_WritingSystem_ScaleMetricsFunc)af_cjk_metrics_scale, 2298 (AF_WritingSystem_DoneMetricsFunc) NULL, 2299 (AF_WritingSystem_GetStdWidthsFunc)af_cjk_get_standard_widths, 2300 2301 (AF_WritingSystem_InitHintsFunc) af_cjk_hints_init, 2302 (AF_WritingSystem_ApplyHintsFunc) af_cjk_hints_apply 2303 ) 2304 2305 2306 #else /* !AF_CONFIG_OPTION_CJK */ 2307 2308 2309 AF_DEFINE_WRITING_SYSTEM_CLASS( 2310 af_cjk_writing_system_class, 2311 2312 AF_WRITING_SYSTEM_CJK, 2313 2314 sizeof ( AF_CJKMetricsRec ), 2315 2316 (AF_WritingSystem_InitMetricsFunc) NULL, 2317 (AF_WritingSystem_ScaleMetricsFunc)NULL, 2318 (AF_WritingSystem_DoneMetricsFunc) NULL, 2319 (AF_WritingSystem_GetStdWidthsFunc)NULL, 2320 2321 (AF_WritingSystem_InitHintsFunc) NULL, 2322 (AF_WritingSystem_ApplyHintsFunc) NULL 2323 ) 2324 2325 2326 #endif /* !AF_CONFIG_OPTION_CJK */ 2327 2328 2329 /* END */ 2330