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

Side by Side Diff: src/doc/SkDocument_PDF.cpp

Issue 1287443002: SkPDF: add assert for that SkWStream behaves. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | no next file » | 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 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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698