| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/mock_printer_driver_win.h" | 5 #include "chrome/renderer/mock_printer_driver_win.h" |
| 6 | 6 |
| 7 #include "base/gfx/gdi_util.h" | 7 #include "base/gfx/gdi_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/common/gfx/emf.h" | 9 #include "printing/emf_win.h" |
| 10 #include "chrome/renderer/mock_printer.h" | 10 #include "chrome/renderer/mock_printer.h" |
| 11 #include "skia/ext/platform_device.h" | 11 #include "skia/ext/platform_device.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // A simple class which temporarily overrides system settings. | 15 // A simple class which temporarily overrides system settings. |
| 16 // The bitmap image rendered via the PlayEnhMetaFile() function depends on | 16 // The bitmap image rendered via the PlayEnhMetaFile() function depends on |
| 17 // some system settings. | 17 // some system settings. |
| 18 // As a workaround for such dependency, this class saves the system settings | 18 // As a workaround for such dependency, this class saves the system settings |
| 19 // and changes them. This class also restore the saved settings in its | 19 // and changes them. This class also restore the saved settings in its |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 if (bitmap_) { | 50 if (bitmap_) { |
| 51 DeleteObject(bitmap_); | 51 DeleteObject(bitmap_); |
| 52 bitmap_ = NULL; | 52 bitmap_ = NULL; |
| 53 } | 53 } |
| 54 if (dc_) { | 54 if (dc_) { |
| 55 DeleteDC(dc_); | 55 DeleteDC(dc_); |
| 56 dc_ = NULL; | 56 dc_ = NULL; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 const void* Create(int width, int height, const gfx::Emf* emf) { | 60 const void* Create(int width, int height, const printing::Emf* emf) { |
| 61 CHECK(!dc_ && !bitmap_); | 61 CHECK(!dc_ && !bitmap_); |
| 62 | 62 |
| 63 BITMAPV4HEADER header; | 63 BITMAPV4HEADER header; |
| 64 gfx::CreateBitmapV4Header(width, height, &header); | 64 gfx::CreateBitmapV4Header(width, height, &header); |
| 65 | 65 |
| 66 dc_ = CreateCompatibleDC(NULL); | 66 dc_ = CreateCompatibleDC(NULL); |
| 67 if (!dc_) | 67 if (!dc_) |
| 68 return NULL; | 68 return NULL; |
| 69 | 69 |
| 70 void* bits; | 70 void* bits; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 MockPrinterDriverWin::MockPrinterDriverWin() { | 91 MockPrinterDriverWin::MockPrinterDriverWin() { |
| 92 } | 92 } |
| 93 | 93 |
| 94 MockPrinterDriverWin::~MockPrinterDriverWin() { | 94 MockPrinterDriverWin::~MockPrinterDriverWin() { |
| 95 } | 95 } |
| 96 | 96 |
| 97 MockPrinterPage* MockPrinterDriverWin::LoadSource(const void* source_data, | 97 MockPrinterPage* MockPrinterDriverWin::LoadSource(const void* source_data, |
| 98 size_t source_size) { | 98 size_t source_size) { |
| 99 // This code is mostly copied from the Image::LoadEMF() function in | 99 // This code is mostly copied from the Image::LoadEMF() function in |
| 100 // "src/chrome/browser/printing/printing_layout_uitest.cc". | 100 // "src/chrome/browser/printing/printing_layout_uitest.cc". |
| 101 gfx::Emf emf; | 101 printing::Emf emf; |
| 102 emf.CreateFromData(source_data, source_size); | 102 emf.CreateFromData(source_data, source_size); |
| 103 gfx::Rect rect(emf.GetBounds()); | 103 gfx::Rect rect(emf.GetBounds()); |
| 104 | 104 |
| 105 // Create a temporary DC and bitmap to retrieve the renderered data. | 105 // Create a temporary DC and bitmap to retrieve the renderered data. |
| 106 if (rect.width() <= 0 || rect.height() <= 0) | 106 if (rect.width() <= 0 || rect.height() <= 0) |
| 107 return NULL; | 107 return NULL; |
| 108 | 108 |
| 109 // Disable the font-smoothing feature of Windows. | 109 // Disable the font-smoothing feature of Windows. |
| 110 SystemSettingsOverride system_settings; | 110 SystemSettingsOverride system_settings; |
| 111 system_settings.Init(FALSE); | 111 system_settings.Init(FALSE); |
| 112 | 112 |
| 113 // Render the EMF data and create a bitmap. | 113 // Render the EMF data and create a bitmap. |
| 114 EmfRenderer renderer; | 114 EmfRenderer renderer; |
| 115 const void* bitmap_data = renderer.Create(rect.width(), rect.height(), &emf); | 115 const void* bitmap_data = renderer.Create(rect.width(), rect.height(), &emf); |
| 116 if (!bitmap_data) | 116 if (!bitmap_data) |
| 117 return NULL; | 117 return NULL; |
| 118 | 118 |
| 119 // Create a new MockPrinterPage instance and return it. | 119 // Create a new MockPrinterPage instance and return it. |
| 120 size_t row_byte_width = rect.width() * 4; | 120 size_t row_byte_width = rect.width() * 4; |
| 121 size_t bitmap_size = row_byte_width * rect.height(); | 121 size_t bitmap_size = row_byte_width * rect.height(); |
| 122 return new MockPrinterPage(rect.width(), rect.height(), | 122 return new MockPrinterPage(rect.width(), rect.height(), |
| 123 source_data, source_size, | 123 source_data, source_size, |
| 124 bitmap_data, bitmap_size); | 124 bitmap_data, bitmap_size); |
| 125 } | 125 } |
| OLD | NEW |