diff options
author | 2016-08-12 07:59:38 -0700 | |
---|---|---|
committer | 2016-08-12 07:59:38 -0700 | |
commit | 7e8d5d3519ea2d4c7f158ff9737843e20daad0cb (patch) | |
tree | 3df7ff4e9de0e2b177900f589cb32cdc9e466290 /src/pdf/SkPDFDevice.cpp | |
parent | 70c43efb6e83fb034f387ffd767b5a4fcbca6ea1 (diff) |
SkPDF: Subset Type3 (fallback) font
Motivation: significant file-size reduction.
Also: SkPDFFont::subsetFont() returns a sk_sp<SkPDFObject>
rather than a SkPDFFont*.
SkPDFType3Font constructor no longer populates font info;
relies on subsetting.
SkPDFFont::Create is easier to read
Also: SkPDFType3Font are scaled by emSize rather than 1000.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2231483002
Committed: https://skia.googlesource.com/skia/+/88b138da99328b04cae9a8ee19c3882b8847a550
Review-Url: https://codereview.chromium.org/2231483002
Diffstat (limited to 'src/pdf/SkPDFDevice.cpp')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index b9e1f3b48b..f3ede3524d 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1206,7 +1206,11 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage(); while (numGlyphs > consumedGlyphCount) { - this->updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); + if (!this->updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry())) { + SkDebugf("SkPDF: Font error."); + content.entry()->fContent.writeText("ET\n%SkPDF: Font error.\n"); + return; + } SkPDFFont* font = content.entry()->fState.fFont; int availableGlyphs = font->glyphsToPDFFontEncoding( @@ -1273,7 +1277,11 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, SkAutoGlyphCache autoGlyphCache(textPaint, nullptr, nullptr); content.entry()->fContent.writeText("BT\n"); - this->updateFont(textPaint, glyphIDs[0], content.entry()); + if (!this->updateFont(textPaint, glyphIDs[0], content.entry())) { + SkDebugf("SkPDF: Font error."); + content.entry()->fContent.writeText("ET\n%SkPDF: Font error.\n"); + return; + } GlyphPositioner glyphPositioner(&content.entry()->fContent, textPaint.getTextSkewX(), content.entry()->fState.fFont->multiByteGlyphs()); @@ -1286,7 +1294,11 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, // The current pdf font cannot encode the current glyph. // Try to get a pdf font which can encode the current glyph. glyphPositioner.flush(); - this->updateFont(textPaint, glyphIDs[i], content.entry()); + if (!this->updateFont(textPaint, glyphIDs[i], content.entry())) { + SkDebugf("SkPDF: Font error."); + content.entry()->fContent.writeText("ET\n%SkPDF: Font error.\n"); + return; + } font = content.entry()->fState.fFont; glyphPositioner.setWideChars(font->multiByteGlyphs()); if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { @@ -1997,13 +2009,16 @@ int SkPDFDevice::addXObjectResource(SkPDFObject* xObject) { return result; } -void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, +bool SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, SkPDFDevice::ContentEntry* contentEntry) { SkTypeface* typeface = paint.getTypeface(); if (contentEntry->fState.fFont == nullptr || contentEntry->fState.fTextSize != paint.getTextSize() || !contentEntry->fState.fFont->hasGlyph(glyphID)) { int fontIndex = getFontResourceIndex(typeface, glyphID); + if (fontIndex < 0) { + return false; + } contentEntry->fContent.writeText("/"); contentEntry->fContent.writeText(SkPDFResourceDict::getResourceName( SkPDFResourceDict::kFont_ResourceType, @@ -2013,11 +2028,15 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, contentEntry->fContent.writeText(" Tf\n"); contentEntry->fState.fFont = fFontResources[fontIndex]; } + return true; } int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { sk_sp<SkPDFFont> newFont( SkPDFFont::GetFontResource(fDocument->canon(), typeface, glyphID)); + if (!newFont) { + return -1; + } int resourceIndex = fFontResources.find(newFont.get()); if (resourceIndex < 0) { resourceIndex = fFontResources.count(); |