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

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

Issue 641923002: Change PDF scaling factor from double to float. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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
« no previous file with comments | « chrome/utility/printing_handler.h ('k') | printing/metafile_skia_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/printing_handler.h" 5 #include "chrome/utility/printing_handler.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_native_library.h" 10 #include "base/scoped_native_library.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit); 288 base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit);
289 int page_count = LoadPDF(pdf_file.Pass()); 289 int page_count = LoadPDF(pdf_file.Pass());
290 Send( 290 Send(
291 new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count)); 291 new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count));
292 } 292 }
293 293
294 void PrintingHandler::OnRenderPDFPagesToMetafileGetPage( 294 void PrintingHandler::OnRenderPDFPagesToMetafileGetPage(
295 int page_number, 295 int page_number,
296 IPC::PlatformFileForTransit output_file) { 296 IPC::PlatformFileForTransit output_file) {
297 base::File emf_file = IPC::PlatformFileForTransitToFile(output_file); 297 base::File emf_file = IPC::PlatformFileForTransitToFile(output_file);
298 double scale_factor = 1.0; 298 float scale_factor = 1.0f;
299 bool success = 299 bool success =
300 RenderPdfPageToMetafile(page_number, emf_file.Pass(), &scale_factor); 300 RenderPdfPageToMetafile(page_number, emf_file.Pass(), &scale_factor);
301 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone( 301 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone(
302 success, scale_factor)); 302 success, scale_factor));
303 } 303 }
304 304
305 void PrintingHandler::OnRenderPDFPagesToMetafileStop() { 305 void PrintingHandler::OnRenderPDFPagesToMetafileStop() {
306 ReleaseProcessIfNeeded(); 306 ReleaseProcessIfNeeded();
307 } 307 }
308 308
(...skipping 15 matching lines...) Expand all
324 } 324 }
325 ReleaseProcessIfNeeded(); 325 ReleaseProcessIfNeeded();
326 } 326 }
327 #endif // ENABLE_FULL_PRINTING 327 #endif // ENABLE_FULL_PRINTING
328 328
329 #if defined(OS_WIN) 329 #if defined(OS_WIN)
330 int PrintingHandler::LoadPDF(base::File pdf_file) { 330 int PrintingHandler::LoadPDF(base::File pdf_file) {
331 if (!g_pdf_lib.Get().IsValid()) 331 if (!g_pdf_lib.Get().IsValid())
332 return 0; 332 return 0;
333 333
334 int64 length = pdf_file.GetLength(); 334 int64 length64 = pdf_file.GetLength();
335 if (length < 0) 335 if (length64 < 0 || length64 > std::numeric_limits<int>::max())
Vitaly Buka (NO REVIEWS) 2014/10/09 19:17:51 better length64 <= 0 to avoid call of pdf_data_.da
Peter Kasting 2014/10/09 19:49:35 Done.
336 return 0; 336 return 0;
337 int length = static_cast<int>(length64);
337 338
338 pdf_data_.resize(length); 339 pdf_data_.resize(length);
339 if (length != pdf_file.Read(0, pdf_data_.data(), pdf_data_.size())) 340 if (length != pdf_file.Read(0, pdf_data_.data(), pdf_data_.size()))
340 return 0; 341 return 0;
341 342
342 int total_page_count = 0; 343 int total_page_count = 0;
343 if (!g_pdf_lib.Get().GetPDFDocInfo( 344 if (!g_pdf_lib.Get().GetPDFDocInfo(
344 &pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) { 345 &pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) {
345 return 0; 346 return 0;
346 } 347 }
347 return total_page_count; 348 return total_page_count;
348 } 349 }
349 350
350 bool PrintingHandler::RenderPdfPageToMetafile(int page_number, 351 bool PrintingHandler::RenderPdfPageToMetafile(int page_number,
351 base::File output_file, 352 base::File output_file,
352 double* scale_factor) { 353 float* scale_factor) {
353 printing::Emf metafile; 354 printing::Emf metafile;
354 metafile.Init(); 355 metafile.Init();
355 356
356 // We need to scale down DC to fit an entire page into DC available area. 357 // We need to scale down DC to fit an entire page into DC available area.
357 // Current metafile is based on screen DC and have current screen size. 358 // Current metafile is based on screen DC and have current screen size.
358 // Writing outside of those boundaries will result in the cut-off output. 359 // Writing outside of those boundaries will result in the cut-off output.
359 // On metafiles (this is the case here), scaling down will still record 360 // On metafiles (this is the case here), scaling down will still record
360 // original coordinates and we'll be able to print in full resolution. 361 // original coordinates and we'll be able to print in full resolution.
361 // Before playback we'll need to counter the scaling up that will happen 362 // Before playback we'll need to counter the scaling up that will happen
362 // in the service (print_system_win.cc). 363 // in the service (print_system_win.cc).
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 bool PrintingHandler::RenderPDFPagesToPWGRaster( 399 bool PrintingHandler::RenderPDFPagesToPWGRaster(
399 base::File pdf_file, 400 base::File pdf_file,
400 const printing::PdfRenderSettings& settings, 401 const printing::PdfRenderSettings& settings,
401 const printing::PwgRasterSettings& bitmap_settings, 402 const printing::PwgRasterSettings& bitmap_settings,
402 base::File bitmap_file) { 403 base::File bitmap_file) {
403 bool autoupdate = true; 404 bool autoupdate = true;
404 if (!g_pdf_lib.Get().IsValid()) 405 if (!g_pdf_lib.Get().IsValid())
405 return false; 406 return false;
406 407
407 base::File::Info info; 408 base::File::Info info;
408 if (!pdf_file.GetInfo(&info) || info.size <= 0) 409 if (!pdf_file.GetInfo(&info) || info.size <= 0 ||
410 info.size > std::numeric_limits<int>::max())
409 return false; 411 return false;
412 int data_size = static_cast<int>(info.size);
410 413
411 std::string data(info.size, 0); 414 std::string data(data_size, 0);
412 int data_size = pdf_file.Read(0, &data[0], data.size()); 415 if (pdf_file.Read(0, &data[0], data_size) != data_size)
Vitaly Buka (NO REVIEWS) 2014/10/09 19:17:51 data.data() for consistency?
Peter Kasting 2014/10/09 19:49:35 We can't; data() returns a const char* (it's for r
413 if (data_size != static_cast<int>(data.size()))
414 return false; 416 return false;
415 417
416 int total_page_count = 0; 418 int total_page_count = 0;
417 if (!g_pdf_lib.Get().GetPDFDocInfo(data.data(), data.size(), 419 if (!g_pdf_lib.Get().GetPDFDocInfo(data.data(), data_size,
418 &total_page_count, NULL)) { 420 &total_page_count, NULL)) {
419 return false; 421 return false;
420 } 422 }
421 423
422 cloud_print::PwgEncoder encoder; 424 cloud_print::PwgEncoder encoder;
423 std::string pwg_header; 425 std::string pwg_header;
424 encoder.EncodeDocumentHeader(&pwg_header); 426 encoder.EncodeDocumentHeader(&pwg_header);
425 int bytes_written = bitmap_file.WriteAtCurrentPos(pwg_header.data(), 427 int bytes_written = bitmap_file.WriteAtCurrentPos(pwg_header.data(),
426 pwg_header.size()); 428 pwg_header.size());
427 if (bytes_written != static_cast<int>(pwg_header.size())) 429 if (bytes_written != static_cast<int>(pwg_header.size()))
428 return false; 430 return false;
429 431
430 cloud_print::BitmapImage image(settings.area().size(), 432 cloud_print::BitmapImage image(settings.area().size(),
431 cloud_print::BitmapImage::BGRA); 433 cloud_print::BitmapImage::BGRA);
432 for (int i = 0; i < total_page_count; ++i) { 434 for (int i = 0; i < total_page_count; ++i) {
433 int page_number = i; 435 int page_number = i;
434 436
435 if (bitmap_settings.reverse_page_order) { 437 if (bitmap_settings.reverse_page_order) {
436 page_number = total_page_count - 1 - page_number; 438 page_number = total_page_count - 1 - page_number;
437 } 439 }
438 440
439 if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(), 441 if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(),
440 data.size(), 442 data_size,
Vitaly Buka (NO REVIEWS) 2014/10/09 19:17:50 data.size() is best source of truth regarding size
Peter Kasting 2014/10/09 19:49:35 Using data_size here was intentional: (1) We ensur
441 page_number, 443 page_number,
442 image.pixel_data(), 444 image.pixel_data(),
443 image.size().width(), 445 image.size().width(),
444 image.size().height(), 446 image.size().height(),
445 settings.dpi(), 447 settings.dpi(),
446 settings.dpi(), 448 settings.dpi(),
447 autoupdate)) { 449 autoupdate)) {
448 return false; 450 return false;
449 } 451 }
450 452
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 &printer_info)) { 520 &printer_info)) {
519 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded( 521 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
520 printer_name, printer_info)); 522 printer_name, printer_info));
521 } else { 523 } else {
522 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( 524 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
523 printer_name)); 525 printer_name));
524 } 526 }
525 ReleaseProcessIfNeeded(); 527 ReleaseProcessIfNeeded();
526 } 528 }
527 #endif // ENABLE_FULL_PRINTING 529 #endif // ENABLE_FULL_PRINTING
OLDNEW
« no previous file with comments | « chrome/utility/printing_handler.h ('k') | printing/metafile_skia_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698