From b97424f7677d9517f40fdb25163273dbd7f96a24 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 10 Nov 2024 13:21:11 +0100 Subject: [PATCH] HTML: fixed wrong rendering if HTML text contains `" + bodyInBody + "", bodyPlain ); + testHtmlBaseSize( "${BASE_SIZE}

header1

" + body + "", "header1\n" + bodyPlain ); + + testHtmlBaseSize( "${BASE_SIZE}" + bodyInBody + "", bodyPlain ); + testHtmlBaseSize( "${BASE_SIZE}

header1

" + body + "", "header1\n" + bodyPlain ); + } + + private void testHtmlBaseSize( String html, String expectedPlain ) { + testHtmlBaseSizeImpl( html, expectedPlain ); + testHtmlBaseSizeImpl( html.toUpperCase( Locale.ENGLISH ), expectedPlain.toUpperCase( Locale.ENGLISH ) ); + } + + private void testHtmlBaseSizeImpl( String html, String expectedPlain ) { + String baseSize = ""; + String baseSizeInHead = "" + baseSize + ""; + + String expectedHtml = html.replace( "${BASE_SIZE}", baseSize ).replace( "${BASE_SIZE_IN_HEAD}", baseSizeInHead ); + html = html.replace( "${BASE_SIZE}", "" ).replace( "${BASE_SIZE_IN_HEAD}", "" ); + + testHtml( html, expectedHtml, expectedPlain ); + } + + private void testHtml( String html, String expectedHtml, String expectedPlain ) { + FlatHTML.testUpdateRenderer = (c, newHtml) -> { + assertEquals( expectedHtml, newHtml ); + assertEquals( expectedPlain, getPlainText( c ) ); + }; + new JLabel( html ); + FlatHTML.testUpdateRenderer = null; + } + + private String getPlainText( JComponent c ) { + View view = (View) c.getClientProperty( BasicHTML.propertyKey ); + if( view == null ) + return null; + + Document doc = view.getDocument(); + try { + return doc.getText( 0, doc.getLength() ).trim(); + } catch( BadLocationException ex ) { + ex.printStackTrace(); + return null; + } + } +} diff --git a/gradle.properties b/gradle.properties index 45d95dee..3dbb0b31 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # flatlaf.releaseVersion = 3.5.2 -flatlaf.developmentVersion = 3.6-SNAPSHOT +flatlaf.developmentVersion = 3.5.3-SNAPSHOT org.gradle.parallel = true # org.gradle.warning.mode = all