Skip to content

Commit

Permalink
Printing: Temporary fix on Linux using dummy print settings until we …
Browse files Browse the repository at this point in the history
…get the entire Linux printing pipeline to match Win/Mac.

BUG=none
TEST=printing works.
Review URL: http://codereview.chromium.org/3619002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61556 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed Oct 5, 2010
1 parent d4a66c9 commit 6d15689
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
34 changes: 1 addition & 33 deletions chrome/renderer/print_web_view_helper_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
#include "printing/native_metafile.h"
#include "printing/units.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
Expand All @@ -18,34 +17,6 @@ using printing::NativeMetafile;
using WebKit::WebFrame;
using WebKit::WebSize;

static void FillDefaultPrintParams(ViewMsg_Print_Params* params) {
// TODO(myhuang): Get printing parameters via IPC
// using the print_web_view_helper.cc version of Print.
// For testing purpose, we hard-coded printing parameters here.

// The paper size is US Letter (8.5 in. by 11 in.).
double page_width_in_pixel = 8.5 * printing::kPixelsPerInch;
double page_height_in_pixel = 11.0 * printing::kPixelsPerInch;
params->page_size = gfx::Size(
static_cast<int>(page_width_in_pixel),
static_cast<int>(page_height_in_pixel));
params->printable_size = gfx::Size(
static_cast<int>(
page_width_in_pixel -
(NativeMetafile::kLeftMarginInInch +
NativeMetafile::kRightMarginInInch) * printing::kPixelsPerInch),
static_cast<int>(
page_height_in_pixel -
(NativeMetafile::kTopMarginInInch +
NativeMetafile::kBottomMarginInInch) * printing::kPixelsPerInch));
params->margin_top = static_cast<int>(
NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch);
params->margin_left = static_cast<int>(
NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch);
params->dpi = printing::kPixelsPerInch;
params->desired_dpi = params->dpi;
}

void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params,
WebFrame* frame) {
PrepareFrameAndViewForPrint prep_frame_view(params.params,
Expand Down Expand Up @@ -104,9 +75,6 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame,
printing::NativeMetafile* metafile) {
ViewMsg_Print_Params default_params;
FillDefaultPrintParams(&default_params);

double content_width_in_points;
double content_height_in_points;
double margin_top_in_points;
Expand All @@ -115,7 +83,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
double margin_left_in_points;
GetPageSizeAndMarginsInPoints(frame,
params.page_number,
default_params,
params.params,
&content_width_in_points,
&content_height_in_points,
&margin_top_in_points,
Expand Down
49 changes: 35 additions & 14 deletions printing/print_settings.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -7,6 +7,8 @@
// TODO(jhawkins): Move platform-specific implementations to their own files.
#if defined(USE_X11)
#include <gtk/gtk.h>
#include <gtk/gtkprinter.h>
#include "printing/native_metafile.h"
#endif // defined(USE_X11)

#include "base/atomic_sequence_num.h"
Expand Down Expand Up @@ -129,7 +131,7 @@ void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format,
printable_area_device_units,
72);
}
#elif defined(OS_LINUX)
#elif defined(USE_X11)
void PrintSettings::Init(GtkPrintSettings* settings,
GtkPageSetup* page_setup,
const PageRanges& new_ranges,
Expand All @@ -140,23 +142,42 @@ void PrintSettings::Init(GtkPrintSettings* settings,
printer_name_ = UTF8ToWide(name);
device_name_ = printer_name_;
ranges = new_ranges;
selection_only = print_selection_only;

GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings);
landscape_ = orientation == GTK_PAGE_ORIENTATION_LANDSCAPE;
selection_only = print_selection_only;

gfx::Size physical_size_device_units;
gfx::Rect printable_area_device_units;
dpi_ = gtk_print_settings_get_resolution(settings);

// Initialize page_setup_device_units_.
gfx::Size physical_size_device_units(
gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_);
gfx::Rect printable_area_device_units(
gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_);

if (dpi_) {
// Initialize page_setup_device_units_.
physical_size_device_units.SetSize(
gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_);
printable_area_device_units.SetRect(
gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_,
gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_);
} else {
// Use dummy values if we cannot get valid values.
// TODO(jhawkins) Remove this hack when the Linux printing refactoring
// finishes.
dpi_ = kPixelsPerInch;
double page_width_in_pixel = 8.5 * dpi_;
double page_height_in_pixel = 11.0 * dpi_;
physical_size_device_units.SetSize(
static_cast<int>(page_width_in_pixel),
static_cast<int>(page_height_in_pixel));
printable_area_device_units.SetRect(
static_cast<int>(
NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch),
static_cast<int>(
NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch),
page_width_in_pixel,
page_height_in_pixel);
}
SetPrinterPrintableArea(physical_size_device_units,
printable_area_device_units,
dpi_);
Expand Down
9 changes: 6 additions & 3 deletions printing/print_settings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -14,10 +14,13 @@
#import <ApplicationServices/ApplicationServices.h>
#endif

#if defined(OS_WIN)
typedef struct HDC__* HDC;
typedef struct _devicemodeW DEVMODE;
#elif defined(USE_X11)
typedef struct _GtkPrintSettings GtkPrintSettings;
typedef struct _GtkPageSetup GtkPageSetup;
#endif

namespace printing {

Expand All @@ -30,7 +33,7 @@ class PrintSettings {
// Reinitialize the settings to the default values.
void Clear();

#ifdef WIN32
#if defined(OS_WIN)
// Reads the settings from the selected device context. Calculates derived
// values like printable_area_.
void Init(HDC hdc,
Expand All @@ -42,7 +45,7 @@ class PrintSettings {
// Reads the settings from the given PMPrinter and PMPageFormat.
void Init(PMPrinter printer, PMPageFormat page_format,
const PageRanges& new_ranges, bool print_selection_only);
#elif defined(OS_LINUX)
#elif defined(USE_X11)
// Initializes the settings from the given GtkPrintSettings and GtkPageSetup.
// TODO(jhawkins): This method is a mess across the platforms. Refactor.
void Init(GtkPrintSettings* settings,
Expand Down

0 comments on commit 6d15689

Please sign in to comment.