diff options
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFCanon.h | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 25 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.h | 1 |
3 files changed, 23 insertions, 7 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h index 99d8ab8a0d..8d0e8f8fed 100644 --- a/src/pdf/SkPDFCanon.h +++ b/src/pdf/SkPDFCanon.h @@ -7,6 +7,8 @@ #ifndef SkPDFCanon_DEFINED #define SkPDFCanon_DEFINED +#include <vector> + #include "SkBitmapKey.h" #include "SkPDFGradientShader.h" #include "SkPDFGraphicState.h" @@ -14,6 +16,7 @@ #include "SkTDArray.h" #include "SkTHash.h" #include "SkTypeface.h" +#include "SkString.h" class SkPDFFont; struct SkAdvancedTypefaceMetrics; @@ -38,6 +41,7 @@ public: SkTHashMap<SkBitmapKey, sk_sp<SkPDFObject>> fPDFBitmapMap; SkTHashMap<uint32_t, std::unique_ptr<SkAdvancedTypefaceMetrics>> fTypefaceMetrics; + SkTHashMap<uint32_t, std::vector<SkString>> fType1GlyphNames; SkTHashMap<uint32_t, sk_sp<SkPDFDict>> fFontDescriptors; SkTHashMap<uint64_t, sk_sp<SkPDFFont>> fFontMap; diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index c8b576afe6..9ba411495a 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -521,6 +521,7 @@ static sk_sp<SkPDFDict> make_type1_font_descriptor( static void populate_type_1_font(SkPDFDict* font, const SkAdvancedTypefaceMetrics& info, + const std::vector<SkString>& glyphNames, SkTypeface* typeface, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID) { @@ -547,14 +548,12 @@ static void populate_type_1_font(SkPDFDict* font, auto encDiffs = sk_make_sp<SkPDFArray>(); encDiffs->reserve(lastGlyphID - firstGlyphID + 3); encDiffs->appendInt(0); - const SkTArray<SkString>& glyphNames = info.fGlyphNames; - SkASSERT(glyphNames.count() > lastGlyphID); - encDiffs->appendName(glyphNames[0].c_str()); + + SkASSERT(glyphNames.size() > lastGlyphID); const SkString unknown("UNKNOWN"); + encDiffs->appendName(glyphNames[0].isEmpty() ? unknown : glyphNames[0]); for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) { - const bool valid = gID < glyphNames.count() && !glyphNames[gID].isEmpty(); - const SkString& name = valid ? glyphNames[gID] : unknown; - encDiffs->appendName(name); + encDiffs->appendName(glyphNames[gID].isEmpty() ? unknown : glyphNames[gID]); } auto encoding = sk_make_sp<SkPDFDict>("Encoding"); @@ -562,6 +561,10 @@ static void populate_type_1_font(SkPDFDict* font, font->insertObject("Encoding", std::move(encoding)); } +void SkPDFFont::GetType1GlyphNames(const SkTypeface& face, SkString* dst) { + face.getPostScriptGlyphNames(dst); +} + SkPDFType1Font::SkPDFType1Font(SkPDFFont::Info info, const SkAdvancedTypefaceMetrics& metrics, SkPDFCanon* canon) @@ -576,8 +579,16 @@ SkPDFType1Font::SkPDFType1Font(SkPDFFont::Info info, canon->fFontDescriptors.set(fontID, fontDescriptor); } this->insertObjRef("FontDescriptor", std::move(fontDescriptor)); + + std::vector<SkString>* glyphNames = canon->fType1GlyphNames.find(fontID); + if (!glyphNames) { + std::vector<SkString> names(this->typeface()->countGlyphs()); + SkPDFFont::GetType1GlyphNames(*this->typeface(), names.data()); + glyphNames = canon->fType1GlyphNames.set(fontID, std::move(names)); + } + SkASSERT(glyphNames); // TODO(halcanary): subset this (advances and names). - populate_type_1_font(this, metrics, this->typeface(), + populate_type_1_font(this, metrics, *glyphNames, this->typeface(), this->firstGlyphID(), this->lastGlyphID()); } diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index 746f4fab25..9dc4655501 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -42,6 +42,7 @@ public: SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; } static SkAdvancedTypefaceMetrics::FontType FontType(const SkAdvancedTypefaceMetrics&); + static void GetType1GlyphNames(const SkTypeface&, SkString*); static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type) { return type == SkAdvancedTypefaceMetrics::kType1CID_Font || |