summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 07:45:16 +0000
committerhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 07:45:16 +0000
commit5a0700785783202483cfee429fd2e11e6cd8d93e (patch)
tree8f55328fc85c11ebc7ede42255fcf210ece8cc83 /printing
parent19b818418f6e629f740a46429bdd4e940368bfb2 (diff)
downloadchromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.zip
chromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.tar.gz
chromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.tar.bz2
Implement limited paged media support for linux.
BUG=47277 TEST=none Review URL: http://codereview.chromium.org/2847025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/pdf_ps_metafile_cairo.cc30
-rw-r--r--printing/pdf_ps_metafile_cairo.h15
-rw-r--r--printing/pdf_ps_metafile_cairo_unittest.cc8
3 files changed, 32 insertions, 21 deletions
diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc
index 96b72c5..a4b10b2 100644
--- a/printing/pdf_ps_metafile_cairo.cc
+++ b/printing/pdf_ps_metafile_cairo.cc
@@ -98,11 +98,6 @@ bool PdfPsMetafile::Init() {
return false;
}
- // Don't let WebKit draw over the margins.
- cairo_surface_set_device_offset(surface_,
- static_cast<int>(kLeftMargin),
- static_cast<int>(kTopMargin));
-
// Cairo always returns a valid pointer.
// Hence, we have to check if it points to a "nil" object.
if (!IsSurfaceValid(surface_)) {
@@ -139,7 +134,11 @@ bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) {
}
cairo_t* PdfPsMetafile::StartPage(double width_in_points,
- double height_in_points) {
+ double height_in_points,
+ double margin_top_in_points,
+ double margin_right_in_points,
+ double margin_bottom_in_points,
+ double margin_left_in_points) {
DCHECK(IsSurfaceValid(surface_));
DCHECK(IsContextValid(context_));
// Passing this check implies page_surface_ is NULL, and current_page_ is
@@ -149,8 +148,15 @@ cairo_t* PdfPsMetafile::StartPage(double width_in_points,
// We build in extra room for the margins. The Cairo PDF backend will scale
// the output to fit a page.
- double width = width_in_points + kLeftMargin + kRightMargin;
- double height = height_in_points + kTopMargin + kBottomMargin;
+ double width =
+ width_in_points + margin_left_in_points + margin_right_in_points;
+ double height =
+ height_in_points + margin_top_in_points + margin_bottom_in_points;
+
+ // Don't let WebKit draw over the margins.
+ cairo_surface_set_device_offset(surface_,
+ margin_left_in_points,
+ margin_top_in_points);
switch (format_) {
case PDF:
@@ -243,9 +249,9 @@ void PdfPsMetafile::CleanUpAll() {
skia::VectorPlatformDevice::ClearFontCache();
}
-const double PdfPsMetafile::kTopMargin = 0.25 * printing::kPointsPerInch;
-const double PdfPsMetafile::kBottomMargin = 0.56 * printing::kPointsPerInch;
-const double PdfPsMetafile::kLeftMargin = 0.25 * printing::kPointsPerInch;
-const double PdfPsMetafile::kRightMargin = 0.25 * printing::kPointsPerInch;
+const double PdfPsMetafile::kTopMarginInInch = 0.25;
+const double PdfPsMetafile::kBottomMarginInInch = 0.56;
+const double PdfPsMetafile::kLeftMarginInInch = 0.25;
+const double PdfPsMetafile::kRightMarginInInch = 0.25;
} // namespace printing
diff --git a/printing/pdf_ps_metafile_cairo.h b/printing/pdf_ps_metafile_cairo.h
index 8027188..24b5d36 100644
--- a/printing/pdf_ps_metafile_cairo.h
+++ b/printing/pdf_ps_metafile_cairo.h
@@ -53,7 +53,12 @@ class PdfPsMetafile {
// Prepares a new cairo surface/context for rendering a new page.
// The unit is in point (=1/72 in).
// Returns NULL when failed.
- cairo_t* StartPage(double width, double height);
+ cairo_t* StartPage(double width_in_points,
+ double height_in_points,
+ double margin_top_in_points,
+ double margin_right_in_points,
+ double margin_bottom_in_points,
+ double margin_left_in_points);
// Destroys the surface and the context used in rendering current page.
// The results of current page will be appended into buffer |data_|.
@@ -79,10 +84,10 @@ class PdfPsMetafile {
// The hardcoded margins, in points. These values are based on 72 dpi,
// with 0.25 margins on top, left, and right, and 0.56 on bottom.
- static const double kTopMargin;
- static const double kRightMargin;
- static const double kBottomMargin;
- static const double kLeftMargin;
+ static const double kTopMarginInInch;
+ static const double kRightMarginInInch;
+ static const double kBottomMarginInInch;
+ static const double kLeftMarginInInch;
private:
// Cleans up all resources.
diff --git a/printing/pdf_ps_metafile_cairo_unittest.cc b/printing/pdf_ps_metafile_cairo_unittest.cc
index 6fcc170..e1b84d0 100644
--- a/printing/pdf_ps_metafile_cairo_unittest.cc
+++ b/printing/pdf_ps_metafile_cairo_unittest.cc
@@ -27,13 +27,13 @@ TEST_F(PdfPsTest, Pdf) {
EXPECT_TRUE(pdf.Init());
// Renders page 1.
- cairo_t* context = pdf.StartPage(72, 72);
+ cairo_t* context = pdf.StartPage(72, 72, 1, 2, 3, 4);
EXPECT_TRUE(context != NULL);
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(pdf.FinishPage());
// Renders page 2.
- context = pdf.StartPage(64, 64);
+ context = pdf.StartPage(64, 64, 1, 2, 3, 4);
EXPECT_TRUE(context != NULL);
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(pdf.FinishPage());
@@ -71,13 +71,13 @@ TEST_F(PdfPsTest, Ps) {
EXPECT_TRUE(ps.Init());
// Renders page 1.
- cairo_t* context = ps.StartPage(72, 72);
+ cairo_t* context = ps.StartPage(72, 72, 1, 2, 3, 4);
EXPECT_TRUE(context != NULL);
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(ps.FinishPage());
// Renders page 2.
- context = ps.StartPage(64, 64);
+ context = ps.StartPage(64, 64, 1, 2, 3, 4);
EXPECT_TRUE(context != NULL);
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(ps.FinishPage());