From 9d1d8bed12c048b378ba73673f5dcc22aa70fc2c Mon Sep 17 00:00:00 2001 From: Jurgen Date: Tue, 30 Aug 2022 18:31:34 +0200 Subject: [PATCH] Fixed multi line text calculation --- .../java9/org/fxmisc/richtext/TextFlowLayout.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/richtextfx/src/main/java9/org/fxmisc/richtext/TextFlowLayout.java b/richtextfx/src/main/java9/org/fxmisc/richtext/TextFlowLayout.java index 7408d462..82d567a4 100644 --- a/richtextfx/src/main/java9/org/fxmisc/richtext/TextFlowLayout.java +++ b/richtextfx/src/main/java9/org/fxmisc/richtext/TextFlowLayout.java @@ -82,9 +82,14 @@ int getLineCount() { PathElement[] shape = flow.rangeShape( totCharSoFar, totCharSoFar+length ); double lines = Math.max( 1.0, Math.floor( shape.length / 5 ) ); double nodeMinY = Math.max( 0.0, nodeBounds.getMinY() ); - - if ( nodeMinY >= prevMaxY ) totLines += lines; - else if ( lines > 1 ) totLines += lines - 1; // Staggered multiline text node + + if ( lines > 1.0 ) { // Staggered multiline text node + if ( totLines > 0.0 ) lines--; + totLines += lines; + } + else if ( nodeMinY >= prevMaxY ) { // Node is on next line + totLines++; + } if ( lineMetrics.size() < totLines ) { // Add additional lines