From 8d722b0fe116b0d4ef08018e48b6e97ef4f5a277 Mon Sep 17 00:00:00 2001 From: Ronald Roskens Date: Sun, 25 Nov 2012 18:43:41 -0600 Subject: [PATCH] NMS-2691 - JRobin --font handling --- .../netmgt/rrd/jrobin/JRobinRrdStrategy.java | 60 ++++++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/opennms-rrd/opennms-rrd-jrobin/src/main/java/org/opennms/netmgt/rrd/jrobin/JRobinRrdStrategy.java b/opennms-rrd/opennms-rrd-jrobin/src/main/java/org/opennms/netmgt/rrd/jrobin/JRobinRrdStrategy.java index 5700424..95c44eb 100644 --- a/opennms-rrd/opennms-rrd-jrobin/src/main/java/org/opennms/netmgt/rrd/jrobin/JRobinRrdStrategy.java +++ b/opennms-rrd/opennms-rrd-jrobin/src/main/java/org/opennms/netmgt/rrd/jrobin/JRobinRrdStrategy.java @@ -29,6 +29,7 @@ package org.opennms.netmgt.rrd.jrobin; import java.awt.Color; +import java.awt.Font; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -725,23 +726,60 @@ public class JRobinRrdStrategy implements RrdStrategy { } private void processRrdFontArgument(RrdGraphDef graphDef, String argParm) { - /* - String[] argValue = tokenize(argParm, ":", true); - if (argValue[0].equals("DEFAULT")) { + String[] argValue = tokenize(argParm, ":", false); + if (argValue.length < 2 || argValue.length > 3) { + log().warn("invalid number of arguments ("+argValue.length+") for font argument " + argParm); + return; + } int newPointSize = Integer.parseInt(argValue[1]); - graphDef.setSmallFont(graphDef.getSmallFont().deriveFont(newPointSize)); + int fontTag; + Font font; + + if (argValue[0].equals("DEFAULT")) { + fontTag = RrdGraphDef.FONTTAG_DEFAULT; } else if (argValue[0].equals("TITLE")) { - int newPointSize = Integer.parseInt(argValue[1]); - graphDef.setLargeFont(graphDef.getLargeFont().deriveFont(newPointSize)); + fontTag = RrdGraphDef.FONTTAG_TITLE; + } else if (argValue[0].equals("AXIS")) { + fontTag = RrdGraphDef.FONTTAG_AXIS; + } else if (argValue[0].equals("UNIT")) { + fontTag = RrdGraphDef.FONTTAG_UNIT; + } else if (argValue[0].equals("LEGEND")) { + fontTag = RrdGraphDef.FONTTAG_LEGEND; + } else if (argValue[0].equals("WATERMARK")) { + fontTag = RrdGraphDef.FONTTAG_WATERMARK; } else { + log().warn("invalid font tag " + argValue[0]); + return; + } + try { - Font font = Font.createFont(Font.TRUETYPE_FONT, new File(argValue[0])); - } catch (Throwable e) { - // oh well, fall back to existing font stuff - log().warn("unable to create font from font argument " + argParm, e); + font = graphDef.getFont(fontTag); + + // If we have a font specified, try and get a font object for it. + if (argValue[2] != null && argValue[2].length() > 0) { + int origPointSize = font.getSize(); + font = Font.decode(argValue[2]); + + // Font.decode() returns a 12 px font size, by default unless you specify + // a font size in the font name pattern. + if (newPointSize > 0) { + font = font.deriveFont((float) newPointSize); + } else { + font = font.deriveFont((float) origPointSize); } + } else { + // If we don't have a font name specified, then we just adjust the font size. + font = font.deriveFont((float) newPointSize); + } + + if (fontTag == RrdGraphDef.FONTTAG_DEFAULT) { + graphDef.setFont(fontTag, font, true, newPointSize == 0); + } else { + graphDef.setFont(fontTag, font); + } + } catch (Throwable e) { + log().warn("unable to create font from font argument " + argParm + " " + e.getMessage()); } - */ } private String[] tokenize(final String line, final String delimiters, final boolean processQuotes) { -- 1.7.11.7