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; }
/** 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; }