OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/emf_win.h" | 5 #include "printing/emf_win.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 return 1; // Continue enumeration | 89 return 1; // Continue enumeration |
90 } | 90 } |
91 | 91 |
92 // Bitmapt for rasterization. | 92 // Bitmapt for rasterization. |
93 class RasterBitmap { | 93 class RasterBitmap { |
94 public: | 94 public: |
95 explicit RasterBitmap(const gfx::Size& raster_size) | 95 explicit RasterBitmap(const gfx::Size& raster_size) |
96 : saved_object_(NULL) { | 96 : saved_object_(NULL) { |
97 context_.Set(::CreateCompatibleDC(NULL)); | 97 context_.Set(::CreateCompatibleDC(NULL)); |
98 if (!context_) { | 98 if (!context_.IsValid()) { |
99 NOTREACHED() << "Bitmap DC creation failed"; | 99 NOTREACHED() << "Bitmap DC creation failed"; |
100 return; | 100 return; |
101 } | 101 } |
102 ::SetGraphicsMode(context_, GM_ADVANCED); | 102 ::SetGraphicsMode(context_.Get(), GM_ADVANCED); |
103 void* bits = NULL; | 103 void* bits = NULL; |
104 gfx::Rect bitmap_rect(raster_size); | 104 gfx::Rect bitmap_rect(raster_size); |
105 gfx::CreateBitmapHeader(raster_size.width(), raster_size.height(), | 105 gfx::CreateBitmapHeader(raster_size.width(), raster_size.height(), |
106 &header_.bmiHeader); | 106 &header_.bmiHeader); |
107 bitmap_.Set(::CreateDIBSection(context_, &header_, DIB_RGB_COLORS, &bits, | 107 bitmap_.Set(::CreateDIBSection(context_.Get(), &header_, DIB_RGB_COLORS, |
108 NULL, 0)); | 108 &bits, NULL, 0)); |
109 if (!bitmap_) | 109 if (!bitmap_) |
110 NOTREACHED() << "Raster bitmap creation for printing failed"; | 110 NOTREACHED() << "Raster bitmap creation for printing failed"; |
111 | 111 |
112 saved_object_ = ::SelectObject(context_, bitmap_); | 112 saved_object_ = ::SelectObject(context_.Get(), bitmap_); |
113 RECT rect = bitmap_rect.ToRECT(); | 113 RECT rect = bitmap_rect.ToRECT(); |
114 ::FillRect(context_, &rect, | 114 ::FillRect(context_.Get(), &rect, |
115 static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH))); | 115 static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH))); |
116 | 116 |
117 } | 117 } |
118 | 118 |
119 ~RasterBitmap() { | 119 ~RasterBitmap() { |
120 ::SelectObject(context_, saved_object_); | 120 ::SelectObject(context_.Get(), saved_object_); |
121 } | 121 } |
122 | 122 |
123 HDC context() const { | 123 HDC context() const { |
124 return context_; | 124 return context_.Get(); |
125 } | 125 } |
126 | 126 |
127 base::win::ScopedCreateDC context_; | 127 base::win::ScopedCreateDC context_; |
128 BITMAPINFO header_; | 128 BITMAPINFO header_; |
129 base::win::ScopedBitmap bitmap_; | 129 base::win::ScopedBitmap bitmap_; |
130 HGDIOBJ saved_object_; | 130 HGDIOBJ saved_object_; |
131 | 131 |
132 private: | 132 private: |
133 DISALLOW_COPY_AND_ASSIGN(RasterBitmap); | 133 DISALLOW_COPY_AND_ASSIGN(RasterBitmap); |
134 }; | 134 }; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 RECT rect = page_bounds.ToRECT(); | 590 RECT rect = page_bounds.ToRECT(); |
591 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); | 591 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); |
592 | 592 |
593 result->FinishDocument(); | 593 result->FinishDocument(); |
594 | 594 |
595 return result.Pass(); | 595 return result.Pass(); |
596 } | 596 } |
597 | 597 |
598 | 598 |
599 } // namespace printing | 599 } // namespace printing |
OLD | NEW |