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

Side by Side Diff: printing/backend/print_backend_win.cc

Issue 333993003: Add paper size support for printing to local printer on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mon 06/16/2014 11:56:53.27 Created 6 years, 6 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
« no previous file with comments | « chrome/service/cloud_print/cdd_conversion_win.cc ('k') | printing/printing_context_win.cc » ('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 (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/backend/print_backend.h" 5 #include "printing/backend/print_backend.h"
6 6
7 #include <objidl.h> 7 #include <objidl.h>
8 #include <winspool.h> 8 #include <winspool.h>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_bstr.h" 15 #include "base/win/scoped_bstr.h"
15 #include "base/win/scoped_comptr.h" 16 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_hglobal.h" 17 #include "base/win/scoped_hglobal.h"
17 #include "printing/backend/print_backend_consts.h" 18 #include "printing/backend/print_backend_consts.h"
18 #include "printing/backend/printing_info_win.h" 19 #include "printing/backend/printing_info_win.h"
19 #include "printing/backend/win_helper.h" 20 #include "printing/backend/win_helper.h"
20 21
21 namespace printing { 22 namespace printing {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 for (size_t i = 0; i < sizes.size(); ++i) { 89 for (size_t i = 0; i < sizes.size(); ++i) {
89 PrinterSemanticCapsAndDefaults::Paper paper; 90 PrinterSemanticCapsAndDefaults::Paper paper;
90 paper.size_um.SetSize(sizes[i].x * kToUm, sizes[i].y * kToUm); 91 paper.size_um.SetSize(sizes[i].x * kToUm, sizes[i].y * kToUm);
91 if (!names.empty()) { 92 if (!names.empty()) {
92 const wchar_t* name_start = names[i].chars; 93 const wchar_t* name_start = names[i].chars;
93 base::string16 tmp_name(name_start, kMaxPaperName); 94 base::string16 tmp_name(name_start, kMaxPaperName);
94 // Trim trailing zeros. 95 // Trim trailing zeros.
95 tmp_name = tmp_name.c_str(); 96 tmp_name = tmp_name.c_str();
96 paper.display_name = base::WideToUTF8(tmp_name); 97 paper.display_name = base::WideToUTF8(tmp_name);
97 } 98 }
99 if (!ids.empty())
100 paper.vendor_id = base::UintToString(ids[i]);
98 caps->papers.push_back(paper); 101 caps->papers.push_back(paper);
99 } 102 }
100 103
101 if (devmode) { 104 if (devmode) {
102 short default_id = 0; 105 // Copy paper with the same ID as default paper.
106 if (devmode->dmFields & DM_PAPERSIZE) {
107 for (size_t i = 0; i < ids.size(); ++i) {
108 if (ids[i] == devmode->dmPaperSize) {
109 DCHECK_EQ(ids.size(), caps->papers.size());
110 caps->default_paper = caps->papers[i];
111 break;
112 }
113 }
114 }
115
103 gfx::Size default_size; 116 gfx::Size default_size;
104
105 if (devmode->dmFields & DM_PAPERSIZE)
106 default_id = devmode->dmPaperSize;
107 if (devmode->dmFields & DM_PAPERWIDTH) 117 if (devmode->dmFields & DM_PAPERWIDTH)
108 default_size.set_width(devmode->dmPaperWidth * kToUm); 118 default_size.set_width(devmode->dmPaperWidth * kToUm);
109 if (devmode->dmFields & DM_PAPERLENGTH) 119 if (devmode->dmFields & DM_PAPERLENGTH)
110 default_size.set_height(devmode->dmPaperLength * kToUm); 120 default_size.set_height(devmode->dmPaperLength * kToUm);
111 121
112 if (default_size.IsEmpty()) { 122 if (!default_size.IsEmpty()) {
113 for (size_t i = 0; i < ids.size(); ++i) { 123 // Reset default paper if |dmPaperWidth| or |dmPaperLength| does not
114 if (ids[i] == default_id) { 124 // match default paper set by.
115 PrinterSemanticCapsAndDefaults::Paper paper; 125 if (default_size != caps->default_paper.size_um)
116 paper.size_um.SetSize(sizes[i].x * kToUm, sizes[i].y * kToUm); 126 caps->default_paper = PrinterSemanticCapsAndDefaults::Paper();
117 if (!names.empty()) {
118 const wchar_t* name_start = names[i].chars;
119 base::string16 tmp_name(name_start, kMaxPaperName);
120 // Trim trailing zeros.
121 tmp_name = tmp_name.c_str();
122 paper.display_name = base::WideToUTF8(tmp_name);
123 }
124 caps->default_paper = paper;
125 break;
126 }
127 }
128 } else {
129 caps->default_paper.size_um = default_size; 127 caps->default_paper.size_um = default_size;
130 } 128 }
131 } 129 }
132 } 130 }
133 131
134 void LoadDpi(const wchar_t* printer, 132 void LoadDpi(const wchar_t* printer,
135 const wchar_t* port, 133 const wchar_t* port,
136 const DEVMODE* devmode, 134 const DEVMODE* devmode,
137 PrinterSemanticCapsAndDefaults* caps) { 135 PrinterSemanticCapsAndDefaults* caps) {
138 std::vector<POINT> dpis; 136 std::vector<POINT> dpis;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 ScopedPrinterHandle printer_handle; 361 ScopedPrinterHandle printer_handle;
364 return printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str()); 362 return printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str());
365 } 363 }
366 364
367 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( 365 scoped_refptr<PrintBackend> PrintBackend::CreateInstance(
368 const base::DictionaryValue* print_backend_settings) { 366 const base::DictionaryValue* print_backend_settings) {
369 return new PrintBackendWin; 367 return new PrintBackendWin;
370 } 368 }
371 369
372 } // namespace printing 370 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cdd_conversion_win.cc ('k') | printing/printing_context_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698