@Test public void testLayerToDataURL() { ScratchPad scratchPad = mock(ScratchPad.class); Context2D context2D = mock(Context2D.class); when(layer.getScratchPad()).thenReturn(scratchPad); when(scratchPad.getContext()).thenReturn(context2D); when(scratchPad.toDataURL(eq(DataURLType.JPG), eq(1d))).thenReturn("theResultData"); String result = LienzoLayerUtils.layerToDataURL(lienzoLayer, DataURLType.JPG, 1, 3, 111, 333, "#color1"); assertEquals("theResultData", result); verify(scratchPad, times(1)).setPixelSize(eq(111), eq(333)); verify(scratchPad, times(1)).clear(); verify(context2D, times(1)).setFillColor(eq("#color1")); verify(context2D, times(1)).fillRect(eq(0d), eq(0d), eq(111d), eq(333d)); verify(layer, times(1)).drawWithTransforms(eq(context2D), eq(1d), eq(new BoundingBox(1d, 3d, 111d, 333d))); }
public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) { final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer(); final ScratchPad scratchPad = layer.getScratchPad(); scratchPad.setPixelSize(width, height); if (null != bgColor) { scratchPad.getContext().setFillColor(bgColor); scratchPad.getContext().fillRect(0, 0, width, height); } layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height)); final String data = scratchPad.toDataURL(dataURLType, 1); scratchPad.clear(); return data; }
LienzoLayerUtils { public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) { final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer(); final ScratchPad scratchPad = layer.getScratchPad(); scratchPad.setPixelSize(width, height); if (null != bgColor) { scratchPad.getContext().setFillColor(bgColor); scratchPad.getContext().fillRect(0, 0, width, height); } layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height)); final String data = scratchPad.toDataURL(dataURLType, 1); scratchPad.clear(); return data; } }
LienzoLayerUtils { public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) { final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer(); final ScratchPad scratchPad = layer.getScratchPad(); scratchPad.setPixelSize(width, height); if (null != bgColor) { scratchPad.getContext().setFillColor(bgColor); scratchPad.getContext().fillRect(0, 0, width, height); } layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height)); final String data = scratchPad.toDataURL(dataURLType, 1); scratchPad.clear(); return data; }  }
LienzoLayerUtils { public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) { final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer(); final ScratchPad scratchPad = layer.getScratchPad(); scratchPad.setPixelSize(width, height); if (null != bgColor) { scratchPad.getContext().setFillColor(bgColor); scratchPad.getContext().fillRect(0, 0, width, height); } layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height)); final String data = scratchPad.toDataURL(dataURLType, 1); scratchPad.clear(); return data; }  static String layerToDataURL(final LienzoLayer lienzoLayer,
                                        final DataURLType dataURLType,
                                        final int x,
                                        final int y,
                                        final int width,
                                        final int height,
                                        final String bgColor); static Bounds computeBounds(final LienzoLayer layer); static String getUUID_At(final LienzoLayer lienzoLayer,
                                    final double x,
                                    final double y); }
LienzoLayerUtils { public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) { final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer(); final ScratchPad scratchPad = layer.getScratchPad(); scratchPad.setPixelSize(width, height); if (null != bgColor) { scratchPad.getContext().setFillColor(bgColor); scratchPad.getContext().fillRect(0, 0, width, height); } layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height)); final String data = scratchPad.toDataURL(dataURLType, 1); scratchPad.clear(); return data; }  static String layerToDataURL(final LienzoLayer lienzoLayer,
                                        final DataURLType dataURLType,
                                        final int x,
                                        final int y,
                                        final int width,
                                        final int height,
                                        final String bgColor); static Bounds computeBounds(final LienzoLayer layer); static String getUUID_At(final LienzoLayer lienzoLayer,
                                    final double x,
                                    final double y);  }