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 // For quick access. | 7 // For quick access. |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <wingdi.h> | 9 #include <wingdi.h> |
10 #include <winspool.h> | 10 #include <winspool.h> |
(...skipping 29 matching lines...) Expand all Loading... |
40 DeleteDC(hdc); | 40 DeleteDC(hdc); |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 // PrintingContext::Delegate methods. | 44 // PrintingContext::Delegate methods. |
45 gfx::NativeView GetParentView() override { return nullptr; } | 45 gfx::NativeView GetParentView() override { return nullptr; } |
46 std::string GetAppLocale() override { return std::string(); } | 46 std::string GetAppLocale() override { return std::string(); } |
47 }; | 47 }; |
48 | 48 |
49 const uint32_t EMF_HEADER_SIZE = 128; | 49 const uint32_t EMF_HEADER_SIZE = 128; |
50 const int ONE_MB = 1024 * 1024; | |
51 | 50 |
52 } // namespace | 51 } // namespace |
53 | 52 |
54 TEST(EmfTest, DC) { | 53 TEST(EmfTest, DC) { |
55 // Simplest use case. | 54 // Simplest use case. |
56 uint32_t size; | 55 uint32_t size; |
57 std::vector<char> data; | 56 std::vector<char> data; |
58 { | 57 { |
59 Emf emf; | 58 Emf emf; |
60 EXPECT_TRUE(emf.Init()); | 59 EXPECT_TRUE(emf.Init()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Playback the data. | 203 // Playback the data. |
205 HDC hdc = CreateCompatibleDC(nullptr); | 204 HDC hdc = CreateCompatibleDC(nullptr); |
206 EXPECT_TRUE(hdc); | 205 EXPECT_TRUE(hdc); |
207 Emf emf; | 206 Emf emf; |
208 EXPECT_TRUE(emf.InitFromFile(metafile_path)); | 207 EXPECT_TRUE(emf.InitFromFile(metafile_path)); |
209 RECT output_rect = {0, 0, 10, 10}; | 208 RECT output_rect = {0, 0, 10, 10}; |
210 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); | 209 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); |
211 EXPECT_TRUE(DeleteDC(hdc)); | 210 EXPECT_TRUE(DeleteDC(hdc)); |
212 } | 211 } |
213 | 212 |
214 TEST(EmfTest, RasterizeMetafile) { | |
215 Emf emf; | |
216 EXPECT_TRUE(emf.Init()); | |
217 EXPECT_TRUE(emf.context()); | |
218 HBRUSH brush = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); | |
219 for (int i = 0; i < 4; ++i) { | |
220 RECT rect = { 5 + i, 5 + i, 5 + i + 1, 5 + i + 2}; | |
221 FillRect(emf.context(), &rect, brush); | |
222 } | |
223 EXPECT_TRUE(emf.FinishDocument()); | |
224 | |
225 std::unique_ptr<Emf> raster(emf.RasterizeMetafile(1)); | |
226 // Just 1px bitmap but should be stretched to the same bounds. | |
227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | |
228 | |
229 raster = emf.RasterizeMetafile(20); | |
230 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | |
231 | |
232 raster = emf.RasterizeMetafile(16 * ONE_MB); | |
233 // Expected size about 64MB. | |
234 EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB); | |
235 // Bounds should still be the same. | |
236 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | |
237 } | |
238 | |
239 } // namespace printing | 213 } // namespace printing |
OLD | NEW |