Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PrinterSettings.SupportsColor to use the right PInvoke #34651

Merged
merged 6 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
safern marked this conversation as resolved.
Show resolved Hide resolved
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() };
safern marked this conversation as resolved.
Show resolved Hide resolved
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