| 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> |
| 11 | 11 |
| 12 #include <memory> |
| 12 #include <string> | 13 #include <string> |
| 13 | 14 |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/win/scoped_hdc.h" | 19 #include "base/win/scoped_hdc.h" |
| 20 #include "printing/printing_context.h" | 20 #include "printing/printing_context.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 23 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
| 24 | 24 |
| 25 namespace printing { | 25 namespace printing { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 TEST_F(EmfPrintingTest, Enumerate) { | 81 TEST_F(EmfPrintingTest, Enumerate) { |
| 82 if (IsTestCaseDisabled()) | 82 if (IsTestCaseDisabled()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 PrintSettings settings; | 85 PrintSettings settings; |
| 86 | 86 |
| 87 // My test case is a HP Color LaserJet 4550 PCL. | 87 // My test case is a HP Color LaserJet 4550 PCL. |
| 88 settings.set_device_name(L"UnitTest Printer"); | 88 settings.set_device_name(L"UnitTest Printer"); |
| 89 | 89 |
| 90 // Initialize it. | 90 // Initialize it. |
| 91 scoped_ptr<PrintingContext> context(PrintingContext::Create(this)); | 91 std::unique_ptr<PrintingContext> context(PrintingContext::Create(this)); |
| 92 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); | 92 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); |
| 93 | 93 |
| 94 base::FilePath emf_file; | 94 base::FilePath emf_file; |
| 95 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); | 95 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); |
| 96 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) | 96 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) |
| 97 .Append(FILE_PATH_LITERAL("test")) | 97 .Append(FILE_PATH_LITERAL("test")) |
| 98 .Append(FILE_PATH_LITERAL("data")) | 98 .Append(FILE_PATH_LITERAL("data")) |
| 99 .Append(FILE_PATH_LITERAL("test4.emf")); | 99 .Append(FILE_PATH_LITERAL("test4.emf")); |
| 100 // Load any EMF with an image. | 100 // Load any EMF with an image. |
| 101 Emf emf; | 101 Emf emf; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 Emf emf; | 211 Emf emf; |
| 212 EXPECT_TRUE(emf.Init()); | 212 EXPECT_TRUE(emf.Init()); |
| 213 EXPECT_TRUE(emf.context() != NULL); | 213 EXPECT_TRUE(emf.context() != NULL); |
| 214 HBRUSH brush = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); | 214 HBRUSH brush = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); |
| 215 for (int i = 0; i < 4; ++i) { | 215 for (int i = 0; i < 4; ++i) { |
| 216 RECT rect = { 5 + i, 5 + i, 5 + i + 1, 5 + i + 2}; | 216 RECT rect = { 5 + i, 5 + i, 5 + i + 1, 5 + i + 2}; |
| 217 FillRect(emf.context(), &rect, brush); | 217 FillRect(emf.context(), &rect, brush); |
| 218 } | 218 } |
| 219 EXPECT_TRUE(emf.FinishDocument()); | 219 EXPECT_TRUE(emf.FinishDocument()); |
| 220 | 220 |
| 221 scoped_ptr<Emf> raster(emf.RasterizeMetafile(1)); | 221 std::unique_ptr<Emf> raster(emf.RasterizeMetafile(1)); |
| 222 // Just 1px bitmap but should be stretched to the same bounds. | 222 // Just 1px bitmap but should be stretched to the same bounds. |
| 223 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 223 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
| 224 | 224 |
| 225 raster = emf.RasterizeMetafile(20); | 225 raster = emf.RasterizeMetafile(20); |
| 226 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 226 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
| 227 | 227 |
| 228 raster = emf.RasterizeMetafile(16 * ONE_MB); | 228 raster = emf.RasterizeMetafile(16 * ONE_MB); |
| 229 // Expected size about 64MB. | 229 // Expected size about 64MB. |
| 230 EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB); | 230 EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB); |
| 231 // Bounds should still be the same. | 231 // Bounds should still be the same. |
| 232 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 232 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace printing | 235 } // namespace printing |
| OLD | NEW |