From 5bdc4d590b905b3d3fba0da80051ac576e705e2c Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Tue, 10 Apr 2018 11:13:24 -0400 Subject: SkAdvancedTypefaceMetrics: simplify more Change-Id: I80c28c50aa96c28181d2fef13daad4a80ec91a12 Reviewed-on: https://skia-review.googlesource.com/120160 Reviewed-by: Ben Wagner Commit-Queue: Hal Canary --- src/pdf/SkPDFCanon.h | 4 ++++ src/pdf/SkPDFFont.cpp | 25 ++++++++++++++++++------- src/pdf/SkPDFFont.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/pdf') 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 + #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> fPDFBitmapMap; SkTHashMap> fTypefaceMetrics; + SkTHashMap> fType1GlyphNames; SkTHashMap> fFontDescriptors; SkTHashMap> 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 make_type1_font_descriptor( static void populate_type_1_font(SkPDFDict* font, const SkAdvancedTypefaceMetrics& info, + const std::vector& glyphNames, SkTypeface* typeface, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID) { @@ -547,14 +548,12 @@ static void populate_type_1_font(SkPDFDict* font, auto encDiffs = sk_make_sp(); encDiffs->reserve(lastGlyphID - firstGlyphID + 3); encDiffs->appendInt(0); - const SkTArray& 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("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* glyphNames = canon->fType1GlyphNames.find(fontID); + if (!glyphNames) { + std::vector 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 || -- cgit v1.2.3