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

8262470: Printed GlyphVector outline with low DPI has bad quality on Windows #2756

Closed

Conversation

@AlexanderScherbatiy
Copy link

@AlexanderScherbatiy AlexanderScherbatiy commented Feb 26, 2021

Printing text using GlyphVector outline has bad quality on printers with low DPI on Windows.
The GDI system used for text printing on Windows accepts only integer path coordinates.
Rounding GlyphVector outline coordinates leads to distorted printed text.

The issue had been reported as JDK-8256264 but was reverted because of the regression JDK-8259007 "This test printed a blank page".

The fix JDK-8256264 scaled coordinates in wPrinterJob.moveTo()/lineTo() methods up and scaled transforms in wPrinterJob.beginPath()/endPath() down.

The regression was in the WPathGraphics.deviceDrawLine() method which uses wPrinterJob.moveTo()/lineTo() methods without surrounding them with wPrinterJob.beginPath()/endPath() so the line coordinates were only scaled up.

I tried to put wPrinterJob.beginPath()/endPath() methods around wPrinterJob.moveTo()/lineTo() in the method WPathGraphics.deviceDrawLine() but the line was not drawn at all even without scaling coordinates up and transform down (without JDK-8256264 fix). It looks like GDI treats this case as an empty shape.

The proposed fix applies path coordinates and transform scaling only in WPathGraphics.convertToWPath() method.
The one more PathPrecisionScaleFactorShapeTest.java manual test is added which checks that all methods that draw paths in WPathGraphics are used: line in WPathGraphics.deviceDrawLine() and SEG_LINETO/SEG_QUADTO/SEG_CUBICTO in WPathGraphics.convertToWPath() .

The java/awt/print and java/awt/PrintJob automatic and manual tests were run on Windows 10 Pro with the fix.

There are two failed automated tests which fail without the fix as well:

java/awt/print/PrinterJob/GlyphPositions.java 
java/awt/print/PrinterJob/PSQuestionMark.java

The following manual tests have issues on my system:

  • java/awt/print/Dialog/PrintDlgPageable.java java.lang.IllegalAccessException: class com.sun.javatest.regtest.agent.MainWrapper$MainThread cannot access a member of class PrintDlgPageable with modifiers "public static"

  • java/awt/print/PrinterJob/PrintAttributeUpdateTest.java I select pages radio button, press the print button but the test does not finish and I do not see any other dialogs with pass/fail buttons.

  • java/awt/PrintJob/PrintCheckboxTest/PrintCheckboxManualTest.java Tests that there is no ClassCastException thrown in printing checkbox and scrollbar with XAWT. Error. Can't find HTML file: test\jdk\java\awt\PrintJob\PrintCheckboxTest\PrintCheckboxManualTest.html

  • java/awt/print/PrinterJob/SecurityDialogTest.java A windows with instructions is shown but it does not contain print/pass/fail buttons and it is not possible to close the window.

  • The tests below fail with "Error. Parse Exception: Arguments to `manual' option not supported: yesno" message:

java/awt/print/Dialog/DialogOrient.java
java/awt/print/Dialog/DialogType.java
java/awt/print/PrinterJob/ImagePrinting/ClippedImages.java
java/awt/print/PrinterJob/ImagePrinting/ImageTypes.java
java/awt/print/PrinterJob/ImagePrinting/PrintARGBImage.java
java/awt/print/PrinterJob/PageDialogTest.java
java/awt/print/PrinterJob/PageRanges.java
java/awt/print/PrinterJob/PageRangesDlgTest.java
java/awt/print/PrinterJob/PrintGlyphVectorTest.java
java/awt/print/PrinterJob/PrintLatinCJKTest.java
java/awt/print/PrinterJob/PrintTextTest.java
java/awt/print/PrinterJob/SwingUIText.java
java/awt/PrintJob/ConstrainedPrintingTest/ConstrainedPrintingTest.java
java/awt/PrintJob/PageSetupDlgBlockingTest/PageSetupDlgBlockingTest.java
java/awt/PrintJob/SaveDialogTitleTest.java

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8262470: Printed GlyphVector outline with low DPI has bad quality on Windows

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/2756/head:pull/2756
$ git checkout pull/2756

Update a local copy of the PR:
$ git checkout pull/2756
$ git pull https://git.openjdk.java.net/jdk pull/2756/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2756

View PR using the GUI difftool:
$ git pr show -t 2756

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/2756.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Feb 26, 2021

👋 Welcome back alexsch! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Feb 26, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Feb 26, 2021

@AlexanderScherbatiy The following labels will be automatically applied to this pull request:

  • 2d
  • awt

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Feb 26, 2021

Webrevs

@mrserb
Copy link
Member

@mrserb mrserb commented Mar 6, 2021

I'll run the tests for this fix.

mrserb
mrserb approved these changes Mar 10, 2021
@mrserb
Copy link
Member

@mrserb mrserb commented Mar 10, 2021

@prsadhuk please take a look

@openjdk
Copy link

@openjdk openjdk bot commented Mar 10, 2021

@AlexanderScherbatiy This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8262470: Printed GlyphVector outline with low DPI has bad quality on Windows

Reviewed-by: serb, psadhukhan

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 478 new commits pushed to the master branch:

  • e2ec997: 8263551: Provide shared lock-free FIFO queue implementation
  • dec3447: 8264346: nullptr_t undefined in global namespace for clang+libstdc++
  • 0fa3572: 8264489: Add more logging to LargeCopyWithMark.java
  • f43d14a: 8264396: Use the blessed modifier order in jdk.internal.jvmstat
  • 6225ae6: 8264466: Cut-paste error in InterfaceCalls JMH
  • 40c3249: 8264149: BreakpointInfo::set allocates metaspace object in VM thread
  • 999c134: 8264417: ParallelCompactData::region_offset should not accept pointers outside the current region
  • 604b14c: 8264112: (fs) Reorder methods/constructor/fields in UnixUserDefinedFileAttributeView.java
  • 9061271: 8261957: [PPC64] Support for Concurrent Thread-Stack Processing
  • 8a4a911: 8262894: [macos_aarch64] SIGBUS in Assembler::ld_st2
  • ... and 468 more: https://git.openjdk.java.net/jdk/compare/a4c249610e7c0fcc7fd863f14f51c96abc5ca39f...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Mar 10, 2021
* be one of the following Windows constants:
* {@code GM_COMPATIBLE} or {@code GM_ADVANCED}.
*/
private int setGraphicsMode(int mode) {
Copy link
Contributor

@prsadhuk prsadhuk Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need of "int" return value? I dont see it is used in restoreTransform()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to return void from setGraphicsMode() method.

xForm.eDx = (FLOAT) elems[4];
xForm.eDy = (FLOAT) elems[5];

::SetWorldTransform((HDC)printDC, &xForm);
Copy link
Contributor

@prsadhuk prsadhuk Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should check for the return value of all this system APIs SetGraphicsMode, GetWorldTransform, SetWorldTransform, ModifyWorldTransform to see if it succeeded?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added DASSERT to check SetGraphicsMode and Get/Set/ModifyWorldTransform results.

mrserb
mrserb approved these changes Mar 31, 2021
@AlexanderScherbatiy
Copy link
Author

@AlexanderScherbatiy AlexanderScherbatiy commented Apr 1, 2021

/integrate

@openjdk openjdk bot closed this Apr 1, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Apr 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 1, 2021

@AlexanderScherbatiy Since your change was applied there have been 484 commits pushed to the master branch:

  • 3997c99: 8264222: Use switch expression in jshell where possible
  • 39f0b27: 8176026: SA: Huge heap sizes cause a negative value to be displayed in the jhisto heap total
  • de495df: 8264413: Data is written to file header even if its CRC32 was calculated
  • 52d8a22: 8264054: Bad XMM performance on java.lang.MathBench.sqrtDouble
  • 16acfaf: 8012229: [lcms] Improve performance of color conversion for images with alpha channel
  • cb70ab0: 8263235: sanity/client/SwingSet/src/ColorChooserDemoTest.java failed throwing java.lang.NoClassDefFoundError
  • e2ec997: 8263551: Provide shared lock-free FIFO queue implementation
  • dec3447: 8264346: nullptr_t undefined in global namespace for clang+libstdc++
  • 0fa3572: 8264489: Add more logging to LargeCopyWithMark.java
  • f43d14a: 8264396: Use the blessed modifier order in jdk.internal.jvmstat
  • ... and 474 more: https://git.openjdk.java.net/jdk/compare/a4c249610e7c0fcc7fd863f14f51c96abc5ca39f...master

Your commit was automatically rebased without conflicts.

Pushed as commit 0228734.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants