diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 23:17:32 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 23:17:32 +0000 |
commit | 732b813ab60ebaad3cd2a60e19154e2c29b5a144 (patch) | |
tree | 9ed80f722ccf2e478ec771614193e88f9126e419 /printing | |
parent | 66122f44aec56f163aed88a673f062f035619bc2 (diff) | |
download | chromium_src-732b813ab60ebaad3cd2a60e19154e2c29b5a144.zip chromium_src-732b813ab60ebaad3cd2a60e19154e2c29b5a144.tar.gz chromium_src-732b813ab60ebaad3cd2a60e19154e2c29b5a144.tar.bz2 |
PrintPreview: Honor the print media page size and margin values.
BUG=104210, 100819
TEST=Added PrintWebViewHelperPreviewTests.
Review URL: http://codereview.chromium.org/8585017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/pdf_metafile_cg_mac.cc | 12 | ||||
-rw-r--r-- | printing/printed_document.cc | 12 | ||||
-rw-r--r-- | printing/printed_document.h | 3 | ||||
-rw-r--r-- | printing/printed_document_win.cc | 2 | ||||
-rw-r--r-- | printing/printed_page.cc | 6 | ||||
-rw-r--r-- | printing/printed_page.h | 7 | ||||
-rw-r--r-- | printing/printed_page_unittest.cc | 16 |
7 files changed, 30 insertions, 28 deletions
diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc index 78c1110..bf2f68d 100644 --- a/printing/pdf_metafile_cg_mac.cc +++ b/printing/pdf_metafile_cg_mac.cc @@ -202,20 +202,16 @@ bool PdfMetafileCg::RenderPage(unsigned int page_number, } } // Some PDFs have a non-zero origin. Need to take that into account. - float x_offset = rect.origin.x - (source_rect.origin.x * scaling_factor); - float y_offset = rect.origin.y - (source_rect.origin.y * scaling_factor); + float x_offset = -1 * source_rect.origin.x * scaling_factor; + float y_offset = -1 * source_rect.origin.y * scaling_factor; - if (center_vertically) { + if (center_horizontally) { x_offset += (rect.size.width - (source_rect.size.width * scaling_factor))/2; } - if (center_horizontally) { + if (center_vertically) { y_offset += (rect.size.height - (source_rect.size.height * scaling_factor))/2; - } else { - // Since 0 y begins at the bottom, we need to adjust so the output appears - // nearer the top if we are not centering horizontally. - y_offset += rect.size.height - (source_rect.size.height * scaling_factor); } CGContextSaveGState(context); CGContextTranslateCTM(context, x_offset, y_offset); diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 77771c4..c4f2254 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -74,7 +74,8 @@ void PrintedDocument::SetPage(int page_number, new PrintedPage(page_number + 1, metafile, paper_size, - page_rect)); + page_rect, + shrink)); { base::AutoLock lock(lock_); mutable_.pages_[page_number] = page; @@ -83,12 +84,6 @@ void PrintedDocument::SetPage(int page_number, if (page_number < mutable_.first_page) mutable_.first_page = page_number; #endif - - if (mutable_.shrink_factor == 0) { - mutable_.shrink_factor = shrink; - } else { - DCHECK_EQ(mutable_.shrink_factor, shrink); - } } DebugDump(*page); } @@ -208,8 +203,7 @@ const FilePath& PrintedDocument::debug_dump_path() { PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) : source_(source), expected_page_count_(0), - page_count_(0), - shrink_factor(0) { + page_count_(0) { #if defined(OS_POSIX) && !defined(OS_MACOSX) first_page = INT_MAX; #endif diff --git a/printing/printed_document.h b/printing/printed_document.h index 3e3217a..3a61541 100644 --- a/printing/printed_document.h +++ b/printing/printed_document.h @@ -127,9 +127,6 @@ class PRINTING_EXPORT PrintedDocument // The total number of pages in the document. int page_count_; - // Shrink done in comparison to desired_dpi. - double shrink_factor; - #if defined(OS_POSIX) && !defined(OS_MACOSX) // Page number of the first page. int first_page; diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index 2d1a117..3926793 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -67,7 +67,7 @@ void PrintedDocument::RenderPrintedPage( context, content_area.x() - page_setup.printable_area().x(), content_area.y() - page_setup.printable_area().y(), - mutable_.shrink_factor); + page.shrink_factor()); if (!page.metafile()->SafePlayback(context)) { NOTREACHED(); diff --git a/printing/printed_page.cc b/printing/printed_page.cc index 7701dbd2..af7b738 100644 --- a/printing/printed_page.cc +++ b/printing/printed_page.cc @@ -9,11 +9,13 @@ namespace printing { PrintedPage::PrintedPage(int page_number, Metafile* metafile, const gfx::Size& page_size, - const gfx::Rect& page_content_rect) + const gfx::Rect& page_content_rect, + double shrink_factor) : page_number_(page_number), metafile_(metafile), page_size_(page_size), - page_content_rect_(page_content_rect) { + page_content_rect_(page_content_rect), + shrink_factor_(shrink_factor) { } PrintedPage::~PrintedPage() { diff --git a/printing/printed_page.h b/printing/printed_page.h index 28bf191..40e96e0 100644 --- a/printing/printed_page.h +++ b/printing/printed_page.h @@ -25,13 +25,15 @@ class PRINTING_EXPORT PrintedPage PrintedPage(int page_number, Metafile* metafile, const gfx::Size& page_size, - const gfx::Rect& page_content_rect); + const gfx::Rect& page_content_rect, + double shrink_factor); // Getters int page_number() const { return page_number_; } const Metafile* metafile() const; const gfx::Size& page_size() const { return page_size_; } const gfx::Rect& page_content_rect() const { return page_content_rect_; } + double shrink_factor() const { return shrink_factor_; } // Get page content rect adjusted based on // http://dev.w3.org/csswg/css3-page/#positioning-page-box @@ -56,6 +58,9 @@ class PRINTING_EXPORT PrintedPage // The printable area of the page. const gfx::Rect page_content_rect_; + // Shrink done in comparison to desired_dpi. + double shrink_factor_; + DISALLOW_COPY_AND_ASSIGN(PrintedPage); }; diff --git a/printing/printed_page_unittest.cc b/printing/printed_page_unittest.cc index 1a33d10..9cce52a 100644 --- a/printing/printed_page_unittest.cc +++ b/printing/printed_page_unittest.cc @@ -15,45 +15,53 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) { page = new PrintedPage(1, NULL, gfx::Size(1200, 1200), - gfx::Rect(0, 0, 400, 1100)); + gfx::Rect(0, 0, 400, 1100), + 0.2f); page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); EXPECT_EQ(0, page_content.x()); EXPECT_EQ(0, page_content.y()); EXPECT_EQ(400, page_content.width()); EXPECT_EQ(1100, page_content.height()); + EXPECT_EQ(0.2f, page->shrink_factor()); // X centered. page = new PrintedPage(1, NULL, gfx::Size(500, 1200), - gfx::Rect(0, 0, 400, 1100)); + gfx::Rect(0, 0, 400, 1100), + 0.8f); page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); EXPECT_EQ(250, page_content.x()); EXPECT_EQ(0, page_content.y()); EXPECT_EQ(400, page_content.width()); EXPECT_EQ(1100, page_content.height()); + EXPECT_EQ(0.8f, page->shrink_factor()); // Y centered. page = new PrintedPage(1, NULL, gfx::Size(1200, 500), - gfx::Rect(0, 0, 400, 1100)); + gfx::Rect(0, 0, 400, 1100), + 1.0f); page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); EXPECT_EQ(0, page_content.x()); EXPECT_EQ(250, page_content.y()); EXPECT_EQ(400, page_content.width()); EXPECT_EQ(1100, page_content.height()); + EXPECT_EQ(1.0f, page->shrink_factor()); // Both X and Y centered. page = new PrintedPage(1, NULL, gfx::Size(500, 500), - gfx::Rect(0, 0, 400, 1100)); + gfx::Rect(0, 0, 400, 1100), + 0.3f); page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); EXPECT_EQ(250, page_content.x()); EXPECT_EQ(250, page_content.y()); EXPECT_EQ(400, page_content.width()); EXPECT_EQ(1100, page_content.height()); + EXPECT_EQ(0.3f, page->shrink_factor()); } } // namespace printing |