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 "SkDocument.h" | 8 #include "SkDocument.h" |
9 #include "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
10 #include "SkPDFCatalog.h" | 10 #include "SkPDFCatalog.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 offsets.push(SkToS32(stream->bytesWritten() - baseOffset)); | 222 offsets.push(SkToS32(stream->bytesWritten() - baseOffset)); |
223 SkASSERT(object == catalog.getSubstituteObject(object)); | 223 SkASSERT(object == catalog.getSubstituteObject(object)); |
224 SkASSERT(catalog.getObjectNumber(object) == i + 1); | 224 SkASSERT(catalog.getObjectNumber(object) == i + 1); |
225 stream->writeDecAsText(i + 1); | 225 stream->writeDecAsText(i + 1); |
226 stream->writeText(" 0 obj\n"); // Generation number is always 0. | 226 stream->writeText(" 0 obj\n"); // Generation number is always 0. |
227 object->emitObject(stream, &catalog); | 227 object->emitObject(stream, &catalog); |
228 stream->writeText("\nendobj\n"); | 228 stream->writeText("\nendobj\n"); |
229 } | 229 } |
230 int32_t xRefFileOffset = SkToS32(stream->bytesWritten() - baseOffset); | 230 int32_t xRefFileOffset = SkToS32(stream->bytesWritten() - baseOffset); |
231 | 231 |
| 232 // Include the zeroth object in the count. |
232 int32_t objCount = SkToS32(offsets.count() + 1); | 233 int32_t objCount = SkToS32(offsets.count() + 1); |
233 | 234 |
234 stream->writeText("xref\n0 "); | 235 stream->writeText("xref\n0 "); |
235 stream->writeDecAsText(objCount + 1); | 236 stream->writeDecAsText(objCount); |
236 stream->writeText("\n0000000000 65535 f \n"); | 237 stream->writeText("\n0000000000 65535 f \n"); |
237 for (int i = 0; i < offsets.count(); i++) { | 238 for (int i = 0; i < offsets.count(); i++) { |
238 SkASSERT(offsets[i] > 0); | 239 SkASSERT(offsets[i] > 0); |
239 stream->writeBigDecAsText(offsets[i], 10); | 240 stream->writeBigDecAsText(offsets[i], 10); |
240 stream->writeText(" 00000 n \n"); | 241 stream->writeText(" 00000 n \n"); |
241 } | 242 } |
242 emit_pdf_footer(stream, &catalog, docCatalog.get(), objCount, | 243 emit_pdf_footer(stream, &catalog, docCatalog.get(), objCount, |
243 xRefFileOffset); | 244 xRefFileOffset); |
244 | 245 |
245 // The page tree has both child and parent pointers, so it creates a | 246 // The page tree has both child and parent pointers, so it creates a |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 359 |
359 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 360 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
360 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 361 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
361 if (!stream->isValid()) { | 362 if (!stream->isValid()) { |
362 SkDELETE(stream); | 363 SkDELETE(stream); |
363 return NULL; | 364 return NULL; |
364 } | 365 } |
365 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; | 366 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; |
366 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); | 367 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
367 } | 368 } |
OLD | NEW |