| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 #else | 404 #else |
| 405 // No embedding is 0x2 and bitmap embedding only is 0x200. | 405 // No embedding is 0x2 and bitmap embedding only is 0x200. |
| 406 TT_OS2* os2_table; | 406 TT_OS2* os2_table; |
| 407 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { | 407 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { |
| 408 return (os2_table->fsType & 0x202) == 0; | 408 return (os2_table->fsType & 0x202) == 0; |
| 409 } | 409 } |
| 410 return false; // We tried, fail safe. | 410 return false; // We tried, fail safe. |
| 411 #endif | 411 #endif |
| 412 } | 412 } |
| 413 | 413 |
| 414 static bool canSubset(FT_Face face) { |
| 415 #ifdef FT_FSTYPE_NO_SUBSETTING |
| 416 FT_UShort fsType = FT_Get_FSType_Flags(face); |
| 417 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0; |
| 418 #else |
| 419 // No subset is 0x100. |
| 420 TT_OS2* os2_table; |
| 421 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { |
| 422 return (os2_table->fsType & 0x100) == 0; |
| 423 } |
| 424 return false; // We tried, fail safe. |
| 425 #endif |
| 426 } |
| 427 |
| 414 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { | 428 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { |
| 415 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); | 429 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); |
| 416 if (!glyph_id) | 430 if (!glyph_id) |
| 417 return false; | 431 return false; |
| 418 FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE); | 432 FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE); |
| 419 FT_Outline_Get_CBox(&face->glyph->outline, bbox); | 433 FT_Outline_Get_CBox(&face->glyph->outline, bbox); |
| 420 return true; | 434 return true; |
| 421 } | 435 } |
| 422 | 436 |
| 423 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) { | 437 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return NULL; | 502 return NULL; |
| 489 #else | 503 #else |
| 490 AutoFTAccess fta(this); | 504 AutoFTAccess fta(this); |
| 491 FT_Face face = fta.face(); | 505 FT_Face face = fta.face(); |
| 492 if (!face) { | 506 if (!face) { |
| 493 return NULL; | 507 return NULL; |
| 494 } | 508 } |
| 495 | 509 |
| 496 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; | 510 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; |
| 497 info->fFontName.set(FT_Get_Postscript_Name(face)); | 511 info->fFontName.set(FT_Get_Postscript_Name(face)); |
| 498 info->fMultiMaster = FT_HAS_MULTIPLE_MASTERS(face); | 512 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; |
| 513 if (FT_HAS_MULTIPLE_MASTERS(face)) { |
| 514 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 515 info->fFlags, SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag); |
| 516 } |
| 517 if (!canEmbed(face)) { |
| 518 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 519 info->fFlags, |
| 520 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); |
| 521 } |
| 522 if (!canSubset(face)) { |
| 523 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( |
| 524 info->fFlags, |
| 525 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag); |
| 526 } |
| 499 info->fLastGlyphID = face->num_glyphs - 1; | 527 info->fLastGlyphID = face->num_glyphs - 1; |
| 500 info->fEmSize = 1000; | 528 info->fEmSize = 1000; |
| 501 | 529 |
| 502 bool cid = false; | 530 bool cid = false; |
| 503 const char* fontType = FT_Get_X11_Font_Format(face); | 531 const char* fontType = FT_Get_X11_Font_Format(face); |
| 504 if (strcmp(fontType, "Type 1") == 0) { | 532 if (strcmp(fontType, "Type 1") == 0) { |
| 505 info->fType = SkAdvancedTypefaceMetrics::kType1_Font; | 533 info->fType = SkAdvancedTypefaceMetrics::kType1_Font; |
| 506 } else if (strcmp(fontType, "CID Type 1") == 0) { | 534 } else if (strcmp(fontType, "CID Type 1") == 0) { |
| 507 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font; | 535 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font; |
| 508 cid = true; | 536 cid = true; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 } else if (got_m && !got_x) { | 609 } else if (got_m && !got_x) { |
| 582 info->fCapHeight = m_bbox.yMax - m_bbox.yMin; | 610 info->fCapHeight = m_bbox.yMax - m_bbox.yMin; |
| 583 } else if (!got_m && got_x) { | 611 } else if (!got_m && got_x) { |
| 584 info->fCapHeight = x_bbox.yMax - x_bbox.yMin; | 612 info->fCapHeight = x_bbox.yMax - x_bbox.yMin; |
| 585 } | 613 } |
| 586 } | 614 } |
| 587 | 615 |
| 588 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, | 616 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, |
| 589 face->bbox.xMax, face->bbox.yMin); | 617 face->bbox.xMax, face->bbox.yMin); |
| 590 | 618 |
| 591 if (!canEmbed(face) || !FT_IS_SCALABLE(face) || | 619 if (!FT_IS_SCALABLE(face)) { |
| 592 info->fType == SkAdvancedTypefaceMetrics::kOther_Font) { | |
| 593 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo; | 620 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo; |
| 594 } | 621 } |
| 595 | 622 |
| 596 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { | 623 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { |
| 597 if (FT_IS_FIXED_WIDTH(face)) { | 624 if (FT_IS_FIXED_WIDTH(face)) { |
| 598 appendRange(&info->fGlyphWidths, 0); | 625 appendRange(&info->fGlyphWidths, 0); |
| 599 int16_t advance = face->max_advance_width; | 626 int16_t advance = face->max_advance_width; |
| 600 info->fGlyphWidths->fAdvance.append(1, &advance); | 627 info->fGlyphWidths->fAdvance.append(1, &advance); |
| 601 finishRange(info->fGlyphWidths.get(), 0, | 628 finishRange(info->fGlyphWidths.get(), 0, |
| 602 SkAdvancedTypefaceMetrics::WidthRange::kDefault); | 629 SkAdvancedTypefaceMetrics::WidthRange::kDefault); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 info->fGlyphNames->get()[gID].set(glyphName); | 672 info->fGlyphNames->get()[gID].set(glyphName); |
| 646 } | 673 } |
| 647 } | 674 } |
| 648 | 675 |
| 649 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo && | 676 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo && |
| 650 info->fType != SkAdvancedTypefaceMetrics::kType1_Font && | 677 info->fType != SkAdvancedTypefaceMetrics::kType1_Font && |
| 651 face->num_charmaps) { | 678 face->num_charmaps) { |
| 652 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode)); | 679 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode)); |
| 653 } | 680 } |
| 654 | 681 |
| 655 if (!canEmbed(face)) | |
| 656 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; | |
| 657 | |
| 658 return info; | 682 return info; |
| 659 #endif | 683 #endif |
| 660 } | 684 } |
| 661 | 685 |
| 662 /////////////////////////////////////////////////////////////////////////// | 686 /////////////////////////////////////////////////////////////////////////// |
| 663 | 687 |
| 664 #define BLACK_LUMINANCE_LIMIT 0x40 | 688 #define BLACK_LUMINANCE_LIMIT 0x40 |
| 665 #define WHITE_LUMINANCE_LIMIT 0xA0 | 689 #define WHITE_LUMINANCE_LIMIT 0xA0 |
| 666 | 690 |
| 667 static bool bothZero(SkScalar a, SkScalar b) { | 691 static bool bothZero(SkScalar a, SkScalar b) { |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 *style = (SkTypeface::Style) tempStyle; | 1547 *style = (SkTypeface::Style) tempStyle; |
| 1524 } | 1548 } |
| 1525 if (isFixedPitch) { | 1549 if (isFixedPitch) { |
| 1526 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1550 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
| 1527 } | 1551 } |
| 1528 | 1552 |
| 1529 FT_Done_Face(face); | 1553 FT_Done_Face(face); |
| 1530 FT_Done_FreeType(library); | 1554 FT_Done_FreeType(library); |
| 1531 return true; | 1555 return true; |
| 1532 } | 1556 } |
| OLD | NEW |