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

Unified Diff: src/pdf/SkPDFDocument.h

Issue 1802033003: SkPDF: SkPDFDocument reorganized so that some objects can be serialized early. (Closed) Base URL: https://skia.googlesource.com/skia.git@SkPdfDumpMethod
Patch Set: 2016-03-21 (Monday) 16:31:34 EDT Created 4 years, 9 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 | « no previous file | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDocument.h
diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h
index 8ed76778fe91b8fb79f466967bf50af9f56d5e0d..de1d8830bc118217766e5e6a45ca5ece48de125c 100644
--- a/src/pdf/SkPDFDocument.h
+++ b/src/pdf/SkPDFDocument.h
@@ -8,6 +8,8 @@
#define SkPDFDocument_DEFINED
#include "SkDocument.h"
+#include "SkPDFMetadata.h"
+#include "SkPDFTypes.h"
sk_sp<SkDocument> SkPDFMakeDocument(
SkWStream* stream,
@@ -15,4 +17,63 @@ sk_sp<SkDocument> SkPDFMakeDocument(
SkScalar rasterDpi,
SkPixelSerializer* jpegEncoder);
+// Logically part of SkPDFDocument (like SkPDFCanon), but separate to
+// keep similar functionality together.
+struct SkPDFObjectSerializer : SkNoncopyable {
+ SkPDFObjNumMap fObjNumMap;
+ SkPDFSubstituteMap fSubstituteMap;
+ SkTDArray<int32_t> fOffsets;
+ sk_sp<SkPDFObject> fInfoDict;
+ size_t fBaseOffset;
+ int32_t fNextToBeSerialized; // index in fObjNumMap
+
+ SkPDFObjectSerializer();
+ void addObjectRecursively(const sk_sp<SkPDFObject>&);
+ void serializeHeader(SkWStream*, const SkPDFMetadata&);
+ void serializeObjects(SkWStream*);
+ void serializeFooter(SkWStream*, const sk_sp<SkPDFObject>, sk_sp<SkPDFObject>);
+ int32_t offset(SkWStream*);
+};
+
+/** Concrete implementation of SkDocument that creates PDF files. This
+ class does not produced linearized or optimized PDFs; instead it
+ it attempts to use a minimum amount of RAM. */
+class SkPDFDocument : public SkDocument {
+public:
+ SkPDFDocument(SkWStream*,
+ void (*)(SkWStream*, bool),
+ SkScalar,
+ SkPixelSerializer*);
+ virtual ~SkPDFDocument();
+ SkCanvas* onBeginPage(SkScalar, SkScalar, const SkRect&) override;
+ void onEndPage() override;
+ bool onClose(SkWStream*) override;
+ void onAbort() override;
+ void setMetadata(const SkDocument::Attribute[],
+ int,
+ const SkTime::DateTime*,
+ const SkTime::DateTime*) override;
+ /**
+ Serialize the object, as well as any other objects it
+ indirectly refers to. If any any other objects have been added
+ to the SkPDFObjNumMap without serializing them, they will be
+ serialized as well.
+
+ It might go without saying that objects should not be changed
+ after calling serialize, since those changes will be too late.
+ The same goes for changes to the SkPDFSubstituteMap that effect
+ the object or its dependencies.
+ */
+ void serialize(const sk_sp<SkPDFObject>&);
+ SkPDFCanon* canon() { return &fCanon; }
+
+private:
+ SkPDFObjectSerializer fObjectSerializer;
+ SkPDFCanon fCanon;
+ SkTArray<sk_sp<const SkPDFDevice>> fPageDevices;
+ sk_sp<SkCanvas> fCanvas;
+ SkScalar fRasterDpi;
+ SkPDFMetadata fMetadata;
+};
+
#endif // SkPDFDocument_DEFINED
« no previous file with comments | « no previous file | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698