public static void scale(final Shape shape, final double width, final double height) { final BoundingBox bb = shape.getBoundingBox(); final double[] scale = getScaleFactor(bb.getWidth(), bb.getHeight(), width, height); shape.setScale(scale[0], scale[1]); }
@Override @SuppressWarnings("unchecked") public Group render(final ShapeGlyph glyph, final double width, final double height) { final String definitionId = glyph.getDefinitionId(); final Supplier<ShapeFactory> factorySupplier = glyph.getFactorySupplier(); final Shape shape = factorySupplier.get().newShape(factoryManager.newDefinition(definitionId)); final ShapeView<?> view = shape.getShapeView(); final BoundingBox bb = boundingBoxProvider.apply(view); Group group = groupProvider.apply(view); if (null == group) { throw new RuntimeException("Shape view [" + view.toString() + "] not supported for " + "this shape glyph builder [" + this.getClass().getName()); } if (view instanceof HasTitle) { final HasTitle hasTitle = (HasTitle) view; hasTitle.setTitle(null); } // Create a copy of this view. group = group.copy(); // Scale, if necessary, to the given glyph size. final double[] scale = LienzoShapeUtils.getScaleFactor(bb.getWidth(), bb.getHeight(), width, height); group.setScale(scale[0], scale[1]); return group; }
protected void scale(final int width, final int height, final int toWidth, final int toHeight, final boolean keepAspectRatio) { if (null != getHandler() && null != getHandler().getDiagram()) { final double[] sfactor = LienzoShapeUtils.getScaleFactor(width, height, toWidth, toHeight); if (0 != Double.compare(1, sfactor[0]) || 0 != Double.compare(1, sfactor[1])) { final double[] factor = getScaleFactor(sfactor, keepAspectRatio); // Scale the canvas/layer using scale method from the zoom control. getZoomControl().scale(factor[0], factor[1]); // Scale the panel widget - delegated to implementations. scalePanel(toWidth, toHeight); } } else { LOGGER.log(Level.WARNING, "Nothing to scale!"); } }