-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8265761: Font with missed font family name is not properly printed on Windows #3631
8265761: Font with missed font family name is not properly printed on Windows #3631
Conversation
👋 Welcome back alexsch! A progress list of the required criteria for merging this PR into |
@AlexanderScherbatiy The following labels will be automatically applied to this pull request:
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. |
Webrevs
|
The The automated tests pass.
|
@@ -1157,6 +1157,10 @@ protected boolean selectStylePen(int cap, int join, float width, | |||
protected boolean setFont(String family, float size, int style, | |||
int rotation, float awScale) { | |||
|
|||
if (family.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that the non-empty family, but spaces only will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use isBlank() instead of isEmpty() to check a font family name is blank?
if (family.isBlank()) {
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the test SampleBow font family name to one space SampleBowOneSpaceFamilyName.ttf and to two spaces SampleBowTwoSpacesFamilyName.ttf
The PrintFontSample sample program properly prints text drawn by Graphics2D.drawString() and Graphics2D.drawGlyphVector() on Windows with jdk 16 with these two fonts.
It looks like the problem is only with selecting a font in GDI with empty font family name.
I dumped the font you attached and it has
Who are stellarspot ? We can't put their copyrighted font into openjdk. If you created this font by editing The fix itself is probably fine .. I am surprised you get this far with a font with no name |
The stellarpot is my account which I used to create SampleBow font in fontconstruct. If it is necessary, I can recreate the font or create an another font under my name and the required license. What is the right license that I can use to create a simple font for openjdk test? What is the way to contribute the font and the design of all glyphs under OCA? |
We don't have a lot of precedent here. Your name .. BellSoft .. Oracle .. OpenJDK .. nothing at all .. some message like "created for OpenJDK might help !". |
I updated the font so now it uses "Alexander Scherbatiy" as a designer, "SampleFont Regular created for OpenJDK" as name for humans, and copyright:
|
@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:
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 129 new commits pushed to the
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 |
/integrate |
@AlexanderScherbatiy Since your change was applied there have been 173 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit e9370a1. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
PDFBox 1.8 uses Graphics2D.drawGlyphVector() method with scaled glyphs to print a text and PDF 2.0 uses Graphics2D.fill() to print glyphs path. Both methods finally calls WPathGraphics.convertToWPath(...) in jdk on Windows which call GDI FillPath.
Using a custom PageDrawer to draw a text in PDFBox with Graphics2D.drawString() method reveals the fact that some pdf documents which are properly printed by PDFBox 1.8 and PDF 2.0 on Linux and Windows have issues with printing them on Windows.
The reason is that such docs use fonts which have empty font family name.
The awt_PrintJob.jFontToWFontA(...) method is not able to select the required font when the passed font family name is empty.
jdk/src/java.desktop/windows/native/libawt/windows/awt_PrintJob.cpp
Line 2264 in 7c37c02
The proposed solution returns false from WPrinterJob.setFont(...) method when the font family is empty so the text printing falls back to printing a text by GDI FillPath method:
jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrinterJob.java
Line 1157 in 6d49cc3
To reproduce the issue I created a simple SampleBowMissedFamilyName.ttf font which contains only capital letters "ABCDEF" and saved it with empty font family name.
Here is a simple PrintFontSample.java program that helps to reproduce the issue using the SampleBowMissedFamilyName.ttf font.
The PrintFontSample program draws a text using three methods:
Running the program with jdk 16 on Windows (without the fix)
shows that the first and the second lines are not properly printed: sample-doc-without-fix.pdf
Running the program with the fix properly prints all three lines: sample-doc-with-fix.pdf
The provided manual test uses the created SampleBowMissedFamilyName.ttf font with empty font family name.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3631/head:pull/3631
$ git checkout pull/3631
Update a local copy of the PR:
$ git checkout pull/3631
$ git pull https://git.openjdk.java.net/jdk pull/3631/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3631
View PR using the GUI difftool:
$ git pr show -t 3631
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3631.diff