diff options
author | Greg Daniel <egdaniel@google.com> | 2018-05-09 15:35:54 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-09 15:36:06 +0000 |
commit | 97c1108607584b6050a6880d6ce22846e4913a92 (patch) | |
tree | e6cb5bfa22fdd2fba53c9cd49d3beed28fff686b /src/pdf | |
parent | 2ed5f69da6f101e60a3cf49c0767212b563552f3 (diff) |
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 <halcanary@google.com>
> Reviewed-by: Ben Wagner <bungeman@google.com>
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 <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFCanon.h | 1 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 8 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 47 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.h | 3 | ||||
-rw-r--r-- | src/pdf/SkPDFMakeToUnicodeCmap.cpp | 10 | ||||
-rw-r--r-- | src/pdf/SkPDFMakeToUnicodeCmap.h | 4 |
6 files changed, 28 insertions, 45 deletions
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<uint32_t, std::unique_ptr<SkAdvancedTypefaceMetrics>> fTypefaceMetrics; SkTHashMap<uint32_t, std::vector<SkString>> fType1GlyphNames; - SkTHashMap<uint32_t, std::vector<SkUnichar>> fToUnicodeMap; SkTHashMap<uint32_t, sk_sp<SkPDFDict>> fFontDescriptors; SkTHashMap<uint64_t, sk_sp<SkPDFFont>> 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<SkUnichar>& glyphToUnicode, SkGlyphID glyph) { - return glyph < glyphToUnicode.size() ? glyphToUnicode[SkToInt(glyph)] : -1; +static SkUnichar map_glyph(const SkTDArray<SkUnichar>& 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<SkUnichar>& 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<SkUnichar>& 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<SkUnichar>& SkPDFFont::GetUnicodeMap(const SkTypeface* typeface, - SkPDFCanon* canon) { - SkASSERT(typeface); - SkASSERT(canon); - SkFontID id = typeface->uniqueID(); - if (std::vector<SkUnichar>* ptr = canon->fToUnicodeMap.find(id)) { - return *ptr; - } - std::vector<SkUnichar> 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<SkUnichar>& 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<SkUnichar>& 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<SkPDFDict>("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<SkUnichar>& 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>& 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<SkUnichar>& 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<SkPDFStream> SkPDFMakeToUnicodeCmap( - const SkUnichar* glyphToUnicode, + const SkTDArray<SkUnichar>& 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<SkPDFStream> SkPDFMakeToUnicodeCmap( - const SkUnichar* glyphToUnicode, + const SkTDArray<SkUnichar>& glyphToUnicode, const SkBitSet* subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID); // Exposed for unit testing. -void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, +void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, const SkBitSet* subset, SkDynamicMemoryWStream* cmap, bool multiByteGlyphs, |