Generalize the flip origin argument to the PDF device constructor.
The argument still has a default value that does what most users will want, but provides more flexibility.
Chrome will use this change to support an initial translation of the origin to simulate a margin and to scale the entire content (needed on Windows).
When landing to Chrome, this will need http://codereview.chromium.org/6820038
Review URL: http://codereview.appspot.com/4373052
git-svn-id: http://skia.googlecode.com/svn/trunk@1111 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index 9292227..2b9e5e6 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -33,8 +33,8 @@
class SkPDFStream;
class SkPDFDeviceFactory : public SkDeviceFactory {
- virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width, int height,
- bool isOpaque, bool isForLayer);
+ virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
+ int height, bool isOpaque, bool isForLayer);
};
/** \class SkPDFDevice
@@ -43,24 +43,22 @@
*/
class SkPDFDevice : public SkDevice {
public:
- /** Skia generally uses the top left as the origin and PDFs natively use
- the bottom left. We can move the origin to the top left in the PDF
- with a transform, but we have to be careful to apply the transform
- only once.
- */
- enum OriginTransform {
- kFlip_OriginTransform,
- kNoFlip_OriginTransform,
- };
-
/** Create a PDF drawing context with the given width and height.
* 72 points/in means letter paper is 612x792.
* @param width Page width in points.
* @param height Page height in points.
- * @param flipOrigin Flip the origin from lower left to upper left.
+ * @param initialTransform The initial transform to apply to the page.
+ * This may be useful to, for example, move the origin in and
+ * over a bit to account for a margin, scale the canvas,
+ * or apply a rotation. Note1: the SkPDFDevice also applies
+ * a scale+translate transform to move the origin from the
+ * bottom left (PDF default) to the top left. Note2: drawDevice
+ * (used by layer restore) draws the device after this initial
+ * transform is applied, so the PDF device factory does an
+ * inverse scale+translate to accommodate the one that SkPDFDevice
+ * always does.
*/
- SkPDFDevice(int width, int height,
- OriginTransform flipOrigin = kFlip_OriginTransform);
+ SkPDFDevice(int width, int height, const SkMatrix& initialTransform);
virtual ~SkPDFDevice();
virtual SkDeviceFactory* getDeviceFactory() {
@@ -141,7 +139,7 @@
private:
int fWidth;
int fHeight;
- OriginTransform fFlipOrigin;
+ SkMatrix fInitialTransform;
SkRefPtr<SkPDFDict> fResourceDict;
SkTDArray<SkPDFGraphicState*> fGraphicStateResources;