Chromium Code Reviews| Index: src/pdf/SkPDFDevice.cpp |
| diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp |
| index a7d2bd459accb39c70518ef21afc1289b30d3723..64239e02a34a8ec8b5550915fe0c4a375842358a 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) { |
| @@ -2040,6 +2042,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)) { |
| @@ -2062,9 +2067,14 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| // TODO(edisonn): perf - use current clip too. |
| // Retrieve the bounds of the new shape. |
| SkRect bounds = perspectiveOutline.getBounds(); |
| + float scaleX = fRasterDpi / (float)DPI_FOR_RASTER_SCALE_ONE; |
|
vandebo (ex-Chrome)
2013/10/31 23:20:36
This should probably use SkScalar instead of float
edisonn
2013/11/01 15:00:08
Done.
|
| + float scaleY = scaleX; |
| + |
| + scaleX *= SkScalarToFloat(fInitialTransform.getScaleX()); |
| + scaleY *= SkScalarToFloat(fInitialTransform.getScaleY()); |
| - // TODO(edisonn): add DPI settings. Currently 1 pixel/point, which does |
| - // not look great, but it is not producing large PDFs. |
| + scaleX = fabs(scaleX); |
|
vandebo (ex-Chrome)
2013/10/31 23:20:36
SkScalarAbs
edisonn
2013/11/01 15:00:08
Done.
|
| + scaleY = fabs(scaleY); |
|
vandebo (ex-Chrome)
2013/10/31 23:20:36
Actually, I don't think you want to do this. When
edisonn
2013/11/01 15:00:08
Yes, but getScaleX()/Y() can can return anything,
vandebo (ex-Chrome)
2013/11/01 22:13:42
True, you do need to use Abs for the bitmap.setCon
edisonn
2013/11/04 18:04:58
Incorrect, the initial transform is not affected b
|
| // 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 |
| @@ -2073,9 +2083,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()), |
| + SkScalarCeilToInt(scaleY * bounds.height())); |
| perspectiveBitmap.allocPixels(); |
| perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); |
| @@ -2087,6 +2098,7 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, |
| SkMatrix offsetMatrix = origMatrix; |
| offsetMatrix.postTranslate(-deltaX, -deltaY); |
| + offsetMatrix.postScale(scaleX, scaleY); |
| // Translate the draw in the new canvas, so we perfectly fit the |
| // shape in the bitmap. |
| @@ -2097,8 +2109,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. |
| + matrix.setScale(1 / scaleX, 1 / scaleY); |
| + matrix.postTranslate(deltaX, deltaY); |
| perspectiveBounds.setRect( |
| SkIRect::MakeXYWH(SkScalarFloorToInt(bounds.x()), |
| SkScalarFloorToInt(bounds.y()), |