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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 | 1294 |
1295 SkPDFArray* mediaBox = SkNEW(SkPDFArray); | 1295 SkPDFArray* mediaBox = SkNEW(SkPDFArray); |
1296 mediaBox->reserve(4); | 1296 mediaBox->reserve(4); |
1297 mediaBox->append(zero.get()); | 1297 mediaBox->append(zero.get()); |
1298 mediaBox->append(zero.get()); | 1298 mediaBox->append(zero.get()); |
1299 mediaBox->appendInt(fPageSize.fWidth); | 1299 mediaBox->appendInt(fPageSize.fWidth); |
1300 mediaBox->appendInt(fPageSize.fHeight); | 1300 mediaBox->appendInt(fPageSize.fHeight); |
1301 return mediaBox; | 1301 return mediaBox; |
1302 } | 1302 } |
1303 | 1303 |
1304 SkStream* SkPDFDevice::content() const { | 1304 SkStreamAsset* SkPDFDevice::content() const { |
1305 SkMemoryStream* result = new SkMemoryStream; | 1305 SkDynamicMemoryWStream buffer; |
1306 result->setData(this->copyContentToData())->unref(); | 1306 this->writeContent(&buffer); |
1307 return result; | 1307 return buffer.detachAsStream(); |
1308 } | 1308 } |
1309 | 1309 |
1310 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry, | 1310 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry, |
1311 SkWStream* data) const { | 1311 SkWStream* data) const { |
1312 // TODO(ctguil): For margins, I'm not sure fExistingClipStack/Region is the | 1312 // TODO(ctguil): For margins, I'm not sure fExistingClipStack/Region is the |
1313 // right thing to pass here. | 1313 // right thing to pass here. |
1314 GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data); | 1314 GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data); |
1315 while (entry != NULL) { | 1315 while (entry != NULL) { |
1316 SkPoint translation; | 1316 SkPoint translation; |
1317 translation.iset(this->getOrigin()); | 1317 translation.iset(this->getOrigin()); |
1318 translation.negate(); | 1318 translation.negate(); |
1319 gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion, | 1319 gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion, |
1320 translation); | 1320 translation); |
1321 gsState.updateMatrix(entry->fState.fMatrix); | 1321 gsState.updateMatrix(entry->fState.fMatrix); |
1322 gsState.updateDrawingState(entry->fState); | 1322 gsState.updateDrawingState(entry->fState); |
1323 | 1323 |
1324 entry->fContent.writeToStream(data); | 1324 entry->fContent.writeToStream(data); |
1325 entry = entry->fNext.get(); | 1325 entry = entry->fNext.get(); |
1326 } | 1326 } |
1327 gsState.drainStack(); | 1327 gsState.drainStack(); |
1328 } | 1328 } |
1329 | 1329 |
1330 SkData* SkPDFDevice::copyContentToData() const { | 1330 void SkPDFDevice::writeContent(SkWStream* out) const { |
1331 SkDynamicMemoryWStream data; | |
1332 if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) { | 1331 if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) { |
1333 SkPDFUtils::AppendTransform(fInitialTransform, &data); | 1332 SkPDFUtils::AppendTransform(fInitialTransform, out); |
1334 } | 1333 } |
1335 | 1334 |
1336 // TODO(aayushkumar): Apply clip along the margins. Currently, webkit | 1335 // TODO(aayushkumar): Apply clip along the margins. Currently, webkit |
1337 // colors the contentArea white before it starts drawing into it and | 1336 // colors the contentArea white before it starts drawing into it and |
1338 // that currently acts as our clip. | 1337 // that currently acts as our clip. |
1339 // Also, think about adding a transform here (or assume that the values | 1338 // Also, think about adding a transform here (or assume that the values |
1340 // sent across account for that) | 1339 // sent across account for that) |
1341 SkPDFDevice::copyContentEntriesToData(fMarginContentEntries.get(), &data); | 1340 SkPDFDevice::copyContentEntriesToData(fMarginContentEntries.get(), out); |
1342 | 1341 |
1343 // If the content area is the entire page, then we don't need to clip | 1342 // If the content area is the entire page, then we don't need to clip |
1344 // the content area (PDF area clips to the page size). Otherwise, | 1343 // the content area (PDF area clips to the page size). Otherwise, |
1345 // we have to clip to the content area; we've already applied the | 1344 // we have to clip to the content area; we've already applied the |
1346 // initial transform, so just clip to the device size. | 1345 // initial transform, so just clip to the device size. |
1347 if (fPageSize != fContentSize) { | 1346 if (fPageSize != fContentSize) { |
1348 SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()), | 1347 SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()), |
1349 SkIntToScalar(this->height())); | 1348 SkIntToScalar(this->height())); |
1350 emit_clip(NULL, &r, &data); | 1349 emit_clip(NULL, &r, out); |
1351 } | 1350 } |
1352 | 1351 |
1353 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), &data); | 1352 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), out); |
1354 | |
1355 // potentially we could cache this SkData, and only rebuild it if we | |
1356 // see that our state has changed. | |
1357 return data.copyToData(); | |
1358 } | 1353 } |
1359 | 1354 |
1360 #ifdef SK_PDF_USE_PATHOPS | 1355 #ifdef SK_PDF_USE_PATHOPS |
1361 /* Draws an inverse filled path by using Path Ops to compute the positive | 1356 /* Draws an inverse filled path by using Path Ops to compute the positive |
1362 * inverse using the current clip as the inverse bounds. | 1357 * inverse using the current clip as the inverse bounds. |
1363 * Return true if this was an inverse path and was properly handled, | 1358 * Return true if this was an inverse path and was properly handled, |
1364 * otherwise returns false and the normal drawing routine should continue, | 1359 * otherwise returns false and the normal drawing routine should continue, |
1365 * either as a (incorrect) fallback or because the path was not inverse | 1360 * either as a (incorrect) fallback or because the path was not inverse |
1366 * in the first place. | 1361 * in the first place. |
1367 */ | 1362 */ |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 | 2130 |
2136 SkAutoTUnref<SkPDFObject> image( | 2131 SkAutoTUnref<SkPDFObject> image( |
2137 SkPDFCreateImageObject(fCanon, *bitmap, subset)); | 2132 SkPDFCreateImageObject(fCanon, *bitmap, subset)); |
2138 if (!image) { | 2133 if (!image) { |
2139 return; | 2134 return; |
2140 } | 2135 } |
2141 | 2136 |
2142 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2137 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2143 &content.entry()->fContent); | 2138 &content.entry()->fContent); |
2144 } | 2139 } |
OLD | NEW |