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/backend/cups_helper.h" | 5 #include "printing/backend/cups_helper.h" |
6 | 6 |
7 #include <cups/ppd.h> | 7 #include <cups/ppd.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 const char kColorDevice[] = "ColorDevice"; | 26 const char kColorDevice[] = "ColorDevice"; |
27 const char kColorModel[] = "ColorModel"; | 27 const char kColorModel[] = "ColorModel"; |
28 const char kColorMode[] = "ColorMode"; | 28 const char kColorMode[] = "ColorMode"; |
29 const char kProcessColorModel[] = "ProcessColorModel"; | 29 const char kProcessColorModel[] = "ProcessColorModel"; |
30 const char kPrintoutMode[] = "PrintoutMode"; | 30 const char kPrintoutMode[] = "PrintoutMode"; |
31 const char kDraftGray[] = "Draft.Gray"; | 31 const char kDraftGray[] = "Draft.Gray"; |
32 const char kHighGray[] = "High.Gray"; | 32 const char kHighGray[] = "High.Gray"; |
33 | 33 |
34 const char kDuplex[] = "Duplex"; | 34 const char kDuplex[] = "Duplex"; |
35 const char kDuplexNone[] = "None"; | 35 const char kDuplexNone[] = "None"; |
36 const char kPageSize[] = "PageSize"; | |
37 | |
38 const double kMicronsInPoint = 352.777778; | |
Vitaly Buka (NO REVIEWS)
2014/06/12 19:32:51
kHundrethsMMPerInch / kPointsPerInch * 10
Aleksey Shlyapnikov
2014/06/12 21:21:12
Done.
| |
36 | 39 |
37 #if !defined(OS_MACOSX) | 40 #if !defined(OS_MACOSX) |
38 void ParseLpOptions(const base::FilePath& filepath, | 41 void ParseLpOptions(const base::FilePath& filepath, |
39 const std::string& printer_name, | 42 const std::string& printer_name, |
40 int* num_options, cups_option_t** options) { | 43 int* num_options, cups_option_t** options) { |
41 std::string content; | 44 std::string content; |
42 if (!base::ReadFileToString(filepath, &content)) | 45 if (!base::ReadFileToString(filepath, &content)) |
43 return; | 46 return; |
44 | 47 |
45 const char kDest[] = "dest"; | 48 const char kDest[] = "dest"; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 VLOG(1) << "Unknown printer color model"; | 393 VLOG(1) << "Unknown printer color model"; |
391 } | 394 } |
392 | 395 |
393 caps.color_changeable = ((cm_color != UNKNOWN_COLOR_MODEL) && | 396 caps.color_changeable = ((cm_color != UNKNOWN_COLOR_MODEL) && |
394 (cm_black != UNKNOWN_COLOR_MODEL) && | 397 (cm_black != UNKNOWN_COLOR_MODEL) && |
395 (cm_color != cm_black)); | 398 (cm_color != cm_black)); |
396 caps.color_default = is_color; | 399 caps.color_default = is_color; |
397 caps.color_model = cm_color; | 400 caps.color_model = cm_color; |
398 caps.bw_model = cm_black; | 401 caps.bw_model = cm_black; |
399 | 402 |
403 if (ppd->num_sizes > 0 && ppd->sizes) { | |
404 VLOG(1) << "Paper list size - " << ppd->num_sizes; | |
405 ppd_option_t* paper_option = ppdFindOption(ppd, kPageSize); | |
406 for (int i = 0; i < ppd->num_sizes; ++i) { | |
407 gfx::Size paper_size_microns( | |
408 static_cast<int>(ppd->sizes[i].width * kMicronsInPoint + 0.5), | |
Vitaly Buka (NO REVIEWS)
2014/06/12 19:32:51
std::lrint ?
Aleksey Shlyapnikov
2014/06/12 21:21:12
I'd prefer predictable rounding behavior.
| |
409 static_cast<int>(ppd->sizes[i].length * kMicronsInPoint + 0.5)); | |
410 if (paper_size_microns.width() > 0 && paper_size_microns.height() > 0) { | |
Vitaly Buka (NO REVIEWS)
2014/06/12 19:32:51
should we report continuous paper?
Aleksey Shlyapnikov
2014/06/12 21:21:12
And what print preview is supposed to do about it?
| |
411 PrinterSemanticCapsAndDefaults::Paper paper; | |
412 paper.size_um = paper_size_microns; | |
413 paper.vendor_id = ppd->sizes[i].name; | |
414 if (paper_option) { | |
415 ppd_choice_t* paper_choice = | |
416 ppdFindChoice(paper_option, ppd->sizes[i].name); | |
417 // Human readable paper name should be UTF-8 encoded, but some PPDs | |
418 // do not follow this standard. | |
419 if (paper_choice && base::IsStringUTF8(paper_choice->text)) { | |
420 paper.display_name = paper_choice->text; | |
421 } | |
422 } | |
423 caps.papers.push_back(paper); | |
424 if (i == 0 || ppd->sizes[i].marked) { | |
425 caps.default_paper = paper; | |
426 } | |
427 } | |
428 } | |
429 } | |
430 | |
400 ppdClose(ppd); | 431 ppdClose(ppd); |
401 base::DeleteFile(ppd_file_path, false); | 432 base::DeleteFile(ppd_file_path, false); |
402 | 433 |
403 *printer_info = caps; | 434 *printer_info = caps; |
404 return true; | 435 return true; |
405 } | 436 } |
406 | 437 |
407 } // namespace printing | 438 } // namespace printing |
OLD | NEW |