diff options
author | halcanary <halcanary@google.com> | 2016-08-31 12:52:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-31 12:52:35 -0700 |
commit | 3d01c62e19df9f369cdfaeff82ec8af2c0be75f1 (patch) | |
tree | 6f7d30931b95a3c97ae59ed9c849bed57af1aa41 /src/pdf/SkPDFFont.cpp | |
parent | 41a8f323f7ac63c753bc50d434ff61c350c176bd (diff) |
SkPDF: Fix Type3 ToUnicode table.
This seems to fix text extraction on Adobe Reader
- Registry/Ordering is now set to Skia/SkiaOrdering.
- Type3 fonts now get a FontDescriptor (force symbolic font).
- CMapName is now Skia-Identity-SkiaOrdering
- CMap behaves correctly for single-byte fonts.
Also:
- SkTestTypeface returns tounicode map for testing.
- Unit test updated
All PDFs render the same
BUG=skia:5606
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2292303004
Review-Url: https://codereview.chromium.org/2292303004
Diffstat (limited to 'src/pdf/SkPDFFont.cpp')
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 93f48332d8..32e365388a 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -29,7 +29,7 @@ namespace { // PDF's notion of symbolic vs non-symbolic is related to the character set, not // symbols vs. characters. Rarely is a font the right character set to call it // non-symbolic, so always call it symbolic. (PDF 1.4 spec, section 5.7.1) -static const int kPdfSymbolic = 4; +static const int32_t kPdfSymbolic = 4; struct SkPDFType0Font final : public SkPDFFont { SkPDFType0Font(SkPDFFont::Info, const SkAdvancedTypefaceMetrics&); @@ -426,8 +426,9 @@ void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { } auto sysInfo = sk_make_sp<SkPDFDict>(); - sysInfo->insertString("Registry", "Adobe"); - sysInfo->insertString("Ordering", "Identity"); + sysInfo->insertString("Registry", "Skia"); + // TODO: Registry+Ordering should be globally unique! + sysInfo->insertString("Ordering", "SkiaOrdering"); sysInfo->insertInt("Supplement", 0); newCIDFont->insertObject("CIDSystemInfo", std::move(sysInfo)); @@ -597,6 +598,7 @@ static void add_type3_font_info(SkPDFCanon* canon, const SkBitSet& subset, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID) { + const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, canon); SkASSERT(lastGlyphID >= firstGlyphID); // Remove unused glyphs at the end of the range. // Keep the lastGlyphID >= firstGlyphID invariant true. @@ -684,8 +686,7 @@ static void add_type3_font_info(SkPDFCanon* canon, fontBBox->appendInt(bbox.top()); font->insertObject("FontBBox", std::move(fontBBox)); font->insertName("CIDToGIDMap", "Identity"); - const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, canon); - if (metrics /* && metrics->fGlyphToUnicode.count() > 0 */) { + if (metrics && metrics->fGlyphToUnicode.count() > 0) { font->insertObjRef("ToUnicode", SkPDFMakeToUnicodeCmap(metrics->fGlyphToUnicode, &subset, @@ -693,6 +694,16 @@ static void add_type3_font_info(SkPDFCanon* canon, firstGlyphID, lastGlyphID)); } + auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); + int32_t fontDescriptorFlags = kPdfSymbolic; + if (metrics) { + // Type3 FontDescriptor does not require all the same fields. + descriptor->insertName("FontName", metrics->fFontName); + descriptor->insertInt("ItalicAngle", metrics->fItalicAngle); + fontDescriptorFlags |= (int32_t)metrics->fStyle; + } + descriptor->insertInt("Flags", fontDescriptorFlags); + font->insertObjRef("FontDescriptor", std::move(descriptor)); font->insertObject("Widths", std::move(widthArray)); font->insertObject("Encoding", std::move(encoding)); font->insertObject("CharProcs", std::move(charProcs)); |