On Thu, 22 Apr 2021 15:13:45 GMT, Alexander Scherbatiy <alex...@openjdk.org> wrote:
> PDFBox 1.8 uses > [Graphics2D.drawGlyphVector()](https://github.com/apache/pdfbox/blob/41ae21bd4c3f304373d3b05f63af5325df248019/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java#L352) > method with scaled glyphs to print a text and PDF 2.0 uses > [Graphics2D.fill()](https://github.com/apache/pdfbox/blob/4f14dee47ff821e44d9e2ff11532959d95e94d5b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java#L512) > 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. > https://github.com/openjdk/jdk/blob/7c37c022a1664437bf8d2c8d76ad039521f3ffa7/src/java.desktop/windows/native/libawt/windows/awt_PrintJob.cpp#L2264 > > > 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: > https://github.com/openjdk/jdk/blob/6d49cc3b655433d00e967fdcec3f3759412cd925/src/java.desktop/windows/classes/sun/awt/windows/WPrinterJob.java#L1157 > > To reproduce the issue I created a simple > [SampleBowMissedFamilyName.ttf](https://bugs.openjdk.java.net/secure/attachment/94344/SampleBowMissedFamilyName.ttf) > font which contains only capital letters "ABCDEF" and saved it with empty > font family name. > > Here is a simple > [PrintFontSample.java](https://bugs.openjdk.java.net/secure/attachment/94343/PrintFontSample.java) > program that helps to reproduce the issue using the > SampleBowMissedFamilyName.ttf font. > > The PrintFontSample program draws a text using three methods: > - Graphics2D.drawString(...) > - Graphics2D.drawGlyphVector(...) > - Graphics2D.drawGlyphVector(...) using transformed glyphs > > Running the program with jdk 16 on Windows (without the fix) >> java PrintFontSample SampleBowMissedFamilyName.ttf > > shows that the first and the second lines are not properly printed: > [sample-doc-without-fix.pdf](https://bugs.openjdk.java.net/secure/attachment/94345/sample-doc-without-fix.pdf) > Running the program with the fix properly prints all three lines: > [sample-doc-with-fix.pdf](https://bugs.openjdk.java.net/secure/attachment/94349/sample-doc-with-fix.pdf) > > The provided manual test uses the created SampleBowMissedFamilyName.ttf font > with empty font family name. The `java/awt/print` and `java/awt/PrintJob` automated and manual tests were run with the fix. The automated tests pass. The following manual tests fail with and without the fix: java/awt/print/Dialog/DialogOrient.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/Dialog/DialogType.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/ImagePrinting/ClippedImages.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/ImagePrinting/ImageTypes.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/ImagePrinting/PrintARGBImage.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PageDialogTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PageRanges.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PageRangesDlgTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PrintGlyphVectorTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PrintLatinCJKTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/PrintTextTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/PrinterJob/SwingUIText.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/PrintJob/ConstrainedPrintingTest/ConstrainedPrintingTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/PrintJob/PageSetupDlgBlockingTest/PageSetupDlgBlockingTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/PrintJob/SaveDialogTitleTest.java Error. Parse Exception: Arguments to `manual' option not supported: yesno java/awt/print/Dialog/PrintDlgPageable.java Error. java.lang.IllegalAccessException: class com.sun.javatest.regtest.agent.MainWrapper$MainThread cannot access a member of class PrintDlgPageable with modifiers "public static" java/awt/PrintJob/PrintCheckboxTest/PrintCheckboxManualTest.java Error. Can't find HTML file: test\jdk\java\awt\PrintJob\PrintCheckboxTest\PrintCheckboxManualTest.html ------------- PR: https://git.openjdk.java.net/jdk/pull/3631