Add DPI stettings to SkDocument::CreatePDF(). Tests will be added in a future cl, once DPI will be used in SkPDFDevice

R=reed@google.com, bungeman@google.com, vandebo@chromium.org

Author: edisonn@google.com

Review URL: https://codereview.chromium.org/32233003

git-svn-id: http://skia.googlecode.com/svn/trunk@11886 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
index b941d1b..66946fe 100644
--- a/include/core/SkDocument.h
+++ b/include/core/SkDocument.h
@@ -16,6 +16,10 @@
 class SkCanvas;
 class SkWStream;
 
+/** SK_ScalarDefaultDPI is 72 DPI.
+*/
+#define SK_ScalarDefaultRasterDPI           SkFloatToScalar(72.0f)
+
 /**
  *  High-level API for creating a document-based canvas. To use..
  *
@@ -35,9 +39,19 @@
      *  If there is an error trying to create the doc, returns NULL.
      *  encoder sets the DCTEncoder for images, to encode a bitmap
      *    as JPEG (DCT).
+     *  rasterDpi - the DPI at which features without native PDF support
+     *              will be rasterized (e.g. draw image with perspective,
+     *              draw text with perspective, ...)
+     *              A larger DPI would create a PDF that reflects the original
+     *              intent with better fidelity, but it can make for larger
+     *              PDF files too, which would use more memory while rendering,
+     *              and it would be slower to be processed or sent online or
+     *              to printer.
      */
-    static SkDocument* CreatePDF(const char filename[],
-                                 SkPicture::EncodeBitmap encoder = NULL);
+    static SkDocument* CreatePDF(
+            const char filename[],
+            SkPicture::EncodeBitmap encoder = NULL,
+            SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
 
     /**
      *  Create a PDF-backed document, writing the results into a stream.
@@ -50,9 +64,18 @@
      *  The proc can delete the stream, or whatever it needs to do.
      *  encoder sets the DCTEncoder for images, to encode a bitmap
      *    as JPEG (DCT).
-     */
-    static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL,
-                                 SkPicture::EncodeBitmap encoder = NULL);
+     *  rasterDpi - the DPI at which features without native PDF support
+     *              will be rasterized (e.g. draw image with perspective,
+     *              draw text with perspective, ...)
+     *              A larger DPI would create a PDF that reflects the original
+     *              intent with better fidelity, but it can make for larger
+     *              PDF files too, which would use more memory while rendering,
+     *              and it would be slower to be processed or sent online or
+     *              to printer.     */
+    static SkDocument* CreatePDF(
+            SkWStream*, void (*Done)(SkWStream*) = NULL,
+            SkPicture::EncodeBitmap encoder = NULL,
+            SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
 
     /**
      *  Begin a new page for the document, returning the canvas that will draw
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index d668be5..e68623e 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -197,6 +197,20 @@
 
     virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE;
 
+    /**
+     *  rasterDpi - the DPI at which features without native PDF support
+     *              will be rasterized (e.g. draw image with perspective,
+     *              draw text with perspective, ...)
+     *              A larger DPI would create a PDF that reflects the original
+     *              intent with better fidelity, but it can make for larger
+     *              PDF files too, which would use more memory while rendering,
+     *              and it would be slower to be processed or sent online or
+     *              to printer.
+     */
+    void setRasterDpi(SkScalar rasterDpi) {
+        fRasterDpi = rasterDpi;
+    }
+
 private:
     // TODO(vandebo): push most of SkPDFDevice's state into a core object in
     // order to get the right access levels without using friend.
@@ -233,6 +247,7 @@
     SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
 
     SkPicture::EncodeBitmap fEncoder;
+    SkScalar fRasterDpi;
 
     SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack,
                 const SkRegion& existingClipRegion);
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index 695929f..362493d 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -12,9 +12,11 @@
 class SkDocument_PDF : public SkDocument {
 public:
     SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*),
-                   SkPicture::EncodeBitmap encoder)
+                   SkPicture::EncodeBitmap encoder,
+                   SkScalar rasterDpi)
             : SkDocument(stream, doneProc)
-            , fEncoder(encoder) {
+            , fEncoder(encoder)
+            , fRasterDpi(rasterDpi) {
         fDoc = SkNEW(SkPDFDocument);
         fCanvas = NULL;
         fDevice = NULL;
@@ -38,6 +40,9 @@
         if (fEncoder) {
             fDevice->setDCTEncoder(fEncoder);
         }
+        if (fRasterDpi != 0) {
+            fDevice->setRasterDpi(fRasterDpi);
+        }
         fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
         return fCanvas;
     }
@@ -76,24 +81,28 @@
     SkPDFDeviceFlattener* fDevice;
     SkCanvas*       fCanvas;
     SkPicture::EncodeBitmap fEncoder;
+    SkScalar        fRasterDpi;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
 
 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*),
-                                  SkPicture::EncodeBitmap enc) {
-    return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc)) : NULL;
+                                  SkPicture::EncodeBitmap enc,
+                                  SkScalar dpi) {
+    return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL;
 }
 
 static void delete_wstream(SkWStream* stream) {
     SkDELETE(stream);
 }
 
-SkDocument* SkDocument::CreatePDF(const char path[], SkPicture::EncodeBitmap enc) {
+SkDocument* SkDocument::CreatePDF(const char path[],
+                                  SkPicture::EncodeBitmap enc,
+                                  SkScalar dpi) {
     SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
     if (!stream->isValid()) {
         SkDELETE(stream);
         return NULL;
     }
-    return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc));
+    return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi));
 }
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index e90edb1..1aed856 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -704,7 +704,8 @@
       fLastContentEntry(NULL),
       fLastMarginContentEntry(NULL),
       fClipStack(NULL),
-      fEncoder(NULL) {
+      fEncoder(NULL),
+      fRasterDpi(SkFloatToScalar(72.0f)) {
     // just report that PDF does not supports perspective
     // TODO(edisonn): update the shape when possible
     // or dump in an image otherwise
@@ -734,7 +735,9 @@
       fExistingClipRegion(existingClipRegion),
       fLastContentEntry(NULL),
       fLastMarginContentEntry(NULL),
-      fClipStack(NULL) {
+      fClipStack(NULL),
+      fEncoder(NULL),
+      fRasterDpi(SkFloatToScalar(72.0f)) {
     fInitialTransform.reset();
     this->init();
 }