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.cpp91
1 files changed, 65 insertions, 26 deletions
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 0d41176982..49d383b204 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -761,6 +761,24 @@ SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() {
return fFontType;
}
+bool SkPDFFont::canEmbed() const {
+ if (!fFontInfo.get()) {
+ SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font);
+ return true;
+ }
+ return (fFontInfo->fFlags &
+ SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag) == 0;
+}
+
+bool SkPDFFont::canSubset() const {
+ if (!fFontInfo.get()) {
+ SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font);
+ return true;
+ }
+ return (fFontInfo->fFlags &
+ SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag) == 0;
+}
+
bool SkPDFFont::hasGlyph(uint16_t id) {
return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0;
}
@@ -808,7 +826,7 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) {
// This only is to catch callers who pass invalid glyph ids.
// If glyph id is invalid, then we will create duplicate entries
- // for True Type fonts.
+ // for TrueType fonts.
SkAdvancedTypefaceMetrics::FontType fontType =
fontMetrics.get() ? fontMetrics.get()->fType :
SkAdvancedTypefaceMetrics::kOther_Font;
@@ -888,9 +906,8 @@ SkPDFFont::SkPDFFont(SkAdvancedTypefaceMetrics* info, SkTypeface* typeface,
fLastGlyphID(info ? info->fLastGlyphID : 0),
fFontInfo(SkSafeRef(info)),
fDescriptor(SkSafeRef(relatedFontDescriptor)) {
- if (info == NULL) {
- fFontType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
- } else if (info->fMultiMaster) {
+ if (info == NULL ||
+ info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) {
fFontType = SkAdvancedTypefaceMetrics::kOther_Font;
} else {
fFontType = info->fType;
@@ -902,9 +919,10 @@ SkPDFFont* SkPDFFont::Create(SkAdvancedTypefaceMetrics* info,
SkTypeface* typeface, uint16_t glyphID,
SkPDFDict* relatedFontDescriptor) {
SkAdvancedTypefaceMetrics::FontType type =
- info ? info->fType : SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
+ info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font;
- if (info && info->fMultiMaster) {
+ if (info &&
+ (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
NOT_IMPLEMENTED(true, true);
return new SkPDFType3Font(info,
typeface,
@@ -923,8 +941,7 @@ SkPDFFont* SkPDFFont::Create(SkAdvancedTypefaceMetrics* info,
}
SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font ||
- type == SkAdvancedTypefaceMetrics::kOther_Font ||
- type == SkAdvancedTypefaceMetrics::kNotEmbeddable_Font);
+ type == SkAdvancedTypefaceMetrics::kOther_Font);
return new SkPDFType3Font(info, typeface, glyphID);
}
@@ -1052,11 +1069,17 @@ SkPDFType0Font::SkPDFType0Font(SkAdvancedTypefaceMetrics* info,
SkTypeface* typeface)
: SkPDFFont(info, typeface, NULL) {
SkDEBUGCODE(fPopulated = false);
+ if (!canSubset()) {
+ populate(NULL);
+ }
}
SkPDFType0Font::~SkPDFType0Font() {}
SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
+ if (!canSubset()) {
+ return NULL;
+ }
SkPDFType0Font* newSubset = new SkPDFType0Font(fontInfo(), typeface());
newSubset->populate(subset);
return newSubset;
@@ -1105,19 +1128,34 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
setFontDescriptor(descriptor.get());
addResource(descriptor.get());
+ insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
+ if (!addCommonFontDescriptorEntries(defaultWidth)) {
+ return false;
+ }
+ if (!canEmbed()) {
+ return true;
+ }
switch (getType()) {
case SkAdvancedTypefaceMetrics::kTrueType_Font: {
- SkASSERT(subset);
- // Font subsetting
- SkPDFStream* rawStream = NULL;
- size_t fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
- typeface(),
- *subset,
- &rawStream);
+ SkAutoTUnref<SkPDFStream> fontStream;
+ size_t fontSize = 0;
+ if (canSubset()) {
+ SkPDFStream* rawStream = NULL;
+ fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
+ typeface(),
+ *subset,
+ &rawStream);
+ fontStream.reset(rawStream);
+ } else {
+ int ttcIndex;
+ SkAutoTUnref<SkStream> fontData(
+ typeface()->openStream(&ttcIndex));
+ fontStream.reset(new SkPDFStream(fontData.get()));
+ fontSize = fontData->getLength();
+ }
SkASSERT(fontSize);
- SkASSERT(rawStream);
- SkAutoTUnref<SkPDFStream> fontStream(rawStream);
+ SkASSERT(fontStream.get());
addResource(fontStream.get());
fontStream->insertInt("Length1", fontSize);
@@ -1145,9 +1183,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
default:
SkASSERT(false);
}
-
- insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
- return addCommonFontDescriptorEntries(defaultWidth);
+ return true;
}
bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
@@ -1266,12 +1302,15 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
if (fontData == NULL) {
return false;
}
- SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData));
- addResource(fontStream.get());
- fontStream->insertInt("Length1", header);
- fontStream->insertInt("Length2", data);
- fontStream->insertInt("Length3", trailer);
- descriptor->insert("FontFile", new SkPDFObjRef(fontStream.get()))->unref();
+ if (canEmbed()) {
+ SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData));
+ addResource(fontStream.get());
+ fontStream->insertInt("Length1", header);
+ fontStream->insertInt("Length2", data);
+ fontStream->insertInt("Length3", trailer);
+ descriptor->insert("FontFile",
+ new SkPDFObjRef(fontStream.get()))->unref();
+ }
addResource(descriptor.get());
insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();