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"
16 void SimpleModifyWorldTransform(HDC context
,
19 float shrink_factor
) {
21 xform
.eDx
= static_cast<float>(offset_x
);
22 xform
.eDy
= static_cast<float>(offset_y
);
23 xform
.eM11
= xform
.eM22
= 1.f
/ shrink_factor
;
24 BOOL res
= ModifyWorldTransform(context
, &xform
, MWT_LEFTMULTIPLY
);
32 void PrintedDocument::RenderPrintedPage(
33 const PrintedPage
& page
, gfx::NativeDrawingContext context
) const {
36 // Make sure the page is from our list.
37 base::AutoLock
lock(lock_
);
38 DCHECK(&page
== mutable_
.pages_
.find(page
.page_number() - 1)->second
.get());
44 const PageSetup
& page_setup(immutable_
.settings_
.page_setup_device_units());
45 gfx::Rect content_area
;
46 page
.GetCenteredPageContentRect(page_setup
.physical_size(), &content_area
);
48 // Save the state to make sure the context this function call does not modify
49 // the device context.
50 int saved_state
= SaveDC(context
);
51 DCHECK_NE(saved_state
, 0);
52 skia::InitializeDC(context
);
54 // Save the state (again) to apply the necessary world transformation.
55 int saved_state
= SaveDC(context
);
56 DCHECK_NE(saved_state
, 0);
58 // Setup the matrix to translate and scale to the right place. Take in
59 // account the actual shrinking factor.
60 // Note that the printing output is relative to printable area of the page.
61 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page.
62 SimpleModifyWorldTransform(
64 content_area
.x() - page_setup
.printable_area().x(),
65 content_area
.y() - page_setup
.printable_area().y(),
66 page
.shrink_factor());
69 if (!page
.metafile()->SafePlayback(context
)) {
74 BOOL res
= RestoreDC(context
, saved_state
);
78 int res
= RestoreDC(context
, saved_state
);
82 } // namespace printing