diff options
author | Hal Canary <halcanary@google.com> | 2018-04-10 11:27:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-09 14:24:45 +0000 |
commit | 1c2bcd8b14e029a70e88b1e81acd29553cab0d1c (patch) | |
tree | 723a0c85100bcb59590bd2e46fc5eb5c10472406 /tools/fonts | |
parent | a2595f925596aca234d4ac4e35da689ef13cc27c (diff) |
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>
Diffstat (limited to 'tools/fonts')
-rw-r--r-- | tools/fonts/SkRandomScalerContext.cpp | 4 | ||||
-rw-r--r-- | tools/fonts/SkRandomScalerContext.h | 1 | ||||
-rw-r--r-- | tools/fonts/SkTestSVGTypeface.cpp | 16 | ||||
-rw-r--r-- | tools/fonts/SkTestSVGTypeface.h | 1 | ||||
-rw-r--r-- | tools/fonts/SkTestTypeface.cpp | 15 | ||||
-rw-r--r-- | tools/fonts/SkTestTypeface.h | 1 |
6 files changed, 23 insertions, 15 deletions
diff --git a/tools/fonts/SkRandomScalerContext.cpp b/tools/fonts/SkRandomScalerContext.cpp index 2d472129a1..9379759ff0 100644 --- a/tools/fonts/SkRandomScalerContext.cpp +++ b/tools/fonts/SkRandomScalerContext.cpp @@ -164,6 +164,10 @@ void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const { rec->fMaskFormat = SkMask::kARGB32_Format; } +void SkRandomTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const { + fProxy->getGlyphToUnicodeMap(glyphToUnicode); +} + std::unique_ptr<SkAdvancedTypefaceMetrics> SkRandomTypeface::onGetAdvancedMetrics() const { return fProxy->getAdvancedMetrics(); } diff --git a/tools/fonts/SkRandomScalerContext.h b/tools/fonts/SkRandomScalerContext.h index b71689d9e2..5dbdac68b8 100644 --- a/tools/fonts/SkRandomScalerContext.h +++ b/tools/fonts/SkRandomScalerContext.h @@ -27,6 +27,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; + void getGlyphToUnicodeMap(SkUnichar*) const override; std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override; void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override; diff --git a/tools/fonts/SkTestSVGTypeface.cpp b/tools/fonts/SkTestSVGTypeface.cpp index ceb523aa72..199c3b5df6 100644 --- a/tools/fonts/SkTestSVGTypeface.cpp +++ b/tools/fonts/SkTestSVGTypeface.cpp @@ -100,15 +100,17 @@ void SkTestSVGTypeface::onFilterRec(SkScalerContextRec* rec) const { rec->setHinting(SkPaint::kNo_Hinting); } +void SkTestSVGTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const { + SkDEBUGCODE(unsigned glyphCount = this->countGlyphs()); + fCMap.foreach([=](const SkUnichar& c, const SkGlyphID& g) { + SkASSERT(g < glyphCount); + glyphToUnicode[g] = c; + }); +} + std::unique_ptr<SkAdvancedTypefaceMetrics> SkTestSVGTypeface::onGetAdvancedMetrics() const { std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics); - info->fFontName.set(fName); - - SkTDArray<SkUnichar>& toUnicode = info->fGlyphToUnicode; - toUnicode.setCount(fGlyphCount); - fCMap.foreach([&toUnicode](const SkUnichar& c, const SkGlyphID& g) { - toUnicode[g] = c; - }); + info->fFontName = fName; return info; } diff --git a/tools/fonts/SkTestSVGTypeface.h b/tools/fonts/SkTestSVGTypeface.h index 0b53245b70..249cd8bfc1 100644 --- a/tools/fonts/SkTestSVGTypeface.h +++ b/tools/fonts/SkTestSVGTypeface.h @@ -77,6 +77,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor* desc) const override; void onFilterRec(SkScalerContextRec* rec) const override; + void getGlyphToUnicodeMap(SkUnichar*) const override; std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override { diff --git a/tools/fonts/SkTestTypeface.cpp b/tools/fonts/SkTestTypeface.cpp index d7caa5a392..bf3a1a3e9e 100644 --- a/tools/fonts/SkTestTypeface.cpp +++ b/tools/fonts/SkTestTypeface.cpp @@ -119,17 +119,16 @@ void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { rec->setHinting(SkPaint::kNo_Hinting); } +void SkTestTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const { + unsigned glyphCount = fTestFont->fCharCodesCount; + for (unsigned gid = 0; gid < glyphCount; ++gid) { + glyphToUnicode[gid] = SkTo<SkUnichar>(fTestFont->fCharCodes[gid]); + } +} + std::unique_ptr<SkAdvancedTypefaceMetrics> SkTestTypeface::onGetAdvancedMetrics() const { // pdf only std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics); info->fFontName.set(fTestFont->fName); - int glyphCount = this->onCountGlyphs(); - - SkTDArray<SkUnichar>& toUnicode = info->fGlyphToUnicode; - toUnicode.setCount(glyphCount); - SkASSERT(glyphCount == SkToInt(fTestFont->fCharCodesCount)); - for (int gid = 0; gid < glyphCount; ++gid) { - toUnicode[gid] = SkToS32(fTestFont->fCharCodes[gid]); - } return info; } diff --git a/tools/fonts/SkTestTypeface.h b/tools/fonts/SkTestTypeface.h index d3365f972a..205d82c30f 100644 --- a/tools/fonts/SkTestTypeface.h +++ b/tools/fonts/SkTestTypeface.h @@ -71,6 +71,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor* desc) const override; void onFilterRec(SkScalerContextRec* rec) const override; + void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override; std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override { |