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

Unified Diff: src/pdf/SkPDFFont.cpp

Issue 1401763002: SkPDF: fall back on paths for unembeddable fonts. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-10-12 (Monday) 15:54:45 EDT Created 5 years, 2 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/SkPDFFont.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFFont.cpp
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 8df59b77f147fc01d403b1b4b9daea9854dc0761..9cbada836403dbde8307f77f054d3b38e3e08d44 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -1051,10 +1051,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
this->insertObjRef("FontDescriptor", descriptor.detach());
return false;
}
- if (!canEmbed()) {
- this->insertObjRef("FontDescriptor", descriptor.detach());
- return true;
- }
+ SkASSERT(this->canEmbed());
switch (getType()) {
case SkAdvancedTypefaceMetrics::kTrueType_Font: {
@@ -1222,13 +1219,12 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
if (fontData.get() == nullptr) {
return false;
}
- if (canEmbed()) {
- SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
- fontStream->insertInt("Length1", header);
- fontStream->insertInt("Length2", data);
- fontStream->insertInt("Length3", trailer);
- descriptor->insertObjRef("FontFile", fontStream.detach());
- }
+ SkASSERT(this->canEmbed());
+ SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
+ fontStream->insertInt("Length1", header);
+ fontStream->insertInt("Length2", data);
+ fontStream->insertInt("Length3", trailer);
+ descriptor->insertObjRef("FontFile", fontStream.detach());
this->insertObjRef("FontDescriptor", descriptor.detach());
@@ -1418,3 +1414,22 @@ SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match
: SkPDFFont::kRelated_Match;
}
+
+// Since getAdvancedTypefaceMetrics is expensive, cache the result.
+bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) {
+ SkAutoResolveDefaultTypeface face(typeface);
+ uint32_t id = face->uniqueID();
+ if (bool* value = canon->fCanEmbedTypeface.find(id)) {
+ return *value;
+ }
+ bool canEmbed = true;
+ SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics(
+ face->getAdvancedTypefaceMetrics(
+ SkTypeface::kNo_PerGlyphInfo, nullptr, 0));
+ if (fontMetrics) {
+ canEmbed = !SkToBool(
+ fontMetrics->fFlags &
+ SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag);
+ }
+ return *canon->fCanEmbedTypeface.set(id, canEmbed);
+}
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698