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

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) 14:05:05 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
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::PerGlyphInfo)(
bungeman-skia 2016/08/15 20:17:03 Seems like SkTypeface::PerGlyphInfo needs flag ope
hal.canary 2016/08/15 21:14:42 I agree. Later CL.
558 SkTBitOr(SkTypeface::kGlyphNames_PerGlyphInfo, 543 SkTypeface::kGlyphNames_PerGlyphInfo |
559 SkTypeface::kToUnicode_PerGlyphInfo); 544 SkTypeface::kToUnicode_PerGlyphInfo);
560 fontMetrics.reset( 545 fontMetrics.reset(
561 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0)); 546 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0));
562 } 547 }
563 548
564 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, 549 sk_sp<SkPDFFont> font = SkPDFFont::Create(
565 glyphID, relatedFontDescriptor); 550 canon, std::move(fontMetrics), std::move(typeface),
566 canon->addFont(font, fontID, font->fFirstGlyphID); 551 glyphID, std::move(relatedFontDescriptor));
567 return font; 552
553 // When firstGlyphID==0, SkFont::IsMatch() matches all glyphs in font.
554 SkGlyphID firstGlyphID = font->multiByteGlyphs() ? 0 : font->fFirstGlyphID;
555 // TODO(halcanary) Make SkCanon::addFont take sk_sp<SkPDFFont>.
556 canon->addFont(font.get(), fontID, firstGlyphID);
557 return font.release(); // TODO(halcanary) return sk_sp<SkPDFFont>.
568 } 558 }
569 559
570 sk_sp<SkPDFObject> SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { 560 sk_sp<SkPDFObject> SkPDFFont::getFontSubset(const SkPDFGlyphSet*) {
571 return nullptr; // Default: no support. 561 return nullptr; // Default: no support.
572 } 562 }
573 563
574 // TODO: take a sk_sp<SkAdvancedTypefaceMetrics> and sk_sp<SkTypeface> 564 // TODO: take a sk_sp<SkAdvancedTypefaceMetrics> and sk_sp<SkTypeface>
575 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info, 565 SkPDFFont::SkPDFFont(sk_sp<const SkAdvancedTypefaceMetrics> info,
576 SkTypeface* typeface, 566 sk_sp<SkTypeface> typeface,
577 SkPDFDict* relatedFontDescriptor) 567 sk_sp<SkPDFDict> relatedFontDescriptor,
568 SkAdvancedTypefaceMetrics::FontType fontType,
569 bool multiByteGlyphs)
578 : SkPDFDict("Font") 570 : SkPDFDict("Font")
579 , fTypeface(ref_or_default(typeface)) 571 , fTypeface(std::move(typeface))
572 , fFontInfo(std::move(info))
573 , fDescriptor(std::move(relatedFontDescriptor))
580 , fFirstGlyphID(1) 574 , fFirstGlyphID(1)
581 , fLastGlyphID(info ? info->fLastGlyphID : 0) 575 , fFontType(fontType)
582 , fFontInfo(SkSafeRef(info)) 576 , fMultiByteGlyphs(multiByteGlyphs) {
583 , fDescriptor(SkSafeRef(relatedFontDescriptor))
584 , fFontType((!info || info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster _FontFlag)
585 ? SkAdvancedTypefaceMetrics::kOther_Font
586 : info->fType) {
587 SkASSERT(fTypeface); 577 SkASSERT(fTypeface);
578 fLastGlyphID = fFontInfo ? fFontInfo->fLastGlyphID : 0;
588 if (0 == fLastGlyphID) { 579 if (0 == fLastGlyphID) {
589 fLastGlyphID = SkToU16(fTypeface->countGlyphs() - 1); 580 fLastGlyphID = SkToU16(fTypeface->countGlyphs() - 1);
590 } 581 }
591 } 582 }
592 583
593 // static 584 // static
594 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, 585 sk_sp<SkPDFFont> SkPDFFont::Create(SkPDFCanon* canon,
595 const SkAdvancedTypefaceMetrics* info, 586 sk_sp<const SkAdvancedTypefaceMetrics> info,
596 SkTypeface* typeface, 587 sk_sp<SkTypeface> typeface,
597 uint16_t glyphID, 588 uint16_t glyphID,
598 SkPDFDict* relatedFontDescriptor) { 589 sk_sp<SkPDFDict> relatedFontDescriptor) {
599 SkAdvancedTypefaceMetrics::FontType type = 590 SkAdvancedTypefaceMetrics::FontType type =
600 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; 591 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font;
601 SkAdvancedTypefaceMetrics::FontFlags flags = 592 SkAdvancedTypefaceMetrics::FontFlags flags =
602 info ? info->fFlags : SkAdvancedTypefaceMetrics::kEmpty_FontFlag; 593 info ? info->fFlags : (SkAdvancedTypefaceMetrics::FontFlags)0;
603 if (SkToBool(flags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) { 594 if (SkToBool(flags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
604 return new SkPDFType3Font(info, typeface, glyphID); 595 return sk_make_sp<SkPDFType3Font>(info, typeface, type, glyphID);
605 } 596 }
606 switch (type) { 597 switch (type) {
607 case SkAdvancedTypefaceMetrics::kType1CID_Font: 598 case SkAdvancedTypefaceMetrics::kType1CID_Font:
608 case SkAdvancedTypefaceMetrics::kTrueType_Font: 599 case SkAdvancedTypefaceMetrics::kTrueType_Font:
609 SkASSERT(relatedFontDescriptor == nullptr); 600 SkASSERT(relatedFontDescriptor == nullptr);
610 SkASSERT(info != nullptr); 601 SkASSERT(info != nullptr);
611 return new SkPDFType0Font(info, typeface); 602 return sk_make_sp<SkPDFType0Font>(std::move(info),
603 std::move(typeface),
604 type);
612 case SkAdvancedTypefaceMetrics::kType1_Font: 605 case SkAdvancedTypefaceMetrics::kType1_Font:
613 SkASSERT(info != nullptr); 606 SkASSERT(info != nullptr);
614 return new SkPDFType1Font(info, typeface, glyphID, relatedFontDescri ptor); 607 return sk_make_sp<SkPDFType1Font>(std::move(info),
608 std::move(typeface),
609 glyphID,
610 std::move(relatedFontDescriptor));
615 case SkAdvancedTypefaceMetrics::kCFF_Font: 611 case SkAdvancedTypefaceMetrics::kCFF_Font:
616 SkASSERT(info != nullptr); 612 SkASSERT(info != nullptr);
617 // fallthrough 613 // fallthrough
618 case SkAdvancedTypefaceMetrics::kOther_Font: 614 case SkAdvancedTypefaceMetrics::kOther_Font:
619 return new SkPDFType3Font(info, typeface, glyphID); 615 return sk_make_sp<SkPDFType3Font>(std::move(info),
616 std::move(typeface),
617 type,
618 glyphID);
620 } 619 }
621 SkDEBUGFAIL("invalid SkAdvancedTypefaceMetrics::FontType"); 620 SkDEBUGFAIL("invalid SkAdvancedTypefaceMetrics::FontType");
622 return nullptr; 621 return nullptr;
623 } 622 }
624 623
625 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { 624 void SkPDFFont::setFontInfo(sk_sp<const SkAdvancedTypefaceMetrics> info) {
626 return fFontInfo.get(); 625 if (info) {
627 } 626 fFontInfo = std::move(info);
628
629 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) {
630 if (info == nullptr || info == fFontInfo.get()) {
631 return;
632 } 627 }
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 } 628 }
644 629
645 void SkPDFFont::setLastGlyphID(uint16_t glyphID) { 630 void SkPDFFont::setLastGlyphID(uint16_t glyphID) {
646 fLastGlyphID = glyphID; 631 fLastGlyphID = glyphID;
647 } 632 }
648 633
649 SkPDFDict* SkPDFFont::getFontDescriptor() { 634 void SkPDFFont::setFontDescriptor(sk_sp<SkPDFDict> descriptor) {
650 return fDescriptor.get(); 635 fDescriptor = std::move(descriptor);
651 }
652
653 void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) {
654 fDescriptor.reset(descriptor);
655 SkSafeRef(descriptor);
656 } 636 }
657 637
658 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) { 638 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) {
659 if (fDescriptor.get() == nullptr) { 639 if (fDescriptor.get() == nullptr) {
660 return false; 640 return false;
661 } 641 }
662 642
663 const uint16_t emSize = fFontInfo->fEmSize; 643 const uint16_t emSize = fFontInfo->fEmSize;
664 644
665 fDescriptor->insertName("FontName", fFontInfo->fFontName); 645 fDescriptor->insertName("FontName", fFontInfo->fFontName);
666 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic); 646 fDescriptor->insertInt("Flags", (size_t)(fFontInfo->fStyle | kPdfSymbolic));
667 fDescriptor->insertScalar("Ascent", 647 fDescriptor->insertScalar("Ascent",
668 scaleFromFontUnits(fFontInfo->fAscent, emSize)); 648 scaleFromFontUnits(fFontInfo->fAscent, emSize));
669 fDescriptor->insertScalar("Descent", 649 fDescriptor->insertScalar("Descent",
670 scaleFromFontUnits(fFontInfo->fDescent, emSize)); 650 scaleFromFontUnits(fFontInfo->fDescent, emSize));
671 fDescriptor->insertScalar("StemV", 651 fDescriptor->insertScalar("StemV",
672 scaleFromFontUnits(fFontInfo->fStemV, emSize)); 652 scaleFromFontUnits(fFontInfo->fStemV, emSize));
673 653
674 fDescriptor->insertScalar("CapHeight", 654 fDescriptor->insertScalar("CapHeight",
675 scaleFromFontUnits(fFontInfo->fCapHeight, emSize)); 655 scaleFromFontUnits(fFontInfo->fCapHeight, emSize));
676 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle); 656 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle);
(...skipping 24 matching lines...) Expand all
701 subset, 681 subset,
702 multiByteGlyphs(), 682 multiByteGlyphs(),
703 firstGlyphID(), 683 firstGlyphID(),
704 lastGlyphID())); 684 lastGlyphID()));
705 } 685 }
706 686
707 /////////////////////////////////////////////////////////////////////////////// 687 ///////////////////////////////////////////////////////////////////////////////
708 // class SkPDFType0Font 688 // class SkPDFType0Font
709 /////////////////////////////////////////////////////////////////////////////// 689 ///////////////////////////////////////////////////////////////////////////////
710 690
711 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, SkTypeface * typeface) 691 SkPDFType0Font::SkPDFType0Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
712 : SkPDFFont(info, typeface, nullptr) { 692 sk_sp<SkTypeface> typeface,
693 SkAdvancedTypefaceMetrics::FontType fontType)
694 : SkPDFFont(std::move(info), std::move(typeface), nullptr, fontType, true) {
713 SkDEBUGCODE(fPopulated = false); 695 SkDEBUGCODE(fPopulated = false);
714 if (!canSubset()) { 696 if (!canSubset()) {
715 this->populate(nullptr); 697 this->populate(nullptr);
716 } 698 }
717 } 699 }
718 700
719 SkPDFType0Font::~SkPDFType0Font() {} 701 SkPDFType0Font::~SkPDFType0Font() {}
720 702
721 sk_sp<SkPDFObject> SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { 703 sk_sp<SkPDFObject> SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
722 if (!canSubset()) { 704 if (!canSubset()) {
723 return nullptr; 705 return nullptr;
724 } 706 }
725 auto newSubset = sk_make_sp<SkPDFType0Font>(fontInfo(), typeface()); 707 auto newSubset = sk_make_sp<SkPDFType0Font>(refFontInfo(), refTypeface(), ge tType());
726 newSubset->populate(subset); 708 newSubset->populate(subset);
727 return newSubset; 709 return newSubset;
728 } 710 }
729 711
730 #ifdef SK_DEBUG 712 #ifdef SK_DEBUG
731 void SkPDFType0Font::emitObject(SkWStream* stream, 713 void SkPDFType0Font::emitObject(SkWStream* stream,
732 const SkPDFObjNumMap& objNumMap, 714 const SkPDFObjNumMap& objNumMap,
733 const SkPDFSubstituteMap& substitutes) const { 715 const SkPDFSubstituteMap& substitutes) const {
734 SkASSERT(fPopulated); 716 SkASSERT(fPopulated);
735 return INHERITED::emitObject(stream, objNumMap, substitutes); 717 return INHERITED::emitObject(stream, objNumMap, substitutes);
736 } 718 }
737 #endif 719 #endif
738 720
739 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { 721 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
740 insertName("Subtype", "Type0"); 722 insertName("Subtype", "Type0");
741 insertName("BaseFont", fontInfo()->fFontName); 723 insertName("BaseFont", this->getFontInfo()->fFontName);
742 insertName("Encoding", "Identity-H"); 724 insertName("Encoding", "Identity-H");
743 725
744 sk_sp<SkPDFCIDFont> newCIDFont( 726 sk_sp<SkPDFCIDFont> newCIDFont(
745 new SkPDFCIDFont(fontInfo(), typeface(), subset)); 727 sk_make_sp<SkPDFCIDFont>(this->refFontInfo(),
728 this->refTypeface(),
729 this->getType(),
730 subset));
746 auto descendantFonts = sk_make_sp<SkPDFArray>(); 731 auto descendantFonts = sk_make_sp<SkPDFArray>();
747 descendantFonts->appendObjRef(std::move(newCIDFont)); 732 descendantFonts->appendObjRef(std::move(newCIDFont));
748 this->insertObject("DescendantFonts", std::move(descendantFonts)); 733 this->insertObject("DescendantFonts", std::move(descendantFonts));
749 734
750 this->populateToUnicodeTable(subset); 735 this->populateToUnicodeTable(subset);
751 736
752 SkDEBUGCODE(fPopulated = true); 737 SkDEBUGCODE(fPopulated = true);
753 return true; 738 return true;
754 } 739 }
755 740
756 /////////////////////////////////////////////////////////////////////////////// 741 ///////////////////////////////////////////////////////////////////////////////
757 // class SkPDFCIDFont 742 // class SkPDFCIDFont
758 /////////////////////////////////////////////////////////////////////////////// 743 ///////////////////////////////////////////////////////////////////////////////
759 744
760 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, 745 SkPDFCIDFont::SkPDFCIDFont(sk_sp<const SkAdvancedTypefaceMetrics> info,
761 SkTypeface* typeface, 746 sk_sp<SkTypeface> typeface,
747 SkAdvancedTypefaceMetrics::FontType fontType,
762 const SkPDFGlyphSet* subset) 748 const SkPDFGlyphSet* subset)
763 : SkPDFFont(info, typeface, nullptr) { 749 : SkPDFFont(std::move(info), std::move(typeface), nullptr,
750 fontType , /* multiByteGlyphs = */ true) {
764 this->populate(subset); 751 this->populate(subset);
765 } 752 }
766 753
767 SkPDFCIDFont::~SkPDFCIDFont() {} 754 SkPDFCIDFont::~SkPDFCIDFont() {}
768 755
769 #ifdef SK_SFNTLY_SUBSETTER 756 #ifdef SK_SFNTLY_SUBSETTER
770 // if possible, make no copy. 757 // if possible, make no copy.
771 static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) { 758 static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) {
772 SkASSERT(stream); 759 SkASSERT(stream);
773 (void)stream->rewind(); 760 (void)stream->rewind();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 [](const void* p, void*) { delete[] (unsigned char*)p; }, 802 [](const void* p, void*) { delete[] (unsigned char*)p; },
816 nullptr)); 803 nullptr));
817 subsetStream->dict()->insertInt("Length1", subsetFontSize); 804 subsetStream->dict()->insertInt("Length1", subsetFontSize);
818 return subsetStream; 805 return subsetStream;
819 } 806 }
820 #endif // SK_SFNTLY_SUBSETTER 807 #endif // SK_SFNTLY_SUBSETTER
821 808
822 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 809 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
823 const SkTDArray<uint32_t>* subset) { 810 const SkTDArray<uint32_t>* subset) {
824 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); 811 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
825 setFontDescriptor(descriptor.get()); 812 setFontDescriptor(descriptor);
826 if (!addCommonFontDescriptorEntries(defaultWidth)) { 813 if (!addCommonFontDescriptorEntries(defaultWidth)) {
827 this->insertObjRef("FontDescriptor", std::move(descriptor)); 814 this->insertObjRef("FontDescriptor", std::move(descriptor));
828 return false; 815 return false;
829 } 816 }
830 SkASSERT(this->canEmbed()); 817 SkASSERT(this->canEmbed());
831 818
832 switch (getType()) { 819 switch (getType()) {
833 case SkAdvancedTypefaceMetrics::kTrueType_Font: { 820 case SkAdvancedTypefaceMetrics::kTrueType_Font: {
834 int ttcIndex; 821 int ttcIndex;
835 std::unique_ptr<SkStreamAsset> fontAsset( 822 std::unique_ptr<SkStreamAsset> fontAsset(
836 this->typeface()->openStream(&ttcIndex)); 823 this->typeface()->openStream(&ttcIndex));
837 SkASSERT(fontAsset); 824 SkASSERT(fontAsset);
838 if (!fontAsset) { 825 if (!fontAsset) {
839 return false; 826 return false;
840 } 827 }
841 size_t fontSize = fontAsset->getLength(); 828 size_t fontSize = fontAsset->getLength();
842 SkASSERT(fontSize > 0); 829 SkASSERT(fontSize > 0);
843 if (fontSize == 0) { 830 if (fontSize == 0) {
844 return false; 831 return false;
845 } 832 }
846 833
847 #ifdef SK_SFNTLY_SUBSETTER 834 #ifdef SK_SFNTLY_SUBSETTER
848 if (this->canSubset() && subset) { 835 if (this->canSubset() && subset) {
836 const char* name = this->getFontInfo()->fFontName.c_str();
849 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( 837 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream(
850 std::move(fontAsset), *subset, fontInfo()->fFontName.c_s tr()); 838 std::move(fontAsset), *subset, name);
851 if (subsetStream) { 839 if (subsetStream) {
852 descriptor->insertObjRef("FontFile2", std::move(subsetStream )); 840 descriptor->insertObjRef("FontFile2", std::move(subsetStream ));
853 break; 841 break;
854 } 842 }
855 // If subsetting fails, fall back to original font data. 843 // If subsetting fails, fall back to original font data.
856 fontAsset.reset(this->typeface()->openStream(&ttcIndex)); 844 fontAsset.reset(this->typeface()->openStream(&ttcIndex));
857 } 845 }
858 #endif // SK_SFNTLY_SUBSETTER 846 #endif // SK_SFNTLY_SUBSETTER
859 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset) ); 847 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset) );
860 fontStream->dict()->insertInt("Length1", fontSize); 848 fontStream->dict()->insertInt("Length1", fontSize);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { 908 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
921 // Generate new font metrics with advance info for true type fonts. 909 // Generate new font metrics with advance info for true type fonts.
922 // Generate glyph id array. 910 // Generate glyph id array.
923 SkTDArray<uint32_t> glyphIDs; 911 SkTDArray<uint32_t> glyphIDs;
924 if (subset) { 912 if (subset) {
925 if (!subset->has(0)) { 913 if (!subset->has(0)) {
926 glyphIDs.push(0); // Always include glyph 0. 914 glyphIDs.push(0); // Always include glyph 0.
927 } 915 }
928 subset->exportTo(&glyphIDs); 916 subset->exportTo(&glyphIDs);
929 } 917 }
930 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { 918 if (this->getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
931 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); 919 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin();
932 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; 920 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
933 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics = 921 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics =
934 SkPDFFont::GetFontMetricsWithGlyphNames(this->typeface(), glyphs, gl yphsCount); 922 SkPDFFont::GetFontMetricsWithGlyphNames(this->typeface(), glyphs, gl yphsCount);
935 this->setFontInfo(fontMetrics.get()); 923 this->setFontInfo(std::move(fontMetrics));
936 this->addFontDescriptor(0, &glyphIDs); 924 this->addFontDescriptor(0, &glyphIDs);
937 } else { 925 } else {
938 // Other CID fonts 926 // Other CID fonts
939 addFontDescriptor(0, nullptr); 927 addFontDescriptor(0, nullptr);
940 } 928 }
941 929
942 insertName("BaseFont", fontInfo()->fFontName); 930 insertName("BaseFont", this->getFontInfo()->fFontName);
943 931
944 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { 932 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) {
945 insertName("Subtype", "CIDFontType0"); 933 insertName("Subtype", "CIDFontType0");
946 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { 934 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
947 insertName("Subtype", "CIDFontType2"); 935 insertName("Subtype", "CIDFontType2");
948 insertName("CIDToGIDMap", "Identity"); 936 insertName("CIDToGIDMap", "Identity");
949 } else { 937 } else {
950 SkASSERT(false); 938 SkASSERT(false);
951 } 939 }
952 940
953 auto sysInfo = sk_make_sp<SkPDFDict>(); 941 auto sysInfo = sk_make_sp<SkPDFDict>();
954 sysInfo->insertString("Registry", "Adobe"); 942 sysInfo->insertString("Registry", "Adobe");
955 sysInfo->insertString("Ordering", "Identity"); 943 sysInfo->insertString("Ordering", "Identity");
956 sysInfo->insertInt("Supplement", 0); 944 sysInfo->insertInt("Supplement", 0);
957 this->insertObject("CIDSystemInfo", std::move(sysInfo)); 945 this->insertObject("CIDSystemInfo", std::move(sysInfo));
958 946
959 SkSinglyLinkedList<AdvanceMetric> tmpMetrics; 947 SkSinglyLinkedList<AdvanceMetric> tmpMetrics;
960 set_glyph_widths(this->typeface(), &glyphIDs, &tmpMetrics); 948 set_glyph_widths(this->typeface(), &glyphIDs, &tmpMetrics);
961 int16_t defaultWidth = 0; 949 int16_t defaultWidth = 0;
962 uint16_t emSize = (uint16_t)this->fontInfo()->fEmSize; 950 uint16_t emSize = (uint16_t)this->getFontInfo()->fEmSize;
963 sk_sp<SkPDFArray> widths = composeAdvanceData(tmpMetrics, emSize, &defaultWi dth); 951 sk_sp<SkPDFArray> widths = composeAdvanceData(tmpMetrics, emSize, &defaultWi dth);
964 if (widths->size()) { 952 if (widths->size()) {
965 this->insertObject("W", std::move(widths)); 953 this->insertObject("W", std::move(widths));
966 } 954 }
967 955
968 this->insertScalar( 956 this->insertScalar(
969 "DW", scaleFromFontUnits(defaultWidth, emSize)); 957 "DW", scaleFromFontUnits(defaultWidth, emSize));
970 return true; 958 return true;
971 } 959 }
972 960
973 /////////////////////////////////////////////////////////////////////////////// 961 ///////////////////////////////////////////////////////////////////////////////
974 // class SkPDFType1Font 962 // class SkPDFType1Font
975 /////////////////////////////////////////////////////////////////////////////// 963 ///////////////////////////////////////////////////////////////////////////////
976 964
977 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 965 SkPDFType1Font::SkPDFType1Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
978 SkTypeface* typeface, 966 sk_sp<SkTypeface> typeface,
979 uint16_t glyphID, 967 uint16_t glyphID,
980 SkPDFDict* relatedFontDescriptor) 968 sk_sp<SkPDFDict> relatedFontDescriptor)
981 : SkPDFFont(info, typeface, relatedFontDescriptor) { 969 : SkPDFFont(std::move(info),
982 this->populate(glyphID); 970 std::move(typeface),
971 std::move(relatedFontDescriptor),
972 SkAdvancedTypefaceMetrics::kType1_Font,
973 /* multiByteGlyphs = */ false) {
974 this->populate(glyphID); // TODO(halcanary): subset this.
983 } 975 }
984 976
985 SkPDFType1Font::~SkPDFType1Font() {} 977 SkPDFType1Font::~SkPDFType1Font() {}
986 978
987 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 979 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
988 if (SkPDFDict* descriptor = getFontDescriptor()) { 980 if (sk_sp<SkPDFDict> descriptor = this->refFontDescriptor()) {
989 this->insertObjRef("FontDescriptor", 981 this->insertObjRef("FontDescriptor", std::move(descriptor));
990 sk_ref_sp(descriptor));
991 return true; 982 return true;
992 } 983 }
993 984
994 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); 985 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
995 setFontDescriptor(descriptor.get()); 986 setFontDescriptor(descriptor);
996 987
997 int ttcIndex; 988 int ttcIndex;
998 size_t header SK_INIT_TO_AVOID_WARNING; 989 size_t header SK_INIT_TO_AVOID_WARNING;
999 size_t data SK_INIT_TO_AVOID_WARNING; 990 size_t data SK_INIT_TO_AVOID_WARNING;
1000 size_t trailer SK_INIT_TO_AVOID_WARNING; 991 size_t trailer SK_INIT_TO_AVOID_WARNING;
1001 std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex) ); 992 std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex) );
1002 sk_sp<SkData> fontData = SkPDFConvertType1FontStream(std::move(rawFontData), 993 sk_sp<SkData> fontData = SkPDFConvertType1FontStream(std::move(rawFontData),
1003 &header, &data, &traile r); 994 &header, &data, &traile r);
1004 if (!fontData) { 995 if (!fontData) {
1005 return false; 996 return false;
1006 } 997 }
1007 SkASSERT(this->canEmbed()); 998 SkASSERT(this->canEmbed());
1008 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData)); 999 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData));
1009 fontStream->dict()->insertInt("Length1", header); 1000 fontStream->dict()->insertInt("Length1", header);
1010 fontStream->dict()->insertInt("Length2", data); 1001 fontStream->dict()->insertInt("Length2", data);
1011 fontStream->dict()->insertInt("Length3", trailer); 1002 fontStream->dict()->insertInt("Length3", trailer);
1012 descriptor->insertObjRef("FontFile", std::move(fontStream)); 1003 descriptor->insertObjRef("FontFile", std::move(fontStream));
1013 1004
1014 this->insertObjRef("FontDescriptor", std::move(descriptor)); 1005 this->insertObjRef("FontDescriptor", std::move(descriptor));
1015 1006
1016 return addCommonFontDescriptorEntries(defaultWidth); 1007 return addCommonFontDescriptorEntries(defaultWidth);
1017 } 1008 }
1018 1009
1019 bool SkPDFType1Font::populate(int16_t glyphID) { 1010 bool SkPDFType1Font::populate(int16_t glyphID) {
1020 this->insertName("Subtype", "Type1"); 1011 this->insertName("Subtype", "Type1");
1021 this->insertName("BaseFont", fontInfo()->fFontName); 1012 this->insertName("BaseFont", this->getFontInfo()->fFontName);
1022 adjustGlyphRangeForSingleByteEncoding(glyphID); 1013 adjustGlyphRangeForSingleByteEncoding(glyphID);
1023 SkGlyphID firstGlyphID = this->firstGlyphID(); 1014 SkGlyphID firstGlyphID = this->firstGlyphID();
1024 SkGlyphID lastGlyphID = this->lastGlyphID(); 1015 SkGlyphID lastGlyphID = this->lastGlyphID();
1025 1016
1026 // glyphCount not including glyph 0 1017 // glyphCount not including glyph 0
1027 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID; 1018 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID;
1028 SkASSERT(glyphCount > 0 && glyphCount <= 255); 1019 SkASSERT(glyphCount > 0 && glyphCount <= 255);
1029 this->insertInt("FirstChar", (size_t)0); 1020 this->insertInt("FirstChar", (size_t)0);
1030 this->insertInt("LastChar", (size_t)glyphCount); 1021 this->insertInt("LastChar", (size_t)glyphCount);
1031 { 1022 {
1032 SkPaint tmpPaint; 1023 SkPaint tmpPaint;
1033 tmpPaint.setHinting(SkPaint::kNo_Hinting); 1024 tmpPaint.setHinting(SkPaint::kNo_Hinting);
1034 tmpPaint.setTypeface(sk_ref_sp(this->typeface())); 1025 tmpPaint.setTypeface(sk_ref_sp(this->typeface()));
1035 tmpPaint.setTextSize((SkScalar)this->typeface()->getUnitsPerEm()); 1026 tmpPaint.setTextSize((SkScalar)this->typeface()->getUnitsPerEm());
1036 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 1027 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
1037 SkAutoGlyphCache glyphCache(tmpPaint, &props, nullptr); 1028 SkAutoGlyphCache glyphCache(tmpPaint, &props, nullptr);
1038 auto widths = sk_make_sp<SkPDFArray>(); 1029 auto widths = sk_make_sp<SkPDFArray>();
1039 SkScalar advance = glyphCache->getGlyphIDAdvance(0).fAdvanceX; 1030 SkScalar advance = glyphCache->getGlyphIDAdvance(0).fAdvanceX;
1040 const uint16_t emSize = this->fontInfo()->fEmSize; 1031 const uint16_t emSize = this->getFontInfo()->fEmSize;
1041 widths->appendScalar(from_font_units(advance, emSize)); 1032 widths->appendScalar(from_font_units(advance, emSize));
1042 for (unsigned gID = firstGlyphID; gID <= lastGlyphID; gID++) { 1033 for (unsigned gID = firstGlyphID; gID <= lastGlyphID; gID++) {
1043 advance = glyphCache->getGlyphIDAdvance(gID).fAdvanceX; 1034 advance = glyphCache->getGlyphIDAdvance(gID).fAdvanceX;
1044 widths->appendScalar(from_font_units(advance, emSize)); 1035 widths->appendScalar(from_font_units(advance, emSize));
1045 } 1036 }
1046 this->insertObject("Widths", std::move(widths)); 1037 this->insertObject("Widths", std::move(widths));
1047 } 1038 }
1048 if (!addFontDescriptor(0)) { 1039 if (!addFontDescriptor(0)) {
1049 return false; 1040 return false;
1050 } 1041 }
1051 auto encDiffs = sk_make_sp<SkPDFArray>(); 1042 auto encDiffs = sk_make_sp<SkPDFArray>();
1052 encDiffs->reserve(lastGlyphID - firstGlyphID + 3); 1043 encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
1053 encDiffs->appendInt(0); 1044 encDiffs->appendInt(0);
1054 const SkTArray<SkString>& glyphNames = this->fontInfo()->fGlyphNames; 1045 const SkTArray<SkString>& glyphNames = this->getFontInfo()->fGlyphNames;
1055 SkASSERT(glyphNames.count() > lastGlyphID); 1046 SkASSERT(glyphNames.count() > lastGlyphID);
1056 encDiffs->appendName(glyphNames[0].c_str()); 1047 encDiffs->appendName(glyphNames[0].c_str());
1057 const SkString unknown("UNKNOWN"); 1048 const SkString unknown("UNKNOWN");
1058 for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) { 1049 for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) {
1059 const bool valid = gID < glyphNames.count() && !glyphNames[gID].isEmpty( ); 1050 const bool valid = gID < glyphNames.count() && !glyphNames[gID].isEmpty( );
1060 const SkString& name = valid ? glyphNames[gID] : unknown; 1051 const SkString& name = valid ? glyphNames[gID] : unknown;
1061 encDiffs->appendName(name); 1052 encDiffs->appendName(name);
1062 } 1053 }
1063 1054
1064 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); 1055 auto encoding = sk_make_sp<SkPDFDict>("Encoding");
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 subset, 1205 subset,
1215 false, 1206 false,
1216 firstGlyphID, 1207 firstGlyphID,
1217 lastGlyphID)); 1208 lastGlyphID));
1218 } 1209 }
1219 font->insertObject("Widths", std::move(widthArray)); 1210 font->insertObject("Widths", std::move(widthArray));
1220 font->insertObject("Encoding", std::move(encoding)); 1211 font->insertObject("Encoding", std::move(encoding));
1221 font->insertObject("CharProcs", std::move(charProcs)); 1212 font->insertObject("CharProcs", std::move(charProcs));
1222 } 1213 }
1223 1214
1224 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 1215 SkPDFType3Font::SkPDFType3Font(sk_sp<const SkAdvancedTypefaceMetrics> info,
1225 SkTypeface* typeface, 1216 sk_sp<SkTypeface> typeface,
1217 SkAdvancedTypefaceMetrics::FontType fontType,
1226 uint16_t glyphID) 1218 uint16_t glyphID)
1227 : SkPDFFont(info, typeface, nullptr) { 1219 : SkPDFFont(std::move(info), std::move(typeface), nullptr,
1220 fontType, /* multiByteGlyphs = */ false) {
1228 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up. 1221 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up.
1229 this->setLastGlyphID(SkToU16(typeface->countGlyphs() - 1)); 1222 this->setLastGlyphID(SkToU16(typeface->countGlyphs() - 1));
1230 this->adjustGlyphRangeForSingleByteEncoding(glyphID); 1223 this->adjustGlyphRangeForSingleByteEncoding(glyphID);
1231 } 1224 }
1232 1225
1233 sk_sp<SkPDFObject> SkPDFType3Font::getFontSubset(const SkPDFGlyphSet* usage) { 1226 sk_sp<SkPDFObject> SkPDFType3Font::getFontSubset(const SkPDFGlyphSet* usage) {
1234 // All fonts are subset before serialization. 1227 // All fonts are subset before serialization.
1235 // TODO(halcanary): all fonts should follow this pattern. 1228 // TODO(halcanary): all fonts should follow this pattern.
1236 auto font = sk_make_sp<SkPDFDict>("Font"); 1229 auto font = sk_make_sp<SkPDFDict>("Font");
1237 const SkAdvancedTypefaceMetrics* info = this->fontInfo(); 1230 const SkAdvancedTypefaceMetrics* info = this->getFontInfo();
1238 uint16_t emSize = info && info->fEmSize > 0 ? info->fEmSize : 1000; 1231 uint16_t emSize = info && info->fEmSize > 0 ? info->fEmSize : 1000;
1239 add_type3_font_info(font.get(), this->typeface(), (SkScalar)emSize, usage, 1232 add_type3_font_info(font.get(), this->typeface(), (SkScalar)emSize, usage,
1240 this->firstGlyphID(), this->lastGlyphID()); 1233 this->firstGlyphID(), this->lastGlyphID());
1241 return font; 1234 return font;
1242 } 1235 }
1243 1236
1244 1237
1245 //////////////////////////////////////////////////////////////////////////////// 1238 ////////////////////////////////////////////////////////////////////////////////
1246 1239
1247 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, 1240 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 } 1276 }
1284 return *canon->fCanEmbedTypeface.set(id, canEmbed); 1277 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1285 } 1278 }
1286 1279
1287 void SkPDFFont::drop() { 1280 void SkPDFFont::drop() {
1288 fTypeface = nullptr; 1281 fTypeface = nullptr;
1289 fFontInfo = nullptr; 1282 fFontInfo = nullptr;
1290 fDescriptor = nullptr; 1283 fDescriptor = nullptr;
1291 this->SkPDFDict::drop(); 1284 this->SkPDFDict::drop();
1292 } 1285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698