diff options
author | Hal Canary <halcanary@google.com> | 2018-03-29 10:59:02 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-29 18:33:05 +0000 |
commit | e1fec19deaa648fdea74adc30378156ce72d8002 (patch) | |
tree | 58bf34d506a3939ab6ffd1b77cc80f30e6d04844 | |
parent | cc7df552f641c3c093f266f8393daf5ec04f737e (diff) |
SkAdvancedTypefaceMetrics: distinguish between font names
Change-Id: I7d094c7327fae7a6da42b118858c59ab524ee6ae
Reviewed-on: https://skia-review.googlesource.com/117157
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
-rw-r--r-- | src/core/SkAdvancedTypefaceMetrics.h | 2 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 3 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 10 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h index 0ed7de4720..891677e6ba 100644 --- a/src/core/SkAdvancedTypefaceMetrics.h +++ b/src/core/SkAdvancedTypefaceMetrics.h @@ -26,6 +26,8 @@ struct SkAdvancedTypefaceMetrics { SkAdvancedTypefaceMetrics& operator=(const SkAdvancedTypefaceMetrics&) = delete; ~SkAdvancedTypefaceMetrics() {} + // The PostScript name of the font. See `FontName` and `BaseFont` in PDF standard. + SkString fPostScriptName; SkString fFontName; // These enum values match the values used in the PDF file format. diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index d3191e2d39..c6337d7852 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -293,6 +293,9 @@ void SkTypeface::getFamilyName(SkString* name) const { std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface::getAdvancedMetrics() const { std::unique_ptr<SkAdvancedTypefaceMetrics> result = this->onGetAdvancedMetrics(); + if (result && result->fPostScriptName.isEmpty()) { + result->fPostScriptName = result->fFontName; + } if (result && result->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { SkOTTableOS2::Version::V2::Type::Field fsType; constexpr SkFontTableTag os2Tag = SkTEndian_SwapBE32(SkOTTableOS2::TAG); diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 4fe24b06b7..ff3b84cf75 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -269,7 +269,7 @@ static void add_common_font_descriptor_entries(SkPDFDict* descriptor, const SkAdvancedTypefaceMetrics& metrics, uint16_t emSize, int16_t defaultWidth) { - descriptor->insertName("FontName", metrics.fFontName); + descriptor->insertName("FontName", metrics.fPostScriptName); descriptor->insertInt("Flags", (size_t)(metrics.fStyle | kPdfSymbolic)); descriptor->insertScalar("Ascent", scaleFromFontUnits(metrics.fAscent, emSize)); @@ -435,7 +435,7 @@ void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { auto newCIDFont = sk_make_sp<SkPDFDict>("Font"); newCIDFont->insertObjRef("FontDescriptor", std::move(descriptor)); - newCIDFont->insertName("BaseFont", metrics.fFontName); + newCIDFont->insertName("BaseFont", metrics.fPostScriptName); switch (type) { case SkAdvancedTypefaceMetrics::kType1CID_Font: @@ -470,7 +470,7 @@ void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { //////////////////////////////////////////////////////////////////////////// this->insertName("Subtype", "Type0"); - this->insertName("BaseFont", metrics.fFontName); + this->insertName("BaseFont", metrics.fPostScriptName); this->insertName("Encoding", "Identity-H"); auto descendantFonts = sk_make_sp<SkPDFArray>(); descendantFonts->appendObjRef(std::move(newCIDFont)); @@ -524,7 +524,7 @@ static void populate_type_1_font(SkPDFDict* font, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID) { font->insertName("Subtype", "Type1"); - font->insertName("BaseFont", info.fFontName); + font->insertName("BaseFont", info.fPostScriptName); // glyphCount not including glyph 0 unsigned glyphCount = 1 + lastGlyphID - firstGlyphID; @@ -721,7 +721,7 @@ static void add_type3_font_info(SkPDFCanon* canon, int32_t fontDescriptorFlags = kPdfSymbolic; if (metrics) { // Type3 FontDescriptor does not require all the same fields. - descriptor->insertName("FontName", metrics->fFontName); + descriptor->insertName("FontName", metrics->fPostScriptName); descriptor->insertInt("ItalicAngle", metrics->fItalicAngle); fontDescriptorFlags |= (int32_t)metrics->fStyle; // Adobe requests CapHeight, XHeight, and StemV be added |