RFR: 8167268: StandardGlyphVector.getGlyphMetrics creates metrics with erroneous bounds for characters with no outline (e.g., the space character ' ')

Sergey Bylokhov serb at openjdk.org
Tue Sep 30 19:21:49 UTC 2025


On Tue, 30 Sep 2025 14:26:34 GMT, Daniel Gredler <dgredler at openjdk.org> wrote:

> `GlyphMetrics` objects returned by `StandardGlyphVector.getGlyphMetrics(int)` contain bounds that are calculated by taking the glyph’s visual bounds and normalizing them by subtracting the glyph’s position.
> 
> However, some glyphs (e.g., the glyph for the space character) do not have visual bounds. Their outline is an empty shape. In such a case the bounds in the metrics should not be normalized by the glyph’s position. The code erroneously ignores this special case, thus producing bounds with inconsistent negative x-positions.

src/java.desktop/share/classes/sun/font/StandardGlyphVector.java line 611:

> 609: 
> 610:         Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
> 611:         if (!vb.isEmpty()) {

Just to double check: do we want to skip glyphs only when the bounds are empty, or we also want to skip them when the bounds are flipped (negative width/height)?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27580#discussion_r2392601857


More information about the client-libs-dev mailing list