Graphs: Clean up font setting, fix bugs (ticket #2684)

Unit font now monospaced on Linux and Mac as intended
Don't set Droid Sans font, not present in any platform by default
Fix font scaling for Japanese
Detect more RTL languages
Make fonts configurable
This commit is contained in:
zzz
2020-02-03 14:19:35 +00:00
parent c4fce448c3
commit 0f7bcbf4bb
3 changed files with 48 additions and 29 deletions

View File

@ -46,8 +46,17 @@ class SummaryRenderer {
private static final Color AREA_COLOR = new Color(100, 160, 200, 200);
private static final Color LINE_COLOR = new Color(0, 30, 110, 255);
private static final Color RESTART_BAR_COLOR = new Color(223, 13, 13, 255);
private static final String DEFAULT_FONT_NAME = System.getProperty("os.name").toLowerCase().contains("windows") ?
private static final boolean IS_WIN = SystemVersion.isWindows();
private static final String DEFAULT_FONT_NAME = IS_WIN ?
"Lucida Console" : "Monospaced";
private static final String DEFAULT_TITLE_FONT_NAME = "Dialog";
private static final String DEFAULT_LEGEND_FONT_NAME = "Dialog";
private static final String PROP_FONT_MONO = "routerconsole.graphFont.unit";
private static final String PROP_FONT_LEGEND = "routerconsole.graphFont.legend";
private static final String PROP_FONT_TITLE = "routerconsole.graphFont.title";
private static final int SIZE_MONO = 10;
private static final int SIZE_LEGEND = 10;
private static final int SIZE_TITLE = 13;
public SummaryRenderer(I2PAppContext ctx, SummaryListener lsnr) {
_log = ctx.logManager().getLog(SummaryRenderer.class);
@ -144,28 +153,30 @@ class SummaryRenderer {
def.setColor(RrdGraphDef.COLOR_MGRID, MGRID_COLOR);
def.setColor(RrdGraphDef.COLOR_FONT, FONT_COLOR);
def.setColor(RrdGraphDef.COLOR_FRAME, FRAME_COLOR);
def.setFont(RrdGraphDef.FONTTAG_DEFAULT, new Font(DEFAULT_FONT_NAME, Font.PLAIN, 10));
def.setFont(RrdGraphDef.FONTTAG_TITLE, new Font(DEFAULT_FONT_NAME, Font.PLAIN, 10));
def.setFont(RrdGraphDef.FONTTAG_AXIS, new Font("Droid Sans Mono", Font.PLAIN, 10));
def.setFont(RrdGraphDef.FONTTAG_UNIT, new Font(DEFAULT_FONT_NAME, Font.PLAIN, 10));
def.setFont(RrdGraphDef.FONTTAG_LEGEND, new Font("Droid Sans Mono", Font.PLAIN, 10));
// improve text legibility
String lang = Messages.getLanguage(_context);
Font small = def.getSmallFont();
Font large = def.getLargeFont();
if ("ar".equals(lang) || "jp".equals(lang) || ("zh".equals(lang) && !IS_WIN)) {
small = small.deriveFont(small.getSize2D() + 2.0f);
large = large.deriveFont(Font.PLAIN, large.getSize2D() + 3.0f);
} else {
// small = small.deriveFont(small.getSize2D() + 1.0f);
// if specified font family is missing, jrobin will use fallback
small = new Font("Droid Sans Mono", Font.PLAIN, 10);
// large = large.deriveFont(large.getSize2D() + 1.0f);
large = new Font("Droid Sans", Font.PLAIN, 13);
int smallSize = SIZE_MONO;
int legendSize = SIZE_LEGEND;
int largeSize = SIZE_TITLE;
if ("ar".equals(lang) || "ja".equals(lang) || ("zh".equals(lang) && !IS_WIN)) {
smallSize += 2;
legendSize += 2;
largeSize += 3;
}
def.setSmallFont(small);
def.setLargeFont(large);
String ssmall = _context.getProperty(PROP_FONT_MONO, DEFAULT_FONT_NAME);
String slegend = _context.getProperty(PROP_FONT_LEGEND, DEFAULT_LEGEND_FONT_NAME);
String stitle = _context.getProperty(PROP_FONT_TITLE, DEFAULT_TITLE_FONT_NAME);
Font small = new Font(ssmall, Font.PLAIN, smallSize);
Font legnd = new Font(slegend, Font.PLAIN, legendSize);
Font large = new Font(stitle, Font.PLAIN, largeSize);
// DEFAULT is unused since we set all the others
def.setFont(RrdGraphDef.FONTTAG_DEFAULT, small);
// AXIS is unused, we do not set any axis labels
def.setFont(RrdGraphDef.FONTTAG_AXIS, small);
def.setFont(RrdGraphDef.FONTTAG_UNIT, small);
def.setFont(RrdGraphDef.FONTTAG_LEGEND, legnd);
def.setFont(RrdGraphDef.FONTTAG_TITLE, large);
def.setTimeSpan(start/1000, end/1000);
def.setMinValue(0d);
@ -247,13 +258,14 @@ class SummaryRenderer {
long started = event.getKey().longValue();
if (started > start && started < end) {
// String legend = _t("Restart") + ' ' + sdf.format(new Date(started)) + " UTC " + event.getValue() + "\\l";
if ("ar".equals(lang)) {
String legend = _t("Restart") + ' ' + sdf.format(new Date(started)) + " - " + event.getValue() + "\\l";
def.vrule(started / 1000, RESTART_BAR_COLOR, legend, 2.0f);
String legend;
if ("ar".equals(lang) || "fa".equals(lang) || "iw".equals(lang)) {
// RTL languages
legend = _t("Restart") + ' ' + sdf.format(new Date(started)) + " - " + event.getValue() + "\\l";
} else {
String legend = _t("Restart") + ' ' + sdf.format(new Date(started)) + " [" + event.getValue() + "]\\l";
def.vrule(started / 1000, RESTART_BAR_COLOR, legend, 2.0f);
legend = _t("Restart") + ' ' + sdf.format(new Date(started)) + " [" + event.getValue() + "]\\l";
}
def.vrule(started / 1000, RESTART_BAR_COLOR, legend, 2.0f);
}
}
def.comment(sdf.format(new Date(start)) + "" + sdf.format(new Date(end)) + " UTC\\r");
@ -322,8 +334,6 @@ class SummaryRenderer {
}
}
private static final boolean IS_WIN = SystemVersion.isWindows();
/** translate a string */
private String _t(String s) {
// the RRD font doesn't have zh chars, at least on my system