use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Sprite method getBoundingBox.
@Override
public BoundingBox getBoundingBox() {
double wide = 0;
double high = 0;
for (final BoundingBox bbox : m_frames) {
wide = Math.max(wide, bbox.getWidth());
high = Math.max(high, bbox.getHeight());
}
return new BoundingBox(0, 0, wide, high);
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class TextBoundsAndLineBreaksWrap method drawString.
@Override
public void drawString(final Context2D context, final Attributes attr, final IDrawString drawCommand) {
final BoundingBox wrapBoundaries = getWrapBoundaries();
final String[] textLines = attr.getText().split("\\r?\\n");
if (textLines.length < 1) {
return;
}
final ArrayList<String> lines = new ArrayList<>();
for (final String line : textLines) {
final String[] words = line.split("\\s");
if (words.length < 1) {
lines.add("");
continue;
}
final StringBuilder nextLine = new StringBuilder(words[0]);
for (int i = 1; i < words.length; i++) {
if (getBoundingBoxForString(nextLine + " " + words[i]).getWidth() <= wrapBoundaries.getWidth()) {
nextLine.append(" ").append(words[i]);
} else {
lines.add(nextLine.toString());
nextLine.setLength(words[i].length());
nextLine.replace(0, words[i].length(), words[i]);
}
}
lines.add(nextLine.toString());
}
double xOffset = 0;
switch(textAlignSupplier.get()) {
case START:
case LEFT:
xOffset = 0;
break;
case CENTER:
xOffset = wrapBoundaries.getWidth() / 2;
break;
case END:
case RIGHT:
xOffset = wrapBoundaries.getWidth();
break;
}
final double yOffset = 0.8;
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
final int toPad = (int) Math.round((wrapBoundaries.getWidth() - getBoundingBoxForString(line).getWidth()) / getBoundingBoxForString(" ").getWidth());
line = TextUtils.padString(line, line.length() + toPad, ' ', textAlignSupplier.get());
drawCommand.draw(context, line, xOffset, i + yOffset);
}
}
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(final DataURLType mimetype) {
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(mimetype, 1.0);
} else {
return "data:,";
}
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Scene method toDataURL.
// package protected
final String toDataURL(final DataURLType mimetype, final Layer background) {
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();
if (null != background) {
background.drawWithTransforms(context, 1, bbox);
}
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(mimetype, 1.0);
} else {
return "data:,";
}
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Scene method toDataURL.
// package protected
final String toDataURL(final Layer background) {
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();
if (null != background) {
background.drawWithTransforms(context, 1, bbox);
}
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