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 "chrome/utility/utility_thread.h" | 5 #include "chrome/utility/utility_thread.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa
lue.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa
lue.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 #include "webkit/glue/idb_bindings.h" | 26 #include "webkit/glue/idb_bindings.h" |
27 #include "webkit/glue/image_decoder.h" | 27 #include "webkit/glue/image_decoder.h" |
28 | 28 |
29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
30 #include "app/win/iat_patch_function.h" | 30 #include "app/win/iat_patch_function.h" |
31 #include "base/scoped_ptr.h" | 31 #include "base/scoped_ptr.h" |
32 #include "base/win/scoped_handle.h" | 32 #include "base/win/scoped_handle.h" |
33 #include "printing/native_metafile_factory.h" | 33 #include "printing/emf_win.h" |
34 #include "printing/native_metafile.h" | |
35 #endif | 34 #endif |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 template<typename SRC, typename DEST> | 38 template<typename SRC, typename DEST> |
40 void ConvertVector(const SRC& src, DEST* dest) { | 39 void ConvertVector(const SRC& src, DEST* dest) { |
41 dest->reserve(src.size()); | 40 dest->reserve(src.size()); |
42 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) | 41 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) |
43 dest->push_back(typename DEST::value_type(*i)); | 42 dest->push_back(typename DEST::value_type(*i)); |
44 } | 43 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 buffer.resize(length); | 249 buffer.resize(length); |
251 DWORD bytes_read = 0; | 250 DWORD bytes_read = 0; |
252 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || | 251 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || |
253 (bytes_read != length)) | 252 (bytes_read != length)) |
254 return false; | 253 return false; |
255 | 254 |
256 int total_page_count = 0; | 255 int total_page_count = 0; |
257 if (!get_info_proc(&buffer.front(), buffer.size(), &total_page_count, NULL)) | 256 if (!get_info_proc(&buffer.front(), buffer.size(), &total_page_count, NULL)) |
258 return false; | 257 return false; |
259 | 258 |
260 scoped_ptr<printing::NativeMetafile> metafile( | 259 printing::Emf metafile; |
261 printing::NativeMetafileFactory::CreateMetafile()); | 260 metafile.Init(metafile_path); |
262 metafile->CreateFileBackedDc(NULL, NULL, metafile_path); | |
263 // Since we created the metafile using the screen DPI (but we actually want | 261 // Since we created the metafile using the screen DPI (but we actually want |
264 // the PDF DLL to print using the passed in render_dpi, we apply the following | 262 // the PDF DLL to print using the passed in render_dpi, we apply the following |
265 // transformation. | 263 // transformation. |
266 SetGraphicsMode(metafile->context(), GM_ADVANCED); | 264 SetGraphicsMode(metafile.context(), GM_ADVANCED); |
267 XFORM xform = {0}; | 265 XFORM xform = {0}; |
268 int screen_dpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSX); | 266 int screen_dpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSX); |
269 xform.eM11 = xform.eM22 = | 267 xform.eM11 = xform.eM22 = |
270 static_cast<float>(screen_dpi) / static_cast<float>(render_dpi); | 268 static_cast<float>(screen_dpi) / static_cast<float>(render_dpi); |
271 ModifyWorldTransform(metafile->context(), &xform, MWT_LEFTMULTIPLY); | 269 ModifyWorldTransform(metafile.context(), &xform, MWT_LEFTMULTIPLY); |
272 | 270 |
273 bool ret = false; | 271 bool ret = false; |
274 std::vector<printing::PageRange>::const_iterator iter; | 272 std::vector<printing::PageRange>::const_iterator iter; |
275 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { | 273 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { |
276 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { | 274 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { |
277 if (page_number >= total_page_count) | 275 if (page_number >= total_page_count) |
278 break; | 276 break; |
279 metafile->StartPage(); | 277 metafile.StartPage(); |
280 if (render_proc(&buffer.front(), buffer.size(), page_number, | 278 if (render_proc(&buffer.front(), buffer.size(), page_number, |
281 metafile->context(), render_dpi, render_dpi, | 279 metafile.context(), render_dpi, render_dpi, |
282 render_area.x(), render_area.y(), render_area.width(), | 280 render_area.x(), render_area.y(), render_area.width(), |
283 render_area.height(), true, false, true, true)) | 281 render_area.height(), true, false, true, true)) |
284 if (*highest_rendered_page_number < page_number) | 282 if (*highest_rendered_page_number < page_number) |
285 *highest_rendered_page_number = page_number; | 283 *highest_rendered_page_number = page_number; |
286 ret = true; | 284 ret = true; |
287 metafile->FinishPage(); | 285 metafile.FinishPage(); |
288 } | 286 } |
289 } | 287 } |
290 metafile->Close(); | 288 metafile.Close(); |
291 return ret; | 289 return ret; |
292 } | 290 } |
293 #endif // defined(OS_WIN) | 291 #endif // defined(OS_WIN) |
294 | 292 |
295 void UtilityThread::OnIDBKeysFromValuesAndKeyPath( | 293 void UtilityThread::OnIDBKeysFromValuesAndKeyPath( |
296 int id, | 294 int id, |
297 const std::vector<SerializedScriptValue>& serialized_script_values, | 295 const std::vector<SerializedScriptValue>& serialized_script_values, |
298 const string16& idb_key_path) { | 296 const string16& idb_key_path) { |
299 std::vector<WebKit::WebSerializedScriptValue> web_values; | 297 std::vector<WebKit::WebSerializedScriptValue> web_values; |
300 ConvertVector(serialized_script_values, &web_values); | 298 ConvertVector(serialized_script_values, &web_values); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } else { | 337 } else { |
340 Send(new UtilityHostMsg_GetPrinterCapsAndDefaults_Failed(printer_name)); | 338 Send(new UtilityHostMsg_GetPrinterCapsAndDefaults_Failed(printer_name)); |
341 } | 339 } |
342 ReleaseProcessIfNeeded(); | 340 ReleaseProcessIfNeeded(); |
343 } | 341 } |
344 | 342 |
345 void UtilityThread::ReleaseProcessIfNeeded() { | 343 void UtilityThread::ReleaseProcessIfNeeded() { |
346 if (!batch_mode_) | 344 if (!batch_mode_) |
347 ChildProcess::current()->ReleaseProcess(); | 345 ChildProcess::current()->ReleaseProcess(); |
348 } | 346 } |
OLD | NEW |