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

Side by Side Diff: include/core/SkDocument.h

Issue 1916093002: SkDocument/PDF: new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-04-25 (Monday) 14:51:30 EDT Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « gyp/pdf.gyp ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkDocument_DEFINED 8 #ifndef SkDocument_DEFINED
9 #define SkDocument_DEFINED 9 #define SkDocument_DEFINED
10 10
(...skipping 17 matching lines...) Expand all
28 * 28 *
29 * 1. Create a document, specifying a stream to store the output. 29 * 1. Create a document, specifying a stream to store the output.
30 * 2. For each "page" of content: 30 * 2. For each "page" of content:
31 * a. canvas = doc->beginPage(...) 31 * a. canvas = doc->beginPage(...)
32 * b. draw_my_content(canvas); 32 * b. draw_my_content(canvas);
33 * c. doc->endPage(); 33 * c. doc->endPage();
34 * 3. Close the document with doc->close(). 34 * 3. Close the document with doc->close().
35 */ 35 */
36 class SK_API SkDocument : public SkRefCnt { 36 class SK_API SkDocument : public SkRefCnt {
37 public: 37 public:
38 struct OptionalTimestamp {
39 bool enabled;
40 SkTime::DateTime dateTime;
41 OptionalTimestamp() : enabled(false) {}
42 };
43
38 /** 44 /**
45 * Optional metadata to be passed into the PDF factory function.
46 */
47 struct PDFMetadata {
48 SkString title;
reed1 2016/04/25 19:14:30 why not use skia fField convention?
hal.canary 2016/04/25 21:51:33 Done.
49 SkString author;
50 SkString subject;
51 SkString keywords;
52 SkString creator;
53 OptionalTimestamp creation;
54 OptionalTimestamp modified;
55 };
56
57 /**
58 * Create a PDF-backed document, writing the results into a
59 * SkWStream.
60 *
61 * PDF pages are sized in point units. 1 pt == 1/72 inch ==
62 * 127/360 mm.
63 *
64 * @param stream A PDF document will be written to this
65 * stream. The document may write to the stream at
66 * anytime during its lifetime, until either close() is
67 * called or the document is deleted.
68 * @param dpi The DPI (pixels-per-inch) at which features without
69 * native PDF support will be rasterized (e.g. draw image
70 * with perspective, draw text with perspective, ...) A
71 * larger DPI would create a PDF that reflects the
72 * original intent with better fidelity, but it can make
73 * for larger PDF files too, which would use more memory
74 * while rendering, and it would be slower to be processed
75 * or sent online or to printer.
76 * @param metadata a PDFmetadata object. Any fields may be left
77 * empty.
78 * @param jpegEncoder For PDF documents, if a jpegEncoder is set,
79 * use it to encode SkImages and SkBitmaps as [JFIF]JPEGs.
80 * This feature is deprecated and is only supplied for
81 * backwards compatability.
82 * The prefered method to create PDFs with JPEG images is
83 * to use SkImage::NewFromEncoded() and not jpegEncoder.
84 * Chromium uses NewFromEncoded.
85 * If the encoder is unset, or if jpegEncoder->onEncode()
86 * returns NULL, fall back on encoding images losslessly
87 * with Deflate.
88 * @param pdfa Iff true, include XMP metadata, a document UUID,
89 * and sRGB output intent information. This adds length
90 * to the document and makes it non-reproducable, but are
91 * necessary features for PDF/A-2b conformance
92 *
93 * @returns NULL if there is an error, otherwise a newly created
94 * PDF-backed SkDocument.
95 */
96 static sk_sp<SkDocument> MakePDF(
97 SkWStream* stream,
98 SkScalar dpi,
99 const SkDocument::PDFMetadata& metadata,
100 SkPixelSerializer* jpegEncoder,
101 bool pdfa);
102
103 /**
104 * DEPRECATED: use SkDocument::MakePDF instead.
105 *
39 * Create a PDF-backed document, writing the results into a SkWStream. 106 * Create a PDF-backed document, writing the results into a SkWStream.
40 * 107 *
41 * PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm. 108 * PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm.
42 * 109 *
43 * @param SkWStream* A PDF document will be written to this 110 * @param SkWStream* A PDF document will be written to this
44 * stream. The document may write to the stream at 111 * stream. The document may write to the stream at
45 * anytime during its lifetime, until either close() is 112 * anytime during its lifetime, until either close() is
46 * called or the document is deleted. 113 * called or the document is deleted.
47 * @param dpi The DPI (pixels-per-inch) at which features without 114 * @param dpi The DPI (pixels-per-inch) at which features without
48 * native PDF support will be rasterized (e.g. draw image 115 * native PDF support will be rasterized (e.g. draw image
49 * with perspective, draw text with perspective, ...) A 116 * with perspective, draw text with perspective, ...) A
50 * larger DPI would create a PDF that reflects the 117 * larger DPI would create a PDF that reflects the
51 * original intent with better fidelity, but it can make 118 * original intent with better fidelity, but it can make
52 * for larger PDF files too, which would use more memory 119 * for larger PDF files too, which would use more memory
53 * while rendering, and it would be slower to be processed 120 * while rendering, and it would be slower to be processed
54 * or sent online or to printer. 121 * or sent online or to printer.
55 * @returns NULL if there is an error, otherwise a newly created 122 * @returns NULL if there is an error, otherwise a newly created
56 * PDF-backed SkDocument. 123 * PDF-backed SkDocument.
57 */ 124 */
58 static SkDocument* CreatePDF(SkWStream*, 125 static SkDocument* CreatePDF(SkWStream*,
reed1 2016/04/25 19:14:30 We've been adding build flags to guard/hide the ol
hal.canary 2016/04/25 21:51:33 Done.
59 SkScalar dpi = SK_ScalarDefaultRasterDPI); 126 SkScalar dpi = SK_ScalarDefaultRasterDPI);
60 127
61 /** 128 /**
129 * DEPRECATED: use SkDocument::MakePDF instead.
130 *
62 * @param jpegEncoder For PDF documents, if a jpegEncoder is set, 131 * @param jpegEncoder For PDF documents, if a jpegEncoder is set,
63 * use it to encode SkImages and SkBitmaps as [JFIF]JPEGs. 132 * use it to encode SkImages and SkBitmaps as [JFIF]JPEGs.
64 * This feature is deprecated and is only supplied for 133 * This feature is deprecated and is only supplied for
65 * backwards compatability. 134 * backwards compatability.
66 * 135 *
67 * The prefered method to create PDFs with JPEG images is 136 * The prefered method to create PDFs with JPEG images is
68 * to use SkImage::NewFromEncoded() and not jpegEncoder. 137 * to use SkImage::NewFromEncoded() and not jpegEncoder.
69 * Chromium uses NewFromEncoded. 138 * Chromium uses NewFromEncoded.
70 * 139 *
71 * If the encoder is unset, or if jpegEncoder->onEncode() 140 * If the encoder is unset, or if jpegEncoder->onEncode()
72 * returns NULL, fall back on encoding images losslessly 141 * returns NULL, fall back on encoding images losslessly
73 * with Deflate. 142 * with Deflate.
74 */ 143 */
75 static SkDocument* CreatePDF(SkWStream*, 144 static SkDocument* CreatePDF(SkWStream*,
76 SkScalar dpi, 145 SkScalar dpi,
77 SkPixelSerializer* jpegEncoder); 146 SkPixelSerializer* jpegEncoder);
78 147
79 /** 148 /**
149 * DEPRECATED: use SkDocument::MakePDF instead.
150 *
80 * Create a PDF-backed document, writing the results into a file. 151 * Create a PDF-backed document, writing the results into a file.
81 */ 152 */
82 static SkDocument* CreatePDF(const char outputFilePath[], 153 static SkDocument* CreatePDF(const char outputFilePath[],
83 SkScalar dpi = SK_ScalarDefaultRasterDPI); 154 SkScalar dpi = SK_ScalarDefaultRasterDPI);
84 155
85 /** 156 /**
86 * Create a XPS-backed document, writing the results into the stream. 157 * Create a XPS-backed document, writing the results into the stream.
87 * Returns NULL if XPS is not supported. 158 * Returns NULL if XPS is not supported.
88 */ 159 */
89 static SkDocument* CreateXPS(SkWStream* stream, 160 static SkDocument* CreateXPS(SkWStream* stream,
(...skipping 29 matching lines...) Expand all
119 */ 190 */
120 bool close(); 191 bool close();
121 192
122 /** 193 /**
123 * Call abort() to stop producing the document immediately. 194 * Call abort() to stop producing the document immediately.
124 * The stream output must be ignored, and should not be trusted. 195 * The stream output must be ignored, and should not be trusted.
125 */ 196 */
126 void abort(); 197 void abort();
127 198
128 /** 199 /**
200 * DEPRECATED: use SkDocument::PDFMetadata and
201 * SkDocument::MakePDF instead.
202 *
129 * Set the document's metadata, if supported by the document 203 * Set the document's metadata, if supported by the document
130 * type. The creationDate and modifiedDate parameters can be 204 * type. The creationDate and modifiedDate parameters can be
131 * nullptr. For example: 205 * nullptr. For example:
132 * 206 *
133 * SkDocument* make_doc(SkWStream* output) { 207 * SkDocument* make_doc(SkWStream* output) {
134 * std::vector<SkDocument::Attribute> info; 208 * std::vector<SkDocument::Attribute> info;
135 * info.emplace_back(SkString("Title"), SkString("...")); 209 * info.emplace_back(SkString("Title"), SkString("..."));
136 * info.emplace_back(SkString("Author"), SkString("...")); 210 * info.emplace_back(SkString("Author"), SkString("..."));
137 * info.emplace_back(SkString("Subject"), SkString("...")); 211 * info.emplace_back(SkString("Subject"), SkString("..."));
138 * info.emplace_back(SkString("Keywords"), SkString("...")); 212 * info.emplace_back(SkString("Keywords"), SkString("..."));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 252
179 private: 253 private:
180 SkWStream* fStream; 254 SkWStream* fStream;
181 void (*fDoneProc)(SkWStream*, bool aborted); 255 void (*fDoneProc)(SkWStream*, bool aborted);
182 State fState; 256 State fState;
183 257
184 typedef SkRefCnt INHERITED; 258 typedef SkRefCnt INHERITED;
185 }; 259 };
186 260
187 #endif 261 #endif
OLDNEW
« no previous file with comments | « gyp/pdf.gyp ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698