From 97c1108607584b6050a6880d6ce22846e4913a92 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Wed, 9 May 2018 15:35:54 +0000 Subject: Revert "SkAdvancedTypefaceMetrics: factor out GlyphToUnicode" This reverts commit 1c2bcd8b14e029a70e88b1e81acd29553cab0d1c. Reason for revert: breaking chrome roll Original change's description: > SkAdvancedTypefaceMetrics: factor out GlyphToUnicode > > Change-Id: Iedce8c1ea2c405d5ab64ccac353970d5cd2b9d63 > Reviewed-on: https://skia-review.googlesource.com/126507 > Commit-Queue: Hal Canary > Reviewed-by: Ben Wagner TBR=halcanary@google.com,bungeman@google.com,reed@google.com Change-Id: Ib1ff8484ffd09cdb88d461ac00745aa32c191124 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/127000 Reviewed-by: Greg Daniel Commit-Queue: Greg Daniel --- src/pdf/SkPDFCanon.h | 1 - src/pdf/SkPDFDevice.cpp | 8 +++---- src/pdf/SkPDFFont.cpp | 47 +++++++++++++------------------------- src/pdf/SkPDFFont.h | 3 --- src/pdf/SkPDFMakeToUnicodeCmap.cpp | 10 +++++--- src/pdf/SkPDFMakeToUnicodeCmap.h | 4 ++-- 6 files changed, 28 insertions(+), 45 deletions(-) (limited to 'src/pdf') diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h index 8e97db05f5..8d0e8f8fed 100644 --- a/src/pdf/SkPDFCanon.h +++ b/src/pdf/SkPDFCanon.h @@ -42,7 +42,6 @@ public: SkTHashMap> fTypefaceMetrics; SkTHashMap> fType1GlyphNames; - SkTHashMap> fToUnicodeMap; SkTHashMap> fFontDescriptors; SkTHashMap> fFontMap; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index c18219ab0d..6e36fb3d82 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1052,8 +1052,8 @@ private: }; } // namespace -static SkUnichar map_glyph(const std::vector& glyphToUnicode, SkGlyphID glyph) { - return glyph < glyphToUnicode.size() ? glyphToUnicode[SkToInt(glyph)] : -1; +static SkUnichar map_glyph(const SkTDArray& glyphToUnicode, SkGlyphID glyph) { + return SkToInt(glyph) < glyphToUnicode.count() ? glyphToUnicode[SkToInt(glyph)] : -1; } static void update_font(SkWStream* wStream, int fontIndex, SkScalar textSize) { @@ -1200,9 +1200,6 @@ void SkPDFDevice::internalDrawText( if (!metrics) { return; } - const std::vector& glyphToUnicode = SkPDFFont::GetUnicodeMap( - typeface, fDocument->canon()); - SkClusterator clusterator(sourceText, sourceByteCount, paint, clusters, textByteLength, utf8Text); const SkGlyphID* glyphs = clusterator.glyphs(); @@ -1247,6 +1244,7 @@ void SkPDFDevice::internalDrawText( return; } SkDynamicMemoryWStream* out = content.stream(); + const SkTDArray& glyphToUnicode = metrics->fGlyphToUnicode; out->writeText("BT\n"); SK_AT_SCOPE_EXIT(out->writeText("ET\n")); diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 3b89f62cbe..9ba411495a 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -186,19 +186,6 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface, return canon->fTypefaceMetrics.set(id, std::move(metrics))->get(); } -const std::vector& SkPDFFont::GetUnicodeMap(const SkTypeface* typeface, - SkPDFCanon* canon) { - SkASSERT(typeface); - SkASSERT(canon); - SkFontID id = typeface->uniqueID(); - if (std::vector* ptr = canon->fToUnicodeMap.find(id)) { - return *ptr; - } - std::vector buffer(typeface->countGlyphs()); - typeface->getGlyphToUnicodeMap(buffer.data()); - return *canon->fToUnicodeMap.set(id, std::move(buffer)); -} - SkAdvancedTypefaceMetrics::FontType SkPDFFont::FontType(const SkAdvancedTypefaceMetrics& metrics) { if (SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) || SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag)) { @@ -490,15 +477,14 @@ void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { descendantFonts->appendObjRef(std::move(newCIDFont)); this->insertObject("DescendantFonts", std::move(descendantFonts)); - const std::vector& glyphToUnicode = - SkPDFFont::GetUnicodeMap(this->typeface(), canon); - SkASSERT(SkToSizeT(this->typeface()->countGlyphs()) == glyphToUnicode.size()); - this->insertObjRef("ToUnicode", - SkPDFMakeToUnicodeCmap(glyphToUnicode.data(), - &this->glyphUsage(), - this->multiByteGlyphs(), - this->firstGlyphID(), - this->lastGlyphID())); + if (metrics.fGlyphToUnicode.count() > 0) { + this->insertObjRef("ToUnicode", + SkPDFMakeToUnicodeCmap(metrics.fGlyphToUnicode, + &this->glyphUsage(), + multiByteGlyphs(), + firstGlyphID(), + lastGlyphID())); + } SkDEBUGCODE(fPopulated = true); return; } @@ -736,15 +722,14 @@ static void add_type3_font_info(SkPDFCanon* canon, fontBBox->appendInt(bbox.top()); font->insertObject("FontBBox", std::move(fontBBox)); font->insertName("CIDToGIDMap", "Identity"); - - const std::vector& glyphToUnicode = SkPDFFont::GetUnicodeMap(typeface, canon); - SkASSERT(glyphToUnicode.size() == SkToSizeT(typeface->countGlyphs())); - font->insertObjRef("ToUnicode", - SkPDFMakeToUnicodeCmap(glyphToUnicode.data(), - &subset, - false, - firstGlyphID, - lastGlyphID)); + if (metrics && metrics->fGlyphToUnicode.count() > 0) { + font->insertObjRef("ToUnicode", + SkPDFMakeToUnicodeCmap(metrics->fGlyphToUnicode, + &subset, + false, + firstGlyphID, + lastGlyphID)); + } auto descriptor = sk_make_sp("FontDescriptor"); int32_t fontDescriptorFlags = kPdfSymbolic; if (metrics) { diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index 1441eedad9..9dc4655501 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -95,9 +95,6 @@ public: static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface, SkPDFCanon* canon); - static const std::vector& GetUnicodeMap(const SkTypeface* typeface, - SkPDFCanon* canon); - /** Subset the font based on current usage. * Must be called before emitObject(). */ diff --git a/src/pdf/SkPDFMakeToUnicodeCmap.cpp b/src/pdf/SkPDFMakeToUnicodeCmap.cpp index c93aa6f2c5..afe773207d 100644 --- a/src/pdf/SkPDFMakeToUnicodeCmap.cpp +++ b/src/pdf/SkPDFMakeToUnicodeCmap.cpp @@ -147,12 +147,15 @@ static void append_bfrange_section(const SkTDArray& bfrange, // For the worst case (having 65536 continuous unicode and we use every other // one of them), the possible savings by aggressive optimization is 416KB // pre-compressed and does not provide enough motivation for implementation. -void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, +void SkPDFAppendCmapSections(const SkTDArray& glyphToUnicode, const SkBitSet* subset, SkDynamicMemoryWStream* cmap, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID) { + if (glyphToUnicode.isEmpty()) { + return; + } int glyphOffset = 0; if (!multiByteGlyphs) { glyphOffset = firstGlyphID - 1; @@ -163,7 +166,8 @@ void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, BFRange currentRangeEntry = {0, 0, 0}; bool rangeEmpty = true; - const int limit = (int)lastGlyphID + 1 - glyphOffset; + const int limit = + SkMin32(lastGlyphID + 1, glyphToUnicode.count()) - glyphOffset; for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) { bool inSubset = i < limit && @@ -206,7 +210,7 @@ void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, } sk_sp SkPDFMakeToUnicodeCmap( - const SkUnichar* glyphToUnicode, + const SkTDArray& glyphToUnicode, const SkBitSet* subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, diff --git a/src/pdf/SkPDFMakeToUnicodeCmap.h b/src/pdf/SkPDFMakeToUnicodeCmap.h index 656af913d0..0c4d1c37dd 100644 --- a/src/pdf/SkPDFMakeToUnicodeCmap.h +++ b/src/pdf/SkPDFMakeToUnicodeCmap.h @@ -12,14 +12,14 @@ #include "SkStream.h" sk_sp SkPDFMakeToUnicodeCmap( - const SkUnichar* glyphToUnicode, + const SkTDArray& glyphToUnicode, const SkBitSet* subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID); // Exposed for unit testing. -void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, +void SkPDFAppendCmapSections(const SkTDArray& glyphToUnicode, const SkBitSet* subset, SkDynamicMemoryWStream* cmap, bool multiByteGlyphs, -- cgit v1.2.3