Fix auto-uninstall of legacy multi-install Chrome Frame.
[chromium-blink-merge.git] / printing / printed_document_win.cc
blob392679384c52875081e6e29bfd50768cc8994c70
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printed_document.h"
7 #include "base/logging.h"
8 #include "printing/page_number.h"
9 #include "printing/printed_pages_source.h"
10 #include "printing/printed_page.h"
11 #include "printing/units.h"
12 #include "skia/ext/platform_device.h"
14 namespace {
16 void SimpleModifyWorldTransform(HDC context,
17 int offset_x,
18 int offset_y,
19 double shrink_factor) {
20 XFORM xform = { 0 };
21 xform.eDx = static_cast<float>(offset_x);
22 xform.eDy = static_cast<float>(offset_y);
23 xform.eM11 = xform.eM22 = static_cast<float>(1. / shrink_factor);
24 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY);
25 DCHECK_NE(res, 0);
28 void DrawRect(HDC context, gfx::Rect rect) {
29 Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom());
32 } // namespace
34 namespace printing {
36 void PrintedDocument::RenderPrintedPage(
37 const PrintedPage& page, gfx::NativeDrawingContext context) const {
38 #ifndef NDEBUG
40 // Make sure the page is from our list.
41 base::AutoLock lock(lock_);
42 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
44 #endif
46 DCHECK(context);
48 const PageSetup& page_setup(immutable_.settings_.page_setup_device_units());
49 gfx::Rect content_area;
50 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area);
52 // Save the state to make sure the context this function call does not modify
53 // the device context.
54 int saved_state = SaveDC(context);
55 DCHECK_NE(saved_state, 0);
56 skia::InitializeDC(context);
58 // Save the state (again) to apply the necessary world transformation.
59 int saved_state = SaveDC(context);
60 DCHECK_NE(saved_state, 0);
62 // Setup the matrix to translate and scale to the right place. Take in
63 // account the actual shrinking factor.
64 // Note that the printing output is relative to printable area of the page.
65 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page.
66 SimpleModifyWorldTransform(
67 context,
68 content_area.x() - page_setup.printable_area().x(),
69 content_area.y() - page_setup.printable_area().y(),
70 page.shrink_factor());
72 if (!page.metafile()->SafePlayback(context)) {
73 NOTREACHED();
76 BOOL res = RestoreDC(context, saved_state);
77 DCHECK_NE(res, 0);
80 int res = RestoreDC(context, saved_state);
81 DCHECK_NE(res, 0);
84 } // namespace printing