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

Unified Diff: src/pdf/SkPDFDocument.cpp

Issue 2253283004: SkPDF: in-place font subsetting (Closed) Base URL: https://skia.googlesource.com/skia.git@SkPdfCacheMetrics
Patch Set: 2016-08-18 (Thursday) 16:02: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/SkPDFDocument.h ('k') | src/pdf/SkPDFFont.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDocument.cpp
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 4f044c87717c90c8c77aced56f2d9f79bd94ba29..75c5de91e324a0dba013d9d3aa029ca6e643160c 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -23,7 +23,7 @@ SkPDFObjectSerializer::~SkPDFObjectSerializer() {
}
void SkPDFObjectSerializer::addObjectRecursively(const sk_sp<SkPDFObject>& object) {
- fObjNumMap.addObjectRecursively(object.get(), fSubstituteMap);
+ fObjNumMap.addObjectRecursively(object.get());
}
#define SKPDF_MAGIC "\xD3\xEB\xE9\xE1"
@@ -58,10 +58,9 @@ void SkPDFObjectSerializer::serializeObjects(SkWStream* wStream) {
// the head of the linked list of free objects."
SkASSERT(fOffsets.count() == fNextToBeSerialized);
fOffsets.push(this->offset(wStream));
- SkASSERT(object == fSubstituteMap.getSubstitute(object));
wStream->writeDecAsText(index);
wStream->writeText(" 0 obj\n"); // Generation number is always 0.
- object->emitObject(wStream, fObjNumMap, fSubstituteMap);
+ object->emitObject(wStream, fObjNumMap);
wStream->writeText("\nendobj\n");
object->drop();
++fNextToBeSerialized;
@@ -93,7 +92,7 @@ void SkPDFObjectSerializer::serializeFooter(SkWStream* wStream,
trailerDict.insertObject("ID", std::move(id));
}
wStream->writeText("trailer\n");
- trailerDict.emitObject(wStream, fObjNumMap, fSubstituteMap);
+ trailerDict.emitObject(wStream, fObjNumMap);
wStream->writeText("\nstartxref\n");
wStream->writeBigDecAsText(xRefFileOffset);
wStream->writeText("\n%%EOF");
@@ -246,11 +245,15 @@ void SkPDFDocument::onEndPage() {
}
void SkPDFDocument::onAbort() {
+ this->reset();
+}
+
+void SkPDFDocument::reset() {
fCanvas.reset(nullptr);
fPages.reset();
fCanon.reset();
renew(&fObjectSerializer);
- renew(&fGlyphUsage);
+ fFonts.reset();
}
#ifdef SK_SUPPORT_LEGACY_DOCUMENT_API
@@ -419,10 +422,7 @@ static sk_sp<SkPDFArray> make_srgb_output_intents() {
bool SkPDFDocument::onClose(SkWStream* stream) {
SkASSERT(!fCanvas.get());
if (fPages.empty()) {
- fPages.reset();
- fCanon.reset();
- renew(&fObjectSerializer);
- renew(&fGlyphUsage);
+ this->reset();
return false;
}
auto docCatalog = sk_make_sp<SkPDFDict>("Catalog");
@@ -442,21 +442,12 @@ bool SkPDFDocument::onClose(SkWStream* stream) {
}
// Build font subsetting info before calling addObjectRecursively().
- for (const auto& entry : fGlyphUsage) {
- sk_sp<SkPDFObject> subsetFont =
- entry.fFont->getFontSubset(&fCanon, &entry.fGlyphSet);
- if (subsetFont) {
- fObjectSerializer.fSubstituteMap.setSubstitute(
- entry.fFont, subsetFont.get());
- }
- }
-
+ SkPDFCanon* canon = &fCanon;
+ fFonts.foreach([canon](SkPDFFont* p){ p->getFontSubset(canon); });
fObjectSerializer.addObjectRecursively(docCatalog);
fObjectSerializer.serializeObjects(this->getStream());
fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID);
- fCanon.reset();
- renew(&fObjectSerializer);
- renew(&fGlyphUsage);
+ this->reset();
return true;
}
« no previous file with comments | « src/pdf/SkPDFDocument.h ('k') | src/pdf/SkPDFFont.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698