use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class TextUtils method getBoundingBox.
public static BoundingBox getBoundingBox(final String text, final double size, final String style, final String family, final TextUnit unit, final TextBaseLine baseline, final TextAlign align) {
if ((null == text) || (text.isEmpty()) || (false == (size > 0))) {
return new BoundingBox(0, 0, 0, 0);
}
final String font = getFontString(size, unit, style, family);
final String base = font + " " + baseline.getValue();
NFastDoubleArrayJSO offs = OFFSCACHE.get(base);
if (null == offs) {
OFFSCACHE.put(base, offs = getTextOffsets(font, baseline));
}
if (null == offs) {
return new BoundingBox(0, 0, 0, 0);
}
FORBOUNDS.getContext().setTextFont(font);
FORBOUNDS.getContext().setTextAlign(TextAlign.LEFT);
FORBOUNDS.getContext().setTextBaseline(TextBaseLine.ALPHABETIC);
final double wide = FORBOUNDS.getContext().measureText(text).getWidth();
final BoundingBox bbox = new BoundingBox().addY(offs.get(0)).addY(offs.get(1));
switch(align) {
case LEFT:
case START:
bbox.addX(0).addX(wide);
break;
case END:
case RIGHT:
bbox.addX(0).addX(0 - wide);
break;
case CENTER:
bbox.addX(wide / 2).addX(0 - (wide / 2));
break;
}
return bbox;
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Layer method draw.
public Layer draw(Context2D context) {
if (LienzoCore.IS_CANVAS_SUPPORTED) {
if (isClearLayerBeforeDraw()) {
clear();
}
if (isVisible()) {
boolean draw = true;
if (null != m_olbd) {
draw = m_olbd.onLayerBeforeDraw(this);
}
if (draw) {
Transform transform = null;
final Viewport viewport = getViewport();
if ((isTransformable()) && (null != viewport)) {
transform = viewport.getTransform();
}
context.save();
if (null != transform) {
context.transform(transform);
}
final BoundingBox bbox = getStorageBounds();
IPathClipper vclp = null;
if (null != viewport) {
vclp = viewport.getPathClipper();
if ((null != vclp) && (vclp.isActive())) {
vclp.clip(context);
}
}
final IPathClipper lclp = getPathClipper();
if ((null != lclp) && (lclp.isActive())) {
lclp.clip(context);
}
drawWithTransforms(context, 1, bbox);
context.restore();
if (null != m_olad) {
m_olad.onLayerAfterDraw(this);
}
final SelectionLayer selection = getSelectionLayer();
if (null != selection) {
selection.clear();
context = selection.getContext();
context.save();
if (null != transform) {
context.transform(transform);
}
if ((null != vclp) && (vclp.isActive())) {
vclp.clip(context);
}
if ((null != lclp) && (lclp.isActive())) {
lclp.clip(context);
}
drawWithTransforms(context, 1, bbox);
context.restore();
}
}
}
}
return this;
}
use of com.ait.lienzo.client.core.types.BoundingBox 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:,";
}
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class ToolTip method show.
private ToolTip show(final double x, final double y, final boolean force) {
m_autoHider = null;
if ((false == force) && (false == m_show)) {
return this;
}
if (false == m_show) {
hide();
}
m_oldx = x;
m_oldy = y;
m_show = false;
double th = 0;
double tw = 0;
double lh = 0;
double lw = 0;
final double pd = getPadding();
if ((null == m_textValue) || (m_textValue.isEmpty())) {
m_text.setText("").setVisible(false);
} else {
m_text.setText(m_textValue).setVisible(true);
final BoundingBox bb = m_text.getBoundingBox();
tw = bb.getWidth();
th = bb.getHeight();
}
if ((null == m_lablValue) || (m_lablValue.isEmpty())) {
m_labl.setText("").setVisible(false);
} else {
m_labl.setText(m_lablValue).setVisible(true);
final BoundingBox bb = m_labl.getBoundingBox();
lw = bb.getWidth();
lh = bb.getHeight();
}
final double p2 = pd * 2;
final double rw = Math.max(tw, lw) + p2 + 2;
final double rh = th + lh + p2 + 4;
final double w2 = rw / 2;
final double h2 = rh / 2;
m_body.setWidth(rw).setHeight(rh).setCornerRadius(5);
final double tv = getTailValue();
if (tv > 1) {
m_tail.setPoints(new Point2D(w2 - tv, rh), new Point2D(w2, rh + tv), new Point2D(w2 + tv, rh)).setVisible(true);
m_mask.setPoints(new Point2D(w2 - tv - 3, rh - 3), new Point2D(w2, (rh + tv) - 3), new Point2D(w2 + tv + 3, rh - 3)).setVisible(true);
} else {
m_tail.setVisible(false);
m_mask.setVisible(false);
}
if (th > 0) {
m_text.setX(w2);
if (lh > 0) {
m_labl.setY(h2 - (th / 2) - 2);
m_text.setY(h2 + (lh / 2) + 2);
} else {
m_text.setY(h2);
}
}
if (lh > 0) {
m_labl.setX(w2);
if (th > 0) {
m_labl.setY(h2 - (th / 2) - 2);
m_text.setY(h2 + (lh / 2) + 2);
} else {
m_labl.setY(h2);
}
}
setX(x - w2);
setY(y - rh);
if ((false == force) && (getAutoHideTime() > 0)) {
m_autoHider = new RepeatingCommand() {
@Override
public boolean execute() {
if ((this == m_autoHider) && (isShowing())) {
hide();
}
return false;
}
};
Scheduler.get().scheduleFixedDelay(m_autoHider, getAutoHideTime());
}
setVisible(true);
return draw();
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class AbstractMultiPathPartShape method getBoundingBox.
@Override
public BoundingBox getBoundingBox() {
NFastArrayList<PathPartList> points = m_points;
if (getCornerRadius() > 0) {
points = m_cornerPoints;
}
final int size = points.size();
if (size < 1) {
return new BoundingBox(0, 0, 0, 0);
}
final BoundingBox bbox = new BoundingBox();
for (int i = 0; i < size; i++) {
bbox.add(points.get(i).getBoundingBox());
}
return bbox;
}
Aggregations