private double getCornerRadius(final String rx, final String ry) { final double cx = SVGAttributeParser.toPixelValue(rx, 0d); final double cy = SVGAttributeParser.toPixelValue(ry, 0d); return cx > cy ? cx : cy; } }
private static ViewDefinition.ViewBoxDefinition build(final String x, final String y, final String width, final String height) { return new ViewBoxDefinitionImpl(SVGAttributeParser.toPixelValue(x, 0d), SVGAttributeParser.toPixelValue(y, 0d), SVGAttributeParser.toPixelValue(width), SVGAttributeParser.toPixelValue(height)); } }
public static double toPixelValue(final String value, final double defaultValue) { if (isEmpty(value)) { return defaultValue; } return toPixelValue(value); }
@Override public RectDefinition doTranslate(final Element rectElement, final SVGTranslatorContext context) { final String rx = rectElement.getAttribute(RX); final String ry = rectElement.getAttribute(RY); final String width = rectElement.getAttribute(WIDTH); final String height = rectElement.getAttribute(HEIGHT); return new RectDefinition(getId(rectElement), SVGAttributeParser.toPixelValue(width), SVGAttributeParser.toPixelValue(height), getCornerRadius(rx, ry)); }
private static double[] parseTransform(final String raw) throws TranslatorException { double sx = 1; double sy = 1; double tx = 0; double ty = 0; final String[] split = raw.split(" "); for (final String transformDec : split) { final Matcher m = TRANSFORM_PATTERN.matcher(transformDec); if (m.matches()) { final String op = m.group(1).trim(); final String x = m.group(2).trim(); final String y = m.group(3).trim(); switch (op) { case TRANSFORM_SCALE: sx = SVGAttributeParser.toPixelValue(x); sy = SVGAttributeParser.toPixelValue(y); break; case TRANSFORM_TRANSLATE: tx = SVGAttributeParser.toPixelValue(x); ty = SVGAttributeParser.toPixelValue(y); break; } } else { throw new TranslatorException("Unrecognized transform attribute value format [" + raw + "]"); } } return new double[]{sx, sy, tx, ty}; }
@Override public CircleDefinition doTranslate(final Element rectElement, final SVGTranslatorContext context) { final String radius = rectElement.getAttribute(RADIUS); return new CircleDefinition(getId(rectElement), SVGAttributeParser.toPixelValue(radius)); }
protected void translatePosition(final E element, final O def, final SVGTranslatorContext context) throws TranslatorException { final String xr = element.getAttribute(getXAttributeName()); final String yr = element.getAttribute(getYAttributeName()); final double x = SVGAttributeParser.toPixelValue(xr, 0d); final double y = SVGAttributeParser.toPixelValue(yr, 0d); def.setX(x); def.setY(y); }
@Test public void testPixelValues() { assertEquals(0d, SVGAttributeParser.toPixelValue("0"), 0d); assertEquals(0d, SVGAttributeParser.toPixelValue("0px"), 0d); assertEquals(10d, SVGAttributeParser.toPixelValue("10px"), 0d); assertEquals(1328.5d, SVGAttributeParser.toPixelValue("1328.5"), 0d); assertEquals(1328.5d, SVGAttributeParser.toPixelValue("1328.5px"), 0d); assertEquals(0d, SVGAttributeParser.toPixelValue("", 0d), 0d); assertEquals(12.3d, SVGAttributeParser.toPixelValue("", 12.3d), 0d); assertEquals(3d, SVGAttributeParser.toPixelValue(null, 3d), 0d); }
switch (property) { case OPACITY: builder.setAlpha(SVGAttributeParser.toPixelValue(value)); break; case FILL: builder.setFillAlpha(SVGAttributeParser.toPixelValue(value)); break; case STROKE: builder.setStrokeAlpha(SVGAttributeParser.toPixelValue(value)); break; case STROKE_WIDTH: builder.setStrokeWidth(SVGAttributeParser.toPixelValue(value)); break; case STROKE_DASHARRAY: break; case FONT_SIZE: builder.setFontSize(SVGAttributeParser.toPixelValue(value)); break;
throw new TranslatorException("The SVG node [" + svgId + "] must contain a valid HEIGHT attribute."); svgCoord[0] = SVGAttributeParser.toPixelValue(x, X_DEFAULT); svgCoord[1] = SVGAttributeParser.toPixelValue(y, Y_DEFAULT); svgSize[0] = SVGAttributeParser.toPixelValue(width); svgSize[1] = SVGAttributeParser.toPixelValue(height); final String vbox = svgNode.getAttribute(VIEW_BOX); if (StringUtils.isEmpty(vbox)) {