| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 #else | 433 #else |
| 434 // No embedding is 0x2 and bitmap embedding only is 0x200. | 434 // No embedding is 0x2 and bitmap embedding only is 0x200. |
| 435 TT_OS2* os2_table; | 435 TT_OS2* os2_table; |
| 436 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { | 436 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { |
| 437 return (os2_table->fsType & 0x202) == 0; | 437 return (os2_table->fsType & 0x202) == 0; |
| 438 } | 438 } |
| 439 return false; // We tried, fail safe. | 439 return false; // We tried, fail safe. |
| 440 #endif | 440 #endif |
| 441 } | 441 } |
| 442 | 442 |
| 443 static bool canSubset(FT_Face face) { |
| 444 #ifdef FT_FSTYPE_NO_SUBSETTING |
| 445 FT_UShort fsType = FT_Get_FSType_Flags(face); |
| 446 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0; |
| 447 #else |
| 448 // No subset is 0x100. |
| 449 TT_OS2* os2_table; |
| 450 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { |
| 451 return (os2_table->fsType & 0x100) == 0; |
| 452 } |
| 453 return false; // We tried, fail safe. |
| 454 #endif |
| 455 } |
| 456 |
| 443 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { | 457 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { |
| 444 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); | 458 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); |
| 445 if (!glyph_id) | 459 if (!glyph_id) |
| 446 return false; | 460 return false; |
| 447 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0) | 461 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0) |
| 448 return false; | 462 return false; |
| 449 FT_Outline_Get_CBox(&face->glyph->outline, bbox); | 463 FT_Outline_Get_CBox(&face->glyph->outline, bbox); |
| 450 return true; | 464 return true; |
| 451 } | 465 } |
| 452 | 466 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 return NULL; | 532 return NULL; |
| 519 #else | 533 #else |
| 520 AutoFTAccess fta(this); | 534 AutoFTAccess fta(this); |
| 521 FT_Face face = fta.face(); | 535 FT_Face face = fta.face(); |
| 522 if (!face) { | 536 if (!face) { |
| 523 return NULL; | 537 return NULL; |
| 524 } | 538 } |
| 525 | 539 |
| 526 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; | 540 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; |
| 527 info->fFontName.set(FT_Get_Postscript_Name(face)); | 541 info->fFontName.set(FT_Get_Postscript_Name(face)); |
| 528 info->fMultiMaster = FT_HAS_MULTIPLE_MASTERS(face); | 542 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; |
| 543 if (FT_HAS_MULTIPLE_MASTERS(face)) { |
| 544 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 545 info->fFlags, SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag); |
| 546 } |
| 547 if (!canEmbed(face)) { |
| 548 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 549 info->fFlags, |
| 550 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); |
| 551 } |
| 552 if (!canSubset(face)) { |
| 553 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 554 info->fFlags, |
| 555 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag); |
| 556 } |
| 529 info->fLastGlyphID = face->num_glyphs - 1; | 557 info->fLastGlyphID = face->num_glyphs - 1; |
| 530 info->fEmSize = 1000; | 558 info->fEmSize = 1000; |
| 531 | 559 |
| 532 bool cid = false; | 560 bool cid = false; |
| 533 const char* fontType = FT_Get_X11_Font_Format(face); | 561 const char* fontType = FT_Get_X11_Font_Format(face); |
| 534 if (strcmp(fontType, "Type 1") == 0) { | 562 if (strcmp(fontType, "Type 1") == 0) { |
| 535 info->fType = SkAdvancedTypefaceMetrics::kType1_Font; | 563 info->fType = SkAdvancedTypefaceMetrics::kType1_Font; |
| 536 } else if (strcmp(fontType, "CID Type 1") == 0) { | 564 } else if (strcmp(fontType, "CID Type 1") == 0) { |
| 537 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font; | 565 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font; |
| 538 cid = true; | 566 cid = true; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 info->fCapHeight = x_bbox.yMax - x_bbox.yMin; | 644 info->fCapHeight = x_bbox.yMax - x_bbox.yMin; |
| 617 } else { | 645 } else { |
| 618 // Last resort, use the ascent. | 646 // Last resort, use the ascent. |
| 619 info->fCapHeight = info->fAscent; | 647 info->fCapHeight = info->fAscent; |
| 620 } | 648 } |
| 621 } | 649 } |
| 622 | 650 |
| 623 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, | 651 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, |
| 624 face->bbox.xMax, face->bbox.yMin); | 652 face->bbox.xMax, face->bbox.yMin); |
| 625 | 653 |
| 626 if (!canEmbed(face) || !FT_IS_SCALABLE(face) || | 654 if (!FT_IS_SCALABLE(face)) { |
| 627 info->fType == SkAdvancedTypefaceMetrics::kOther_Font) { | |
| 628 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo; | 655 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo; |
| 629 } | 656 } |
| 630 | 657 |
| 631 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { | 658 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { |
| 632 if (FT_IS_FIXED_WIDTH(face)) { | 659 if (FT_IS_FIXED_WIDTH(face)) { |
| 633 appendRange(&info->fGlyphWidths, 0); | 660 appendRange(&info->fGlyphWidths, 0); |
| 634 int16_t advance = face->max_advance_width; | 661 int16_t advance = face->max_advance_width; |
| 635 info->fGlyphWidths->fAdvance.append(1, &advance); | 662 info->fGlyphWidths->fAdvance.append(1, &advance); |
| 636 finishRange(info->fGlyphWidths.get(), 0, | 663 finishRange(info->fGlyphWidths.get(), 0, |
| 637 SkAdvancedTypefaceMetrics::WidthRange::kDefault); | 664 SkAdvancedTypefaceMetrics::WidthRange::kDefault); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 info->fGlyphNames->get()[gID].set(glyphName); | 707 info->fGlyphNames->get()[gID].set(glyphName); |
| 681 } | 708 } |
| 682 } | 709 } |
| 683 | 710 |
| 684 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo && | 711 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo && |
| 685 info->fType != SkAdvancedTypefaceMetrics::kType1_Font && | 712 info->fType != SkAdvancedTypefaceMetrics::kType1_Font && |
| 686 face->num_charmaps) { | 713 face->num_charmaps) { |
| 687 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode)); | 714 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode)); |
| 688 } | 715 } |
| 689 | 716 |
| 690 if (!canEmbed(face)) | |
| 691 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; | |
| 692 | |
| 693 return info; | 717 return info; |
| 694 #endif | 718 #endif |
| 695 } | 719 } |
| 696 | 720 |
| 697 /////////////////////////////////////////////////////////////////////////// | 721 /////////////////////////////////////////////////////////////////////////// |
| 698 | 722 |
| 699 static bool bothZero(SkScalar a, SkScalar b) { | 723 static bool bothZero(SkScalar a, SkScalar b) { |
| 700 return 0 == a && 0 == b; | 724 return 0 == a && 0 == b; |
| 701 } | 725 } |
| 702 | 726 |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 *style = (SkTypeface::Style) tempStyle; | 1752 *style = (SkTypeface::Style) tempStyle; |
| 1729 } | 1753 } |
| 1730 if (isFixedPitch) { | 1754 if (isFixedPitch) { |
| 1731 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1755 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
| 1732 } | 1756 } |
| 1733 | 1757 |
| 1734 FT_Done_Face(face); | 1758 FT_Done_Face(face); |
| 1735 FT_Done_FreeType(library); | 1759 FT_Done_FreeType(library); |
| 1736 return true; | 1760 return true; |
| 1737 } | 1761 } |
| OLD | NEW |