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" |
11 #include "SkPDFDocument.h" | 11 #include "SkPDFDocument.h" |
12 #include "SkPDFFont.h" | 12 #include "SkPDFFont.h" |
13 #include "SkPDFStream.h" | 13 #include "SkPDFStream.h" |
14 #include "SkPDFUtils.h" | 14 #include "SkPDFUtils.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 | 16 |
17 | |
18 SkPDFObjectSerializer::SkPDFObjectSerializer() : fBaseOffset(0), fNextToBeSerial
ized(0) {} | 17 SkPDFObjectSerializer::SkPDFObjectSerializer() : fBaseOffset(0), fNextToBeSerial
ized(0) {} |
19 | 18 |
20 template <class T> static void renew(T* t) { t->~T(); new (t) T; } | 19 template <class T> static void renew(T* t) { t->~T(); new (t) T; } |
21 | 20 |
| 21 SkPDFObjectSerializer::~SkPDFObjectSerializer() { |
| 22 for (int i = 0; i < fObjNumMap.objects().count(); ++i) { |
| 23 fObjNumMap.objects()[i]->drop(); |
| 24 } |
| 25 } |
| 26 |
22 void SkPDFObjectSerializer::addObjectRecursively(const sk_sp<SkPDFObject>& objec
t) { | 27 void SkPDFObjectSerializer::addObjectRecursively(const sk_sp<SkPDFObject>& objec
t) { |
23 fObjNumMap.addObjectRecursively(object.get(), fSubstituteMap); | 28 fObjNumMap.addObjectRecursively(object.get(), fSubstituteMap); |
24 } | 29 } |
25 | 30 |
26 void SkPDFObjectSerializer::serializeHeader(SkWStream* wStream, const SkPDFMetad
ata& md) { | 31 void SkPDFObjectSerializer::serializeHeader(SkWStream* wStream, const SkPDFMetad
ata& md) { |
27 fBaseOffset = wStream->bytesWritten(); | 32 fBaseOffset = wStream->bytesWritten(); |
28 static const char kHeader[] = "%PDF-1.4\n%\xE1\xE9\xEB\xD3\n"; | 33 static const char kHeader[] = "%PDF-1.4\n%\xE1\xE9\xEB\xD3\n"; |
29 wStream->write(kHeader, strlen(kHeader)); | 34 wStream->write(kHeader, strlen(kHeader)); |
30 // The PDF spec recommends including a comment with four | 35 // The PDF spec recommends including a comment with four |
31 // bytes, all with their high bits set. "\xD3\xEB\xE9\xE1" is | 36 // bytes, all with their high bits set. "\xD3\xEB\xE9\xE1" is |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); | 360 return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); |
356 } | 361 } |
357 | 362 |
358 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 363 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
359 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 364 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
360 SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); | 365 SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); |
361 return stream->isValid() | 366 return stream->isValid() |
362 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, nullptr).rele
ase() | 367 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, nullptr).rele
ase() |
363 : nullptr; | 368 : nullptr; |
364 } | 369 } |
OLD | NEW |