Search in sources :

Example 11 with ScratchPad

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;
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ImageData(com.ait.lienzo.client.core.types.ImageData) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) DashArray(com.ait.lienzo.client.core.types.DashArray) UmbrellaException(com.google.gwt.event.shared.UmbrellaException)

Example 12 with ScratchPad

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);
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad)

Example 13 with ScratchPad

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:,";
    }
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Aggregations

ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)13 Context2D (com.ait.lienzo.client.core.Context2D)8 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)6 ImageData (com.ait.lienzo.client.core.types.ImageData)2 Point2D (com.ait.lienzo.client.core.types.Point2D)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)1 DashArray (com.ait.lienzo.client.core.types.DashArray)1 PathPartEntryJSO (com.ait.lienzo.client.core.types.PathPartEntryJSO)1 PathPartList (com.ait.lienzo.client.core.types.PathPartList)1 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)1 NFastStringMap (com.ait.tooling.nativetools.client.collection.NFastStringMap)1 UmbrellaException (com.google.gwt.event.shared.UmbrellaException)1