mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Merge PR #931: Fixing NPE when using HTML text on a component with null font
This commit is contained in:
@@ -8,6 +8,10 @@ FlatLaf Change Log
|
|||||||
- Extras: `FlatSVGIcon` color filters now can access painting component to
|
- Extras: `FlatSVGIcon` color filters now can access painting component to
|
||||||
implement component state based color mappings. (PR #906)
|
implement component state based color mappings. (PR #906)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- HTML: Fixed NPE when using HTML text on a component with `null` font. (issue
|
||||||
|
#930; PR #931; regression in 3.5)
|
||||||
|
|
||||||
## 3.5.3
|
## 3.5.3
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -74,9 +75,9 @@ public class FlatHTML
|
|||||||
for( int i = 1; i <= 7; i++ )
|
for( int i = 1; i <= 7; i++ )
|
||||||
System.out.println( i+": "+ styleSheet.getPointSize( i ) );
|
System.out.println( i+": "+ styleSheet.getPointSize( i ) );
|
||||||
debug*/
|
debug*/
|
||||||
int fontBaseSize = c.getFont().getSize();
|
Font font = c.getFont();
|
||||||
if( styleSheet.getPointSize( 7 ) != 36f ||
|
if( styleSheet.getPointSize( 7 ) != 36f ||
|
||||||
styleSheet.getPointSize( 4 ) == fontBaseSize )
|
font == null || styleSheet.getPointSize( 4 ) == font.getSize() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check whether view uses "absolute-size" keywords (e.g. "x-large") for font-size
|
// check whether view uses "absolute-size" keywords (e.g. "x-large") for font-size
|
||||||
@@ -97,7 +98,7 @@ debug*/
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
|
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
|
||||||
String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
|
String style = "<style>BASE_SIZE " + font.getSize() + "</style>";
|
||||||
String openTag = "";
|
String openTag = "";
|
||||||
String closeTag = "";
|
String closeTag = "";
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -73,6 +74,15 @@ public class TestFlatHTML
|
|||||||
testHtmlBaseSize( "<html>${BASE_SIZE}<style type='text/css'>body { color: #f00; }</style><h1>header1</h1>" + body + "</html>", "header1\n" + bodyPlain );
|
testHtmlBaseSize( "<html>${BASE_SIZE}<style type='text/css'>body { color: #f00; }</style><h1>header1</h1>" + body + "</html>", "header1\n" + bodyPlain );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void htmlOnComponentWithNullFont() {
|
||||||
|
assertDoesNotThrow( () -> {
|
||||||
|
JLabel label = new JLabel();
|
||||||
|
label.setFont( null );
|
||||||
|
label.setText( "<html>foo<br>bar</html>" );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
private void testHtmlBaseSize( String html, String expectedPlain ) {
|
private void testHtmlBaseSize( String html, String expectedPlain ) {
|
||||||
testHtmlBaseSizeImpl( html, expectedPlain );
|
testHtmlBaseSizeImpl( html, expectedPlain );
|
||||||
testHtmlBaseSizeImpl( html.toUpperCase( Locale.ENGLISH ), expectedPlain.toUpperCase( Locale.ENGLISH ) );
|
testHtmlBaseSizeImpl( html.toUpperCase( Locale.ENGLISH ), expectedPlain.toUpperCase( Locale.ENGLISH ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user