OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkPDFCanon.h" | 8 #include "SkPDFCanon.h" |
9 #include "SkPDFCanvas.h" | 9 #include "SkPDFCanvas.h" |
10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 208 } |
209 } | 209 } |
210 #endif | 210 #endif |
211 | 211 |
212 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } | 212 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } |
213 //////////////////////////////////////////////////////////////////////////////// | 213 //////////////////////////////////////////////////////////////////////////////// |
214 | 214 |
215 SkPDFDocument::SkPDFDocument(SkWStream* stream, | 215 SkPDFDocument::SkPDFDocument(SkWStream* stream, |
216 void (*doneProc)(SkWStream*, bool), | 216 void (*doneProc)(SkWStream*, bool), |
217 SkScalar rasterDpi, | 217 SkScalar rasterDpi, |
218 SkPixelSerializer* jpegEncoder, | 218 SkPixelSerializer* jpegEncoder) |
219 bool pdfa) | |
220 : SkDocument(stream, doneProc) | 219 : SkDocument(stream, doneProc) |
221 , fRasterDpi(rasterDpi) | 220 , fRasterDpi(rasterDpi) { |
222 , fPDFA(pdfa) { | |
223 fCanon.setPixelSerializer(SkSafeRef(jpegEncoder)); | 221 fCanon.setPixelSerializer(SkSafeRef(jpegEncoder)); |
224 } | 222 } |
225 | 223 |
226 SkPDFDocument::~SkPDFDocument() { | 224 SkPDFDocument::~SkPDFDocument() { |
227 // subclasses of SkDocument must call close() in their destructors. | 225 // subclasses of SkDocument must call close() in their destructors. |
228 this->close(); | 226 this->close(); |
229 } | 227 } |
230 | 228 |
231 void SkPDFDocument::serialize(const sk_sp<SkPDFObject>& object) { | 229 void SkPDFDocument::serialize(const sk_sp<SkPDFObject>& object) { |
232 fObjectSerializer.addObjectRecursively(object); | 230 fObjectSerializer.addObjectRecursively(object); |
233 fObjectSerializer.serializeObjects(this->getStream()); | 231 fObjectSerializer.serializeObjects(this->getStream()); |
234 } | 232 } |
235 | 233 |
236 SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height, | 234 SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height, |
237 const SkRect& trimBox) { | 235 const SkRect& trimBox) { |
238 SkASSERT(!fCanvas.get()); // endPage() was called before this. | 236 SkASSERT(!fCanvas.get()); // endPage() was called before this. |
239 if (fPages.empty()) { | 237 if (fPages.empty()) { |
240 // if this is the first page if the document. | 238 // if this is the first page if the document. |
241 fObjectSerializer.serializeHeader(this->getStream(), fMetadata); | 239 fObjectSerializer.serializeHeader(this->getStream(), fMetadata); |
242 fDests = sk_make_sp<SkPDFDict>(); | 240 fDests = sk_make_sp<SkPDFDict>(); |
243 if (fPDFA) { | 241 #ifdef SK_PDF_GENERATE_PDFA |
244 SkPDFMetadata::UUID uuid = fMetadata.uuid(); | 242 SkPDFMetadata::UUID uuid = fMetadata.uuid(); |
245 // We use the same UUID for Document ID and Instance ID since this | 243 // We use the same UUID for Document ID and Instance ID since this |
246 // is the first revision of this document (and Skia does not | 244 // is the first revision of this document (and Skia does not |
247 // support revising existing PDF documents). | 245 // support revising existing PDF documents). |
248 // If we are not in PDF/A mode, don't use a UUID since testing | 246 // If we are not in PDF/A mode, don't use a UUID since testing |
249 // works best with reproducible outputs. | 247 // works best with reproducible outputs. |
250 fID.reset(SkPDFMetadata::CreatePdfId(uuid, uuid)); | 248 fID.reset(SkPDFMetadata::CreatePdfId(uuid, uuid)); |
251 fXMP.reset(fMetadata.createXMPObject(uuid, uuid)); | 249 fXMP.reset(fMetadata.createXMPObject(uuid, uuid)); |
252 fObjectSerializer.addObjectRecursively(fXMP); | 250 fObjectSerializer.addObjectRecursively(fXMP); |
253 fObjectSerializer.serializeObjects(this->getStream()); | 251 fObjectSerializer.serializeObjects(this->getStream()); |
254 } | 252 #endif |
255 } | 253 } |
256 SkISize pageSize = SkISize::Make( | 254 SkISize pageSize = SkISize::Make( |
257 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); | 255 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
258 fPageDevice.reset( | 256 fPageDevice.reset( |
259 SkPDFDevice::Create(pageSize, fRasterDpi, this)); | 257 SkPDFDevice::Create(pageSize, fRasterDpi, this)); |
260 fCanvas = sk_make_sp<SkPDFCanvas>(fPageDevice); | 258 fCanvas = sk_make_sp<SkPDFCanvas>(fPageDevice); |
261 fCanvas->clipRect(trimBox); | 259 fCanvas->clipRect(trimBox); |
262 fCanvas->translate(trimBox.x(), trimBox.y()); | 260 fCanvas->translate(trimBox.x(), trimBox.y()); |
263 return fCanvas.get(); | 261 return fCanvas.get(); |
264 } | 262 } |
(...skipping 30 matching lines...) Expand all Loading... |
295 | 293 |
296 void SkPDFDocument::setMetadata(const SkDocument::Attribute info[], | 294 void SkPDFDocument::setMetadata(const SkDocument::Attribute info[], |
297 int infoCount, | 295 int infoCount, |
298 const SkTime::DateTime* creationDate, | 296 const SkTime::DateTime* creationDate, |
299 const SkTime::DateTime* modifiedDate) { | 297 const SkTime::DateTime* modifiedDate) { |
300 fMetadata.fInfo.reset(info, infoCount); | 298 fMetadata.fInfo.reset(info, infoCount); |
301 fMetadata.fCreation.reset(clone(creationDate)); | 299 fMetadata.fCreation.reset(clone(creationDate)); |
302 fMetadata.fModified.reset(clone(modifiedDate)); | 300 fMetadata.fModified.reset(clone(modifiedDate)); |
303 } | 301 } |
304 | 302 |
| 303 #ifdef SK_PDF_GENERATE_PDFA |
305 static sk_sp<SkData> SkSrgbIcm() { | 304 static sk_sp<SkData> SkSrgbIcm() { |
306 // Source: http://www.argyllcms.com/icclibsrc.html | 305 // Source: http://www.argyllcms.com/icclibsrc.html |
307 static const char kProfile[] = | 306 static const char kProfile[] = |
308 "\0\0\14\214argl\2 \0\0mntrRGB XYZ \7\336\0\1\0\6\0\26\0\17\0:acspM" | 307 "\000\000\014\214argl\002 \000\000mntrRGB XYZ \007\335\000\007\000\037" |
309 "SFT\0\0\0\0IEC sRGB\0\0\0\0\0\0\0\0\0\0\0\0\0\0\366\326\0\1\0\0\0\0" | 308 "\000\023\000\020\000'acspMSFT\000\000\000\000IEC sRGB\000\000\000\000" |
310 "\323-argl\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | 309 "\000\000\000\000\000\000\000\000\000\000\366\326\000\001\000\000\000" |
311 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\21desc\0\0\1P\0\0\0\231cprt\0" | 310 "\000\323-argl\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
312 "\0\1\354\0\0\0gdmnd\0\0\2T\0\0\0pdmdd\0\0\2\304\0\0\0\210tech\0\0\3" | 311 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
313 "L\0\0\0\14vued\0\0\3X\0\0\0gview\0\0\3\300\0\0\0$lumi\0\0\3\344\0\0" | 312 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\021" |
314 "\0\24meas\0\0\3\370\0\0\0$wtpt\0\0\4\34\0\0\0\24bkpt\0\0\0040\0\0\0" | 313 "desc\000\000\001P\000\000\000\231cprt\000\000\001\354\000\000\000g" |
315 "\24rXYZ\0\0\4D\0\0\0\24gXYZ\0\0\4X\0\0\0\24bXYZ\0\0\4l\0\0\0\24rTR" | 314 "dmnd\000\000\002T\000\000\000pdmdd\000\000\002\304\000\000\000\210" |
316 "C\0\0\4\200\0\0\10\14gTRC\0\0\4\200\0\0\10\14bTRC\0\0\4\200\0\0\10" | 315 "tech\000\000\003L\000\000\000\014vued\000\000\003X\000\000\000gvie" |
317 "\14desc\0\0\0\0\0\0\0?sRGB IEC61966-2.1 (Equivalent to www.srgb.co" | 316 "w\000\000\003\300\000\000\000$lumi\000\000\003\344\000\000\000\024" |
318 "m 1998 HP profile)\0\0\0\0\0\0\0\0\0\0\0?sRGB IEC61966-2.1 (Equiva" | 317 "meas\000\000\003\370\000\000\000$wtpt\000\000\004\034\000\000\000\024" |
319 "lent to www.srgb.com 1998 HP profile)\0\0\0\0\0\0\0\0text\0\0\0\0C" | 318 "bkpt\000\000\0040\000\000\000\024rXYZ\000\000\004D\000\000\000\024" |
320 "reated by Graeme W. Gill. Released into the public domain. No Warr" | 319 "gXYZ\000\000\004X\000\000\000\024bXYZ\000\000\004l\000\000\000\024" |
321 "anty, Use at your own risk.\0\0desc\0\0\0\0\0\0\0\26IEC http://www" | 320 "rTRC\000\000\004\200\000\000\010\014gTRC\000\000\004\200\000\000\010" |
322 ".iec.ch\0\0\0\0\0\0\0\0\0\0\0\26IEC http://www.iec.ch\0\0\0\0\0\0\0" | 321 "\014bTRC\000\000\004\200\000\000\010\014desc\000\000\000\000\000\000" |
323 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | 322 "\000?sRGB IEC61966-2.1 (Equivalent to www.srgb.com 1998 HP profile" |
324 "\0\0\0\0\0\0desc\0\0\0\0\0\0\0.IEC 61966-2.1 Default RGB colour sp" | 323 ")\000\000\000\000\000\000\000\000\000\000\000?sRGB IEC61966-2.1 (E" |
325 "ace - sRGB\0\0\0\0\0\0\0\0\0\0\0.IEC 61966-2.1 Default RGB colour " | 324 "quivalent to www.srgb.com 1998 HP profile)\000\000\000\000\000\000" |
326 "space - sRGB\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0sig \0\0\0" | 325 "\000\000text\000\000\000\000Created by Graeme W. Gill. Released in" |
327 "\0CRT desc\0\0\0\0\0\0\0\rIEC61966-2.1\0\0\0\0\0\0\0\0\0\0\0\rIEC6" | 326 "to the public domain. No Warranty, Use at your own risk.\000\000de" |
328 "1966-2.1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | 327 "sc\000\000\000\000\000\000\000\026IEC http://www.iec.ch\000\000\000" |
329 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0view\0\0\0\0" | 328 "\000\000\000\000\000\000\000\000\026IEC http://www.iec.ch\000\000\000" |
330 "\0\23\244|\0\24_0\0\20\316\2\0\3\355\262\0\4\23\n\0\3\\g\0\0\0\1XY" | 329 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
331 "Z \0\0\0\0\0L\n=\0P\0\0\0W\36\270meas\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0" | 330 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
332 "\0\0\0\0\0\0\0\0\0\0\0\2\217\0\0\0\2XYZ \0\0\0\0\0\0\363Q\0\1\0\0\0" | 331 "\000\000\000\000\000\000\000\000\000desc\000\000\000\000\000\000\000" |
333 "\1\26\314XYZ \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0XYZ \0\0\0\0\0\0o\240" | 332 ".IEC 61966-2.1 Default RGB colour space - sRGB\000\000\000\000\000" |
334 "\0\0008\365\0\0\3\220XYZ \0\0\0\0\0\0b\227\0\0\267\207\0\0\30\331X" | 333 "\000\000\000\000\000\000.IEC 61966-2.1 Default RGB colour space - " |
335 "YZ \0\0\0\0\0\0$\237\0\0\17\204\0\0\266\304curv\0\0\0\0\0\0\4\0\0\0" | 334 "sRGB\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
336 "\0\5\0\n\0\17\0\24\0\31\0\36\0#\0(\0-\0002\0007\0;\0@\0E\0J\0O\0T\0" | 335 "\000\000\000\000\000\000sig \000\000\000\000CRT desc\000\000\000\000" |
337 "Y\0^\0c\0h\0m\0r\0w\0|\0\201\0\206\0\213\0\220\0\225\0\232\0\237\0" | 336 "\000\000\000\rIEC61966-2.1\000\000\000\000\000\000\000\000\000\000" |
338 "\244\0\251\0\256\0\262\0\267\0\274\0\301\0\306\0\313\0\320\0\325\0" | 337 "\000\rIEC61966-2.1\000\000\000\000\000\000\000\000\000\000\000\000" |
339 "\333\0\340\0\345\0\353\0\360\0\366\0\373\1\1\1\7\1\r\1\23\1\31\1\37" | 338 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
340 "\1%\1+\0012\0018\1>\1E\1L\1R\1Y\1`\1g\1n\1u\1|\1\203\1\213\1\222\1" | 339 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
341 "\232\1\241\1\251\1\261\1\271\1\301\1\311\1\321\1\331\1\341\1\351\1" | 340 "\000\000\000\000\000\000\000\000\000\000view\000\000\000\000\000\023" |
342 "\362\1\372\2\3\2\14\2\24\2\35\2&\2/\0028\2A\2K\2T\2]\2g\2q\2z\2\204" | 341 "\244|\000\024_0\000\020\316\002\000\003\355\262\000\004\023\n\000\003" |
343 "\2\216\2\230\2\242\2\254\2\266\2\301\2\313\2\325\2\340\2\353\2\365" | 342 "\\g\000\000\000\001XYZ \000\000\000\000\000L\n=\000P\000\000\000W\036" |
344 "\3\0\3\13\3\26\3!\3-\0038\3C\3O\3Z\3f\3r\3~\3\212\3\226\3\242\3\256" | 343 "\270meas\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000" |
345 "\3\272\3\307\3\323\3\340\3\354\3\371\4\6\4\23\4 \4-\4;\4H\4U\4c\4q" | 344 "\000\000\000\000\000\000\000\000\000\000\000\002\217\000\000\000\002" |
346 "\4~\4\214\4\232\4\250\4\266\4\304\4\323\4\341\4\360\4\376\5\r\5\34" | 345 "XYZ \000\000\000\000\000\000\363Q\000\001\000\000\000\001\026\314X" |
347 "\5+\5:\5I\5X\5g\5w\5\206\5\226\5\246\5\265\5\305\5\325\5\345\5\366" | 346 "YZ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" |
348 "\6\6\6\26\6'\0067\6H\6Y\6j\6{\6\214\6\235\6\257\6\300\6\321\6\343\6" | 347 "XYZ \000\000\000\000\000\000o\240\000\0008\365\000\000\003\220XYZ " |
349 "\365\7\7\7\31\7+\7=\7O\7a\7t\7\206\7\231\7\254\7\277\7\322\7\345\7" | 348 "\000\000\000\000\000\000b\227\000\000\267\207\000\000\030\331XYZ \000" |
350 "\370\10\13\10\37\0102\10F\10Z\10n\10\202\10\226\10\252\10\276\10\322" | 349 "\000\000\000\000\000$\237\000\000\017\204\000\000\266\303curv\000\000" |
351 "\10\347\10\373\t\20\t%\t:\tO\td\ty\t\217\t\244\t\272\t\317\t\345\t" | 350 "\000\000\000\000\004\000\000\000\000\005\000\n\000\017\000\024\000" |
352 "\373\n\21\n'\n=\nT\nj\n\201\n\230\n\256\n\305\n\334\n\363\13\13\13" | 351 "\031\000\036\000#\000(\000-\0002\0007\000;\000@\000E\000J\000O\000" |
353 "\"\0139\13Q\13i\13\200\13\230\13\260\13\310\13\341\13\371\14\22\14" | 352 "T\000Y\000^\000c\000h\000m\000r\000w\000|\000\201\000\206\000\213\000" |
354 "*\14C\14\\\14u\14\216\14\247\14\300\14\331\14\363\r\r\r&\r@\rZ\rt\r" | 353 "\220\000\225\000\232\000\237\000\244\000\251\000\256\000\262\000\267" |
355 "\216\r\251\r\303\r\336\r\370\16\23\16.\16I\16d\16\177\16\233\16\266" | 354 "\000\274\000\301\000\306\000\313\000\320\000\325\000\333\000\340\000" |
356 "\16\322\16\356\17\t\17%\17A\17^\17z\17\226\17\263\17\317\17\354\20" | 355 "\345\000\353\000\360\000\366\000\373\001\001\001\007\001\r\001\023" |
357 "\t\20&\20C\20a\20~\20\233\20\271\20\327\20\365\21\23\0211\21O\21m\21" | 356 "\001\031\001\037\001%\001+\0012\0018\001>\001E\001L\001R\001Y\001`" |
358 "\214\21\252\21\311\21\350\22\7\22&\22E\22d\22\204\22\243\22\303\22" | 357 "\001g\001n\001u\001|\001\203\001\213\001\222\001\232\001\241\001\251" |
359 "\343\23\3\23#\23C\23c\23\203\23\244\23\305\23\345\24\6\24'\24I\24j" | 358 "\001\261\001\271\001\301\001\311\001\321\001\331\001\341\001\351\001" |
360 "\24\213\24\255\24\316\24\360\25\22\0254\25V\25x\25\233\25\275\25\340" | 359 "\362\001\372\002\003\002\014\002\024\002\035\002&\002/\0028\002A\002" |
361 "\26\3\26&\26I\26l\26\217\26\262\26\326\26\372\27\35\27A\27e\27\211" | 360 "K\002T\002]\002g\002q\002z\002\204\002\216\002\230\002\242\002\254" |
362 "\27\256\27\322\27\367\30\33\30@\30e\30\212\30\257\30\325\30\372\31" | 361 "\002\266\002\301\002\313\002\325\002\340\002\353\002\365\003\000\003" |
363 " \31E\31k\31\221\31\267\31\335\32\4\32*\32Q\32w\32\236\32\305\32\354" | 362 "\013\003\026\003!\003-\0038\003C\003O\003Z\003f\003r\003~\003\212\003" |
364 "\33\24\33;\33c\33\212\33\262\33\332\34\2\34*\34R\34{\34\243\34\314" | 363 "\226\003\242\003\256\003\272\003\307\003\323\003\340\003\354\003\371" |
365 "\34\365\35\36\35G\35p\35\231\35\303\35\354\36\26\36@\36j\36\224\36" | 364 "\004\006\004\023\004 \004-\004;\004H\004U\004c\004q\004~\004\214\004" |
366 "\276\36\351\37\23\37>\37i\37\224\37\277\37\352 \25 A l \230 \304 \360" | 365 "\232\004\250\004\266\004\304\004\323\004\341\004\360\004\376\005\r" |
367 "!\34!H!u!\241!\316!\373\"'\"U\"\202\"\257\"\335#\n#8#f#\224#\302#\360" | 366 "\005\034\005+\005:\005I\005X\005g\005w\005\206\005\226\005\246\005" |
368 "$\37$M$|$\253$\332%\t%8%h%\227%\307%\367&'&W&\207&\267&\350'\30'I'" | 367 "\265\005\305\005\325\005\345\005\366\006\006\006\026\006'\0067\006" |
369 "z'\253'\334(\r(?(q(\242(\324)\6)8)k)\235)\320*\2*5*h*\233*\317+\2+" | 368 "H\006Y\006j\006{\006\214\006\235\006\257\006\300\006\321\006\343\006" |
370 "6+i+\235+\321,\5,9,n,\242,\327-\14-A-v-\253-\341.\26.L.\202.\267.\356" | 369 "\365\007\007\007\031\007+\007=\007O\007a\007t\007\206\007\231\007\254" |
371 "/$/Z/\221/\307/\376050l0\2440\3331\0221J1\2021\2721\3622*2c2\2332\324" | 370 "\007\277\007\322\007\345\007\370\010\013\010\037\0102\010F\010Z\010" |
372 "3\r3F3\1773\2703\3614+4e4\2364\3305\0235M5\2075\3025\375676r6\2566" | 371 "n\010\202\010\226\010\252\010\276\010\322\010\347\010\373\t\020\t%" |
373 "\3517$7`7\2347\3278\0248P8\2148\3109\0059B9\1779\2749\371:6:t:\262" | 372 "\t:\tO\td\ty\t\217\t\244\t\272\t\317\t\345\t\373\n\021\n'\n=\nT\nj" |
374 ":\357;-;k;\252;\350<'<e<\244<\343=\"=a=\241=\340> >`>\240>\340?!?a" | 373 "\n\201\n\230\n\256\n\305\n\334\n\363\013\013\013\"\0139\013Q\013i\013" |
375 "?\242?\342@#@d@\246@\347A)AjA\254A\356B0BrB\265B\367C:C}C\300D\3DG" | 374 "\200\013\230\013\260\013\310\013\341\013\371\014\022\014*\014C\014" |
376 "D\212D\316E\22EUE\232E\336F\"FgF\253F\360G5G{G\300H\5HKH\221H\327I" | 375 "\\\014u\014\216\014\247\014\300\014\331\014\363\r\r\r&\r@\rZ\rt\r\216" |
377 "\35IcI\251I\360J7J}J\304K\14KSK\232K\342L*LrL\272M\2MJM\223M\334N%" | 376 "\r\251\r\303\r\336\r\370\016\023\016.\016I\016d\016\177\016\233\016" |
378 "NnN\267O\0OIO\223O\335P'PqP\273Q\6QPQ\233Q\346R1R|R\307S\23S_S\252" | 377 "\266\016\322\016\356\017\t\017%\017A\017^\017z\017\226\017\263\017" |
379 "S\366TBT\217T\333U(UuU\302V\17V\\V\251V\367WDW\222W\340X/X}X\313Y\32" | 378 "\317\017\354\020\t\020&\020C\020a\020~\020\233\020\271\020\327\020" |
380 "YiY\270Z\7ZVZ\246Z\365[E[\225[\345\\5\\\206\\\326]']x]\311^\32^l^\275" | 379 "\365\021\023\0211\021O\021m\021\214\021\252\021\311\021\350\022\007" |
381 "_\17_a_\263`\5`W`\252`\374aOa\242a\365bIb\234b\360cCc\227c\353d@d\224" | 380 "\022&\022E\022d\022\204\022\243\022\303\022\343\023\003\023#\023C\023" |
382 "d\351e=e\222e\347f=f\222f\350g=g\223g\351h?h\226h\354iCi\232i\361j" | 381 "c\023\203\023\244\023\305\023\345\024\006\024'\024I\024j\024\213\024" |
383 "Hj\237j\367kOk\247k\377lWl\257m\10m`m\271n\22nkn\304o\36oxo\321p+p" | 382 "\255\024\316\024\360\025\022\0254\025V\025x\025\233\025\275\025\340" |
384 "\206p\340q:q\225q\360rKr\246s\1s]s\270t\24tpt\314u(u\205u\341v>v\233" | 383 "\026\003\026&\026I\026l\026\217\026\262\026\326\026\372\027\035\027" |
385 "v\370wVw\263x\21xnx\314y*y\211y\347zFz\245{\4{c{\302|!|\201|\341}A" | 384 "A\027e\027\211\027\256\027\322\027\367\030\033\030@\030e\030\212\030" |
386 "}\241~\1~b~\302\177#\177\204\177\345\200G\200\250\201\n\201k\201\315" | 385 "\257\030\325\030\372\031 \031E\031k\031\221\031\267\031\335\032\004" |
387 "\2020\202\222\202\364\203W\203\272\204\35\204\200\204\343\205G\205" | 386 "\032*\032Q\032w\032\236\032\305\032\354\033\024\033;\033c\033\212\033" |
388 "\253\206\16\206r\206\327\207;\207\237\210\4\210i\210\316\2113\211\231" | 387 "\262\033\332\034\002\034*\034R\034{\034\243\034\314\034\365\035\036" |
389 "\211\376\212d\212\312\2130\213\226\213\374\214c\214\312\2151\215\230" | 388 "\035G\035p\035\231\035\303\035\354\036\026\036@\036j\036\224\036\276" |
390 "\215\377\216f\216\316\2176\217\236\220\6\220n\220\326\221?\221\250" | 389 "\036\351\037\023\037>\037i\037\224\037\277\037\352 \025 A l \230 \304" |
391 "\222\21\222z\222\343\223M\223\266\224 \224\212\224\364\225_\225\311" | 390 " \360!\034!H!u!\241!\316!\373\"'\"U\"\202\"\257\"\335#\n#8#f#\224#" |
392 "\2264\226\237\227\n\227u\227\340\230L\230\270\231$\231\220\231\374" | 391 "\302#\360$\037$M$|$\253$\332%\t%8%h%\227%\307%\367&'&W&\207&\267&\350" |
393 "\232h\232\325\233B\233\257\234\34\234\211\234\367\235d\235\322\236" | 392 "'\030'I'z'\253'\334(\r(?(q(\242(\324)\006)8)k)\235)\320*\002*5*h*\233" |
394 "@\236\256\237\35\237\213\237\372\240i\240\330\241G\241\266\242&\242" | 393 "*\317+\002+6+i+\235+\321,\005,9,n,\242,\327-\014-A-v-\253-\341.\026" |
395 "\226\243\6\243v\243\346\244V\244\307\2458\245\251\246\32\246\213\246" | 394 ".L.\202.\267.\356/$/Z/\221/\307/\376050l0\2440\3331\0221J1\2021\272" |
396 "\375\247n\247\340\250R\250\304\2517\251\251\252\34\252\217\253\2\253" | 395 "1\3622*2c2\2332\3243\r3F3\1773\2703\3614+4e4\2364\3305\0235M5\2075" |
397 "u\253\351\254\\\254\320\255D\255\270\256-\256\241\257\26\257\213\260" | 396 "\3025\375676r6\2566\3517$7`7\2347\3278\0248P8\2148\3109\0059B9\177" |
398 "\0\260u\260\352\261`\261\326\262K\262\302\2638\263\256\264%\264\234" | 397 "9\2749\371:6:t:\262:\357;-;k;\252;\350<'<e<\244<\343=\"=a=\241=\340" |
399 "\265\23\265\212\266\1\266y\266\360\267h\267\340\270Y\270\321\271J\271" | 398 "> >`>\240>\340?!?a?\242?\342@#@d@\246@\347A)AjA\254A\356B0BrB\265B" |
400 "\302\272;\272\265\273.\273\247\274!\274\233\275\25\275\217\276\n\276" | 399 "\367C:C}C\300D\003DGD\212D\316E\022EUE\232E\336F\"FgF\253F\360G5G{" |
401 "\204\276\377\277z\277\365\300p\300\354\301g\301\343\302_\302\333\303" | 400 "G\300H\005HKH\221H\327I\035IcI\251I\360J7J}J\304K\014KSK\232K\342L" |
402 "X\303\324\304Q\304\316\305K\305\310\306F\306\303\307A\307\277\310=" | 401 "*LrL\272M\002MJM\223M\334N%NnN\267O\000OIO\223O\335P'PqP\273Q\006Q" |
403 "\310\274\311:\311\271\3128\312\267\3136\313\266\3145\314\265\3155\315" | 402 "PQ\233Q\346R1R|R\307S\023S_S\252S\366TBT\217T\333U(UuU\302V\017V\\" |
404 "\265\3166\316\266\3177\317\270\3209\320\272\321<\321\276\322?\322\301" | 403 "V\251V\367WDW\222W\340X/X}X\313Y\032YiY\270Z\007ZVZ\246Z\365[E[\225" |
405 "\323D\323\306\324I\324\313\325N\325\321\326U\326\330\327\\\327\340" | 404 "[\345\\5\\\206\\\326]']x]\311^\032^l^\275_\017_a_\263`\005`W`\252`" |
406 "\330d\330\350\331l\331\361\332v\332\373\333\200\334\5\334\212\335\20" | 405 "\374aOa\242a\365bIb\234b\360cCc\227c\353d@d\224d\351e=e\222e\347f=" |
407 "\335\226\336\34\336\242\337)\337\257\3406\340\275\341D\341\314\342" | 406 "f\222f\350g=g\223g\351h?h\226h\354iCi\232i\361jHj\237j\367kOk\247k" |
408 "S\342\333\343c\343\353\344s\344\374\345\204\346\r\346\226\347\37\347" | 407 "\377lWl\257m\010m`m\271n\022nkn\304o\036oxo\321p+p\206p\340q:q\225" |
409 "\251\3502\350\274\351F\351\320\352[\352\345\353p\353\373\354\206\355" | 408 "q\360rKr\246s\001s]s\270t\024tpt\314u(u\205u\341v>v\233v\370wVw\263" |
410 "\21\355\234\356(\356\264\357@\357\314\360X\360\345\361r\361\377\362" | 409 "x\021xnx\314y*y\211y\347zFz\245{\004{c{\302|!|\201|\341}A}\241~\001" |
411 "\214\363\31\363\247\3644\364\302\365P\365\336\366m\366\373\367\212" | 410 "~b~\302\177#\177\204\177\345\200G\200\250\201\n\201k\201\315\2020\202" |
412 "\370\31\370\250\3718\371\307\372W\372\347\373w\374\7\374\230\375)\375" | 411 "\222\202\364\203W\203\272\204\035\204\200\204\343\205G\205\253\206" |
413 "\272\376K\376\334\377m\377\377"; | 412 "\016\206r\206\327\207;\207\237\210\004\210i\210\316\2113\211\231\211" |
414 const size_t kProfileLength = 3212; | 413 "\376\212d\212\312\2130\213\226\213\374\214c\214\312\2151\215\230\215" |
415 static_assert(kProfileLength == sizeof(kProfile) - 1, ""); | 414 "\377\216f\216\316\2176\217\236\220\006\220n\220\326\221?\221\250\222" |
416 return SkData::MakeWithoutCopy(kProfile, kProfileLength); | 415 "\021\222z\222\343\223M\223\266\224 \224\212\224\364\225_\225\311\226" |
| 416 "4\226\237\227\n\227u\227\340\230L\230\270\231$\231\220\231\374\232" |
| 417 "h\232\325\233B\233\257\234\034\234\211\234\367\235d\235\322\236@\236" |
| 418 "\256\237\035\237\213\237\372\240i\240\330\241G\241\266\242&\242\226" |
| 419 "\243\006\243v\243\346\244V\244\307\2458\245\251\246\032\246\213\246" |
| 420 "\375\247n\247\340\250R\250\304\2517\251\251\252\034\252\217\253\002" |
| 421 "\253u\253\351\254\\\254\320\255D\255\270\256-\256\241\257\026\257\213" |
| 422 "\260\000\260u\260\352\261`\261\326\262K\262\302\2638\263\256\264%\264" |
| 423 "\234\265\023\265\212\266\001\266y\266\360\267h\267\340\270Y\270\321" |
| 424 "\271J\271\302\272;\272\265\273.\273\247\274!\274\233\275\025\275\217" |
| 425 "\276\n\276\204\276\377\277z\277\365\300p\300\354\301g\301\343\302_" |
| 426 "\302\333\303X\303\324\304Q\304\316\305K\305\310\306F\306\303\307A\307" |
| 427 "\277\310=\310\274\311:\311\271\3128\312\267\3136\313\266\3145\314\265" |
| 428 "\3155\315\265\3166\316\266\3177\317\270\3209\320\272\321<\321\276\322" |
| 429 "?\322\301\323D\323\306\324I\324\313\325N\325\321\326U\326\330\327\\" |
| 430 "\327\340\330d\330\350\331l\331\361\332v\332\373\333\200\334\005\334" |
| 431 "\212\335\020\335\226\336\034\336\242\337)\337\257\3406\340\275\341" |
| 432 "D\341\314\342S\342\333\343c\343\353\344s\344\374\345\204\346\r\346" |
| 433 "\226\347\037\347\251\3502\350\274\351F\351\320\352[\352\345\353p\353" |
| 434 "\373\354\206\355\021\355\234\356(\356\264\357@\357\314\360X\360\345" |
| 435 "\361r\361\377\362\214\363\031\363\247\3644\364\302\365P\365\336\366" |
| 436 "m\366\373\367\212\370\031\370\250\3718\371\307\372W\372\347\373w\374" |
| 437 "\007\374\230\375)\375\272\376K\376\334\377m\377\377"; |
| 438 return SkData::MakeWithoutCopy(kProfile, sizeof(kProfile) - 1); |
417 } | 439 } |
418 | 440 |
419 static sk_sp<SkPDFStream> make_srgb_color_profile() { | 441 static sk_sp<SkPDFStream> make_srgb_color_profile() { |
420 sk_sp<SkData> profile = SkSrgbIcm(); | 442 sk_sp<SkData> profile = SkSrgbIcm(); |
421 sk_sp<SkPDFStream> stream = sk_make_sp<SkPDFStream>(profile.get()); | 443 sk_sp<SkPDFStream> stream = sk_make_sp<SkPDFStream>(profile.get()); |
422 stream->insertInt("N", 3); | 444 stream->insertInt("N", 3); |
423 sk_sp<SkPDFArray> array = sk_make_sp<SkPDFArray>(); | 445 sk_sp<SkPDFArray> array = sk_make_sp<SkPDFArray>(); |
424 array->appendScalar(0.0f); | 446 array->appendScalar(0.0f); |
425 array->appendScalar(1.0f); | 447 array->appendScalar(1.0f); |
426 array->appendScalar(0.0f); | 448 array->appendScalar(0.0f); |
427 array->appendScalar(1.0f); | 449 array->appendScalar(1.0f); |
428 array->appendScalar(0.0f); | 450 array->appendScalar(0.0f); |
429 array->appendScalar(1.0f); | 451 array->appendScalar(1.0f); |
430 stream->insertObject("Range", std::move(array)); | 452 stream->insertObject("Range", std::move(array)); |
431 return stream; | 453 return stream; |
432 } | 454 } |
433 | 455 #endif // SK_PDF_GENERATE_PDFA |
434 static sk_sp<SkPDFArray> make_srgb_output_intents() { | |
435 // sRGB is specified by HTML, CSS, and SVG. | |
436 auto outputIntent = sk_make_sp<SkPDFDict>("OutputIntent"); | |
437 outputIntent->insertName("S", "GTS_PDFA1"); | |
438 outputIntent->insertString("RegistryName", "http://www.color.org"); | |
439 outputIntent->insertString("OutputConditionIdentifier", | |
440 "Custom"); | |
441 outputIntent->insertString("Info","sRGB IEC61966-2.1"); | |
442 outputIntent->insertObjRef("DestOutputProfile", | |
443 make_srgb_color_profile()); | |
444 auto intentArray = sk_make_sp<SkPDFArray>(); | |
445 intentArray->appendObject(std::move(outputIntent)); | |
446 return intentArray; | |
447 } | |
448 | 456 |
449 bool SkPDFDocument::onClose(SkWStream* stream) { | 457 bool SkPDFDocument::onClose(SkWStream* stream) { |
450 SkASSERT(!fCanvas.get()); | 458 SkASSERT(!fCanvas.get()); |
451 if (fPages.empty()) { | 459 if (fPages.empty()) { |
452 fPages.reset(); | 460 fPages.reset(); |
453 fCanon.reset(); | 461 fCanon.reset(); |
454 renew(&fObjectSerializer); | 462 renew(&fObjectSerializer); |
455 return false; | 463 return false; |
456 } | 464 } |
457 auto docCatalog = sk_make_sp<SkPDFDict>("Catalog"); | 465 auto docCatalog = sk_make_sp<SkPDFDict>("Catalog"); |
458 if (fPDFA) { | 466 #ifdef SK_PDF_GENERATE_PDFA |
459 SkASSERT(fXMP); | 467 SkASSERT(fXMP); |
460 docCatalog->insertObjRef("Metadata", fXMP); | 468 docCatalog->insertObjRef("Metadata", fXMP); |
| 469 // sRGB is specified by HTML, CSS, and SVG. |
| 470 auto outputIntent = sk_make_sp<SkPDFDict>("OutputIntent"); |
| 471 outputIntent->insertName("S", "GTS_PDFA1"); |
| 472 outputIntent->insertString("RegistryName", "http://www.color.org"); |
| 473 outputIntent->insertString("OutputConditionIdentifier", |
| 474 "Custom"); |
| 475 outputIntent->insertString("Info","sRGB IEC61966-2.1"); |
| 476 outputIntent->insertObjRef("DestOutputProfile", |
| 477 make_srgb_color_profile()); |
| 478 auto intentArray = sk_make_sp<SkPDFArray>(); |
| 479 intentArray->appendObject(std::move(outputIntent)); |
461 // Don't specify OutputIntents if we are not in PDF/A mode since | 480 // Don't specify OutputIntents if we are not in PDF/A mode since |
462 // no one has ever asked for this feature. | 481 // no one has ever asked for this feature. |
463 docCatalog->insertObject("OutputIntents", make_srgb_output_intents()); | 482 docCatalog->insertObject("OutputIntents", std::move(intentArray)); |
464 } | 483 #endif |
465 SkASSERT(!fPages.empty()); | |
466 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); | 484 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); |
467 SkASSERT(fPages.empty()); | |
468 | 485 |
469 if (fDests->size() > 0) { | 486 if (fDests->size() > 0) { |
470 docCatalog->insertObjRef("Dests", std::move(fDests)); | 487 docCatalog->insertObjRef("Dests", std::move(fDests)); |
471 } | 488 } |
472 | 489 |
473 // Build font subsetting info before calling addObjectRecursively(). | 490 // Build font subsetting info before calling addObjectRecursively(). |
474 for (const auto& entry : fGlyphUsage) { | 491 for (const auto& entry : fGlyphUsage) { |
475 sk_sp<SkPDFFont> subsetFont( | 492 sk_sp<SkPDFFont> subsetFont( |
476 entry.fFont->getFontSubset(entry.fGlyphSet)); | 493 entry.fFont->getFontSubset(entry.fGlyphSet)); |
477 if (subsetFont) { | 494 if (subsetFont) { |
478 fObjectSerializer.fSubstituteMap.setSubstitute( | 495 fObjectSerializer.fSubstituteMap.setSubstitute( |
479 entry.fFont, subsetFont.get()); | 496 entry.fFont, subsetFont.get()); |
480 } | 497 } |
481 } | 498 } |
482 | 499 |
483 fObjectSerializer.addObjectRecursively(docCatalog); | 500 fObjectSerializer.addObjectRecursively(docCatalog); |
484 fObjectSerializer.serializeObjects(this->getStream()); | 501 fObjectSerializer.serializeObjects(this->getStream()); |
485 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); | 502 #ifdef SK_PDF_GENERATE_PDFA |
| 503 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); |
| 504 #else |
| 505 fObjectSerializer.serializeFooter( |
| 506 this->getStream(), docCatalog, nullptr); |
| 507 #endif |
| 508 SkASSERT(fPages.count() == 0); |
486 fCanon.reset(); | 509 fCanon.reset(); |
487 renew(&fObjectSerializer); | 510 renew(&fObjectSerializer); |
488 return true; | 511 return true; |
489 } | 512 } |
490 | 513 |
491 /////////////////////////////////////////////////////////////////////////////// | 514 /////////////////////////////////////////////////////////////////////////////// |
492 | 515 |
493 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, | 516 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, |
494 void (*proc)(SkWStream*, bool), | 517 void (*proc)(SkWStream*, bool), |
495 SkScalar dpi, | 518 SkScalar dpi, |
496 SkPixelSerializer* jpeg, | 519 SkPixelSerializer* jpeg) { |
497 bool pdfa) { | 520 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, jpeg) : nullptr
; |
498 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, jpeg, pdfa) | |
499 : nullptr; | |
500 } | 521 } |
501 | 522 |
502 #ifdef SK_PDF_GENERATE_PDFA | |
503 static const bool kPDFA = true; | |
504 #else | |
505 static const bool kPDFA = false; | |
506 #endif | |
507 | |
508 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 523 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
509 return SkPDFMakeDocument(stream, nullptr, dpi, nullptr, kPDFA).release(); | 524 return SkPDFMakeDocument(stream, nullptr, dpi, nullptr).release(); |
510 } | 525 } |
511 | 526 |
512 SkDocument* SkDocument::CreatePDF(SkWStream* stream, | 527 SkDocument* SkDocument::CreatePDF(SkWStream* stream, |
513 SkScalar dpi, | 528 SkScalar dpi, |
514 SkPixelSerializer* jpegEncoder) { | 529 SkPixelSerializer* jpegEncoder) { |
515 return SkPDFMakeDocument(stream, nullptr, dpi, | 530 return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); |
516 jpegEncoder, kPDFA).release(); | |
517 } | 531 } |
518 | 532 |
519 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 533 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
520 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 534 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
521 std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path)); | 535 std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path)); |
522 return stream->isValid() | 536 return stream->isValid() |
523 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, | 537 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, nullptr).rele
ase() |
524 nullptr, kPDFA).release() | |
525 : nullptr; | 538 : nullptr; |
526 } | 539 } |
OLD | NEW |