use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class Scene method toDataURL.
// package protected
final String toDataURL(final Layer background) {
if (LienzoCore.IS_CANVAS_SUPPORTED) {
final ScratchPad scratch = new ScratchPad(getWidth(), getHeight());
final Context2D context = scratch.getContext();
final NFastArrayList<Layer> layers = getChildNodes();
BoundingBox bbox = getStorageBounds();
if (null == bbox) {
final Viewport viewport = getViewport();
if (null != viewport) {
bbox = viewport.getStorageBounds();
}
}
if (null != layers) {
final int size = layers.size();
if (null != background) {
background.drawWithTransforms(context, 1, bbox);
}
final IPathClipper clip = getPathClipper();
if ((null != clip) && (clip.isActive())) {
context.save();
clip.clip(context);
}
for (int i = size - 1; i >= 0; i--) {
final Layer layer = layers.get(i);
if ((null != layer) && (layer.isVisible())) {
layer.drawWithTransforms(context, 1, bbox);
}
}
if ((null != clip) && (clip.isActive())) {
context.restore();
}
}
return scratch.toDataURL();
} else {
return "data:,";
}
}
use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class MagnetManager method drawMagnetsToBack.
public ImageData drawMagnetsToBack(final Magnets magnets, final NFastStringMap<WiresShape> shapeColors, final NFastStringMap<WiresMagnet> magnetColors, final ScratchPad scratch) {
scratch.clear();
final Context2D ctx = scratch.getContext();
drawShapeToBacking(magnets, shapeColors, ctx);
magnetColors.clear();
for (int i = 0; i < magnets.size(); i++) {
drawMagnet(magnetColors, ctx, magnets.getMagnet(i));
}
return ctx.getImageData(0, 0, scratch.getWidth(), scratch.getHeight());
}
use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class ImageData method copy.
/**
* ImageData can't be cloned or deep-copied, it's an internal data structure and has some CRAZY crap in it, this is cheeeeeezy, but hey, it works, and it's portable!!!
*/
public final ImageData copy() {
final Context2D context = new ScratchPad(getWidth(), getHeight()).getContext();
context.putImageData(this, 0, 0);
return context.getImageData(0, 0, getWidth(), getHeight());
}
use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class BackingColorMapUtils method drawShapesToBacking.
public static ImageData drawShapesToBacking(final NFastArrayList<WiresShape> prims, final ScratchPad scratch, final WiresContainer skip, final NFastStringMap<WiresShape> shape_color_map) {
scratch.clear();
final Context2D ctx = scratch.getContext();
shape_color_map.clear();
drawShapesToBacking(prims, ctx, skip, shape_color_map);
return ctx.getImageData(0, 0, scratch.getWidth(), scratch.getHeight());
}
use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class LienzoCore method examineNativeLineDashSupported.
private final boolean examineNativeLineDashSupported() {
if (IS_CANVAS_SUPPORTED) {
try {
final ScratchPad scratch = new ScratchPad(20, 10);
final Context2D context = scratch.getContext();
context.setStrokeWidth(10);
context.setLineCap(LineCap.BUTT);
context.setStrokeColor(ColorName.BLUE);
context.beginPath();
context.moveTo(0, 5);
context.lineTo(20, 5);
context.stroke();
context.setStrokeColor(ColorName.RED);
context.setLineDash(new DashArray(5, 5));
context.beginPath();
context.moveTo(0, 5);
context.lineTo(20, 5);
context.stroke();
final ImageData backing = context.getImageData(0, 0, 20, 10);
if (null != backing) {
if ((backing.getRedAt(3, 5) == 255) && (backing.getBlueAt(3, 5) == 0) && (backing.getGreenAt(3, 5) == 0)) {
if ((backing.getRedAt(8, 5) == 0) && (backing.getBlueAt(8, 5) == 255) && (backing.getGreenAt(8, 5) == 0)) {
return true;
}
}
}
} catch (final Exception e) {
// FF 22 dev mode does not like line dashes
error("Line Dash test failed ", e);
}
}
return false;
}
Aggregations