Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: printing/printed_document_win.cc

Issue 3474014: Printing: Remove OS_WIN ifdef in a win-only file. Remove an unused debugging (Closed)
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/printed_document.h" 5 #include "printing/printed_document.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "gfx/font.h" 9 #include "gfx/font.h"
10 #include "printing/page_number.h" 10 #include "printing/page_number.h"
11 #include "printing/page_overlays.h" 11 #include "printing/page_overlays.h"
12 #include "printing/printed_pages_source.h" 12 #include "printing/printed_pages_source.h"
13 #include "printing/printed_page.h" 13 #include "printing/printed_page.h"
14 #include "printing/units.h" 14 #include "printing/units.h"
15 #include "skia/ext/platform_device.h" 15 #include "skia/ext/platform_device.h"
16 16
17 #if defined(OS_WIN)
18 namespace { 17 namespace {
19 18
20 void SimpleModifyWorldTransform(HDC context, 19 void SimpleModifyWorldTransform(HDC context,
21 int offset_x, 20 int offset_x,
22 int offset_y, 21 int offset_y,
23 double shrink_factor) { 22 double shrink_factor) {
24 XFORM xform = { 0 }; 23 XFORM xform = { 0 };
25 xform.eDx = static_cast<float>(offset_x); 24 xform.eDx = static_cast<float>(offset_x);
26 xform.eDy = static_cast<float>(offset_y); 25 xform.eDy = static_cast<float>(offset_y);
27 xform.eM11 = xform.eM22 = static_cast<float>(1. / shrink_factor); 26 xform.eM11 = xform.eM22 = static_cast<float>(1. / shrink_factor);
28 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); 27 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY);
29 DCHECK_NE(res, 0); 28 DCHECK_NE(res, 0);
30 } 29 }
31 30
32 void DrawRect(HDC context, gfx::Rect rect) { 31 void DrawRect(HDC context, gfx::Rect rect) {
33 Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom()); 32 Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom());
34 } 33 }
35 34
36 } // namespace 35 } // namespace
37 #endif // OS_WIN
38 36
39 namespace printing { 37 namespace printing {
40 38
41 void PrintedDocument::RenderPrintedPage( 39 void PrintedDocument::RenderPrintedPage(
42 const PrintedPage& page, gfx::NativeDrawingContext context) const { 40 const PrintedPage& page, gfx::NativeDrawingContext context) const {
43 #ifndef NDEBUG 41 #ifndef NDEBUG
44 { 42 {
45 // Make sure the page is from our list. 43 // Make sure the page is from our list.
46 AutoLock lock(lock_); 44 AutoLock lock(lock_);
47 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); 45 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
48 } 46 }
49 #endif 47 #endif
50 48
51 const printing::PageSetup& page_setup( 49 const printing::PageSetup& page_setup(
52 immutable_.settings_.page_setup_device_units()); 50 immutable_.settings_.page_setup_device_units());
53 gfx::Rect content_area; 51 gfx::Rect content_area;
54 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area); 52 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area);
55 53
56 // Save the state to make sure the context this function call does not modify 54 // Save the state to make sure the context this function call does not modify
57 // the device context. 55 // the device context.
58 int saved_state = SaveDC(context); 56 int saved_state = SaveDC(context);
59 DCHECK_NE(saved_state, 0); 57 DCHECK_NE(saved_state, 0);
60 skia::PlatformDevice::InitializeDC(context); 58 skia::PlatformDevice::InitializeDC(context);
61 { 59 {
62 // Save the state (again) to apply the necessary world transformation. 60 // Save the state (again) to apply the necessary world transformation.
63 int saved_state = SaveDC(context); 61 int saved_state = SaveDC(context);
64 DCHECK_NE(saved_state, 0); 62 DCHECK_NE(saved_state, 0);
65 63
66 #if 0
67 // Debug code to visually verify margins (leaks GDI handles).
68 XFORM debug_xform = { 0 };
69 ModifyWorldTransform(context, &debug_xform, MWT_IDENTITY);
70 // Printable area:
71 SelectObject(context, CreatePen(PS_SOLID, 1, RGB(0, 0, 0)));
72 SelectObject(context, CreateSolidBrush(RGB(0x90, 0x90, 0x90)));
73 Rectangle(context,
74 0,
75 0,
76 page_setup.printable_area().width(),
77 page_setup.printable_area().height());
78 // Overlay area:
79 gfx::Rect debug_overlay_area(page_setup.overlay_area());
80 debug_overlay_area.Offset(-page_setup.printable_area().x(),
81 -page_setup.printable_area().y());
82 SelectObject(context, CreateSolidBrush(RGB(0xb0, 0xb0, 0xb0)));
83 DrawRect(context, debug_overlay_area);
84 // Content area:
85 gfx::Rect debug_content_area(content_area());
86 debug_content_area.Offset(-page_setup.printable_area().x(),
87 -page_setup.printable_area().y());
88 SelectObject(context, CreateSolidBrush(RGB(0xd0, 0xd0, 0xd0)));
89 DrawRect(context, debug_content_area);
90 #endif
91
92 // Setup the matrix to translate and scale to the right place. Take in 64 // Setup the matrix to translate and scale to the right place. Take in
93 // account the actual shrinking factor. 65 // account the actual shrinking factor.
94 // Note that the printing output is relative to printable area of the page. 66 // Note that the printing output is relative to printable area of the page.
95 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. 67 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page.
96 SimpleModifyWorldTransform( 68 SimpleModifyWorldTransform(
97 context, 69 context,
98 content_area.x() - page_setup.printable_area().x(), 70 content_area.x() - page_setup.printable_area().x(),
99 content_area.y() - page_setup.printable_area().y(), 71 content_area.y() - page_setup.printable_area().y(),
100 mutable_.shrink_factor); 72 mutable_.shrink_factor);
101 73
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 font); 106 font);
135 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM, 107 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM,
136 font); 108 font);
137 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM, 109 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM,
138 font); 110 font);
139 int res = RestoreDC(context, saved_state); 111 int res = RestoreDC(context, saved_state);
140 DCHECK_NE(res, 0); 112 DCHECK_NE(res, 0);
141 } 113 }
142 114
143 } // namespace printing 115 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698