Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 2246903002: SkPDF: SkPDFFont class changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-15 (Monday) 21:25:47 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkGlyphCache.h" 9 #include "SkGlyphCache.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 SkTDArray<int16_t> fAdvance; 49 SkTDArray<int16_t> fAdvance;
50 AdvanceMetric(uint16_t startId) : fStartId(startId) {} 50 AdvanceMetric(uint16_t startId) : fStartId(startId) {}
51 AdvanceMetric(AdvanceMetric&&) = default; 51 AdvanceMetric(AdvanceMetric&&) = default;
52 AdvanceMetric& operator=(AdvanceMetric&& other) = default; 52 AdvanceMetric& operator=(AdvanceMetric&& other) = default;
53 AdvanceMetric(const AdvanceMetric&) = delete; 53 AdvanceMetric(const AdvanceMetric&) = delete;
54 AdvanceMetric& operator=(const AdvanceMetric&) = delete; 54 AdvanceMetric& operator=(const AdvanceMetric&) = delete;
55 }; 55 };
56 56
57 class SkPDFType0Font final : public SkPDFFont { 57 class SkPDFType0Font final : public SkPDFFont {
58 public: 58 public:
59 SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, 59 SkPDFType0Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
60 SkTypeface* typeface); 60 sk_sp<SkTypeface> typeface,
61 SkAdvancedTypefaceMetrics::FontType type);
61 virtual ~SkPDFType0Font(); 62 virtual ~SkPDFType0Font();
62 bool multiByteGlyphs() const override { return true; }
63 sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage) override; 63 sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage) override;
64 #ifdef SK_DEBUG 64 #ifdef SK_DEBUG
65 void emitObject(SkWStream*, 65 void emitObject(SkWStream*,
66 const SkPDFObjNumMap&, 66 const SkPDFObjNumMap&,
67 const SkPDFSubstituteMap&) const override; 67 const SkPDFSubstituteMap&) const override;
68 #endif 68 #endif
69 69
70 private: 70 private:
71 #ifdef SK_DEBUG 71 #ifdef SK_DEBUG
72 bool fPopulated; 72 bool fPopulated;
73 #endif 73 #endif
74 bool populate(const SkPDFGlyphSet* subset); 74 bool populate(const SkPDFGlyphSet* subset);
75 typedef SkPDFDict INHERITED; 75 typedef SkPDFDict INHERITED;
76 }; 76 };
77 77
78 class SkPDFCIDFont final : public SkPDFFont { 78 class SkPDFCIDFont final : public SkPDFFont {
79 public: 79 public:
80 SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, 80 SkPDFCIDFont(sk_sp<const SkAdvancedTypefaceMetrics> info,
81 SkTypeface* typeface, 81 sk_sp<SkTypeface> typeface,
82 SkAdvancedTypefaceMetrics::FontType fontType,
82 const SkPDFGlyphSet* subset); 83 const SkPDFGlyphSet* subset);
83 virtual ~SkPDFCIDFont(); 84 virtual ~SkPDFCIDFont();
84 bool multiByteGlyphs() const override { return true; }
85 85
86 private: 86 private:
87 bool populate(const SkPDFGlyphSet* subset); 87 bool populate(const SkPDFGlyphSet* subset);
88 bool addFontDescriptor(int16_t defaultWidth, 88 bool addFontDescriptor(int16_t defaultWidth,
89 const SkTDArray<uint32_t>* subset); 89 const SkTDArray<uint32_t>* subset);
90 }; 90 };
91 91
92 class SkPDFType1Font final : public SkPDFFont { 92 class SkPDFType1Font final : public SkPDFFont {
93 public: 93 public:
94 SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 94 SkPDFType1Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
95 SkTypeface* typeface, 95 sk_sp<SkTypeface> typeface,
96 uint16_t glyphID, 96 uint16_t glyphID,
97 SkPDFDict* relatedFontDescriptor); 97 sk_sp<SkPDFDict> relatedFontDescriptor);
98 virtual ~SkPDFType1Font(); 98 virtual ~SkPDFType1Font();
99 bool multiByteGlyphs() const override { return false; }
100 99
101 private: 100 private:
102 bool populate(int16_t glyphID); 101 bool populate(int16_t glyphID);
103 bool addFontDescriptor(int16_t defaultWidth); 102 bool addFontDescriptor(int16_t defaultWidth);
104 }; 103 };
105 104
106 class SkPDFType3Font final : public SkPDFFont { 105 class SkPDFType3Font final : public SkPDFFont {
107 public: 106 public:
108 SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 107 SkPDFType3Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
109 SkTypeface* typeface, 108 sk_sp<SkTypeface> typeface,
109 SkAdvancedTypefaceMetrics::FontType fontType,
110 uint16_t glyphID); 110 uint16_t glyphID);
111 virtual ~SkPDFType3Font() {} 111 virtual ~SkPDFType3Font() {}
112 void emitObject(SkWStream*, 112 void emitObject(SkWStream*,
113 const SkPDFObjNumMap&, 113 const SkPDFObjNumMap&,
114 const SkPDFSubstituteMap&) const override { 114 const SkPDFSubstituteMap&) const override {
115 SkDEBUGFAIL("should call getFontSubset!"); 115 SkDEBUGFAIL("should call getFontSubset!");
116 } 116 }
117 sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage) override; 117 sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage) override;
118 bool multiByteGlyphs() const override { return false; }
119 }; 118 };
120 119
121 /////////////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////////////
122 // File-Local Functions 121 // File-Local Functions
123 /////////////////////////////////////////////////////////////////////////////// 122 ///////////////////////////////////////////////////////////////////////////////
124 123
125 const int16_t kInvalidAdvance = SK_MinS16; 124 const int16_t kInvalidAdvance = SK_MinS16;
126 const int16_t kDontCareAdvance = SK_MinS16 + 1; 125 const int16_t kDontCareAdvance = SK_MinS16 + 1;
127 126
128 static void stripUninterestingTrailingAdvancesFromRange( 127 static void stripUninterestingTrailingAdvancesFromRange(
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 * some additional state indicating which subset of the font is used. It 460 * some additional state indicating which subset of the font is used. It
462 * must be maintained at the page granularity and then combined at the document 461 * must be maintained at the page granularity and then combined at the document
463 * granularity. a) change SkPDFFont to fill in its state on demand, kind of 462 * granularity. a) change SkPDFFont to fill in its state on demand, kind of
464 * like SkPDFGraphicState. b) maintain a per font glyph usage class in each 463 * like SkPDFGraphicState. b) maintain a per font glyph usage class in each
465 * page/pdf device. c) in the document, retrieve the per font glyph usage 464 * page/pdf device. c) in the document, retrieve the per font glyph usage
466 * from each page and combine it and ask for a resource with that subset. 465 * from each page and combine it and ask for a resource with that subset.
467 */ 466 */
468 467
469 SkPDFFont::~SkPDFFont() {} 468 SkPDFFont::~SkPDFFont() {}
470 469
471 SkTypeface* SkPDFFont::typeface() {
472 return fTypeface.get();
473 }
474
475 SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() {
476 return fFontType;
477 }
478
479 bool SkPDFFont::canEmbed() const { 470 bool SkPDFFont::canEmbed() const {
480 if (!fFontInfo.get()) { 471 if (!fFontInfo.get()) {
481 SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font); 472 SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font);
482 return true; 473 return true;
483 } 474 }
484 return (fFontInfo->fFlags & 475 return (fFontInfo->fFlags &
485 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag) == 0; 476 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag) == 0;
486 } 477 }
487 478
488 bool SkPDFFont::canSubset() const { 479 bool SkPDFFont::canSubset() const {
(...skipping 23 matching lines...) Expand all
512 return i; 503 return i;
513 } 504 }
514 glyphIDs[i] -= (fFirstGlyphID - 1); 505 glyphIDs[i] -= (fFirstGlyphID - 1);
515 } 506 }
516 507
517 return numGlyphs; 508 return numGlyphs;
518 } 509 }
519 510
520 // static 511 // static
521 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, 512 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon,
522 SkTypeface* typeface, 513 SkTypeface* face,
523 uint16_t glyphID) { 514 uint16_t glyphID) {
524 SkASSERT(canon); 515 SkASSERT(canon);
525 const uint32_t fontID = SkTypeface::UniqueID(typeface); 516 const uint32_t fontID = SkTypeface::UniqueID(face);
526 SkPDFFont* relatedFont; 517 SkPDFFont* relatedFont;
527 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { 518 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) {
528 return SkRef(pdfFont); 519 return SkRef(pdfFont);
529 } 520 }
530 SkAutoResolveDefaultTypeface autoResolve(typeface); 521 sk_sp<SkTypeface> typeface(face ? sk_ref_sp(face) : SkTypeface::MakeDefault( ));
531 typeface = autoResolve.get();
532 SkASSERT(typeface); 522 SkASSERT(typeface);
533 int glyphCount = typeface->countGlyphs(); 523 int glyphCount = typeface->countGlyphs();
534 if (glyphCount < 1 || // typeface lacks even a NOTDEF glyph. 524 if (glyphCount < 1 || // typeface lacks even a NOTDEF glyph.
535 glyphCount > 1 + SK_MaxU16 || // invalid glyphCount 525 glyphCount > 1 + SK_MaxU16 || // invalid glyphCount
536 glyphID >= glyphCount) { // invalid glyph 526 glyphID >= glyphCount) { // invalid glyph
537 return nullptr; 527 return nullptr;
538 } 528 }
539 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics; 529 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics;
540 SkPDFDict* relatedFontDescriptor = nullptr; 530 sk_sp<SkPDFDict> relatedFontDescriptor;
541 if (relatedFont) { 531 if (relatedFont) {
542 fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); 532 fontMetrics = relatedFont->refFontInfo();
543 relatedFontDescriptor = relatedFont->getFontDescriptor(); 533 relatedFontDescriptor = relatedFont->refFontDescriptor();
544 534
545 // This only is to catch callers who pass invalid glyph ids. 535 // This only is to catch callers who pass invalid glyph ids.
546 // If glyph id is invalid, then we will create duplicate entries 536 // If glyph id is invalid, then we will create duplicate entries
547 // for TrueType fonts. 537 // for TrueType fonts.
548 SkAdvancedTypefaceMetrics::FontType fontType = 538 SkDEBUGCODE(SkAdvancedTypefaceMetrics::FontType fontType = relatedFont-> getType());
549 fontMetrics.get() ? fontMetrics.get()->fType : 539 SkASSERT(fontType != SkAdvancedTypefaceMetrics::kType1CID_Font);
550 SkAdvancedTypefaceMetrics::kOther_Font; 540 SkASSERT(fontType != SkAdvancedTypefaceMetrics::kTrueType_Font);
551
552 if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font ||
553 fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
554 return SkRef(relatedFont);
555 }
556 } else { 541 } else {
557 SkTypeface::PerGlyphInfo info = 542 SkTypeface::PerGlyphInfo info = SkTypeface::kGlyphNames_PerGlyphInfo |
558 SkTBitOr(SkTypeface::kGlyphNames_PerGlyphInfo, 543 SkTypeface::kToUnicode_PerGlyphInfo;
559 SkTypeface::kToUnicode_PerGlyphInfo);
560 fontMetrics.reset( 544 fontMetrics.reset(
561 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0)); 545 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0));
562 } 546 }
563 547
564 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, 548 SkAdvancedTypefaceMetrics::FontType type =
565 glyphID, relatedFontDescriptor); 549 fontMetrics ? fontMetrics->fType : SkAdvancedTypefaceMetrics::kOther_Fon t;
566 canon->addFont(font, fontID, font->fFirstGlyphID); 550 if (fontMetrics &&
567 return font; 551 SkToBool(fontMetrics->fFlags &
552 SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
553 // force Type3 fallback.
554 type = SkAdvancedTypefaceMetrics::kOther_Font;
555 }
556
557 sk_sp<SkPDFFont> font;
558 switch (type) {
559 case SkAdvancedTypefaceMetrics::kType1CID_Font:
560 case SkAdvancedTypefaceMetrics::kTrueType_Font:
561 SkASSERT(relatedFontDescriptor == nullptr);
562 SkASSERT(fontMetrics != nullptr);
563 font = sk_make_sp<SkPDFType0Font>(std::move(fontMetrics),
564 std::move(typeface),
565 type);
566 break;
567 case SkAdvancedTypefaceMetrics::kType1_Font:
568 SkASSERT(fontMetrics != nullptr);
569 font = sk_make_sp<SkPDFType1Font>(std::move(fontMetrics),
570 std::move(typeface),
571 glyphID,
572 std::move(relatedFontDescriptor));
573 break;
574 case SkAdvancedTypefaceMetrics::kCFF_Font:
575 SkASSERT(fontMetrics != nullptr);
576 // fallthrough
577 case SkAdvancedTypefaceMetrics::kOther_Font:
578 font = sk_make_sp<SkPDFType3Font>(std::move(fontMetrics),
579 std::move(typeface),
580 type,
581 glyphID);
582 break;
583 default:
584 SkDEBUGFAIL("invalid SkAdvancedTypefaceMetrics::FontType");
585 return nullptr;
586 }
587 // When firstGlyphID==0, SkFont::IsMatch() matches all glyphs in font.
588 SkGlyphID firstGlyphID = font->multiByteGlyphs() ? 0 : font->fFirstGlyphID;
589 // TODO(halcanary) Make SkCanon::addFont take sk_sp<SkPDFFont>.
590 canon->addFont(font.get(), fontID, firstGlyphID);
591 return font.release(); // TODO(halcanary) return sk_sp<SkPDFFont>.
568 } 592 }
569 593
570 sk_sp<SkPDFObject> SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { 594 sk_sp<SkPDFObject> SkPDFFont::getFontSubset(const SkPDFGlyphSet*) {
571 return nullptr; // Default: no support. 595 return nullptr; // Default: no support.
572 } 596 }
573 597
574 // TODO: take a sk_sp<SkAdvancedTypefaceMetrics> and sk_sp<SkTypeface> 598 // TODO: take a sk_sp<SkAdvancedTypefaceMetrics> and sk_sp<SkTypeface>
575 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info, 599 SkPDFFont::SkPDFFont(sk_sp<const SkAdvancedTypefaceMetrics> info,
576 SkTypeface* typeface, 600 sk_sp<SkTypeface> typeface,
577 SkPDFDict* relatedFontDescriptor) 601 sk_sp<SkPDFDict> relatedFontDescriptor,
602 SkAdvancedTypefaceMetrics::FontType fontType,
603 bool multiByteGlyphs)
578 : SkPDFDict("Font") 604 : SkPDFDict("Font")
579 , fTypeface(ref_or_default(typeface)) 605 , fTypeface(std::move(typeface))
606 , fFontInfo(std::move(info))
607 , fDescriptor(std::move(relatedFontDescriptor))
580 , fFirstGlyphID(1) 608 , fFirstGlyphID(1)
581 , fLastGlyphID(info ? info->fLastGlyphID : 0) 609 , fFontType(fontType)
582 , fFontInfo(SkSafeRef(info)) 610 , fMultiByteGlyphs(multiByteGlyphs) {
583 , fDescriptor(SkSafeRef(relatedFontDescriptor))
584 , fFontType((!info || info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster _FontFlag)
585 ? SkAdvancedTypefaceMetrics::kOther_Font
586 : info->fType) {
587 SkASSERT(fTypeface); 611 SkASSERT(fTypeface);
612 fLastGlyphID = fFontInfo ? fFontInfo->fLastGlyphID : 0;
588 if (0 == fLastGlyphID) { 613 if (0 == fLastGlyphID) {
589 fLastGlyphID = SkToU16(fTypeface->countGlyphs() - 1); 614 fLastGlyphID = SkToU16(fTypeface->countGlyphs() - 1);
590 } 615 }
591 } 616 }
592 617
593 // static 618 void SkPDFFont::setFontInfo(sk_sp<const SkAdvancedTypefaceMetrics> info) {
594 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, 619 if (info) {
595 const SkAdvancedTypefaceMetrics* info, 620 fFontInfo = std::move(info);
596 SkTypeface* typeface,
597 uint16_t glyphID,
598 SkPDFDict* relatedFontDescriptor) {
599 SkAdvancedTypefaceMetrics::FontType type =
600 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font;
601 SkAdvancedTypefaceMetrics::FontFlags flags =
602 info ? info->fFlags : SkAdvancedTypefaceMetrics::kEmpty_FontFlag;
603 if (SkToBool(flags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
604 return new SkPDFType3Font(info, typeface, glyphID);
605 } 621 }
606 switch (type) {
607 case SkAdvancedTypefaceMetrics::kType1CID_Font:
608 case SkAdvancedTypefaceMetrics::kTrueType_Font:
609 SkASSERT(relatedFontDescriptor == nullptr);
610 SkASSERT(info != nullptr);
611 return new SkPDFType0Font(info, typeface);
612 case SkAdvancedTypefaceMetrics::kType1_Font:
613 SkASSERT(info != nullptr);
614 return new SkPDFType1Font(info, typeface, glyphID, relatedFontDescri ptor);
615 case SkAdvancedTypefaceMetrics::kCFF_Font:
616 SkASSERT(info != nullptr);
617 // fallthrough
618 case SkAdvancedTypefaceMetrics::kOther_Font:
619 return new SkPDFType3Font(info, typeface, glyphID);
620 }
621 SkDEBUGFAIL("invalid SkAdvancedTypefaceMetrics::FontType");
622 return nullptr;
623 }
624
625 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() {
626 return fFontInfo.get();
627 }
628
629 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) {
630 if (info == nullptr || info == fFontInfo.get()) {
631 return;
632 }
633 fFontInfo.reset(info);
634 SkSafeRef(info);
635 }
636
637 uint16_t SkPDFFont::firstGlyphID() const {
638 return fFirstGlyphID;
639 }
640
641 uint16_t SkPDFFont::lastGlyphID() const {
642 return fLastGlyphID;
643 } 622 }
644 623
645 void SkPDFFont::setLastGlyphID(uint16_t glyphID) { 624 void SkPDFFont::setLastGlyphID(uint16_t glyphID) {
646 fLastGlyphID = glyphID; 625 fLastGlyphID = glyphID;
647 } 626 }
648 627
649 SkPDFDict* SkPDFFont::getFontDescriptor() { 628 void SkPDFFont::setFontDescriptor(sk_sp<SkPDFDict> descriptor) {
650 return fDescriptor.get(); 629 fDescriptor = std::move(descriptor);
651 }
652
653 void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) {
654 fDescriptor.reset(descriptor);
655 SkSafeRef(descriptor);
656 } 630 }
657 631
658 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) { 632 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) {
659 if (fDescriptor.get() == nullptr) { 633 if (fDescriptor.get() == nullptr) {
660 return false; 634 return false;
661 } 635 }
662 636
663 const uint16_t emSize = fFontInfo->fEmSize; 637 const uint16_t emSize = fFontInfo->fEmSize;
664 638
665 fDescriptor->insertName("FontName", fFontInfo->fFontName); 639 fDescriptor->insertName("FontName", fFontInfo->fFontName);
666 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic); 640 fDescriptor->insertInt("Flags", (size_t)(fFontInfo->fStyle | kPdfSymbolic));
667 fDescriptor->insertScalar("Ascent", 641 fDescriptor->insertScalar("Ascent",
668 scaleFromFontUnits(fFontInfo->fAscent, emSize)); 642 scaleFromFontUnits(fFontInfo->fAscent, emSize));
669 fDescriptor->insertScalar("Descent", 643 fDescriptor->insertScalar("Descent",
670 scaleFromFontUnits(fFontInfo->fDescent, emSize)); 644 scaleFromFontUnits(fFontInfo->fDescent, emSize));
671 fDescriptor->insertScalar("StemV", 645 fDescriptor->insertScalar("StemV",
672 scaleFromFontUnits(fFontInfo->fStemV, emSize)); 646 scaleFromFontUnits(fFontInfo->fStemV, emSize));
673 647
674 fDescriptor->insertScalar("CapHeight", 648 fDescriptor->insertScalar("CapHeight",
675 scaleFromFontUnits(fFontInfo->fCapHeight, emSize)); 649 scaleFromFontUnits(fFontInfo->fCapHeight, emSize));
676 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle); 650 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle);
(...skipping 24 matching lines...) Expand all
701 subset, 675 subset,
702 multiByteGlyphs(), 676 multiByteGlyphs(),
703 firstGlyphID(), 677 firstGlyphID(),
704 lastGlyphID())); 678 lastGlyphID()));
705 } 679 }
706 680
707 /////////////////////////////////////////////////////////////////////////////// 681 ///////////////////////////////////////////////////////////////////////////////
708 // class SkPDFType0Font 682 // class SkPDFType0Font
709 /////////////////////////////////////////////////////////////////////////////// 683 ///////////////////////////////////////////////////////////////////////////////
710 684
711 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, SkTypeface * typeface) 685 SkPDFType0Font::SkPDFType0Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
712 : SkPDFFont(info, typeface, nullptr) { 686 sk_sp<SkTypeface> typeface,
687 SkAdvancedTypefaceMetrics::FontType fontType)
688 : SkPDFFont(std::move(info), std::move(typeface), nullptr, fontType, true) {
713 SkDEBUGCODE(fPopulated = false); 689 SkDEBUGCODE(fPopulated = false);
714 if (!canSubset()) { 690 if (!canSubset()) {
715 this->populate(nullptr); 691 this->populate(nullptr);
716 } 692 }
717 } 693 }
718 694
719 SkPDFType0Font::~SkPDFType0Font() {} 695 SkPDFType0Font::~SkPDFType0Font() {}
720 696
721 sk_sp<SkPDFObject> SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { 697 sk_sp<SkPDFObject> SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
722 if (!canSubset()) { 698 if (!canSubset()) {
723 return nullptr; 699 return nullptr;
724 } 700 }
725 auto newSubset = sk_make_sp<SkPDFType0Font>(fontInfo(), typeface()); 701 auto newSubset = sk_make_sp<SkPDFType0Font>(refFontInfo(), refTypeface(), ge tType());
726 newSubset->populate(subset); 702 newSubset->populate(subset);
727 return newSubset; 703 return newSubset;
728 } 704 }
729 705
730 #ifdef SK_DEBUG 706 #ifdef SK_DEBUG
731 void SkPDFType0Font::emitObject(SkWStream* stream, 707 void SkPDFType0Font::emitObject(SkWStream* stream,
732 const SkPDFObjNumMap& objNumMap, 708 const SkPDFObjNumMap& objNumMap,
733 const SkPDFSubstituteMap& substitutes) const { 709 const SkPDFSubstituteMap& substitutes) const {
734 SkASSERT(fPopulated); 710 SkASSERT(fPopulated);
735 return INHERITED::emitObject(stream, objNumMap, substitutes); 711 return INHERITED::emitObject(stream, objNumMap, substitutes);
736 } 712 }
737 #endif 713 #endif
738 714
739 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { 715 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
740 insertName("Subtype", "Type0"); 716 insertName("Subtype", "Type0");
741 insertName("BaseFont", fontInfo()->fFontName); 717 insertName("BaseFont", this->getFontInfo()->fFontName);
742 insertName("Encoding", "Identity-H"); 718 insertName("Encoding", "Identity-H");
743 719
744 sk_sp<SkPDFCIDFont> newCIDFont( 720 sk_sp<SkPDFCIDFont> newCIDFont(
745 new SkPDFCIDFont(fontInfo(), typeface(), subset)); 721 sk_make_sp<SkPDFCIDFont>(this->refFontInfo(),
722 this->refTypeface(),
723 this->getType(),
724 subset));
746 auto descendantFonts = sk_make_sp<SkPDFArray>(); 725 auto descendantFonts = sk_make_sp<SkPDFArray>();
747 descendantFonts->appendObjRef(std::move(newCIDFont)); 726 descendantFonts->appendObjRef(std::move(newCIDFont));
748 this->insertObject("DescendantFonts", std::move(descendantFonts)); 727 this->insertObject("DescendantFonts", std::move(descendantFonts));
749 728
750 this->populateToUnicodeTable(subset); 729 this->populateToUnicodeTable(subset);
751 730
752 SkDEBUGCODE(fPopulated = true); 731 SkDEBUGCODE(fPopulated = true);
753 return true; 732 return true;
754 } 733 }
755 734
756 /////////////////////////////////////////////////////////////////////////////// 735 ///////////////////////////////////////////////////////////////////////////////
757 // class SkPDFCIDFont 736 // class SkPDFCIDFont
758 /////////////////////////////////////////////////////////////////////////////// 737 ///////////////////////////////////////////////////////////////////////////////
759 738
760 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, 739 SkPDFCIDFont::SkPDFCIDFont(sk_sp<const SkAdvancedTypefaceMetrics> info,
761 SkTypeface* typeface, 740 sk_sp<SkTypeface> typeface,
741 SkAdvancedTypefaceMetrics::FontType fontType,
762 const SkPDFGlyphSet* subset) 742 const SkPDFGlyphSet* subset)
763 : SkPDFFont(info, typeface, nullptr) { 743 : SkPDFFont(std::move(info), std::move(typeface), nullptr,
744 fontType , /* multiByteGlyphs = */ true) {
764 this->populate(subset); 745 this->populate(subset);
765 } 746 }
766 747
767 SkPDFCIDFont::~SkPDFCIDFont() {} 748 SkPDFCIDFont::~SkPDFCIDFont() {}
768 749
769 #ifdef SK_SFNTLY_SUBSETTER 750 #ifdef SK_SFNTLY_SUBSETTER
770 // if possible, make no copy. 751 // if possible, make no copy.
771 static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) { 752 static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) {
772 SkASSERT(stream); 753 SkASSERT(stream);
773 (void)stream->rewind(); 754 (void)stream->rewind();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 [](const void* p, void*) { delete[] (unsigned char*)p; }, 796 [](const void* p, void*) { delete[] (unsigned char*)p; },
816 nullptr)); 797 nullptr));
817 subsetStream->dict()->insertInt("Length1", subsetFontSize); 798 subsetStream->dict()->insertInt("Length1", subsetFontSize);
818 return subsetStream; 799 return subsetStream;
819 } 800 }
820 #endif // SK_SFNTLY_SUBSETTER 801 #endif // SK_SFNTLY_SUBSETTER
821 802
822 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 803 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
823 const SkTDArray<uint32_t>* subset) { 804 const SkTDArray<uint32_t>* subset) {
824 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); 805 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
825 setFontDescriptor(descriptor.get()); 806 setFontDescriptor(descriptor);
826 if (!addCommonFontDescriptorEntries(defaultWidth)) { 807 if (!addCommonFontDescriptorEntries(defaultWidth)) {
827 this->insertObjRef("FontDescriptor", std::move(descriptor)); 808 this->insertObjRef("FontDescriptor", std::move(descriptor));
828 return false; 809 return false;
829 } 810 }
830 SkASSERT(this->canEmbed()); 811 SkASSERT(this->canEmbed());
831 812
832 switch (getType()) { 813 switch (getType()) {
833 case SkAdvancedTypefaceMetrics::kTrueType_Font: { 814 case SkAdvancedTypefaceMetrics::kTrueType_Font: {
834 int ttcIndex; 815 int ttcIndex;
835 std::unique_ptr<SkStreamAsset> fontAsset( 816 std::unique_ptr<SkStreamAsset> fontAsset(
836 this->typeface()->openStream(&ttcIndex)); 817 this->typeface()->openStream(&ttcIndex));
837 SkASSERT(fontAsset); 818 SkASSERT(fontAsset);
838 if (!fontAsset) { 819 if (!fontAsset) {
839 return false; 820 return false;
840 } 821 }
841 size_t fontSize = fontAsset->getLength(); 822 size_t fontSize = fontAsset->getLength();
842 SkASSERT(fontSize > 0); 823 SkASSERT(fontSize > 0);
843 if (fontSize == 0) { 824 if (fontSize == 0) {
844 return false; 825 return false;
845 } 826 }
846 827
847 #ifdef SK_SFNTLY_SUBSETTER 828 #ifdef SK_SFNTLY_SUBSETTER
848 if (this->canSubset() && subset) { 829 if (this->canSubset() && subset) {
830 const char* name = this->getFontInfo()->fFontName.c_str();
849 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( 831 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream(
850 std::move(fontAsset), *subset, fontInfo()->fFontName.c_s tr()); 832 std::move(fontAsset), *subset, name);
851 if (subsetStream) { 833 if (subsetStream) {
852 descriptor->insertObjRef("FontFile2", std::move(subsetStream )); 834 descriptor->insertObjRef("FontFile2", std::move(subsetStream ));
853 break; 835 break;
854 } 836 }
855 // If subsetting fails, fall back to original font data. 837 // If subsetting fails, fall back to original font data.
856 fontAsset.reset(this->typeface()->openStream(&ttcIndex)); 838 fontAsset.reset(this->typeface()->openStream(&ttcIndex));
857 } 839 }
858 #endif // SK_SFNTLY_SUBSETTER 840 #endif // SK_SFNTLY_SUBSETTER
859 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset) ); 841 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset) );
860 fontStream->dict()->insertInt("Length1", fontSize); 842 fontStream->dict()->insertInt("Length1", fontSize);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { 902 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
921 // Generate new font metrics with advance info for true type fonts. 903 // Generate new font metrics with advance info for true type fonts.
922 // Generate glyph id array. 904 // Generate glyph id array.
923 SkTDArray<uint32_t> glyphIDs; 905 SkTDArray<uint32_t> glyphIDs;
924 if (subset) { 906 if (subset) {
925 if (!subset->has(0)) { 907 if (!subset->has(0)) {
926 glyphIDs.push(0); // Always include glyph 0. 908 glyphIDs.push(0); // Always include glyph 0.
927 } 909 }
928 subset->exportTo(&glyphIDs); 910 subset->exportTo(&glyphIDs);
929 } 911 }
930 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { 912 if (this->getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
931 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); 913 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin();
932 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; 914 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
933 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics = 915 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics =
934 SkPDFFont::GetFontMetricsWithGlyphNames(this->typeface(), glyphs, gl yphsCount); 916 SkPDFFont::GetFontMetricsWithGlyphNames(this->typeface(), glyphs, gl yphsCount);
935 this->setFontInfo(fontMetrics.get()); 917 this->setFontInfo(std::move(fontMetrics));
936 this->addFontDescriptor(0, &glyphIDs); 918 this->addFontDescriptor(0, &glyphIDs);
937 } else { 919 } else {
938 // Other CID fonts 920 // Other CID fonts
939 addFontDescriptor(0, nullptr); 921 addFontDescriptor(0, nullptr);
940 } 922 }
941 923
942 insertName("BaseFont", fontInfo()->fFontName); 924 insertName("BaseFont", this->getFontInfo()->fFontName);
943 925
944 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { 926 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) {
945 insertName("Subtype", "CIDFontType0"); 927 insertName("Subtype", "CIDFontType0");
946 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { 928 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
947 insertName("Subtype", "CIDFontType2"); 929 insertName("Subtype", "CIDFontType2");
948 insertName("CIDToGIDMap", "Identity"); 930 insertName("CIDToGIDMap", "Identity");
949 } else { 931 } else {
950 SkASSERT(false); 932 SkASSERT(false);
951 } 933 }
952 934
953 auto sysInfo = sk_make_sp<SkPDFDict>(); 935 auto sysInfo = sk_make_sp<SkPDFDict>();
954 sysInfo->insertString("Registry", "Adobe"); 936 sysInfo->insertString("Registry", "Adobe");
955 sysInfo->insertString("Ordering", "Identity"); 937 sysInfo->insertString("Ordering", "Identity");
956 sysInfo->insertInt("Supplement", 0); 938 sysInfo->insertInt("Supplement", 0);
957 this->insertObject("CIDSystemInfo", std::move(sysInfo)); 939 this->insertObject("CIDSystemInfo", std::move(sysInfo));
958 940
959 SkSinglyLinkedList<AdvanceMetric> tmpMetrics; 941 SkSinglyLinkedList<AdvanceMetric> tmpMetrics;
960 set_glyph_widths(this->typeface(), &glyphIDs, &tmpMetrics); 942 set_glyph_widths(this->typeface(), &glyphIDs, &tmpMetrics);
961 int16_t defaultWidth = 0; 943 int16_t defaultWidth = 0;
962 uint16_t emSize = (uint16_t)this->fontInfo()->fEmSize; 944 uint16_t emSize = (uint16_t)this->getFontInfo()->fEmSize;
963 sk_sp<SkPDFArray> widths = composeAdvanceData(tmpMetrics, emSize, &defaultWi dth); 945 sk_sp<SkPDFArray> widths = composeAdvanceData(tmpMetrics, emSize, &defaultWi dth);
964 if (widths->size()) { 946 if (widths->size()) {
965 this->insertObject("W", std::move(widths)); 947 this->insertObject("W", std::move(widths));
966 } 948 }
967 949
968 this->insertScalar( 950 this->insertScalar(
969 "DW", scaleFromFontUnits(defaultWidth, emSize)); 951 "DW", scaleFromFontUnits(defaultWidth, emSize));
970 return true; 952 return true;
971 } 953 }
972 954
973 /////////////////////////////////////////////////////////////////////////////// 955 ///////////////////////////////////////////////////////////////////////////////
974 // class SkPDFType1Font 956 // class SkPDFType1Font
975 /////////////////////////////////////////////////////////////////////////////// 957 ///////////////////////////////////////////////////////////////////////////////
976 958
977 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 959 SkPDFType1Font::SkPDFType1Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
978 SkTypeface* typeface, 960 sk_sp<SkTypeface> typeface,
979 uint16_t glyphID, 961 uint16_t glyphID,
980 SkPDFDict* relatedFontDescriptor) 962 sk_sp<SkPDFDict> relatedFontDescriptor)
981 : SkPDFFont(info, typeface, relatedFontDescriptor) { 963 : SkPDFFont(std::move(info),
982 this->populate(glyphID); 964 std::move(typeface),
965 std::move(relatedFontDescriptor),
966 SkAdvancedTypefaceMetrics::kType1_Font,
967 /* multiByteGlyphs = */ false) {
968 this->populate(glyphID); // TODO(halcanary): subset this.
983 } 969 }
984 970
985 SkPDFType1Font::~SkPDFType1Font() {} 971 SkPDFType1Font::~SkPDFType1Font() {}
986 972
987 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 973 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
988 if (SkPDFDict* descriptor = getFontDescriptor()) { 974 if (sk_sp<SkPDFDict> descriptor = this->refFontDescriptor()) {
989 this->insertObjRef("FontDescriptor", 975 this->insertObjRef("FontDescriptor", std::move(descriptor));
990 sk_ref_sp(descriptor));
991 return true; 976 return true;
992 } 977 }
993 978
994 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); 979 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
995 setFontDescriptor(descriptor.get()); 980 setFontDescriptor(descriptor);
996 981
997 int ttcIndex; 982 int ttcIndex;
998 size_t header SK_INIT_TO_AVOID_WARNING; 983 size_t header SK_INIT_TO_AVOID_WARNING;
999 size_t data SK_INIT_TO_AVOID_WARNING; 984 size_t data SK_INIT_TO_AVOID_WARNING;
1000 size_t trailer SK_INIT_TO_AVOID_WARNING; 985 size_t trailer SK_INIT_TO_AVOID_WARNING;
1001 std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex) ); 986 std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex) );
1002 sk_sp<SkData> fontData = SkPDFConvertType1FontStream(std::move(rawFontData), 987 sk_sp<SkData> fontData = SkPDFConvertType1FontStream(std::move(rawFontData),
1003 &header, &data, &traile r); 988 &header, &data, &traile r);
1004 if (!fontData) { 989 if (!fontData) {
1005 return false; 990 return false;
1006 } 991 }
1007 SkASSERT(this->canEmbed()); 992 SkASSERT(this->canEmbed());
1008 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData)); 993 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData));
1009 fontStream->dict()->insertInt("Length1", header); 994 fontStream->dict()->insertInt("Length1", header);
1010 fontStream->dict()->insertInt("Length2", data); 995 fontStream->dict()->insertInt("Length2", data);
1011 fontStream->dict()->insertInt("Length3", trailer); 996 fontStream->dict()->insertInt("Length3", trailer);
1012 descriptor->insertObjRef("FontFile", std::move(fontStream)); 997 descriptor->insertObjRef("FontFile", std::move(fontStream));
1013 998
1014 this->insertObjRef("FontDescriptor", std::move(descriptor)); 999 this->insertObjRef("FontDescriptor", std::move(descriptor));
1015 1000
1016 return addCommonFontDescriptorEntries(defaultWidth); 1001 return addCommonFontDescriptorEntries(defaultWidth);
1017 } 1002 }
1018 1003
1019 bool SkPDFType1Font::populate(int16_t glyphID) { 1004 bool SkPDFType1Font::populate(int16_t glyphID) {
1020 this->insertName("Subtype", "Type1"); 1005 this->insertName("Subtype", "Type1");
1021 this->insertName("BaseFont", fontInfo()->fFontName); 1006 this->insertName("BaseFont", this->getFontInfo()->fFontName);
1022 adjustGlyphRangeForSingleByteEncoding(glyphID); 1007 adjustGlyphRangeForSingleByteEncoding(glyphID);
1023 SkGlyphID firstGlyphID = this->firstGlyphID(); 1008 SkGlyphID firstGlyphID = this->firstGlyphID();
1024 SkGlyphID lastGlyphID = this->lastGlyphID(); 1009 SkGlyphID lastGlyphID = this->lastGlyphID();
1025 1010
1026 // glyphCount not including glyph 0 1011 // glyphCount not including glyph 0
1027 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID; 1012 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID;
1028 SkASSERT(glyphCount > 0 && glyphCount <= 255); 1013 SkASSERT(glyphCount > 0 && glyphCount <= 255);
1029 this->insertInt("FirstChar", (size_t)0); 1014 this->insertInt("FirstChar", (size_t)0);
1030 this->insertInt("LastChar", (size_t)glyphCount); 1015 this->insertInt("LastChar", (size_t)glyphCount);
1031 { 1016 {
1032 SkPaint tmpPaint; 1017 SkPaint tmpPaint;
1033 tmpPaint.setHinting(SkPaint::kNo_Hinting); 1018 tmpPaint.setHinting(SkPaint::kNo_Hinting);
1034 tmpPaint.setTypeface(sk_ref_sp(this->typeface())); 1019 tmpPaint.setTypeface(sk_ref_sp(this->typeface()));
1035 tmpPaint.setTextSize((SkScalar)this->typeface()->getUnitsPerEm()); 1020 tmpPaint.setTextSize((SkScalar)this->typeface()->getUnitsPerEm());
1036 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 1021 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
1037 SkAutoGlyphCache glyphCache(tmpPaint, &props, nullptr); 1022 SkAutoGlyphCache glyphCache(tmpPaint, &props, nullptr);
1038 auto widths = sk_make_sp<SkPDFArray>(); 1023 auto widths = sk_make_sp<SkPDFArray>();
1039 SkScalar advance = glyphCache->getGlyphIDAdvance(0).fAdvanceX; 1024 SkScalar advance = glyphCache->getGlyphIDAdvance(0).fAdvanceX;
1040 const uint16_t emSize = this->fontInfo()->fEmSize; 1025 const uint16_t emSize = this->getFontInfo()->fEmSize;
1041 widths->appendScalar(from_font_units(advance, emSize)); 1026 widths->appendScalar(from_font_units(advance, emSize));
1042 for (unsigned gID = firstGlyphID; gID <= lastGlyphID; gID++) { 1027 for (unsigned gID = firstGlyphID; gID <= lastGlyphID; gID++) {
1043 advance = glyphCache->getGlyphIDAdvance(gID).fAdvanceX; 1028 advance = glyphCache->getGlyphIDAdvance(gID).fAdvanceX;
1044 widths->appendScalar(from_font_units(advance, emSize)); 1029 widths->appendScalar(from_font_units(advance, emSize));
1045 } 1030 }
1046 this->insertObject("Widths", std::move(widths)); 1031 this->insertObject("Widths", std::move(widths));
1047 } 1032 }
1048 if (!addFontDescriptor(0)) { 1033 if (!addFontDescriptor(0)) {
1049 return false; 1034 return false;
1050 } 1035 }
1051 auto encDiffs = sk_make_sp<SkPDFArray>(); 1036 auto encDiffs = sk_make_sp<SkPDFArray>();
1052 encDiffs->reserve(lastGlyphID - firstGlyphID + 3); 1037 encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
1053 encDiffs->appendInt(0); 1038 encDiffs->appendInt(0);
1054 const SkTArray<SkString>& glyphNames = this->fontInfo()->fGlyphNames; 1039 const SkTArray<SkString>& glyphNames = this->getFontInfo()->fGlyphNames;
1055 SkASSERT(glyphNames.count() > lastGlyphID); 1040 SkASSERT(glyphNames.count() > lastGlyphID);
1056 encDiffs->appendName(glyphNames[0].c_str()); 1041 encDiffs->appendName(glyphNames[0].c_str());
1057 const SkString unknown("UNKNOWN"); 1042 const SkString unknown("UNKNOWN");
1058 for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) { 1043 for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) {
1059 const bool valid = gID < glyphNames.count() && !glyphNames[gID].isEmpty( ); 1044 const bool valid = gID < glyphNames.count() && !glyphNames[gID].isEmpty( );
1060 const SkString& name = valid ? glyphNames[gID] : unknown; 1045 const SkString& name = valid ? glyphNames[gID] : unknown;
1061 encDiffs->appendName(name); 1046 encDiffs->appendName(name);
1062 } 1047 }
1063 1048
1064 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); 1049 auto encoding = sk_make_sp<SkPDFDict>("Encoding");
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 subset, 1199 subset,
1215 false, 1200 false,
1216 firstGlyphID, 1201 firstGlyphID,
1217 lastGlyphID)); 1202 lastGlyphID));
1218 } 1203 }
1219 font->insertObject("Widths", std::move(widthArray)); 1204 font->insertObject("Widths", std::move(widthArray));
1220 font->insertObject("Encoding", std::move(encoding)); 1205 font->insertObject("Encoding", std::move(encoding));
1221 font->insertObject("CharProcs", std::move(charProcs)); 1206 font->insertObject("CharProcs", std::move(charProcs));
1222 } 1207 }
1223 1208
1224 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 1209 SkPDFType3Font::SkPDFType3Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
1225 SkTypeface* typeface, 1210 sk_sp<SkTypeface> typeface,
1211 SkAdvancedTypefaceMetrics::FontType fontType,
1226 uint16_t glyphID) 1212 uint16_t glyphID)
1227 : SkPDFFont(info, typeface, nullptr) { 1213 : SkPDFFont(std::move(info), std::move(typeface), nullptr,
1214 fontType, /* multiByteGlyphs = */ false) {
1228 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up. 1215 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up.
1229 this->setLastGlyphID(SkToU16(typeface->countGlyphs() - 1)); 1216 this->setLastGlyphID(SkToU16(this->typeface()->countGlyphs() - 1));
1230 this->adjustGlyphRangeForSingleByteEncoding(glyphID); 1217 this->adjustGlyphRangeForSingleByteEncoding(glyphID);
1231 } 1218 }
1232 1219
1233 sk_sp<SkPDFObject> SkPDFType3Font::getFontSubset(const SkPDFGlyphSet* usage) { 1220 sk_sp<SkPDFObject> SkPDFType3Font::getFontSubset(const SkPDFGlyphSet* usage) {
1234 // All fonts are subset before serialization. 1221 // All fonts are subset before serialization.
1235 // TODO(halcanary): all fonts should follow this pattern. 1222 // TODO(halcanary): all fonts should follow this pattern.
1236 auto font = sk_make_sp<SkPDFDict>("Font"); 1223 auto font = sk_make_sp<SkPDFDict>("Font");
1237 const SkAdvancedTypefaceMetrics* info = this->fontInfo(); 1224 const SkAdvancedTypefaceMetrics* info = this->getFontInfo();
1238 uint16_t emSize = info && info->fEmSize > 0 ? info->fEmSize : 1000; 1225 uint16_t emSize = info && info->fEmSize > 0 ? info->fEmSize : 1000;
1239 add_type3_font_info(font.get(), this->typeface(), (SkScalar)emSize, usage, 1226 add_type3_font_info(font.get(), this->typeface(), (SkScalar)emSize, usage,
1240 this->firstGlyphID(), this->lastGlyphID()); 1227 this->firstGlyphID(), this->lastGlyphID());
1241 return font; 1228 return font;
1242 } 1229 }
1243 1230
1244 1231
1245 //////////////////////////////////////////////////////////////////////////////// 1232 ////////////////////////////////////////////////////////////////////////////////
1246 1233
1247 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, 1234 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 } 1270 }
1284 return *canon->fCanEmbedTypeface.set(id, canEmbed); 1271 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1285 } 1272 }
1286 1273
1287 void SkPDFFont::drop() { 1274 void SkPDFFont::drop() {
1288 fTypeface = nullptr; 1275 fTypeface = nullptr;
1289 fFontInfo = nullptr; 1276 fFontInfo = nullptr;
1290 fDescriptor = nullptr; 1277 fDescriptor = nullptr;
1291 this->SkPDFDict::drop(); 1278 this->SkPDFDict::drop();
1292 } 1279 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698