summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_view_manager_base.cc10
-rw-r--r--chrome/common/print_messages.h2
-rw-r--r--chrome/renderer/printing/print_web_view_helper.h1
-rw-r--r--chrome/renderer/printing/print_web_view_helper_pdf_win.cc37
-rw-r--r--printing/printed_document.cc11
-rw-r--r--printing/printed_document.h9
-rw-r--r--printing/printed_page.cc9
-rw-r--r--printing/printed_page.h16
-rw-r--r--printing/printed_page_unittest.cc44
9 files changed, 65 insertions, 74 deletions
diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
index 42ab491..a26af75 100644
--- a/chrome/browser/printing/print_view_manager_base.cc
+++ b/chrome/browser/printing/print_view_manager_base.cc
@@ -220,10 +220,12 @@ void PrintViewManagerBase::OnDidPrintPage(
#if !defined(WIN_PDF_METAFILE_FOR_PRINTING)
// Update the rendered document. It will send notifications to the listener.
document->SetPage(params.page_number,
- metafile.release(),
- params.actual_shrink,
- params.page_size,
- params.content_area);
+ metafile.release(),
+#if defined(OS_WIN)
+ params.actual_shrink,
+#endif // OS_WIN
+ params.page_size,
+ params.content_area);
ShouldQuitFromInnerMessageLoop();
#else
diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h
index cf91871..cfeb66d 100644
--- a/chrome/common/print_messages.h
+++ b/chrome/common/print_messages.h
@@ -253,8 +253,10 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params)
// Page number.
IPC_STRUCT_MEMBER(int, page_number)
+#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
// Shrink factor used to render this page.
IPC_STRUCT_MEMBER(double, actual_shrink)
+#endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING
// The size of the page the page author specified.
IPC_STRUCT_MEMBER(gfx::Size, page_size)
diff --git a/chrome/renderer/printing/print_web_view_helper.h b/chrome/renderer/printing/print_web_view_helper.h
index f5fb10e..0e83eb9 100644
--- a/chrome/renderer/printing/print_web_view_helper.h
+++ b/chrome/renderer/printing/print_web_view_helper.h
@@ -212,7 +212,6 @@ class PrintWebViewHelper
blink::WebFrame* frame,
Metafile* metafile,
bool is_preview,
- double* actual_shrink,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi);
#else
diff --git a/chrome/renderer/printing/print_web_view_helper_pdf_win.cc b/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
index 5d365ea..4d11bf0 100644
--- a/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
+++ b/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
@@ -37,14 +37,11 @@ bool PrintWebViewHelper::RenderPreviewPage(
}
base::TimeTicks begin_time = base::TimeTicks::Now();
- double actual_shrink =
- static_cast<float>(print_params.desired_dpi / print_params.dpi);
PrintPageInternal(page_params,
print_preview_context_.GetPrintCanvasSize(),
print_preview_context_.prepared_frame(),
initial_render_metafile,
true,
- &actual_shrink,
NULL,
NULL);
print_preview_context_.RenderedPreviewPage(
@@ -105,7 +102,6 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
frame,
&metafile,
false,
- &shrink[i],
&page_size_in_dpi[i],
&content_area_in_dpi[i]);
}
@@ -152,7 +148,6 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
for (size_t i = 0; i < printed_pages.size(); ++i) {
printed_page_params.page_number = printed_pages[i];
- printed_page_params.actual_shrink = shrink[i];
printed_page_params.page_size = page_size_in_dpi[i];
printed_page_params.content_area = content_area_in_dpi[i];
Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params));
@@ -167,7 +162,6 @@ void PrintWebViewHelper::PrintPageInternal(
WebFrame* frame,
Metafile* metafile,
bool is_preview,
- double* actual_shrink,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi) {
PageSizeMargins page_layout_in_points;
@@ -231,11 +225,13 @@ void PrintWebViewHelper::PrintPageInternal(
if (params.params.display_header_footer) {
// |page_number| is 0-based, so 1 is added.
- PrintHeaderAndFooter(canvas.get(), params.page_number + 1,
- print_preview_context_.total_page_count(),
- scale_factor,
- page_layout_in_points, *header_footer_info_,
- params.params);
+ PrintHeaderAndFooter(canvas.get(),
+ params.page_number + 1,
+ print_preview_context_.total_page_count(),
+ scale_factor,
+ page_layout_in_points,
+ *header_footer_info_,
+ params.params);
}
float webkit_scale_factor = RenderPageContent(frame,
@@ -244,24 +240,7 @@ void PrintWebViewHelper::PrintPageInternal(
content_area,
scale_factor,
canvas.get());
-
- if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
- NOTREACHED() << "Printing page " << params.page_number << " failed.";
- } else {
- // While rendering certain plugins (PDF) to metafile, we might need to
- // set custom scale factor. Update |actual_shrink| with custom scale
- // if it is set on canvas.
- // TODO(gene): We should revisit this solution for the next versions.
- // Consider creating metafile of the right size (or resizable)
- // https://code.google.com/p/chromium/issues/detail?id=126037
- if (!MetafileSkiaWrapper::GetCustomScaleOnCanvas(
- *canvas, actual_shrink)) {
- // Update the dpi adjustment with the "page |actual_shrink|" calculated in
- // webkit.
- *actual_shrink /= (webkit_scale_factor * css_scale_factor);
- }
- }
-
+ DCHECK_GT(webkit_scale_factor, 0.0f);
// Done printing. Close the device context to retrieve the compiled metafile.
if (!metafile->FinishPage())
NOTREACHED() << "metafile failed";
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index 7c2392d..77e3953 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -65,17 +65,18 @@ PrintedDocument::~PrintedDocument() {
void PrintedDocument::SetPage(int page_number,
Metafile* metafile,
+#if defined(OS_WIN)
double shrink,
+#endif // OS_WIN
const gfx::Size& paper_size,
const gfx::Rect& page_rect) {
// Notice the page_number + 1, the reason is that this is the value that will
// be shown. Users dislike 0-based counting.
scoped_refptr<PrintedPage> page(
- new PrintedPage(page_number + 1,
- metafile,
- paper_size,
- page_rect,
- shrink));
+ new PrintedPage(page_number + 1, metafile, paper_size, page_rect));
+#if defined(OS_WIN)
+ page->set_shrink_factor(shrink);
+#endif // OS_WIN
{
base::AutoLock lock(lock_);
mutable_.pages_[page_number] = page;
diff --git a/printing/printed_document.h b/printing/printed_document.h
index b8af4bb..3341d54 100644
--- a/printing/printed_document.h
+++ b/printing/printed_document.h
@@ -42,8 +42,13 @@ class PRINTING_EXPORT PrintedDocument
// Sets a page's data. 0-based. Takes metafile ownership.
// Note: locks for a short amount of time.
- void SetPage(int page_number, Metafile* metafile, double shrink,
- const gfx::Size& paper_size, const gfx::Rect& page_rect);
+ void SetPage(int page_number,
+ Metafile* metafile,
+#if defined(OS_WIN)
+ double shrink,
+#endif // OS_WIN
+ const gfx::Size& paper_size,
+ const gfx::Rect& page_rect);
// Retrieves a page. If the page is not available right now, it
// requests to have this page be rendered and returns false.
diff --git a/printing/printed_page.cc b/printing/printed_page.cc
index af7b738..19b9fd3 100644
--- a/printing/printed_page.cc
+++ b/printing/printed_page.cc
@@ -9,13 +9,14 @@ namespace printing {
PrintedPage::PrintedPage(int page_number,
Metafile* metafile,
const gfx::Size& page_size,
- const gfx::Rect& page_content_rect,
- double shrink_factor)
+ const gfx::Rect& page_content_rect)
: page_number_(page_number),
metafile_(metafile),
+#if defined(OS_WIN)
+ shrink_factor_(0.0f),
+#endif // OS_WIN
page_size_(page_size),
- page_content_rect_(page_content_rect),
- shrink_factor_(shrink_factor) {
+ page_content_rect_(page_content_rect) {
}
PrintedPage::~PrintedPage() {
diff --git a/printing/printed_page.h b/printing/printed_page.h
index 40e96e0..a1adfa4 100644
--- a/printing/printed_page.h
+++ b/printing/printed_page.h
@@ -25,15 +25,19 @@ class PRINTING_EXPORT PrintedPage
PrintedPage(int page_number,
Metafile* metafile,
const gfx::Size& page_size,
- const gfx::Rect& page_content_rect,
- double shrink_factor);
+ const gfx::Rect& page_content_rect);
// 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_; }
+#if defined(OS_WIN)
+ void set_shrink_factor(double shrink_factor) {
+ shrink_factor_ = shrink_factor;
+ }
double shrink_factor() const { return shrink_factor_; }
+#endif // OS_WIN
// Get page content rect adjusted based on
// http://dev.w3.org/csswg/css3-page/#positioning-page-box
@@ -51,6 +55,11 @@ class PRINTING_EXPORT PrintedPage
// Actual paint data.
const scoped_ptr<Metafile> metafile_;
+#if defined(OS_WIN)
+ // Shrink done in comparison to desired_dpi.
+ double shrink_factor_;
+#endif // OS_WIN
+
// The physical page size. To support multiple page formats inside on print
// job.
const gfx::Size page_size_;
@@ -58,9 +67,6 @@ 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 9cce52a..d37d93a 100644
--- a/printing/printed_page_unittest.cc
+++ b/printing/printed_page_unittest.cc
@@ -12,56 +12,52 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
gfx::Rect page_content;
// No centering.
- page = new PrintedPage(1,
- NULL,
- gfx::Size(1200, 1200),
- gfx::Rect(0, 0, 400, 1100),
- 0.2f);
+ page = new PrintedPage(
+ 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100));
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),
- 0.8f);
+ page = new PrintedPage(
+ 1, NULL, gfx::Size(500, 1200), gfx::Rect(0, 0, 400, 1100));
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),
- 1.0f);
+ page = new PrintedPage(
+ 1, NULL, gfx::Size(1200, 500), gfx::Rect(0, 0, 400, 1100));
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),
- 0.3f);
+ page =
+ new PrintedPage(1, NULL, gfx::Size(500, 500), gfx::Rect(0, 0, 400, 1100));
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());
}
+#if defined(OS_WIN)
+TEST(PrintedPageTest, Shrink) {
+ scoped_refptr<PrintedPage> page = new PrintedPage(
+ 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100));
+ EXPECT_EQ(0.0f, page->shrink_factor());
+ page->set_shrink_factor(0.2f);
+ EXPECT_EQ(0.2f, page->shrink_factor());
+ page->set_shrink_factor(0.7f);
+ EXPECT_EQ(0.7f, page->shrink_factor());
+}
+#endif // OS_WIN
+
} // namespace printing