| 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/emf_win.h" | 14 #include "printing/metafile.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 void* metafile_src_buffer, | 56 bool Image::LoadMetafile(const Metafile& metafile) { |
| 57 size_t metafile_src_buffer_size) { | 57 gfx::Rect rect(metafile.GetPageBounds(1)); |
| 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)); | |
| 63 DisableFontSmoothing disable_in_this_scope; | 58 DisableFontSmoothing disable_in_this_scope; |
| 64 | 59 |
| 65 // Create a temporary HDC and bitmap to retrieve the rendered data. | 60 // Create a temporary HDC and bitmap to retrieve the rendered data. |
| 66 base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); | 61 base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); |
| 67 BITMAPV4HEADER hdr; | 62 BITMAPV4HEADER hdr; |
| 68 DCHECK_EQ(rect.x(), 0); | 63 DCHECK_EQ(rect.x(), 0); |
| 69 DCHECK_EQ(rect.y(), 0); | 64 DCHECK_EQ(rect.y(), 0); |
| 70 DCHECK_GE(rect.width(), 0); // Metafile could be empty. | 65 DCHECK_GE(rect.width(), 0); // Metafile could be empty. |
| 71 DCHECK_GE(rect.height(), 0); | 66 DCHECK_GE(rect.height(), 0); |
| 72 | 67 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 row_length_ = size_.width() * sizeof(uint32_t); | 84 row_length_ = size_.width() * sizeof(uint32_t); |
| 90 size_t bytes = row_length_ * size_.height(); | 85 size_t bytes = row_length_ * size_.height(); |
| 91 DCHECK(bytes); | 86 DCHECK(bytes); |
| 92 | 87 |
| 93 data_.assign(bits, bits + bytes); | 88 data_.assign(bits, bits + bytes); |
| 94 | 89 |
| 95 return success; | 90 return success; |
| 96 } | 91 } |
| 97 | 92 |
| 98 } // namespace printing | 93 } // namespace printing |
| OLD | NEW |