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

Side by Side Diff: chrome/browser/ui/libgtk2ui/printing_gtk2_util.cc

Issue 2449243002: Gtk3 ui: Add libgtk3ui as a separate build component (Closed)
Patch Set: Add theme_properties dep to //chrome/browser/ui Created 4 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/libgtk2ui/printing_gtk2_util.h"
6
7 #include <gtk/gtk.h>
8 #include <gtk/gtkunixprint.h>
9
10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "printing/print_settings.h"
13 #include "printing/printing_context_linux.h"
14 #include "printing/units.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/geometry/size_f.h"
17
18 namespace {
19
20 const double kTopMarginInInch = 0.25;
21 const double kBottomMarginInInch = 0.56;
22 const double kLeftMarginInInch = 0.25;
23 const double kRightMarginInInch = 0.25;
24
25 } // namespace
26
27 gfx::Size GetPdfPaperSizeDeviceUnitsGtk(
28 printing::PrintingContextLinux* context) {
29 GtkPageSetup* page_setup = gtk_page_setup_new();
30
31 gfx::SizeF paper_size(
32 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH),
33 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH));
34
35 g_object_unref(page_setup);
36
37 const printing::PrintSettings& settings = context->settings();
38
39 return gfx::Size(
40 paper_size.width() * settings.device_units_per_inch(),
41 paper_size.height() * settings.device_units_per_inch());
42 }
43
44 void InitPrintSettingsGtk(GtkPrintSettings* settings,
45 GtkPageSetup* page_setup,
46 printing::PrintSettings* print_settings) {
47 DCHECK(settings);
48 DCHECK(page_setup);
49 DCHECK(print_settings);
50
51 base::string16 name(base::UTF8ToUTF16(static_cast<const char*>(
52 gtk_print_settings_get_printer(settings))));
53 print_settings->set_device_name(name);
54
55 gfx::Size physical_size_device_units;
56 gfx::Rect printable_area_device_units;
57 int dpi = gtk_print_settings_get_resolution(settings);
58 if (dpi) {
59 // Initialize page_setup_device_units_.
60 physical_size_device_units.SetSize(
61 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi,
62 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi);
63 printable_area_device_units.SetRect(
64 gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi,
65 gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi,
66 gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi,
67 gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi);
68 } else {
69 // Use default values if we cannot get valid values from the print dialog.
70 dpi = printing::kPixelsPerInch;
71 double page_width_in_pixel = printing::kLetterWidthInch * dpi;
72 double page_height_in_pixel = printing::kLetterHeightInch * dpi;
73 physical_size_device_units.SetSize(
74 static_cast<int>(page_width_in_pixel),
75 static_cast<int>(page_height_in_pixel));
76 printable_area_device_units.SetRect(
77 static_cast<int>(kLeftMarginInInch * dpi),
78 static_cast<int>(kTopMarginInInch * dpi),
79 page_width_in_pixel - (kLeftMarginInInch + kRightMarginInInch) * dpi,
80 page_height_in_pixel - (kTopMarginInInch + kBottomMarginInInch) * dpi);
81 }
82
83 print_settings->set_dpi(dpi);
84
85 // Note: With the normal GTK print dialog, when the user selects the landscape
86 // orientation, all that does is change the paper size. Which seems to be
87 // enough to render the right output and send it to the printer.
88 // The orientation value stays as portrait and does not actually affect
89 // printing.
90 // Thus this is only useful in print preview mode, where we manually set the
91 // orientation and change the paper size ourselves.
92 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings);
93 // Set before SetPrinterPrintableArea to make it flip area if necessary.
94 print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE);
95 DCHECK_EQ(print_settings->device_units_per_inch(), dpi);
96 print_settings->SetPrinterPrintableArea(physical_size_device_units,
97 printable_area_device_units,
98 true);
99 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/printing_gtk2_util.h ('k') | chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698