use of com.ait.lienzo.client.core.types.FillGradient in project lienzo-core by ahome-it.
the class Shape method fill.
/**
* Fills the Shape using the passed attributes.
* This method will silently also fill the Shape to its unique rgb color if the context is a buffer.
*
* @param context
* @param attr
*/
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();
context.setFillColor(color);
context.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);
context.fill();
context.restore();
return true;
}
final FillGradient grad = attr.getFillGradient();
if (null != grad) {
final String type = grad.getType();
if (LinearGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asLinearGradient());
context.fill();
context.restore();
return true;
} else if (RadialGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asRadialGradient());
context.fill();
context.restore();
return true;
} else if (PatternGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asPatternGradient());
context.fill();
context.restore();
return true;
}
}
context.restore();
}
return false;
}
use of com.ait.lienzo.client.core.types.FillGradient in project lienzo-core by ahome-it.
the class Shape method fill.
protected boolean fill(final Context2D context, final Attributes attr, double alpha, final Path2D path) {
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();
context.setFillColor(color);
context.fill(path);
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);
context.fill(path);
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());
context.fill(path);
context.restore();
return true;
} else if (RadialGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asRadialGradient());
context.fill(path);
context.restore();
return true;
} else if (PatternGradient.TYPE.equals(type)) {
context.setFillGradient(grad.asPatternGradient());
context.fill(path);
context.restore();
return true;
}
}
}
context.restore();
}
return false;
}
use of com.ait.lienzo.client.core.types.FillGradient 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;
}
Aggregations