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