JDK-8295737 : macOS: Print content cut off when width > height with portrait orientation
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 10,19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic
  • Submitted: 2022-10-20
  • Updated: 2023-08-28
  • Resolved: 2023-03-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 21
11.0.21Fixed 17.0.9Fixed 21 b13Fixed
Related Reports
Relates :  
Relates :  
Description
Steps to reproduce:
- Run the attached CutOffImage sample on macOS.

The sample prints four rectangles:
1. size 300x100, portrait orientation
2. size 300x100, landscape orientation
3. size 100x300, portrait orientation
4. size 100x300, landscape orientation

The first image (300x100, portrait) where width is larger than height with portrait orientation and fourth (100x300, landscape) where height is large than width with landscape orientation cut off.

See attached cut-of-image.pdf where the content has been printed to pdf.  
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1700 Date: 2023-08-25 15:08:28 +0000
25-08-2023

Fix request [17u] The fix allows to print a page which width is greater than height with portrait orientation on macOS. Manual test/jdk/java/awt/print and test/jdk/javax/print tests were run to check printing on macOS with and without the fix.
25-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2092 Date: 2023-08-22 13:53:20 +0000
22-08-2023

Fix request [11u] The fix allows to print a page which width is greater than height with portrait orientation on macOS. Manual test/jdk/java/awt/print and test/jdk/javax/print tests were run to check printing on macOS with and without the fix.
22-08-2023

Changeset: d00a7670 Author: Alexander Scherbatiy <alexsch@openjdk.org> Date: 2023-03-06 07:48:37 +0000 URL: https://git.openjdk.org/jdk/commit/d00a767047ec41e233e711dbc5fe7b8818e72f28
06-03-2023

Attached main.m file is a Objective-C code which uses pure Cocoa API with NSPrint and NSPrintInfo classes to print an image. The application shows the issue with printing an image which width is greater than height with portrait orientation. To run the code: - Create macOS App project in Xcode - Open main.m file in the project - Copy the code from the attached file https://bugs.openjdk.org/secure/attachment/101275/main.m to the main.m file - Select the root node in the project and go to the Signing & Capabilities tab - Select 'Hardware->Printing' checkbox - Choose Read Only option in 'File Access Type -> Pictures Folder' - Build the project The application expects that the printed image is stored in Pictures folder and the SAMPLE_PRINTER_NAME environment variable is set to the used printer name. - Copy the attached image-LANDSCAPE-300x100.png image to Pictures folder: https://bugs.openjdk.org/secure/attachment/101274/image-PORTRAIT-300x100.png - Set the SAMPLE_PRINTER_NAME environment variable to the used printer name. - Run the app First, the image size is set to NSPrintInfo and then the Portrait orientation after that: [printInfo setPaperSize: imageSize]; [printInfo setOrientation: NS_PORTRAIT]; The output is: print info: set image size [300.000000, 100.000000] print info orientation: [1] NS_LANDSCAPE, size: [300.000000, 100.000000] print info: set orientation NS_PORTRAIT print info orientation: [0] NS_PORTRAIT, size: [100.000000, 300.000000] NSPrintInfo has paper size 100x300 after changing the landscape orientation to portrait. Second, setting the paper size and the orientation order is manually changed in the code: [printInfo setOrientation: NS_PORTRAIT]; [printInfo setPaperSize: imageSize]; The output is: print info: set orientation NS_PORTRAIT print info orientation: [0] NS_PORTRAIT, size: [612.000000, 792.000000] print info: set image size [300.000000, 100.000000] print info orientation: [1] NS_LANDSCAPE, size: [300.000000, 100.000000] NSPrintInfo has landscape orientation after changing the paper size from the default one to 300x100.
01-11-2022

This is the regression from fixes: JDK-8181659 and JDK-8181192 CutOffImage sample with jdk 11.0.2 (without JDK-8181659 and JDK-8181192 fixes. Image is not truncated, page size is not taken into account): https://bugs.openjdk.org/secure/attachment/101173/cut-jdk-11.0.2.pdf CutOffImage sample with jdk 11.0.3 (with JDK-8181659 and JDK-8181192 fixes. Image is truncated, page size is taken into account): https://bugs.openjdk.org/secure/attachment/101172/cut-jdk-11.0.3.pdf
24-10-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10808 Date: 2022-10-21 08:42:12 +0000
21-10-2022

The problem is that setting a size which width is larger than height to NSPrintInfo on macOS changes the NSPrintInfo orientation from portrait to landscape. javaPageFormatToNSPrintInfo() method from CPrinterJob.m https://github.com/openjdk/jdk/blob/08a7ecf47ee5811f88dfcc82fe8614c72ccf3221/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m#L298 first sets NSPrintInfo size to (300, 100) which changes the NSPrintInfo orientation to landscape: https://github.com/openjdk/jdk/blob/08a7ecf47ee5811f88dfcc82fe8614c72ccf3221/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m#L318 https://github.com/openjdk/jdk/blob/08a7ecf47ee5811f88dfcc82fe8614c72ccf3221/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m#L228 and sets the orientation to portrait after that: https://github.com/openjdk/jdk/blob/08a7ecf47ee5811f88dfcc82fe8614c72ccf3221/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m#L323 which triggers changing the orientation from landscape to portrait and subsequently changing the size from (300, 100) to (100, 300) The Cocoa code which reproduces the size flip: ``` #import <Cocoa/Cocoa.h> int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSApp = [NSApplication sharedApplication]; #ifdef __MAC_10_9 // code for SDK 10.9 or newer #define NS_PORTRAIT NSPaperOrientationPortrait #define NS_LANDSCAPE NSPaperOrientationLandscape #else // code for SDK 10.8 or older #define NS_PORTRAIT NSPortraitOrientation #define NS_LANDSCAPE NSLandscapeOrientation #endif printf("NS_PORTRAIT: %d\n", NS_PORTRAIT); printf("NS_LANDSCAPE: %d\n", NS_LANDSCAPE); printf("create default print info\n"); NSPrintInfo* defaultPrintInfo = [[NSPrintInfo sharedPrintInfo] copy]; NSSize size = [defaultPrintInfo paperSize]; printf("orientation: %d, paper size: [%f, %f]\n", [defaultPrintInfo orientation], size.width, size.height); printf("call setUpPrintOperationDefaultValues\n"); [defaultPrintInfo setUpPrintOperationDefaultValues]; size = [defaultPrintInfo paperSize]; printf("orientation: %d, paper size: [%f, %f]\n", [defaultPrintInfo orientation], size.width, size.height); double w = 300.0; double h = 100.0; printf("set size: [%f, %f]\n", w, h); [defaultPrintInfo setPaperSize:NSMakeSize(w, h)]; size = [defaultPrintInfo paperSize]; printf("orientation: %d, paper size: [%f, %f]\n", [defaultPrintInfo orientation], size.width, size.height); printf("Set NS_PORTRAIT orientation\n"); [defaultPrintInfo setOrientation: NS_PORTRAIT]; size = [defaultPrintInfo paperSize]; printf("orientation: %d, paper size: [%f, %f]\n", [defaultPrintInfo orientation], size.width, size.height); [NSApp run]; [NSApp release]; [pool release]; return(EXIT_SUCCESS); } `` On macOS Mojave 10.14.5 it prints: ``` NS_PORTRAIT: 0 NS_LANDSCAPE: 1 create default print info orientation: 0, paper size: [612.000000, 792.000000] call setUpPrintOperationDefaultValues orientation: 0, paper size: [612.000000, 792.000000] set size: [300.000000, 100.000000] orientation: 1, paper size: [300.000000, 100.000000] // orientation flip Set NS_PORTRAIT orientation orientation: 0, paper size: [100.000000, 300.000000] // size flip ```
20-10-2022