Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/utility/utility_thread.cc

Issue 6695013: Cleanup NativeMetafile (win) interface and EMF class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 #include "ui/gfx/point.h" 25 #include "ui/gfx/point.h"
26 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
27 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
28 #include "webkit/glue/idb_bindings.h" 28 #include "webkit/glue/idb_bindings.h"
29 #include "webkit/glue/image_decoder.h" 29 #include "webkit/glue/image_decoder.h"
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 #include "app/win/iat_patch_function.h" 32 #include "app/win/iat_patch_function.h"
33 #include "base/scoped_ptr.h" 33 #include "base/scoped_ptr.h"
34 #include "base/win/scoped_handle.h" 34 #include "base/win/scoped_handle.h"
35 #include "printing/native_metafile_factory.h" 35 #include "printing/emf_win.h"
36 #include "printing/native_metafile.h"
37 #endif 36 #endif
38 37
39 namespace { 38 namespace {
40 39
41 template<typename SRC, typename DEST> 40 template<typename SRC, typename DEST>
42 void ConvertVector(const SRC& src, DEST* dest) { 41 void ConvertVector(const SRC& src, DEST* dest) {
43 dest->reserve(src.size()); 42 dest->reserve(src.size());
44 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) 43 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
45 dest->push_back(typename DEST::value_type(*i)); 44 dest->push_back(typename DEST::value_type(*i));
46 } 45 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 buffer.resize(length); 251 buffer.resize(length);
253 DWORD bytes_read = 0; 252 DWORD bytes_read = 0;
254 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || 253 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) ||
255 (bytes_read != length)) 254 (bytes_read != length))
256 return false; 255 return false;
257 256
258 int total_page_count = 0; 257 int total_page_count = 0;
259 if (!get_info_proc(&buffer.front(), buffer.size(), &total_page_count, NULL)) 258 if (!get_info_proc(&buffer.front(), buffer.size(), &total_page_count, NULL))
260 return false; 259 return false;
261 260
262 scoped_ptr<printing::NativeMetafile> metafile( 261 printing::Emf metafile;
263 printing::NativeMetafileFactory::Create()); 262 metafile.InitToFile(metafile_path);
264 metafile->CreateFileBackedDc(NULL, NULL, metafile_path);
265 // Since we created the metafile using the screen DPI (but we actually want 263 // Since we created the metafile using the screen DPI (but we actually want
266 // the PDF DLL to print using the passed in render_dpi, we apply the following 264 // the PDF DLL to print using the passed in render_dpi, we apply the following
267 // transformation. 265 // transformation.
268 SetGraphicsMode(metafile->context(), GM_ADVANCED); 266 SetGraphicsMode(metafile.context(), GM_ADVANCED);
269 XFORM xform = {0}; 267 XFORM xform = {0};
270 int screen_dpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSX); 268 int screen_dpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSX);
271 xform.eM11 = xform.eM22 = 269 xform.eM11 = xform.eM22 =
272 static_cast<float>(screen_dpi) / static_cast<float>(render_dpi); 270 static_cast<float>(screen_dpi) / static_cast<float>(render_dpi);
273 ModifyWorldTransform(metafile->context(), &xform, MWT_LEFTMULTIPLY); 271 ModifyWorldTransform(metafile.context(), &xform, MWT_LEFTMULTIPLY);
274 272
275 bool ret = false; 273 bool ret = false;
276 std::vector<printing::PageRange>::const_iterator iter; 274 std::vector<printing::PageRange>::const_iterator iter;
277 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { 275 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) {
278 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { 276 for (int page_number = iter->from; page_number <= iter->to; ++page_number) {
279 if (page_number >= total_page_count) 277 if (page_number >= total_page_count)
280 break; 278 break;
281 // The underlying metafile is of type Emf and ignores the arguments passed 279 // The underlying metafile is of type Emf and ignores the arguments passed
282 // to StartPage. 280 // to StartPage.
283 metafile->StartPage(gfx::Size(), gfx::Point(), 1); 281 metafile.StartPage(gfx::Size(), gfx::Point(), 1);
284 if (render_proc(&buffer.front(), buffer.size(), page_number, 282 if (render_proc(&buffer.front(), buffer.size(), page_number,
285 metafile->context(), render_dpi, render_dpi, 283 metafile.context(), render_dpi, render_dpi,
286 render_area.x(), render_area.y(), render_area.width(), 284 render_area.x(), render_area.y(), render_area.width(),
287 render_area.height(), true, false, true, true)) 285 render_area.height(), true, false, true, true))
288 if (*highest_rendered_page_number < page_number) 286 if (*highest_rendered_page_number < page_number)
289 *highest_rendered_page_number = page_number; 287 *highest_rendered_page_number = page_number;
290 ret = true; 288 ret = true;
291 metafile->FinishPage(); 289 metafile.FinishPage();
292 } 290 }
293 } 291 }
294 metafile->FinishDocument(); 292 metafile.FinishDocument();
295 return ret; 293 return ret;
296 } 294 }
297 #endif // defined(OS_WIN) 295 #endif // defined(OS_WIN)
298 296
299 void UtilityThread::OnIDBKeysFromValuesAndKeyPath( 297 void UtilityThread::OnIDBKeysFromValuesAndKeyPath(
300 int id, 298 int id,
301 const std::vector<SerializedScriptValue>& serialized_script_values, 299 const std::vector<SerializedScriptValue>& serialized_script_values,
302 const string16& idb_key_path) { 300 const string16& idb_key_path) {
303 std::vector<WebKit::WebSerializedScriptValue> web_values; 301 std::vector<WebKit::WebSerializedScriptValue> web_values;
304 ConvertVector(serialized_script_values, &web_values); 302 ConvertVector(serialized_script_values, &web_values);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } else { 341 } else {
344 Send(new UtilityHostMsg_GetPrinterCapsAndDefaults_Failed(printer_name)); 342 Send(new UtilityHostMsg_GetPrinterCapsAndDefaults_Failed(printer_name));
345 } 343 }
346 ReleaseProcessIfNeeded(); 344 ReleaseProcessIfNeeded();
347 } 345 }
348 346
349 void UtilityThread::ReleaseProcessIfNeeded() { 347 void UtilityThread::ReleaseProcessIfNeeded() {
350 if (!batch_mode_) 348 if (!batch_mode_)
351 ChildProcess::current()->ReleaseProcess(); 349 ChildProcess::current()->ReleaseProcess();
352 } 350 }
OLDNEW
« no previous file with comments | « chrome/service/service_utility_process_host.cc ('k') | content/plugin/webplugin_delegate_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698