summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 05:32:38 +0000
committerhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 05:32:38 +0000
commit3c5fb6bed1e6c9ce80276653f4b053583c299d5b (patch)
tree3fff8754dc395584e8d9eab4ec56f0e6f78cc246 /printing
parent638c48f806e23adf510ea2006f66f84f4d43c5de (diff)
downloadchromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.zip
chromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.tar.gz
chromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.tar.bz2
Implement limited paged media support for win.
BUG=47277 TEST=none Review URL: http://codereview.chromium.org/2859040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/page_overlays_unittest.cc2
-rw-r--r--printing/printed_document.cc8
-rw-r--r--printing/printed_document.h3
-rw-r--r--printing/printed_document_win.cc17
-rw-r--r--printing/printed_page.cc6
-rw-r--r--printing/printed_page.h7
6 files changed, 32 insertions, 11 deletions
diff --git a/printing/page_overlays_unittest.cc b/printing/page_overlays_unittest.cc
index 8a19dcd..a7ea283 100644
--- a/printing/page_overlays_unittest.cc
+++ b/printing/page_overlays_unittest.cc
@@ -59,7 +59,7 @@ TEST_F(PageOverlaysTest, StringConversion) {
gfx::Size page_size(100, 100);
gfx::Rect page_content_area(5, 5, 90, 90);
scoped_refptr<printing::PrintedPage> page(
- new printing::PrintedPage(1, NULL, page_size, page_content_area));
+ new printing::PrintedPage(1, NULL, page_size, page_content_area, true));
std::wstring input;
std::wstring out;
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index 333f1d87..ec040d4 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -72,14 +72,16 @@ void PrintedDocument::SetPage(int page_number,
NativeMetafile* metafile,
double shrink,
const gfx::Size& paper_size,
- const gfx::Rect& page_rect) {
+ const gfx::Rect& page_rect,
+ bool has_visible_overlays) {
// 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));
+ page_rect,
+ has_visible_overlays));
{
AutoLock lock(lock_);
mutable_.pages_[page_number] = page;
@@ -184,7 +186,7 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context,
PageOverlays::VerticalPosition y,
const gfx::Font& font) const {
const PrintSettings& settings = immutable_.settings_;
- if (!settings.use_overlays) {
+ if (!settings.use_overlays || !page.has_visible_overlays()) {
return;
}
const std::wstring& line = settings.overlays.GetOverlay(x, y);
diff --git a/printing/printed_document.h b/printing/printed_document.h
index 049add0..752c1c3 100644
--- a/printing/printed_document.h
+++ b/printing/printed_document.h
@@ -43,7 +43,8 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
// Sets a page's data. 0-based. Takes metafile ownership.
// Note: locks for a short amount of time.
void SetPage(int page_number, NativeMetafile* metafile, double shrink,
- const gfx::Size& paper_size, const gfx::Rect& page_rect);
+ const gfx::Size& paper_size, const gfx::Rect& page_rect,
+ bool has_visible_overlays);
// 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_document_win.cc b/printing/printed_document_win.cc
index 42c1b45..e80ac78a 100644
--- a/printing/printed_document_win.cc
+++ b/printing/printed_document_win.cc
@@ -51,6 +51,17 @@ void PrintedDocument::RenderPrintedPage(
const printing::PageSetup& page_setup(
immutable_.settings_.page_setup_device_units());
+ gfx::Rect content_area(page.page_content_rect());
+ const gfx::Size& physical_size = page_setup.physical_size();
+ // http://dev.w3.org/csswg/css3-page/#positioning-page-box
+ if (physical_size.width() > page.page_size().width()) {
+ int diff = physical_size.width() - page.page_size().width();
+ content_area.set_x(content_area.x() + diff / 2);
+ }
+ if (physical_size.height() > page.page_size().height()) {
+ int diff = physical_size.height() - page.page_size().height();
+ content_area.set_y(content_area.y() + diff / 2);
+ }
// Save the state to make sure the context this function call does not modify
// the device context.
@@ -81,7 +92,7 @@ void PrintedDocument::RenderPrintedPage(
SelectObject(context, CreateSolidBrush(RGB(0xb0, 0xb0, 0xb0)));
DrawRect(context, debug_overlay_area);
// Content area:
- gfx::Rect debug_content_area(page_setup.content_area());
+ gfx::Rect debug_content_area(content_area());
debug_content_area.Offset(-page_setup.printable_area().x(),
-page_setup.printable_area().y());
SelectObject(context, CreateSolidBrush(RGB(0xd0, 0xd0, 0xd0)));
@@ -94,8 +105,8 @@ void PrintedDocument::RenderPrintedPage(
// That is 0,0 is offset by PHYSICALOFFSETX/Y from the page.
SimpleModifyWorldTransform(
context,
- page_setup.content_area().x() - page_setup.printable_area().x(),
- page_setup.content_area().y() - page_setup.printable_area().y(),
+ content_area.x() - page_setup.printable_area().x(),
+ content_area.y() - page_setup.printable_area().y(),
mutable_.shrink_factor);
if (!page.native_metafile()->SafePlayback(context)) {
diff --git a/printing/printed_page.cc b/printing/printed_page.cc
index 242adb2..8abedeee 100644
--- a/printing/printed_page.cc
+++ b/printing/printed_page.cc
@@ -9,11 +9,13 @@ namespace printing {
PrintedPage::PrintedPage(int page_number,
NativeMetafile* native_metafile,
const gfx::Size& page_size,
- const gfx::Rect& page_content_rect)
+ const gfx::Rect& page_content_rect,
+ bool has_visible_overlays)
: page_number_(page_number),
native_metafile_(native_metafile),
page_size_(page_size),
- page_content_rect_(page_content_rect) {
+ page_content_rect_(page_content_rect),
+ has_visible_overlays_(has_visible_overlays) {
}
PrintedPage::~PrintedPage() {
diff --git a/printing/printed_page.h b/printing/printed_page.h
index 83425ba..17181c6 100644
--- a/printing/printed_page.h
+++ b/printing/printed_page.h
@@ -24,13 +24,15 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
PrintedPage(int page_number,
NativeMetafile* native_metafile,
const gfx::Size& page_size,
- const gfx::Rect& page_content_rect);
+ const gfx::Rect& page_content_rect,
+ bool has_visible_overlays);
// Getters
int page_number() const { return page_number_; }
const NativeMetafile* native_metafile() const;
const gfx::Size& page_size() const { return page_size_; }
const gfx::Rect& page_content_rect() const { return page_content_rect_; }
+ bool has_visible_overlays() const { return has_visible_overlays_; }
private:
friend class base::RefCountedThreadSafe<PrintedPage>;
@@ -50,6 +52,9 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
// The printable area of the page.
const gfx::Rect page_content_rect_;
+ // True if the overlays should be visible in this page.
+ bool has_visible_overlays_;
+
DISALLOW_COPY_AND_ASSIGN(PrintedPage);
};