| 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/printing_context_win.h" | 5 #include "printing/printing_context_win.h" |
| 6 | 6 |
| 7 #include <winspool.h> | 7 #include <winspool.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "printing/backend/print_backend.h" | 16 #include "printing/backend/print_backend.h" |
| 16 #include "printing/backend/printing_info_win.h" | 17 #include "printing/backend/printing_info_win.h" |
| 17 #include "printing/backend/win_helper.h" | 18 #include "printing/backend/win_helper.h" |
| 18 #include "printing/print_job_constants.h" | 19 #include "printing/print_job_constants.h" |
| 19 #include "printing/print_settings_initializer_win.h" | 20 #include "printing/print_settings_initializer_win.h" |
| 20 #include "printing/printed_document.h" | 21 #include "printing/printed_document.h" |
| 21 #include "printing/printing_utils.h" | 22 #include "printing/printing_utils.h" |
| 22 #include "printing/units.h" | 23 #include "printing/units.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 dev_mode->dmFields |= DM_DUPLEX; | 337 dev_mode->dmFields |= DM_DUPLEX; |
| 337 dev_mode->dmDuplex = DMDUP_SIMPLEX; | 338 dev_mode->dmDuplex = DMDUP_SIMPLEX; |
| 338 break; | 339 break; |
| 339 default: // UNKNOWN_DUPLEX_MODE | 340 default: // UNKNOWN_DUPLEX_MODE |
| 340 break; | 341 break; |
| 341 } | 342 } |
| 342 | 343 |
| 343 dev_mode->dmFields |= DM_ORIENTATION; | 344 dev_mode->dmFields |= DM_ORIENTATION; |
| 344 dev_mode->dmOrientation = settings_.landscape() ? DMORIENT_LANDSCAPE : | 345 dev_mode->dmOrientation = settings_.landscape() ? DMORIENT_LANDSCAPE : |
| 345 DMORIENT_PORTRAIT; | 346 DMORIENT_PORTRAIT; |
| 347 |
| 348 const PrintSettings::RequestedMedia& requested_media = |
| 349 settings_.requested_media(); |
| 350 static const int kFromUm = 100; // Windows uses 0.1mm. |
| 351 int width = requested_media.size_microns.width() / kFromUm; |
| 352 int height = requested_media.size_microns.height() / kFromUm; |
| 353 uint32 id = 0; |
| 354 if (base::HexStringToUInt(requested_media.vendor_id, &id) && id) { |
| 355 dev_mode->dmFields |= DM_PAPERSIZE; |
| 356 dev_mode->dmPaperSize = static_cast<short>(id); |
| 357 } else if (width > 0 && height > 0) { |
| 358 dev_mode->dmFields |= DM_PAPERWIDTH; |
| 359 dev_mode->dmPaperWidth = width; |
| 360 dev_mode->dmFields |= DM_PAPERLENGTH; |
| 361 dev_mode->dmPaperLength = height; |
| 362 } |
| 346 } | 363 } |
| 347 | 364 |
| 348 // Update data using DocumentProperties. | 365 // Update data using DocumentProperties. |
| 349 scoped_dev_mode = CreateDevMode(printer, scoped_dev_mode.get()); | 366 scoped_dev_mode = CreateDevMode(printer, scoped_dev_mode.get()); |
| 350 if (!scoped_dev_mode) | 367 if (!scoped_dev_mode) |
| 351 return OnError(); | 368 return OnError(); |
| 352 | 369 |
| 353 // Set printer then refresh printer settings. | 370 // Set printer then refresh printer settings. |
| 354 if (!AllocateContext(settings_.device_name(), scoped_dev_mode.get(), | 371 if (!AllocateContext(settings_.device_name(), scoped_dev_mode.get(), |
| 355 &context_)) { | 372 &context_)) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 712 |
| 696 if (dialog_options.hDevMode != NULL) | 713 if (dialog_options.hDevMode != NULL) |
| 697 GlobalFree(dialog_options.hDevMode); | 714 GlobalFree(dialog_options.hDevMode); |
| 698 if (dialog_options.hDevNames != NULL) | 715 if (dialog_options.hDevNames != NULL) |
| 699 GlobalFree(dialog_options.hDevNames); | 716 GlobalFree(dialog_options.hDevNames); |
| 700 | 717 |
| 701 return context_ ? OK : FAILED; | 718 return context_ ? OK : FAILED; |
| 702 } | 719 } |
| 703 | 720 |
| 704 } // namespace printing | 721 } // namespace printing |
| OLD | NEW |