Skip to content

Commit

Permalink
Fix PrinterSettings.SupportsColor to use the right PInvoke (#34651)
Browse files Browse the repository at this point in the history
* Fix PrinterSettings.SupportsColor to use the right PInvoke

* PR Fedback

* Fix test

* PR Feedbak
  • Loading branch information
safern authored Apr 15, 2020
1 parent cfb109b commit 4265a13
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public const int
DC_PAPERNAMES = 16,
DC_ORIENTATION = 17,
DC_COPIES = 18,
DC_COLORDEVICE = 32,
PD_ALLPAGES = 0x00000000,
PD_SELECTION = 0x00000001,
PD_PAGENUMS = 0x00000002,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,12 @@ public bool SupportsColor
{
get
{
return GetDeviceCaps(Interop.Gdi32.DeviceCapability.BITSPIXEL, 1) > 1;
// If the printer supports color printing, the return value is 1; otherwise, the return value is zero.
// The pointerToBuffer parameter is not used.
return DeviceCapabilities(
capability: SafeNativeMethods.DC_COLORDEVICE,
pointerToBuffer: IntPtr.Zero,
defaultValue: 0) == 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,14 @@ public void IsDirectPrintingSupported_ImageNotSupported_ReturnsExpected()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.AnyInstalledPrinters, Helpers.IsDrawingSupported)]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PrinterSettingsTests), nameof(CanTestSetHdevmode_IntPtr_Success))]
public void SupportsColor_ReturnsExpected()
{
var printerSettings = new PrinterSettings();
bool supportsColor = printerSettings.SupportsColor;
// XPS and PDF printers support color.
// docs.microsoft.com/en-us/windows-hardware/drivers/print/improved-color-printing
var printerSettings = new PrinterSettings() { PrinterName = GetNameOfTestPrinterSuitableForDevModeTesting() };
Assert.True(printerSettings.SupportsColor);
}

[Theory]
Expand Down Expand Up @@ -608,7 +610,7 @@ private static string GetNameOfTestPrinterSuitableForDevModeTesting()

private static readonly string[] s_TestPrinterNames =
{
// Our method of testing this api requires a printer that supports multi-copy printing, collating and duplex settings. Not all printers
// Our method of testing some apis requires a printer that supports multi-copy printing, collating, color and duplex settings. Not all printers
// support these so rather than trust the machine running the test to have configured such a printer as the default, use the name of
// a known compliant printer that ships with Windows 10.
"Microsoft Print to PDF",
Expand Down

0 comments on commit 4265a13

Please sign in to comment.