@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
93 lines • 4.17 kB
JavaScript
import { RectangleF, PointF } from "@aurigma/design-atoms-model/Math";
import { BaseTextItemHandler } from "../ItemHandlers/BaseTextItemHandler";
import { Graphics } from "../Graphics";
import Environment from "@aurigma/design-atoms-model/Utils/Environment";
export class TextRenderer {
constructor(_staticCanvas, _activeCanvas, _textWhizz, _zoom, _offset, _viewportHandler, _selectionStyle, _rgbColorParser, _canvasFactory) {
this._staticCanvas = _staticCanvas;
this._activeCanvas = _activeCanvas;
this._textWhizz = _textWhizz;
this._zoom = _zoom;
this._offset = _offset;
this._viewportHandler = _viewportHandler;
this._selectionStyle = _selectionStyle;
this._rgbColorParser = _rgbColorParser;
this._canvasFactory = _canvasFactory;
this._workspaceWidth = null;
this._workspaceHeight = null;
}
setWorkspaceSize(width, height) {
this._workspaceWidth = width;
this._workspaceHeight = height;
}
setZoom(value) {
this._zoom = value;
}
set offset(value) {
this._offset = value;
}
get offset() {
return this._offset;
}
get _scale() {
return Environment.screenDpi * this._zoom / 72;
}
_getScaledBounds(bounds) {
const scale = this._scale;
const left = Math.floor(bounds.left * scale);
const top = Math.floor(bounds.top * scale);
const width = Math.ceil(bounds.width * scale);
const height = Math.ceil(bounds.height * scale);
return new RectangleF(left, top, width, height);
}
_getScaledBoundsWithoutRound(bounds) {
const scale = this._scale;
const left = bounds.left * scale;
const top = bounds.top * scale;
const width = bounds.width * scale;
const height = bounds.height * scale;
return new RectangleF(left, top, width, height);
}
_colorToTextWhizz(color) {
return new this._textWhizz.Color(this._textWhizz.ColorType.rgb, [color.b, color.g, color.r, color.alpha]);
}
static renderTextImage(handler, imageContainer, imageContainerRect, itemHandlerCtx, opacityMultiplier, increaseImageRect) {
if (imageContainer.isLoaded) {
this._drawImage(handler, imageContainer, imageContainerRect, itemHandlerCtx, opacityMultiplier, increaseImageRect);
}
else if (imageContainer.isLoading || !handler.ready) {
this._drawWaitClock(handler, itemHandlerCtx);
}
}
_createCanvas(size) {
return this._canvasFactory.createCanvas(size);
}
_copyCanvas(source, size) {
const target = this._canvasFactory.createCanvas(size);
const targetCtx = target.getContext('2d');
targetCtx.drawImage(source, 0, 0);
return target;
}
static _drawWaitClock(handler, itemHandlerCtx) {
const rectangle = handler.rectangle;
handler.canvas.drawWaitClock(itemHandlerCtx, new PointF(rectangle.centerX, rectangle.centerY));
}
static _isUpdatingAfterResize(handler) {
return handler instanceof BaseTextItemHandler &&
(handler.getTypeName() === "BoundedTextItemHandler" || handler.getTypeName() === "PathBoundedTextItemHandler") &&
handler.isUpdatingAfterResize;
}
static _drawImage(handler, imageContainer, imageContainerRect, ctx, opacityMultiplier, increaseImageRect) {
var _a;
const canvas = handler.canvas;
const item = handler.item;
const disableSmoothing = canvas.disableSmoothing;
const scale = Environment.screenDpi * canvas.zoom / 72;
if (!this._isUpdatingAfterResize(handler)) {
const drawObject = (_a = imageContainer.canvas) !== null && _a !== void 0 ? _a : imageContainer.image;
Graphics.drawImage(ctx, drawObject, handler.drawingRectangle, scale, scale, disableSmoothing, null, item.opacity * opacityMultiplier, imageContainerRect, increaseImageRect);
}
}
}
TextRenderer.staticCanvasMargin = 10;
//# sourceMappingURL=TextRenderer.js.map