/** * <b>DOM</b>: Implements {@link SVGRect#getHeight()}. */ public float getHeight() { if (hasAnimVal) { return super.getHeight(); } return getBaseVal().getHeight(); }
/** * <b>DOM</b>: Implements {@link SVGRect#getHeight()}. */ public float getHeight() { if (hasAnimVal) { return super.getHeight(); } return getBaseVal().getHeight(); }
/** * <b>DOM</b>: Implements {@link SVGRect#getHeight()}. */ public float getHeight() { if (hasAnimVal) { return super.getHeight(); } return getBaseVal().getHeight(); }
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); } }); }
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(); } }
public boolean isImgHorizontallyOriented() { SVGSVGElement svg = getSVGRootElement(); SVGRect rect = svg.getRectTrait(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (rect != null) { return (rect.getWidth() > rect.getHeight()); } else { return false; } }
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 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; }
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}; } }
/** * 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); }
private Map<String, String[]> rotateElements() { SceneManager m_sceneMgr = getSceneManager(); int angle = rotateRight ? 90 : -90; SVGSVGElement svgRoot = m_sceneMgr.getPerseusController().getSVGRootElement(); SVGRect viewBoxRect = svgRoot.getRectTrait(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); float translateH = viewBoxRect != null ? viewBoxRect.getHeight() : 0f; float translateW = viewBoxRect != null ? viewBoxRect.getWidth() : 0f; float[] translate = rotateRight ? new float[]{ translateH, 0f} : new float[]{ 0f, translateW}; SVGElement elem = (SVGElement) svgRoot.getFirstElementChild(); Rectangle bBox = new Rectangle(); Map<String, String[]> textChanges = new HashMap<String, String[]>(); while (elem != null) { // process rotateElement(elem, angle, translate, textChanges, bBox); // get next elem = (SVGElement) elem.getNextElementSibling(); } //getModel().setAttributes(textChanges); m_sceneMgr.getScreenManager().repaint(bBox, SVGObjectOutline.SELECTOR_OVERLAP); m_sceneMgr.getScreenManager().refresh(); return textChanges; }
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; }
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 }