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 <wingdi.h> | 8 #include <wingdi.h> |
9 #include <winspool.h> | 9 #include <winspool.h> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 ASSERT_TRUE(emf_data.size()); | 99 ASSERT_TRUE(emf_data.size()); |
100 EXPECT_TRUE(emf.InitFromData(&emf_data[0], emf_data.size())); | 100 EXPECT_TRUE(emf.InitFromData(&emf_data[0], emf_data.size())); |
101 | 101 |
102 // This will print to file. The reason is that when running inside a | 102 // This will print to file. The reason is that when running inside a |
103 // unit_test, PrintingContext automatically dumps its files to the | 103 // unit_test, PrintingContext automatically dumps its files to the |
104 // current directory. | 104 // current directory. |
105 // TODO(maruel): Clean the .PRN file generated in current directory. | 105 // TODO(maruel): Clean the .PRN file generated in current directory. |
106 context->NewDocument(L"EmfTest.Enumerate"); | 106 context->NewDocument(L"EmfTest.Enumerate"); |
107 context->NewPage(); | 107 context->NewPage(); |
108 // Process one at a time. | 108 // Process one at a time. |
109 Emf::Enumerator emf_enum(emf, context->context(), | 109 RECT page_bounds = emf.GetPageBounds(1).ToRECT(); |
110 &emf.GetPageBounds(1).ToRECT()); | 110 Emf::Enumerator emf_enum(emf, context->context(), &page_bounds); |
111 for (Emf::Enumerator::const_iterator itr = emf_enum.begin(); | 111 for (Emf::Enumerator::const_iterator itr = emf_enum.begin(); |
112 itr != emf_enum.end(); | 112 itr != emf_enum.end(); |
113 ++itr) { | 113 ++itr) { |
114 // To help debugging. | 114 // To help debugging. |
115 ptrdiff_t index = itr - emf_enum.begin(); | 115 ptrdiff_t index = itr - emf_enum.begin(); |
116 // If you get this assert, you need to lookup iType in wingdi.h. It starts | 116 // If you get this assert, you need to lookup iType in wingdi.h. It starts |
117 // with EMR_HEADER. | 117 // with EMR_HEADER. |
118 EMR_HEADER; | 118 EMR_HEADER; |
119 EXPECT_TRUE(itr->SafePlayback(&emf_enum.context_)) << | 119 EXPECT_TRUE(itr->SafePlayback(&emf_enum.context_)) << |
120 " index: " << index << " type: " << itr->record()->iType; | 120 " index: " << index << " type: " << itr->record()->iType; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 di.cbSize = sizeof(DOCINFO); | 154 di.cbSize = sizeof(DOCINFO); |
155 di.lpszDocName = L"Test Job"; | 155 di.lpszDocName = L"Test Job"; |
156 int job_id = ::StartDoc(dc.Get(), &di); | 156 int job_id = ::StartDoc(dc.Get(), &di); |
157 Emf emf; | 157 Emf emf; |
158 EXPECT_TRUE(emf.InitFromData(&data.front(), size)); | 158 EXPECT_TRUE(emf.InitFromData(&data.front(), size)); |
159 EXPECT_TRUE(emf.SafePlayback(dc.Get())); | 159 EXPECT_TRUE(emf.SafePlayback(dc.Get())); |
160 ::EndDoc(dc.Get()); | 160 ::EndDoc(dc.Get()); |
161 // Since presumably the printer is not real, let us just delete the job from | 161 // Since presumably the printer is not real, let us just delete the job from |
162 // the queue. | 162 // the queue. |
163 HANDLE printer = NULL; | 163 HANDLE printer = NULL; |
164 if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) { | 164 if (::OpenPrinter(const_cast<LPTSTR>(L"UnitTest Printer"), &printer, NULL)) { |
165 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); | 165 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); |
166 ClosePrinter(printer); | 166 ClosePrinter(printer); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 TEST(EmfTest, FileBackedEmf) { | 170 TEST(EmfTest, FileBackedEmf) { |
171 // Simplest use case. | 171 // Simplest use case. |
172 base::ScopedTempDir scratch_metafile_dir; | 172 base::ScopedTempDir scratch_metafile_dir; |
173 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); | 173 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); |
174 base::FilePath metafile_path; | 174 base::FilePath metafile_path; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
222 | 222 |
223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); | 223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); |
224 // Expected size about 64MB. | 224 // Expected size about 64MB. |
225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); | 225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); |
226 // Bounds should still be the same. | 226 // Bounds should still be the same. |
227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
228 } | 228 } |
229 | 229 |
230 } // namespace printing | 230 } // namespace printing |
OLD | NEW |