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 "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 */ | 194 */ |
195 | 195 |
196 // Build font subsetting info before proceeding. | 196 // Build font subsetting info before proceeding. |
197 SkPDFSubstituteMap substitutes; | 197 SkPDFSubstituteMap substitutes; |
198 perform_font_subsetting(pageDevices, &substitutes); | 198 perform_font_subsetting(pageDevices, &substitutes); |
199 | 199 |
200 SkPDFObjNumMap objNumMap; | 200 SkPDFObjNumMap objNumMap; |
201 if (objNumMap.addObject(docCatalog.get())) { | 201 if (objNumMap.addObject(docCatalog.get())) { |
202 docCatalog->addResources(&objNumMap, substitutes); | 202 docCatalog->addResources(&objNumMap, substitutes); |
203 } | 203 } |
204 size_t baseOffset = SkToOffT(stream->bytesWritten()); | 204 size_t baseOffset = stream->bytesWritten(); |
205 emit_pdf_header(stream); | 205 emit_pdf_header(stream); |
206 SkTDArray<int32_t> offsets; | 206 SkTDArray<int32_t> offsets; |
207 for (int i = 0; i < objNumMap.objects().count(); ++i) { | 207 for (int i = 0; i < objNumMap.objects().count(); ++i) { |
208 SkPDFObject* object = objNumMap.objects()[i]; | 208 SkPDFObject* object = objNumMap.objects()[i]; |
209 offsets.push(SkToS32(stream->bytesWritten() - baseOffset)); | 209 size_t offset = stream->bytesWritten(); |
| 210 // This assert checks that size(pdf_header) > 0 and that |
| 211 // the output stream correctly reports bytesWritten(). |
| 212 SkASSERT(offset > baseOffset); |
| 213 offsets.push(SkToS32(offset - baseOffset)); |
210 SkASSERT(object == substitutes.getSubstitute(object)); | 214 SkASSERT(object == substitutes.getSubstitute(object)); |
211 SkASSERT(objNumMap.getObjectNumber(object) == i + 1); | 215 SkASSERT(objNumMap.getObjectNumber(object) == i + 1); |
212 stream->writeDecAsText(i + 1); | 216 stream->writeDecAsText(i + 1); |
213 stream->writeText(" 0 obj\n"); // Generation number is always 0. | 217 stream->writeText(" 0 obj\n"); // Generation number is always 0. |
214 object->emitObject(stream, objNumMap, substitutes); | 218 object->emitObject(stream, objNumMap, substitutes); |
215 stream->writeText("\nendobj\n"); | 219 stream->writeText("\nendobj\n"); |
216 } | 220 } |
217 int32_t xRefFileOffset = SkToS32(stream->bytesWritten() - baseOffset); | 221 int32_t xRefFileOffset = SkToS32(stream->bytesWritten() - baseOffset); |
218 | 222 |
219 // Include the zeroth object in the count. | 223 // Include the zeroth object in the count. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 350 |
347 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 351 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
348 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 352 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
349 if (!stream->isValid()) { | 353 if (!stream->isValid()) { |
350 SkDELETE(stream); | 354 SkDELETE(stream); |
351 return NULL; | 355 return NULL; |
352 } | 356 } |
353 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; | 357 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; |
354 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); | 358 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
355 } | 359 } |
OLD | NEW |