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

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 60863003: patch from issue 54913004 (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 77aa7a353ce74ff5b0562238842751f94f2a22ce..19db28a0a087668630b2a6e050f82e315addbacc 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,11 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix,
// TODO(edisonn): perf - use current clip too.
// Retrieve the bounds of the new shape.
SkRect bounds = perspectiveOutline.getBounds();
-
- // TODO(edisonn): add DPI settings. Currently 1 pixel/point, which does
- // not look great, but it is not producing large PDFs.
+ SkScalar scaleX = SkIntToScalar(fRasterDpi) /
+ SkIntToScalar(DPI_FOR_RASTER_SCALE_ONE);
+ SkScalar scaleY = scaleX;
+ scaleX *= fInitialTransform.getScaleX();
+ scaleY *= fInitialTransform.getScaleY();
// 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 +2203,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(SkScalarAbs(scaleX) * bounds.width()),
+ SkScalarCeilToInt(SkScalarAbs(scaleY) * bounds.height()));
perspectiveBitmap.allocPixels();
perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT);
@@ -2210,6 +2218,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.
@@ -2220,8 +2229,13 @@ 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.
+ scaleX /= fInitialTransform.getScaleX();
+ scaleY /= fInitialTransform.getScaleY();
+ 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