diff options
Diffstat (limited to 'src/pdf/SkPDFDocument.cpp')
-rw-r--r-- | src/pdf/SkPDFDocument.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp index b06b8b1a96..8219ad385e 100644 --- a/src/pdf/SkPDFDocument.cpp +++ b/src/pdf/SkPDFDocument.cpp @@ -207,11 +207,14 @@ SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height) { fObjectSerializer.serializeObjects(this->getStream()); } } - SkISize pageSize = SkISize::Make( - SkScalarRoundToInt(width), SkScalarRoundToInt(height)); + SkScalar rasterScale = this->rasterDpi() / SkPDFUtils::kDpiForRasterScaleOne; + SkISize pageSize = {SkScalarRoundToInt(width * rasterScale), + SkScalarRoundToInt(height * rasterScale)}; + fPageDevice = sk_make_sp<SkPDFDevice>(pageSize, this); fPageDevice->setFlip(); // Only the top-level device needs to be flipped. fCanvas.reset(new SkCanvas(fPageDevice)); + fCanvas->scale(rasterScale, rasterScale); return fCanvas.get(); } @@ -222,7 +225,13 @@ void SkPDFDocument::onEndPage() { SkASSERT(fPageDevice); auto page = sk_make_sp<SkPDFDict>("Page"); page->insertObject("Resources", fPageDevice->makeResourceDict()); - page->insertObject("MediaBox", fPageDevice->copyMediaBox()); + + SkScalar rasterScale = SkPDFUtils::kDpiForRasterScaleOne / this->rasterDpi(); + + SkISize pageSize = fPageDevice->imageInfo().dimensions(); + page->insertObject("MediaBox", SkPDFUtils::RectToArray( + {0, 0, pageSize.width() * rasterScale, pageSize.height() * rasterScale})); + auto annotations = sk_make_sp<SkPDFArray>(); fPageDevice->appendAnnotations(annotations.get()); if (annotations->size() > 0) { |