RFR: 8315113: Print request Chromaticity.MONOCHROME attribute does not work on macOS
Phil Race
prr at openjdk.org
Wed Apr 17 20:13:01 UTC 2024
On Mon, 11 Mar 2024 13:54:02 GMT, Alexander Scherbatiy <alexsch at openjdk.org> wrote:
> The fix provides ability to print Black & White pages on macOS.
>
> Cocoa API has [PMSetColorMode](https://developer.apple.com/documentation/applicationservices/core_printing/1805783-pmsetcolormode) function but it is marked as deprecated and really does nothing.
>
> There is no replacement; this function was included to facilitate porting legacy applications to macOS,
> but it serves no useful purpose.
>
> Dumping `NSPrintInfo` print settings which were set by the native print dialog on macOS shows that the keys and values used for Black & White printing depend on the used printer type.
> For example, the tested
> `HP Color LaserJet MFP M180n` printer uses `ColorModel` key and`Gray` value, and
> `HP Ink Tank 110 series` uses `HPColorMode` key and `grayscale` value.
>
> Printing all `NSPrintInfo` presets shows that they do not contain key/value pairs for Black&White settings.
> This is the code snippet used to print `NSPrintInfo` presets:
>
> PMPrinter pr;
> PMPrintSession printSession = (PMPrintSession)[printInfo PMPrintSession];
> OSStatus status = PMSessionGetCurrentPrinter(printSession, &pr);
> CFArrayRef presetsList = nil;
> status = PMPrinterCopyPresets(pr, &presetsList);
> CFIndex arrayCount = CFArrayGetCount(presetsList);
>
> for (CFIndex index = 0; index < arrayCount; index++) {
> PMPreset preset = (PMPreset)CFArrayGetValueAtIndex(presetsList, index);
> CFStringRef presetName = nil;
> if (PMPresetCopyName(preset, &presetName) == noErr && CFStringGetLength(presetName) > 0) {
> NSLog(@" presetName: '%@'", presetName);
> NSDictionary* dict = nil;
> if (PMPresetGetAttributes(preset, (CFDictionaryRef*)(&dict)) == noErr) {
> // print preset dict
>
>
> The idea of the proposed fix is to store printer dependent key/value pairs in the `<jdk-home>/conf/printer.properties` property file.
>
> The property file has the format:
>
> print-attribute.print-attribute-value.key=value
>
> where `print-attribute` is the java print attribute, `print-attribute-value` is the corresponding attribute value, and `key` and `value` is the key/value pair used by a specific printer.
>
> For example, for `Chromaticity` attribute the property file could look like:
>
> Chromaticity.MONOCHROME.ColorModel=Gray
> Chromaticity.COLOR.ColorModel=CMYK
> Chromaticity.MONOCHROME.HPColorMode=grayscale
> Chromaticity.COLOR.HPColorMode=color
>
> where `Chromaticity.MONOCHROME` key prefix corresponds to `Chromaticity.MONOCHOROME` print attribute constant with (...
src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m line 551:
> 549:
> 550: if (chromaticityKeyValues == nil) {
> 551:
I'm not trying to revive this PR, but I was looking at it and I got curious about a couple of things.
What is going on here ?
First the Java code will never (I think) return NULL, so the "if" will never be used.
Second, why in the case that it does, did you decide to set ColorModel=Gray or ColorModel=Color ?
Are these a best guess default ? In which case why don't you always specify them anyway ?
You are already throwing the entire set of ones you read from the conf file into the settings.
Also there's no way I can see for you to KNOW that the settings will work.
This could be confusing for apps wanting monochrome/gray
Since you don't report back the supported status then they can't tell that when monochrome would work.
and (btw) you don't even filter this by whether the printer supports color when setting Color.
And on a broader note, the entire PPD API and PPD printer drivers are deprecated by CUPS.
So this seems like an approach on which the clock is ticking before it is even deployed.
test/jdk/javax/print/attribute/ChromaticityAttributeTest.java line 168:
> 166: }
> 167:
> 168: private static Set<Chromaticity> getSupportedChromaticityAttributes() {
The presence of this method is misleading in the test.
You don't use it and just hard code Color + Monochrome in what you test.
And in fact I don't see anywhere you've updated the implementation to report supported values.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18195#discussion_r1569463240
PR Review Comment: https://git.openjdk.org/jdk/pull/18195#discussion_r1569440468
More information about the build-dev
mailing list