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

Unified Diff: printing/print_settings_initializer_win.cc

Issue 2392343003: Fix printing with XPS printers on Windows. (Closed)
Patch Set: memset, buffer size Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « printing/print_settings.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/print_settings_initializer_win.cc
diff --git a/printing/print_settings_initializer_win.cc b/printing/print_settings_initializer_win.cc
index c10562b86c5854284da58a7cc0bae93723ff1857..e72033d04ffa46511978e7a2f9a8f8b538dfa54a 100644
--- a/printing/print_settings_initializer_win.cc
+++ b/printing/print_settings_initializer_win.cc
@@ -10,6 +10,32 @@
namespace printing {
+namespace {
+
+bool IsPrinterXPS(HDC hdc) {
+ int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY);
+ if (device_type != DT_RASPRINTER)
+ return false;
+
+ const DWORD escape = GETTECHNOLOGY;
+ const char* escape_ptr = reinterpret_cast<const char*>(&escape);
+ int ret =
+ ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), escape_ptr, 0, nullptr);
+ if (ret <= 0)
+ return false;
+
+ char buffer[256];
+ memset(buffer, 0, sizeof(buffer));
+ ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer) - 1, buffer);
+ if (ret <= 0)
+ return false;
+
+ static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06";
+ return strcmp(buffer, kXPSDriver) == 0;
+}
+
+} // namespace
+
// static
void PrintSettingsInitializerWin::InitPrintSettings(
HDC hdc,
@@ -17,23 +43,26 @@ void PrintSettingsInitializerWin::InitPrintSettings(
PrintSettings* print_settings) {
DCHECK(hdc);
DCHECK(print_settings);
+
print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE);
int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
print_settings->set_dpi(dpi);
+
const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA;
print_settings->set_supports_alpha_blend(
(GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps);
+
// No printer device is known to advertise different dpi in X and Y axis; even
// the fax device using the 200x100 dpi setting. It's ought to break so many
- // applications that it's not even needed to care about. WebKit doesn't
- // support different dpi settings in X and Y axis.
+ // applications that it's not even needed to care about. Blink doesn't support
+ // different dpi settings in X and Y axis.
DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY));
DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
- // Initialize page_setup_device_units_.
+ // Initialize |page_setup_device_units_|.
gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
GetDeviceCaps(hdc, PHYSICALHEIGHT));
gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
@@ -52,6 +81,8 @@ void PrintSettingsInitializerWin::InitPrintSettings(
print_settings->SetPrinterPrintableArea(physical_size_device_units,
printable_area_device_units,
false);
+
+ print_settings->set_printer_is_xps(IsPrinterXPS(hdc));
}
} // namespace printing
« no previous file with comments | « printing/print_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698