diff options
author | Hal Canary <halcanary@google.com> | 2018-05-09 11:50:34 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-09 18:00:35 +0000 |
commit | 46cc3dabaff7daa6b57e3c33997153d986219579 (patch) | |
tree | 809ca0d62fddcbd3b378d0a4d330692ebd58748d /src/pdf | |
parent | 06d374694a515d064a26e6c5391bce9a0c5c8aa0 (diff) |
Revert "Revert "SkAdvancedTypefaceMetrics: factor out GlyphToUnicode""
This reverts commit 97c1108607584b6050a6880d6ce22846e4913a92.
Change-Id: Ic3c6addc64ced39766bbee3e10b4d88faf61ba2f
Reviewed-on: https://skia-review.googlesource.com/127021
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@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, 45 insertions, 28 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h index 8d0e8f8fed..8e97db05f5 100644 --- a/src/pdf/SkPDFCanon.h +++ b/src/pdf/SkPDFCanon.h @@ -42,6 +42,7 @@ 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 6e36fb3d82..c18219ab0d 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1052,8 +1052,8 @@ private: }; } // namespace -static SkUnichar map_glyph(const SkTDArray<SkUnichar>& glyphToUnicode, SkGlyphID glyph) { - return SkToInt(glyph) < glyphToUnicode.count() ? glyphToUnicode[SkToInt(glyph)] : -1; +static SkUnichar map_glyph(const std::vector<SkUnichar>& glyphToUnicode, SkGlyphID glyph) { + return glyph < glyphToUnicode.size() ? glyphToUnicode[SkToInt(glyph)] : -1; } static void update_font(SkWStream* wStream, int fontIndex, SkScalar textSize) { @@ -1200,6 +1200,9 @@ 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(); @@ -1244,7 +1247,6 @@ 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 9ba411495a..3b89f62cbe 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -186,6 +186,19 @@ 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)) { @@ -477,14 +490,15 @@ void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { descendantFonts->appendObjRef(std::move(newCIDFont)); this->insertObject("DescendantFonts", std::move(descendantFonts)); - if (metrics.fGlyphToUnicode.count() > 0) { - this->insertObjRef("ToUnicode", - SkPDFMakeToUnicodeCmap(metrics.fGlyphToUnicode, - &this->glyphUsage(), - multiByteGlyphs(), - firstGlyphID(), - lastGlyphID())); - } + 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())); SkDEBUGCODE(fPopulated = true); return; } @@ -722,14 +736,15 @@ static void add_type3_font_info(SkPDFCanon* canon, fontBBox->appendInt(bbox.top()); font->insertObject("FontBBox", std::move(fontBBox)); font->insertName("CIDToGIDMap", "Identity"); - if (metrics && metrics->fGlyphToUnicode.count() > 0) { - font->insertObjRef("ToUnicode", - SkPDFMakeToUnicodeCmap(metrics->fGlyphToUnicode, - &subset, - false, - firstGlyphID, - lastGlyphID)); - } + + 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)); 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 9dc4655501..1441eedad9 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -95,6 +95,9 @@ 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 afe773207d..c93aa6f2c5 100644 --- a/src/pdf/SkPDFMakeToUnicodeCmap.cpp +++ b/src/pdf/SkPDFMakeToUnicodeCmap.cpp @@ -147,15 +147,12 @@ 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 SkTDArray<SkUnichar>& glyphToUnicode, +void SkPDFAppendCmapSections(const 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; @@ -166,8 +163,7 @@ void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, BFRange currentRangeEntry = {0, 0, 0}; bool rangeEmpty = true; - const int limit = - SkMin32(lastGlyphID + 1, glyphToUnicode.count()) - glyphOffset; + const int limit = (int)lastGlyphID + 1 - glyphOffset; for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) { bool inSubset = i < limit && @@ -210,7 +206,7 @@ void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, } sk_sp<SkPDFStream> SkPDFMakeToUnicodeCmap( - const SkTDArray<SkUnichar>& glyphToUnicode, + const SkUnichar* glyphToUnicode, const SkBitSet* subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, diff --git a/src/pdf/SkPDFMakeToUnicodeCmap.h b/src/pdf/SkPDFMakeToUnicodeCmap.h index 0c4d1c37dd..656af913d0 100644 --- a/src/pdf/SkPDFMakeToUnicodeCmap.h +++ b/src/pdf/SkPDFMakeToUnicodeCmap.h @@ -12,14 +12,14 @@ #include "SkStream.h" sk_sp<SkPDFStream> SkPDFMakeToUnicodeCmap( - const SkTDArray<SkUnichar>& glyphToUnicode, + const SkUnichar* glyphToUnicode, const SkBitSet* subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID); // Exposed for unit testing. -void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, +void SkPDFAppendCmapSections(const SkUnichar* glyphToUnicode, const SkBitSet* subset, SkDynamicMemoryWStream* cmap, bool multiByteGlyphs, |