use of com.ait.lienzo.client.core.util.ScratchPad 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;
}
use of com.ait.lienzo.client.core.util.ScratchPad in project lienzo-core by ahome-it.
the class TextUtils method getTextOffsets.
public static final NFastDoubleArrayJSO getTextOffsets(final String font, final TextBaseLine baseline) {
FORBOUNDS.getContext().setTextFont(font);
FORBOUNDS.getContext().setTextAlign(TextAlign.LEFT);
FORBOUNDS.getContext().setTextBaseline(TextBaseLine.ALPHABETIC);
final int m = (int) FORBOUNDS.getContext().measureText("M").getWidth();
final int w = (int) FORBOUNDS.getContext().measureText("Mg").getWidth();
final int h = (m * 4);
final ScratchPad temp = new ScratchPad(w, h);
final Context2D ctxt = temp.getContext();
ctxt.setFillColor(ColorName.BLACK);
ctxt.fillRect(0, 0, w, h);
ctxt.setTextFont(font);
ctxt.setTextAlign(TextAlign.LEFT);
ctxt.setTextBaseline(baseline);
ctxt.setFillColor(ColorName.WHITE);
ctxt.fillText("Mg", 0, m * 2);
return getTextOffsets(ctxt.getImageData(0, 0, w, h).getData(), w, h, m * 2);
}
use of com.ait.lienzo.client.core.util.ScratchPad in project lienzo-core by ahome-it.
the class Scene method toDataURL.
public final String toDataURL() {
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();
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:,";
}
}
Aggregations