OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/image.h" | 5 #include "printing/image.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/win/scoped_gdi_object.h" | 11 #include "base/win/scoped_gdi_object.h" |
12 #include "base/win/scoped_hdc.h" | 12 #include "base/win/scoped_hdc.h" |
13 #include "base/win/scoped_select_object.h" | 13 #include "base/win/scoped_select_object.h" |
14 #include "printing/metafile.h" | 14 #include "printing/emf_win.h" |
15 #include "skia/ext/skia_utils_win.h" | 15 #include "skia/ext/skia_utils_win.h" |
16 #include "ui/gfx/gdi_util.h" // EMF support | 16 #include "ui/gfx/gdi_util.h" // EMF support |
17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
18 | 18 |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // A simple class which temporarily overrides system settings. | 22 // A simple class which temporarily overrides system settings. |
23 // The bitmap image rendered via the PlayEnhMetaFile() function depends on | 23 // The bitmap image rendered via the PlayEnhMetaFile() function depends on |
24 // some system settings. | 24 // some system settings. |
(...skipping 21 matching lines...) Expand all Loading... |
46 private: | 46 private: |
47 bool enable_again_; | 47 bool enable_again_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(DisableFontSmoothing); | 49 DISALLOW_COPY_AND_ASSIGN(DisableFontSmoothing); |
50 }; | 50 }; |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace printing { | 54 namespace printing { |
55 | 55 |
56 bool Image::LoadMetafile(const Metafile& metafile) { | 56 bool Image::LoadMetafile(const void* metafile_src_buffer, |
57 gfx::Rect rect(metafile.GetPageBounds(1)); | 57 size_t metafile_src_buffer_size) { |
| 58 Emf metafile; |
| 59 if (!metafile.InitFromData(metafile_src_buffer, metafile_src_buffer_size)) { |
| 60 return false; |
| 61 } |
| 62 gfx::Rect rect(metafile.GetPageBounds(1)); |
58 DisableFontSmoothing disable_in_this_scope; | 63 DisableFontSmoothing disable_in_this_scope; |
59 | 64 |
60 // Create a temporary HDC and bitmap to retrieve the rendered data. | 65 // Create a temporary HDC and bitmap to retrieve the rendered data. |
61 base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); | 66 base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); |
62 BITMAPV4HEADER hdr; | 67 BITMAPV4HEADER hdr; |
63 DCHECK_EQ(rect.x(), 0); | 68 DCHECK_EQ(rect.x(), 0); |
64 DCHECK_EQ(rect.y(), 0); | 69 DCHECK_EQ(rect.y(), 0); |
65 DCHECK_GE(rect.width(), 0); // Metafile could be empty. | 70 DCHECK_GE(rect.width(), 0); // Metafile could be empty. |
66 DCHECK_GE(rect.height(), 0); | 71 DCHECK_GE(rect.height(), 0); |
67 | 72 |
(...skipping 16 matching lines...) Expand all Loading... |
84 row_length_ = size_.width() * sizeof(uint32_t); | 89 row_length_ = size_.width() * sizeof(uint32_t); |
85 size_t bytes = row_length_ * size_.height(); | 90 size_t bytes = row_length_ * size_.height(); |
86 DCHECK(bytes); | 91 DCHECK(bytes); |
87 | 92 |
88 data_.assign(bits, bits + bytes); | 93 data_.assign(bits, bits + bytes); |
89 | 94 |
90 return success; | 95 return success; |
91 } | 96 } |
92 | 97 |
93 } // namespace printing | 98 } // namespace printing |
OLD | NEW |