illustrator.js
Version:
JavaScript image processing library
78 lines (77 loc) • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextTool = void 0;
const ToolBox_1 = require("../base/ToolBox");
const canvas_1 = require("@napi-rs/canvas");
const makeArgs_1 = require("../../utils/makeArgs");
class TextTool extends ToolBox_1.ToolBox {
registerFont(font, nameAlias) {
return canvas_1.GlobalFonts.register(font, nameAlias);
}
registerFontPath(fontPath, nameAlias) {
return canvas_1.GlobalFonts.registerFromPath(fontPath, nameAlias);
}
registerFontsDir(fontDir) {
return canvas_1.GlobalFonts.loadFontsFromDir(fontDir);
}
getFonts() {
return canvas_1.GlobalFonts.families;
}
hasFont(name) {
return canvas_1.GlobalFonts.has(name);
}
setDirection(direction) {
this.history.push((ctx) => {
ctx.direction = direction;
});
return this;
}
setTextAlignment(alignment) {
this.history.push((ctx) => {
ctx.textAlign = alignment;
});
return this;
}
setTextBaseline(alignment) {
this.history.push((ctx) => {
ctx.textBaseline = alignment;
});
return this;
}
setFont(name, size, style) {
this.history.push((ctx) => {
ctx.font = `${style ? style + " " : ""}${name}${size ? " " + size : ""}`;
});
return this;
}
setColor(color) {
this.history.push((ctx) => {
ctx.fillStyle = color;
});
return this;
}
setStrokeColor(color) {
this.history.push((ctx) => {
ctx.strokeStyle = color;
});
return this;
}
writeText(text, x, y, maxWidth) {
this.history.push((ctx) => {
// @ts-expect-error
ctx.fillText(...(0, makeArgs_1.makeArgs)((el) => el != null, [text, x, y, maxWidth]));
});
return this;
}
strokeText(text, x, y, maxWidth) {
this.history.push((ctx) => {
// @ts-expect-error
ctx.strokeText(...(0, makeArgs_1.makeArgs)((el) => el != null, [text, x, y, maxWidth]));
});
return this;
}
measure(text) {
return this.layer.utils.measureText(text);
}
}
exports.TextTool = TextTool;