use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.
the class Text method fill.
@Override
protected boolean fill(final Context2D context, final Attributes attr, double alpha) {
final boolean filled = attr.hasFill();
if ((filled) || (attr.isFillShapeForSelection())) {
alpha = alpha * attr.getFillAlpha();
if (alpha <= 0) {
return false;
}
if (context.isSelection()) {
final String color = getColorKey();
if (null == color) {
return false;
}
context.save();
if (GRADFILLS) {
final TextMetrics size = measureWithIdentityTransform(context);
if (null != size) {
final double wide = size.getWidth();
final double high = size.getHeight();
drawString(context, attr, new IDrawString() {
@Override
public void draw(final Context2D context, final String s, final double xOffset, final double lineNum) {
context.fillTextWithGradient(s, xOffset, getLineHeight(context) * lineNum, 0, 0, wide + (wide / 6), high + (high / 6), color);
}
});
} else {
final Layer layer = getLayer();
drawString(context, attr, new IDrawString() {
@Override
public void draw(final Context2D context, final String s, final double xOffset, final double lineNum) {
context.fillTextWithGradient(s, xOffset, getLineHeight(context) * lineNum, 0, 0, layer.getWidth(), layer.getHeight(), color);
}
});
}
} else {
context.setFillColor(color);
drawString(context, attr, FILL);
}
context.restore();
return true;
}
if (false == filled) {
return false;
}
context.save();
if (attr.hasShadow()) {
doApplyShadow(context, attr);
}
context.setGlobalAlpha(alpha);
final String fill = attr.getFillColor();
if (null != fill) {
context.setFillColor(fill);
drawString(context, attr, FILL);
context.restore();
return true;
} else {
final FillGradient grad = attr.getFillGradient();
if (null != grad) {
final String type = grad.getType();
if (LinearGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asLinearGradient());
drawString(context, attr, FILL);
context.restore();
return true;
} else if (RadialGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asRadialGradient());
drawString(context, attr, FILL);
context.restore();
return true;
} else if (PatternGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asPatternGradient());
drawString(context, attr, FILL);
context.restore();
return true;
}
}
}
context.restore();
}
return false;
}
use of com.ait.lienzo.client.core.Context2D 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.Context2D 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