Scale the interface fractionally on Linux
Java2D on X11 (and so under XWayland) truncates its scale to a whole number, drawing 150 % at 100 %. On Linux, pin Java2D to 1 and hand the full factor to FlatLaf, taken from XSETTINGS Xft/DPI, KWin's Xwayland scale or GDK_SCALE, or chosen in Options → Design. The client's own sizes now go through UIScale: borders, gaps, dialog and row sizes, icons (rendered at the scaled size, so they stay crisp), custom-painted components and font sizes in the HTML views. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package com.ts3client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.ts3client.text.BBCode;
|
||||
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.html.StyleSheet;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
/**
|
||||
* The HTML panes showing TeamSpeak text — chat logs, client and channel information —
|
||||
@@ -70,7 +73,7 @@ final class HtmlStyles {
|
||||
|
||||
private static void installKit(JEditorPane pane, String html, boolean atEnd) {
|
||||
HTMLEditorKit kit = new HTMLEditorKit();
|
||||
StyleSheet css = new StyleSheet();
|
||||
StyleSheet css = new ScaledStyleSheet();
|
||||
css.addStyleSheet(kit.getStyleSheet());
|
||||
|
||||
Object bodyStyle = pane.getClientProperty(BODY_STYLE);
|
||||
@@ -102,7 +105,24 @@ final class HtmlStyles {
|
||||
}
|
||||
}
|
||||
|
||||
/** A CSS length of {@code px} at the interface scale. */
|
||||
static String px(int px) {
|
||||
return UIScale.scale(px) + "px";
|
||||
}
|
||||
|
||||
private static String hex(Color c) {
|
||||
return String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales every font size, the way a browser scales CSS pixels: Swing takes a
|
||||
* {@code font-size} in pixels literally, and the text is written in unscaled ones.
|
||||
*/
|
||||
private static final class ScaledStyleSheet extends StyleSheet {
|
||||
@Override
|
||||
public Font getFont(AttributeSet a) {
|
||||
Font font = super.getFont(a);
|
||||
return UIScale.getUserScaleFactor() == 1f ? font : font.deriveFont(UIScale.scale(font.getSize2D()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user