/** * <b>DOM</b>: Implements {@link SVGRect#getX()}. */ public float getX() { if (hasAnimVal) { return super.getX(); } return getBaseVal().getX(); }
/** * <b>DOM</b>: Implements {@link SVGRect#getX()}. */ public float getX() { if (hasAnimVal) { return super.getX(); } return getBaseVal().getX(); }
/** * <b>DOM</b>: Implements {@link SVGRect#getX()}. */ public float getX() { if (hasAnimVal) { return super.getX(); } return getBaseVal().getX(); }
public static boolean areEqual(SVGRect rect1, SVGRect rect2) { if (rect1 == rect2) { return true; } else if ( rect1 == null || rect2 == null) { return false; } else { return rect1.getX() == rect2.getX() && rect1.getY() == rect2.getY() && rect1.getWidth() == rect2.getWidth() && rect1.getHeight() == rect2.getHeight(); } }
private float[] prepareScalePivot(SVGRect rect){ float[] tempScalePivot = getCurrentScalePivot().isNWCorner() ? new float[]{rect.getX(), rect.getY()} : new float[]{rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight()}; float[] scalePivot = new float[2]; m_initialTransform.transformPoint(tempScalePivot, scalePivot); return scalePivot; }
/** public static SVGRect getMaxBBox(SVGLocatableElement elem) { SVGRect bBox = elem.getBBox(); SceneManager.log(Level.SEVERE, "Null BBox for element:" + elem); //NOI18N ModelNode child = ((ModelNode) elem).getFirstChildNode(); while (child != null) { if (child instanceof SVGLocatableElement) { SceneManager.log(Level.SEVERE, " element:" + child); //NOI18N bBox = calculateMaxBBox(bBox, getMaxBBox((SVGLocatableElement) child)); child = child.getNextSiblingNode(); } } return bBox; } */ private static SVGRect calculateMaxBBox(SVGRect bBox, SVGRect tmpBBox) { if (bBox == null) { bBox = tmpBBox; } else if (tmpBBox != null) { float x1 = Math.min(bBox.getX(), tmpBBox.getX()); float y1 = Math.min(bBox.getY(), tmpBBox.getY()); float x2 = Math.max(bBox.getWidth() + bBox.getX(), tmpBBox.getWidth() + tmpBBox.getX()); float y2 = Math.max(bBox.getHeight() + bBox.getY(), tmpBBox.getHeight() + tmpBBox.getY()); bBox.setX(x1); bBox.setY(y1); bBox.setWidth(x2 - x1); bBox.setHeight(y2 - y1); } return bBox; }
public static SVGRect scale(SVGRect rect, float scale) { return new Box( rect.getX() * scale, rect.getY() * scale, rect.getWidth() * scale, rect.getHeight() * scale); } public static float calcAngle(float x1, float y1, float x2, float y2) {
public static float [][] transformRectangle( SVGRect rect, Transform txf, float [][] coords) { float x = rect.getX(), y = rect.getY(), w = rect.getWidth(), h = rect.getHeight(); float [][] points = new float[][] { {x, y}, {x+w, y}, {x+w, y+h}, {x, y+h} }; assert coords.length == 4; for (int i = 0; i < 4; i++) { txf.transformPoint(points[i], coords[i]); } return coords; } }
/** * Returns the base value of the attribute as an {@link AnimatableValue}. */ public AnimatableValue getUnderlyingValue(AnimationTarget target) { SVGRect r = getBaseVal(); return new AnimatableRectValue (target, r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
/** * Returns the base value of the attribute as an {@link AnimatableValue}. */ public AnimatableValue getUnderlyingValue(AnimationTarget target) { SVGRect r = getBaseVal(); return new AnimatableRectValue (target, r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
private float[] prepareRotatePivot(SVGRect rect){ if (!m_lanscapeUpdate) { //AVK float[] tempRotatePivot = m_rotatePivot != null ? m_rotatePivot : new float[]{ //AVK rect.getX() + rect.getWidth() / 2, //AVK rect.getY() + rect.getHeight() / 2 //AVK }; float[] tempRotatePivot = new float[]{ rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2 }; float[] rotatePivot = new float[2]; m_initialTransform.transformPoint(tempRotatePivot, rotatePivot); return rotatePivot; } else { return new float[]{0f, 0f}; } }
public void setViewBox(final SVGRect rect){ if (rect == null){ return; } final DocumentElement svgRoot = getSVGRoot(m_model); final String [] attributes = new String[]{ SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, rect.getX() + " " + rect.getY() + " " + rect.getWidth() + " " +rect.getHeight(), SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(rect.getWidth()), SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(rect.getHeight()) }; runTransaction(new FileModelTransaction() { protected void transaction() throws BadLocationException { doSetAttributes(svgRoot, attributes, null, false); } }); }
/** * Returns the base value of the attribute as an {@link AnimatableValue}. */ public AnimatableValue getUnderlyingValue(AnimationTarget target) { SVGRect r = getBaseVal(); return new AnimatableRectValue (target, r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
protected void paintPanel(Graphics g, int x, int y) { PerseusController perseus = m_sceneMgr.getPerseusController(); if (perseus != null) { if (m_showAllArea) { SVGLocatableElement elem = perseus.getViewBoxMarker(); if (elem != null) { SVGRect rect = elem.getScreenBBox(); g.setColor( VIEWBOXBORDER_COLOR); g.drawRect((int)(x + rect.getX()), (int)(y + rect.getY()), (int)(rect.getWidth()), (int)(rect.getHeight()) - 1); } } boolean isReadOnly = m_sceneMgr.isReadOnly(); Stack<ComposerAction> actions = m_sceneMgr.getActiveActions(); synchronized( actions) { for (int i = actions.size()-1; i >= 0; i--) { actions.get(i).paint(g, x, y, isReadOnly); } } } } };
/** * Returns the transformation matrix to apply to initialize a viewport or * null if the specified viewBox disables the rendering of the element. * * @param e the element with a viewbox * @param aViewBox the viewBox definition * @param aPAR the preserveAspectRatio definition * @param w the width of the effective viewport * @param h the height of the effective viewport * @param ctx the BridgeContext to use for error information */ public static AffineTransform getPreserveAspectRatioTransform (Element e, SVGAnimatedRect aViewBox, SVGAnimatedPreserveAspectRatio aPAR, float w, float h, BridgeContext ctx) { if (!((SVGOMAnimatedRect) aViewBox).isSpecified()) { // no viewBox specified return new AffineTransform(); } SVGRect viewBox = aViewBox.getAnimVal(); float[] vb = new float[] { viewBox.getX(), viewBox.getY(), viewBox.getWidth(), viewBox.getHeight() }; return getPreserveAspectRatioTransform(e, vb, w, h, aPAR, ctx); }
/** * Returns the transformation matrix to apply to initialize a viewport or * null if the specified viewBox disables the rendering of the element. * * @param e the element with a viewbox * @param aViewBox the viewBox definition * @param aPAR the preserveAspectRatio definition * @param w the width of the effective viewport * @param h the height of the effective viewport * @param ctx the BridgeContext to use for error information */ public static AffineTransform getPreserveAspectRatioTransform (Element e, SVGAnimatedRect aViewBox, SVGAnimatedPreserveAspectRatio aPAR, float w, float h, BridgeContext ctx) { if (!((SVGOMAnimatedRect) aViewBox).isSpecified()) { // no viewBox specified return new AffineTransform(); } SVGRect viewBox = aViewBox.getAnimVal(); float[] vb = new float[] { viewBox.getX(), viewBox.getY(), viewBox.getWidth(), viewBox.getHeight() }; return getPreserveAspectRatioTransform(e, vb, w, h, aPAR, ctx); }
/** * Returns the transformation matrix to apply to initialize a viewport or * null if the specified viewBox disables the rendering of the element. * * @param e the element with a viewbox * @param aViewBox the viewBox definition * @param aPAR the preserveAspectRatio definition * @param w the width of the effective viewport * @param h the height of the effective viewport * @param ctx the BridgeContext to use for error information */ public static AffineTransform getPreserveAspectRatioTransform (Element e, SVGAnimatedRect aViewBox, SVGAnimatedPreserveAspectRatio aPAR, float w, float h, BridgeContext ctx) { if (!((SVGOMAnimatedRect) aViewBox).isSpecified()) { // no viewBox specified return new AffineTransform(); } SVGRect viewBox = aViewBox.getAnimVal(); float[] vb = new float[] { viewBox.getX(), viewBox.getY(), viewBox.getWidth(), viewBox.getHeight() }; return getPreserveAspectRatioTransform(e, vb, w, h, aPAR, ctx); }
(svgRect.getX(), svgRect.getY(), svgRect.getWidth(), svgRect.getHeight()); AffineTransform ati = svgGN.getGlobalTransform();
private Map<DocumentElement, String[]> changeViewBox(boolean isLandscape) { SVGSVGElement svg = getSceneManager().getPerseusController().getSVGRootElement(); SVGRect rect = svg.getRectTrait(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (getScreenManager().isLandscapeMode() != isLandscape){ // exchange width and height float w = rect.getWidth(); float h = rect.getHeight(); rect.setHeight(w); rect.setWidth(h); DocumentElement svgRoot = getModel().getSVGRoot(getModel().getModel()); String[] attributes = new String[]{ SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, rect.getX() + " " + rect.getY() + " " + rect.getWidth() + " " + rect.getHeight(),//NOI18N SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(rect.getWidth()), SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(rect.getHeight()) }; Map<DocumentElement, String[]> textChanges = new HashMap<DocumentElement, String[]>(); textChanges.put(svgRoot, attributes); return textChanges; } return null; }
void initialize() { m_svgImage = m_sceneMgr.getSVGImage(); m_svgDoc = (DocumentNode) m_svgImage.getDocument(); m_animator = (SVGAnimatorImpl) SVGAnimator.createAnimator( m_svgImage, "javax.swing.JComponent"); //NOI18N m_animationState = containsAnimation(m_svgDoc) ? ANIMATION_NOT_RUNNING : ANIMATION_NOT_AVAILABLE; SVGSVGElement svg = getSVGRootElement(); SVGRect rect = svg.getRectTrait(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (rect != null) { m_viewBoxMarker = (SVGLocatableElement) m_svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_RECT_TAG); m_viewBoxMarker.setId(ID_VIEWBOX_MARKER); m_viewBoxMarker.setTrait(SVGConstants.SVG_FILL_ATTRIBUTE, "none"); //NOI18N m_viewBoxMarker.setTrait(SVGConstants.SVG_STROKE_ATTRIBUTE, "none"); //NOI18N m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_X_ATTRIBUTE, rect.getX()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_Y_ATTRIBUTE, rect.getY()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_WIDTH_ATTRIBUTE, rect.getWidth()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_HEIGHT_ATTRIBUTE, rect.getHeight()); svg.appendChild(m_viewBoxMarker); } else { m_viewBoxMarker = null; } // we need to get the animator into the 'paused' state so that // all changes are immediately visible m_animator.play(); m_animator.pause(); SceneManager.log(Level.INFO, toString() + " initialized."); //NOI18N }