Did you mean javafx.print.Paper instead of java.print.Page?

If so, then I think that the getWidth/getHeight functions should be fixed as they're not specified to do any rounding.  They return a double, and specify they return this in points.  Nowhere does it mention they're rounded to an integer number of points (in which case I would also expect an integer return type).  This seems an obvious bug.

--John


On 31/08/2023 11:39, Florian Kirmaier wrote:
Hi JavaFX Developer!

The Problem:

On the class java.print.Page <http://java.print.page/>, the methods “getWidth" and “getHeight" don’t return the correct values.

It especially causes problems when the Paper is defined in mm.
This happens mainly because of this method, which rounds down to full points:

private double getSizeInPoints(double dim) {
    switch (units) {
    case POINT : return (int)(dim+0.5);
    case INCH  : return (int)((dim * 72) + 0.5);
    case MM    : return (int)(((dim * 72) / 25.4) + 0.5);
    }
    return dim;
}

This causes problem because it makes correct computations based on the Paper impossible. So it’s basically not possible to get the size of any Paper which is defined based on mm.

There I suggest 3 solutions:

*Solution1:*
We could just change getSIzeInPoints to return the exact value.
Advantage: Might fix various unknown bugs in user code.
Disadvantage: Might cause regressions.

*Solution2:*
We could add new methods getExactWidth() / getExactHeight() , which returns the exact value without a rounding problem anywhere noticeable.

*Solution3:*
We could provide an API to access the width/height based on a given Unit.
like: getWidth(Unit.MM).
We already have implemented this, in our application code, so it wouldn’t be much effort. But it would require moving com.sun.javafx.print.Units back to javafx.print.Paper.Units. (basically reverting JDK-8093699)


*Summary:*
I am happy with every solution.
I’m a bit in favor of 1, but 2 and 3 is also ok for me.
It would be great if someone could make a decision on which solution to choose, then i would provide a PR.

Greetings Florian Kirmaier

Reply via email to