summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
Diffstat (limited to 'printing')
-rw-r--r--printing/emf_win.cc6
-rw-r--r--printing/emf_win.h8
-rw-r--r--printing/emf_win_unittest.cc2
-rw-r--r--printing/metafile.h11
-rw-r--r--printing/pdf_metafile_cairo_linux.cc10
-rw-r--r--printing/pdf_metafile_cairo_linux.h4
-rw-r--r--printing/pdf_metafile_cairo_linux_unittest.cc8
-rw-r--r--printing/pdf_metafile_cg_mac.cc8
-rw-r--r--printing/pdf_metafile_cg_mac.h4
-rw-r--r--printing/pdf_metafile_cg_mac_unittest.cc12
-rw-r--r--printing/pdf_metafile_skia.cc18
-rw-r--r--printing/pdf_metafile_skia.h6
12 files changed, 52 insertions, 45 deletions
diff --git a/printing/emf_win.cc b/printing/emf_win.cc
index 758abc9..40f4dc8 100644
--- a/printing/emf_win.cc
+++ b/printing/emf_win.cc
@@ -404,9 +404,9 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const {
}
skia::PlatformDevice* Emf::StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
- if (!StartPage(page_size, content_origin, scale_factor))
+ if (!StartPage(page_size, content_area, scale_factor))
return NULL;
return skia::VectorPlatformDeviceEmfFactory::CreateDevice(page_size.width(),
@@ -415,7 +415,7 @@ skia::PlatformDevice* Emf::StartPageForVectorCanvas(
}
bool Emf::StartPage(const gfx::Size& /*page_size*/,
- const gfx::Point& /*content_origin*/,
+ const gfx::Rect& /*content_area*/,
const float& /*scale_factor*/) {
DCHECK(hdc_);
if (!hdc_)
diff --git a/printing/emf_win.h b/printing/emf_win.h
index 1df72f4b..02a1958 100644
--- a/printing/emf_win.h
+++ b/printing/emf_win.h
@@ -46,14 +46,14 @@ class Emf : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
virtual skia::PlatformDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
// Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
// (since StartPage and EndPage do not work in a metafile DC). Only valid
- // when hdc_ is non-NULL. |page_size|, |content_origin|, and |scale_factor|
- // are ignored.
+ // when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are
+ // ignored.
virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor);
virtual bool FinishPage();
virtual bool FinishDocument();
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index 3ea1282..d683729 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -136,7 +136,7 @@ TEST_F(EmfPrintingTest, PageBreak) {
EXPECT_TRUE(emf.context() != NULL);
int pages = 3;
while (pages) {
- EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Point(), 1));
+ EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1));
::Rectangle(emf.context(), 10, 10, 190, 190);
EXPECT_TRUE(emf.FinishPage());
--pages;
diff --git a/printing/metafile.h b/printing/metafile.h
index 264c8fe..1142a39 100644
--- a/printing/metafile.h
+++ b/printing/metafile.h
@@ -57,14 +57,15 @@ class Metafile {
// VectorPlatformDevice implementation bound to the context created by
// StartPage or NULL on error.
virtual skia::PlatformDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size,
+ const gfx::Rect& content_area,
const float& scale_factor) = 0;
- // Prepares a context for rendering a new page at the specified
- // |content_origin| with the given |page_size| and a |scale_factor| to use for
- // the drawing. The units are in points (=1/72 in). Returns true on success.
+ // Prepares a context for rendering a new page with the given |page_size|,
+ // |content_area| and a |scale_factor| to use for the drawing. The units are
+ // in points (=1/72 in). Returns true on success.
virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor) = 0;
// Closes the current page and destroys the context used in rendering that
diff --git a/printing/pdf_metafile_cairo_linux.cc b/printing/pdf_metafile_cairo_linux.cc
index 5780574..435a33c 100644
--- a/printing/pdf_metafile_cairo_linux.cc
+++ b/printing/pdf_metafile_cairo_linux.cc
@@ -119,9 +119,9 @@ bool PdfMetafileCairo::InitFromData(const void* src_buffer,
}
skia::PlatformDevice* PdfMetafileCairo::StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
- if (!StartPage(page_size, content_origin, scale_factor))
+ if (!StartPage(page_size, content_area, scale_factor))
return NULL;
return skia::VectorPlatformDeviceCairoFactory::CreateDevice(
@@ -129,7 +129,7 @@ skia::PlatformDevice* PdfMetafileCairo::StartPageForVectorCanvas(
}
bool PdfMetafileCairo::StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK(IsSurfaceValid(surface_));
DCHECK(IsContextValid(context_));
@@ -142,8 +142,8 @@ bool PdfMetafileCairo::StartPage(const gfx::Size& page_size,
// Don't let WebKit draw over the margins.
cairo_surface_set_device_offset(surface_,
- content_origin.x(),
- content_origin.y());
+ content_area.x(),
+ content_area.y());
cairo_pdf_surface_set_size(surface_, page_size.width(), page_size.height());
return context_ != NULL;
diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h
index fe00ff6..8badf5c 100644
--- a/printing/pdf_metafile_cairo_linux.h
+++ b/printing/pdf_metafile_cairo_linux.h
@@ -37,10 +37,10 @@ class PdfMetafileCairo : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
virtual skia::PlatformDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor);
virtual bool FinishPage();
virtual bool FinishDocument();
diff --git a/printing/pdf_metafile_cairo_linux_unittest.cc b/printing/pdf_metafile_cairo_linux_unittest.cc
index c644a3d..0ea08f81 100644
--- a/printing/pdf_metafile_cairo_linux_unittest.cc
+++ b/printing/pdf_metafile_cairo_linux_unittest.cc
@@ -13,8 +13,8 @@
#include "base/file_util.h"
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
-#include "ui/gfx/point.h"
typedef struct _cairo cairo_t;
@@ -32,12 +32,12 @@ TEST_F(PdfMetafileCairoTest, Pdf) {
EXPECT_TRUE(pdf.Init());
// Renders page 1.
- EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Point(4, 5), 1));
+ EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(pdf.FinishPage());
// Renders page 2.
- EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Point(4, 5), 1));
+ EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(pdf.FinishPage());
@@ -70,7 +70,7 @@ TEST_F(PdfMetafileCairoTest, Pdf) {
// Test overriding the metafile with raw data.
printing::PdfMetafileCairo pdf3;
EXPECT_TRUE(pdf3.Init());
- EXPECT_TRUE(pdf3.StartPage(gfx::Size(72, 73), gfx::Point(4, 5), 1));
+ EXPECT_TRUE(pdf3.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
std::string test_raw_data = "Dummy PDF";
EXPECT_TRUE(pdf3.InitFromData(test_raw_data.c_str(), test_raw_data.size()));
EXPECT_TRUE(pdf3.FinishPage());
diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc
index f1b387a..eedd078 100644
--- a/printing/pdf_metafile_cg_mac.cc
+++ b/printing/pdf_metafile_cg_mac.cc
@@ -64,14 +64,14 @@ bool PdfMetafileCg::InitFromData(const void* src_buffer,
}
skia::PlatformDevice* PdfMetafileCg::StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
NOTIMPLEMENTED();
return NULL;
}
bool PdfMetafileCg::StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK(context_.get());
DCHECK(!page_is_open_);
@@ -88,8 +88,8 @@ bool PdfMetafileCg::StartPage(const gfx::Size& page_size,
CGContextTranslateCTM(context_, 0, height);
CGContextScaleCTM(context_, scale_factor, -scale_factor);
- // Move the context to origin.
- CGContextTranslateCTM(context_, content_origin.x(), content_origin.y());
+ // Move to the context origin.
+ CGContextTranslateCTM(context_, content_area.x(), content_area.y());
return context_.get() != NULL;
}
diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h
index 616d448..92157e1 100644
--- a/printing/pdf_metafile_cg_mac.h
+++ b/printing/pdf_metafile_cg_mac.h
@@ -35,10 +35,10 @@ class PdfMetafileCg : public Metafile {
// Not implemented on mac.
virtual skia::PlatformDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor);
virtual bool FinishPage();
virtual bool FinishDocument();
diff --git a/printing/pdf_metafile_cg_mac_unittest.cc b/printing/pdf_metafile_cg_mac_unittest.cc
index 5324514..3948aa9 100644
--- a/printing/pdf_metafile_cg_mac_unittest.cc
+++ b/printing/pdf_metafile_cg_mac_unittest.cc
@@ -20,16 +20,16 @@ TEST(PdfMetafileCgTest, Pdf) {
EXPECT_TRUE(pdf.Init());
EXPECT_TRUE(pdf.context() != NULL);
- // Render page 1 at origin (10.0, 10.0).
- gfx::Point origin_1(10.0f, 10.0f);
+ // Render page 1.
+ gfx::Rect rect_1(10, 10, 520, 700);
gfx::Size size_1(540, 720);
- pdf.StartPage(size_1, origin_1, 1.25);
+ pdf.StartPage(size_1, rect_1, 1.25);
pdf.FinishPage();
- // Render page 2 at origin (10.0, 10.0).
- gfx::Point origin_2(10.0f, 10.0f);
+ // Render page 2.
+ gfx::Rect rect_2(10, 10, 520, 700);
gfx::Size size_2(720, 540);
- pdf.StartPage(size_2, origin_2, 2.0);
+ pdf.StartPage(size_2, rect_2, 2.0);
pdf.FinishPage();
pdf.FinishDocument();
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index 1d2b0798..80d4931 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -37,26 +37,32 @@ bool PdfMetafileSkia::InitFromData(const void* src_buffer,
}
skia::PlatformDevice* PdfMetafileSkia::StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Point& content_origin,
+ const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK(data_->current_page_.get() == NULL);
// Adjust for the margins and apply the scale factor.
SkMatrix transform;
- transform.setTranslate(SkIntToScalar(content_origin.x()),
- SkIntToScalar(content_origin.y()));
+ transform.setTranslate(SkIntToScalar(content_area.x()),
+ SkIntToScalar(content_area.y()));
transform.preScale(SkFloatToScalar(scale_factor),
SkFloatToScalar(scale_factor));
+ // TODO(ctguil): Refactor: don't create the PDF device explicitly here.
+ SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height());
+ SkISize pdf_content_size =
+ SkISize::Make(content_area.width(), content_area.height());
+ SkRefPtr<SkPDFDevice> pdf_device =
+ new SkPDFDevice(pdf_page_size, pdf_content_size, transform);
+ pdf_device->unref(); // SkRefPtr and new both took a reference.
skia::VectorPlatformDeviceSkia* device =
- new skia::VectorPlatformDeviceSkia(page_size.width(), page_size.height(),
- transform);
+ new skia::VectorPlatformDeviceSkia(pdf_device.get());
data_->current_page_ = device->PdfDevice();
return device;
}
bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor) {
NOTREACHED();
return NULL;
diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h
index 515c3a8..3138114 100644
--- a/printing/pdf_metafile_skia.h
+++ b/printing/pdf_metafile_skia.h
@@ -31,10 +31,10 @@ class PdfMetafileSkia : public Metafile {
virtual skia::PlatformDevice* StartPageForVectorCanvas(
const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor);
virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Point& content_origin,
+ const gfx::Rect& content_area,
const float& scale_factor);
virtual bool FinishPage();
virtual bool FinishDocument();
@@ -66,4 +66,4 @@ class PdfMetafileSkia : public Metafile {
} // namespace printing
-#endif // PRINTING_PDF_METAFILE_MAC_H_
+#endif // PRINTING_PDF_METAFILE_SKIA_H_