aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFFont.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf/SkPDFFont.cpp')
-rw-r--r--src/pdf/SkPDFFont.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 8df59b77f1..9cbada8364 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);
+}