javafxports / openjdk-jfx

The openjfx repo has moved to:
https://github.com/openjdk/jfx
GNU General Public License v2.0
1.01k stars 145 forks source link

Poor printing quality #379

Open Ciruman opened 5 years ago

Ciruman commented 5 years ago

We are trying to print a Javafx Node with a good resolution and we found out that the javafx prints with a poor resolution(in Mac and Windows). This is related to the following ticket:

https://bugs.openjdk.java.net/browse/JDK-8166194

We found a non-acceptable workarround in the Javafx code:

We added in J2DPrinterJob.printNode the following code: ((com.sun.javafx.geom.transform.Affine2D)ppg.getTransformNoClone()).scale(1.1, 1.1); And looks like this:

private void printNode(Node node, Graphics g, int w, int h) {
            PrismPrintGraphics ppg =
                    new PrismPrintGraphics((Graphics2D) g, w, h);
//++++++++++++START
((com.sun.javafx.geom.transform.Affine2D)ppg.getTransformNoClone()).scale(1.0001, 1.0001);
//++++++++++++END
            NGNode pgNode = node.impl_getPeer();
            boolean errored = false;

The difference is huge in the javafx controls.

Could someone help us about it?

Source code to reproduce the problem:

import javafx.application.Application;
import javafx.print.PrinterJob;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class PrintTest extends Application {

    public static void print(final Node node) {
        PrinterJob job = PrinterJob.createPrinterJob();
        job.showPrintDialog(node.getScene().getWindow());
        boolean success = job.printPage(node);
        if (success) {
            job.endJob();
        }
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Button print = new Button("Print");
        HBox hBox = new HBox(print);
        print.setOnAction(event -> PrintTest.print(hBox));
        primaryStage.setScene(new Scene(hBox));
        primaryStage.show();
    }

}
ghost commented 5 years ago

javafx print comparation

Left side you see the printing from javafx (blurry edges) and on the right side you see the sharp printing with the workaround applied.

Ciruman commented 5 years ago

Of course instead of using: ((com.sun.javafx.geom.transform.Affine2D)ppg.getTransformNoClone()).scale(1.0001, 1.0001); could be used: ppg.scale(1.0001, 1.0001); But the thing is how is the best way to flag it as "durty" during the printing rendering. The screenshots @streifi added are from the same JavaFX application printed to two PDFs using Mac. In Windows the result should be the same(not tested).

Ciruman commented 5 years ago

Here it is the Issue: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8223372

Does anybody know how could it be fixed? Any hints are welcome.