@Override public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle) throws JRException { ensureSvg(jasperReportsContext); AffineTransform transform = ViewBox.getPreserveAspectRatioTransform( new float[]{0, 0, (float) documentSize.getWidth(), (float) documentSize.getHeight()}, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE, true, (float) rectangle.getWidth(), (float) rectangle.getHeight()); Graphics2D graphics = (Graphics2D) grx.create(); try { graphics.translate(rectangle.getX(), rectangle.getY()); graphics.transform(transform); // CompositeGraphicsNode not thread safe synchronized (rootNode) { rootNode.paint(graphics); } } finally { graphics.dispose(); } }
/** * Returns the transformation matrix to apply to initalize a viewport or * null if the specified viewBox disables the rendering of the element. * * @param e the element with a viewbox * @param vb the viewBox definition as float * @param w the width of the effective viewport * @param h The height of the effective viewport * @param aPAR The animated preserveAspectRatio value * @param ctx The BridgeContext to use for error information */ public static AffineTransform getPreserveAspectRatioTransform (Element e, float[] vb, float w, float h, SVGAnimatedPreserveAspectRatio aPAR, BridgeContext ctx) { // 'preserveAspectRatio' attribute try { SVGPreserveAspectRatio pAR = aPAR.getAnimVal(); short align = pAR.getAlign(); boolean meet = pAR.getMeetOrSlice() == SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET; return getPreserveAspectRatioTransform(vb, align, meet, w, h); } catch (LiveAttributeException ex) { throw new BridgeException(ctx, ex); } }
@Override public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle) throws JRException { GraphicsNode rootNode = getRootNode(jasperReportsContext); AffineTransform transform = ViewBox.getPreserveAspectRatioTransform( new float[]{0, 0, (float) documentSize.getWidth(), (float) documentSize.getHeight()}, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE, true, (float) rectangle.getWidth(), (float) rectangle.getHeight() ); Graphics2D graphics = (Graphics2D) grx.create(); try { graphics.translate(rectangle.getX(), rectangle.getY()); graphics.transform(transform); // CompositeGraphicsNode not thread safe synchronized (rootNode) { rootNode.paint(graphics); } } finally { graphics.dispose(); } }
/** * <b>DOM</b>: Implements {@link SVGAnimatedPreserveAspectRatio#getBaseVal()}. */ public SVGPreserveAspectRatio getBaseVal() { if (baseVal == null) { baseVal = new BaseSVGPARValue(); } return baseVal; }
/** * <b>DOM</b>: Implements {@link SVGAnimatedPreserveAspectRatio#getAnimVal()}. */ public SVGPreserveAspectRatio getAnimVal() { if (animVal == null) { animVal = new AnimSVGPARValue(); } return animVal; }
/** * Returns a string representation of this object. */ public String toStringRep() { if (align < 1 || align > 10) { return null; } String value = ALIGN_VALUES[align]; if (align == SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE) { return value; } if (meetOrSlice < 1 || meetOrSlice > 2) { return null; } return value + ' ' + MEET_OR_SLICE_VALUES[meetOrSlice]; }
/** * Implements {@link * PreserveAspectRatioHandler#startPreserveAspectRatio()}. */ public void startPreserveAspectRatio() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_UNKNOWN; meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_UNKNOWN; }
/** * Implements {@link PreserveAspectRatioHandler#none()}. */ public void none() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE; }
/** * Implements {@link PreserveAspectRatioHandler#xMaxYMax()}. */ public void xMaxYMax() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMAX; }
/** * Implements {@link PreserveAspectRatioHandler#xMaxYMid()}. */ public void xMaxYMid() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID; }
/** * Implements {@link PreserveAspectRatioHandler#xMaxYMin()}. */ public void xMaxYMin() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN; }
/** * Implements {@link PreserveAspectRatioHandler#xMidYMax()}. */ public void xMidYMax() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMAX; }
/** * Implements {@link PreserveAspectRatioHandler#xMidYMid()}. */ public void xMidYMid() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID; }
/** * Implements {@link PreserveAspectRatioHandler#xMidYMin()}. */ public void xMidYMin() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN; }
/** * Implements {@link PreserveAspectRatioHandler#xMinYMax()}. */ public void xMinYMax() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMAX; }
/** * Implements {@link PreserveAspectRatioHandler#xMinYMid()}. */ public void xMinYMid() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID; }
/** * Implements {@link PreserveAspectRatioHandler#xMinYMin()}. */ public void xMinYMin() throws ParseException { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN; }
/** * Implements {@link PreserveAspectRatioHandler#meet()}. */ public void meet() throws ParseException { meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET; }
/** * Implements {@link PreserveAspectRatioHandler#slice()}. */ public void slice() throws ParseException { meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE; }
public void reset() { align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID; meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET; //setAttributeValue(getValueAsString()); }
/** * Returns the base value of the attribute as an {@link AnimatableValue}. */ public AnimatableValue getUnderlyingValue(AnimationTarget target) { SVGPreserveAspectRatio par = getBaseVal(); return new AnimatablePreserveAspectRatioValue(target, par.getAlign(), par.getMeetOrSlice()); }
/** * Returns a zero value of this AnimatableValue's type. */ public AnimatableValue getZeroValue() { return new AnimatablePreserveAspectRatioValue (target, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE, SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET); }