SvgTextUtil { public static float resolveFontSize(ISvgTextNodeRenderer renderer, float parentFontSize) { float fontSize = Float.NaN; String elementFontSize = renderer.getAttribute(SvgConstants.Attributes.FONT_SIZE); if (null != elementFontSize && !elementFontSize.isEmpty()) { if (CssUtils.isRelativeValue(elementFontSize) || CommonCssConstants.LARGER.equals(elementFontSize) || CommonCssConstants.SMALLER.equals(elementFontSize)) { fontSize = CssUtils.parseRelativeFontSize(elementFontSize, parentFontSize); } else { fontSize = CssUtils.parseAbsoluteFontSize(elementFontSize, CommonCssConstants.PX); } } if ((Float.isNaN(fontSize)) || fontSize < 0f) { fontSize = parentFontSize; } return fontSize; } private  SvgTextUtil(); static String trimLeadingWhitespace(String toTrim); static String trimTrailingWhitespace(String toTrim); static void processWhiteSpace(TextSvgBranchRenderer root, boolean isLeadingElement); static boolean isOnlyWhiteSpace(String s); static float resolveFontSize(ISvgTextNodeRenderer renderer, float parentFontSize); static String filterReferenceValue(String name);  }
@Test public void processFontSizeInEM() { float expected = 120; TextSvgBranchRenderer root = new TextSvgBranchRenderer(); root.setAttribute(SvgConstants.Attributes.FONT_SIZE, "12em"); float actual = SvgTextUtil.resolveFontSize(root, 10); Assert.assertEquals(expected, actual, EPS); }
@Test public void processFontSizeInPX() { float expected = 24; TextSvgBranchRenderer root = new TextSvgBranchRenderer(); root.setAttribute(SvgConstants.Attributes.FONT_SIZE, "32px"); float actual = SvgTextUtil.resolveFontSize(root, 10); Assert.assertEquals(expected, actual, EPS); }
@Test public void processFontSizeInPT() { float expected = 24; TextSvgBranchRenderer root = new TextSvgBranchRenderer(); root.setAttribute(SvgConstants.Attributes.FONT_SIZE, "24pt"); float actual = SvgTextUtil.resolveFontSize(root, 10); Assert.assertEquals(expected, actual, EPS); }
@Test public void processKeywordedFontSize() { float expected = 24; TextSvgBranchRenderer root = new TextSvgBranchRenderer(); root.setAttribute(SvgConstants.Attributes.FONT_SIZE, "xx-large"); float actual = SvgTextUtil.resolveFontSize(root, 10); Assert.assertEquals(expected, actual, EPS); }