mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JRE-269 JLabel doesn't scale <code>text</code> HTML fragments.
(cherry picked from commit 9ef72b6c3a477e4225f9b98e30fa9190613520e4)
(cherry picked from commit c17bc728ee)
This commit is contained in:
committed by
alexey.ushakov@jetbrains.com
parent
e4a49b2664
commit
0d045e6a0c
@@ -27,14 +27,13 @@ package javax.swing.plaf.basic;
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.text.html.*;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
/**
|
||||
* Support for providing html views for the swing components.
|
||||
* This translates a simple html string to a javax.swing.text.View
|
||||
@@ -45,6 +44,14 @@ import sun.swing.SwingUtilities2;
|
||||
* @since 1.3
|
||||
*/
|
||||
public class BasicHTML {
|
||||
// Rebase CSS size map to let relative font sizes scale properly.
|
||||
private final static boolean REBASE_CSS_SIZE_MAP =
|
||||
java.security.AccessController.doPrivileged(
|
||||
(PrivilegedAction<Boolean>)
|
||||
() -> Boolean.getBoolean(
|
||||
"javax.swing.rebaseCssSizeMap"));
|
||||
|
||||
private final static String JLABEL_USER_CSS_KEY = "javax.swing.JLabel.userStyleSheet";
|
||||
|
||||
/**
|
||||
* Constructs a {@code BasicHTML}.
|
||||
@@ -63,6 +70,12 @@ public class BasicHTML {
|
||||
BasicEditorKit kit = getFactory();
|
||||
Document doc = kit.createDefaultDocument(c.getFont(),
|
||||
c.getForeground());
|
||||
if (c instanceof JLabel) {
|
||||
Object userCss = UIManager.getDefaults().get(JLABEL_USER_CSS_KEY);
|
||||
if (userCss instanceof StyleSheet) {
|
||||
((HTMLDocument)doc).getStyleSheet().addStyleSheet((StyleSheet)userCss);
|
||||
}
|
||||
}
|
||||
Object base = c.getClientProperty(documentBaseKey);
|
||||
if (base instanceof URL) {
|
||||
((HTMLDocument)doc).setBase((URL)base);
|
||||
@@ -411,6 +424,10 @@ public class BasicHTML {
|
||||
private void setFontAndColor(Font font, Color fg) {
|
||||
getStyleSheet().addRule(sun.swing.SwingUtilities2.
|
||||
displayPropertiesToCSS(font,fg));
|
||||
if (REBASE_CSS_SIZE_MAP && font != null) {
|
||||
// See: javax.swing.plaf.basic.BasicEditorPaneUI.updateCSS()
|
||||
if (font != null) getStyleSheet().addRule("BASE_SIZE " + font.getSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user