Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(996)

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 2231483002: SkPDF: Subset Type3 (fallback) font (Closed) Base URL: https://skia.googlesource.com/skia.git@SkPDF_next3
Patch Set: 2016-08-12 (Friday) 10:20:16 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index b9e1f3b48bcf9abd12275f682b0180fb85651330..f3ede3524d1fba25caf1a59e8669df9e9bfbf28a 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();
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698