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

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 54913004: Implement DPI for perspective bitmaps in PDF - we save the bitmap at the resolution requested. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 80c/l, remove commentd code Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/pdf/SkPDFDevice.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index a7d2bd459accb39c70518ef21afc1289b30d3723..c97e022a386e9593dfd1c46cfdc5cd37d36d5ec9 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 = sqrt(fRasterDpi / (float)DPI_FOR_RASTER_SCALE_ONE);
vandebo (ex-Chrome) 2013/10/31 19:26:43 I don't understand, why sqrt ?
edisonn 2013/10/31 19:49:31 For some reason I was thinking DPI is "dots per sq
+ 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);
+ scaleY = fabs(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
@@ -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()),
vandebo (ex-Chrome) 2013/10/31 19:26:43 This makes the image bigger
edisonn 2013/10/31 19:49:31 correct, when bitmap is put in perspective mode, i
+ 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);
vandebo (ex-Chrome) 2013/10/31 19:26:43 Then this draws it bigger. Should this be 1/scale
edisonn 2013/10/31 19:49:31 The gms just work, I guess the code is correct.
vandebo (ex-Chrome) 2013/10/31 23:20:36 After much effort, I understand. Above makes the
// 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()),
« no previous file with comments | « include/pdf/SkPDFDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698