Chromium Code Reviews| Index: src/pdf/SkPDFDevice.cpp |
| diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp |
| index 77aa7a353ce74ff5b0562238842751f94f2a22ce..6e88cdefd08d997a08f6ccef8a194b0b6d34119e 100644 |
| --- a/src/pdf/SkPDFDevice.cpp |
| +++ b/src/pdf/SkPDFDevice.cpp |
| @@ -49,6 +49,8 @@ struct TypefaceFallbackData { |
| }; |
| #endif |
| +#define DPI_FOR_RASTER_SCALE_ONE 72 |
| + |
| // Utility functions |
| static void emit_pdf_color(SkColor color, SkWStream* result) { |
| @@ -2163,6 +2165,9 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| // Rasterize the bitmap using perspective in a new bitmap. |
| if (origMatrix.hasPerspective()) { |
| + if (fRasterDpi == 0) { |
| + return; |
| + } |
| SkBitmap* subsetBitmap; |
| if (srcRect) { |
| if (!origBitmap.extractSubset(&tmpSubsetBitmap, *srcRect)) { |
| @@ -2185,9 +2190,15 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| // TODO(edisonn): perf - use current clip too. |
| // Retrieve the bounds of the new shape. |
| SkRect bounds = perspectiveOutline.getBounds(); |
| + SkScalar scaleX = SkIntToScalar(fRasterDpi) / |
| + SkIntToScalar(DPI_FOR_RASTER_SCALE_ONE); |
| + SkScalar scaleY = scaleX; |
| + |
| + scaleX *= fInitialTransform.getScaleX(); |
|
vandebo (ex-Chrome)
2013/11/04 19:55:10
The initial transform is already applied to the ca
edisonn
2013/11/05 20:33:32
Done.
|
| + scaleY *= fInitialTransform.getScaleY(); |
| - // TODO(edisonn): add DPI settings. Currently 1 pixel/point, which does |
| - // not look great, but it is not producing large PDFs. |
| + scaleX = SkScalarAbs(scaleX); |
| + scaleY = SkScalarAbs(scaleY); |
| // TODO(edisonn): A better approach would be to use a bitmap shader |
| // (in clamp mode) and draw a rect over the entire bounding box. Then |
| @@ -2196,9 +2207,10 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| // the image. Avoiding alpha will reduce the pdf size and generation |
| // CPU time some. |
| - perspectiveBitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| - SkScalarCeilToInt(bounds.width()), |
| - SkScalarCeilToInt(bounds.height())); |
| + perspectiveBitmap.setConfig( |
| + SkBitmap::kARGB_8888_Config, |
| + SkScalarCeilToInt(scaleX * bounds.width()), |
|
vandebo (ex-Chrome)
2013/11/04 19:55:10
Apply Abs here instead of on 2200 so you don't hav
edisonn
2013/11/05 20:33:32
Done.
|
| + SkScalarCeilToInt(scaleY * bounds.height())); |
| perspectiveBitmap.allocPixels(); |
| perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); |
| @@ -2210,6 +2222,7 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| SkMatrix offsetMatrix = origMatrix; |
| offsetMatrix.postTranslate(-deltaX, -deltaY); |
| + offsetMatrix.postScale(scaleX, scaleY); |
|
vandebo (ex-Chrome)
2013/11/04 19:55:10
I'm not sure if you need to unapply the initial tr
edisonn
2013/11/05 20:33:32
Done.
|
| // Translate the draw in the new canvas, so we perfectly fit the |
| // shape in the bitmap. |
| @@ -2220,8 +2233,10 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| // Make sure the final bits are in the bitmap. |
| canvas.flush(); |
| - // In the new space, we use the identity matrix translated. |
| - matrix.setTranslate(deltaX, deltaY); |
| + // In the new space, we use the identity matrix translated |
| + // and scaled to reflect DPI. |
|
vandebo (ex-Chrome)
2013/11/04 19:55:10
But we need to unapply it here so that it doesn't
edisonn
2013/11/05 20:33:32
Done.
|
| + matrix.setScale(1 / scaleX, 1 / scaleY); |
| + matrix.postTranslate(deltaX, deltaY); |
| perspectiveBounds.setRect( |
| SkIRect::MakeXYWH(SkScalarFloorToInt(bounds.x()), |
| SkScalarFloorToInt(bounds.y()), |