We have recently completed testing our products on Java 19. As of its release BuildVu, FormVu, JDeli, and JPedal will officially support Java 19.
Whilst testing we did find one change in this version that we thought it worth documenting. In the class Path2D (both Path2D.Float and Path2D.Double) the getBounds() methods return value is changed subtly.
What’s different in Java 19?
Before Java19 Path2D.getBounds would return a Rectangle2D as either a Rectangle2D.Float or a Rectangle.Double. This was based on which Path2D variant you are using.
As of Java19 the Float/Double variants of getBounds() call the same static method to generate the Rectangle2D of the bounds and always returns Rectangle2D.Double.
Why is this interesting?
We have an optimisation to ignore clips in BuildVu output if the shape and clip are rectangular and the shape is completely contained within a clip. This is because in this case the clip has no effect in that case. However different object types would return clip or shape bounds as a Rectangle2D.Float or Rectangle2D.Double.
Due to the use of both Floats and Doubles being handled there is a niche case that may occur. Slight value changes due to the way float and double values are handled can take place. In these cases identical shape and clip values can be shifted resulting in them not being identical. When this happens our code thinks the shape crosses the clip bounds and therefore needs to be clipped.
How do we benefit from this?
In some uses the clip that is applied means we lose a sliver of content and a small gap between content appears which most commonly appears as a fine white line.
Now in Java19 both bounds are returned as Double, the values remain consistent and any shift in the value happens for both the shape and the clip. We can now correctly detect the clip isn’t needed so we don’t lose the sliver and the gap is gone.
For example the coloured bands below have clips identical to the bands and should be ignored. The bands should all be touching with no gap. In Java 18 and lower the clips are applied (image on the left), in Java 19 they are ignored to the sliver isn’t lost (image on the right).
This is a niche case but it has improved the appearance of several files in our baseline.
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Do you need to solve any of these problems?
|Display PDF documents in a Web app|
|Use PDF Forms in a web browser|
|Convert PDF Documents to an image|
|Work with PDF Documents in Java|