Fixing WorkWrap

This commit is contained in:
David Négrier 2021-04-17 18:55:39 +02:00
parent 22cb41dc29
commit 08ca95b143

View File

@ -8,38 +8,46 @@ export class TextUtils {
if (object.text === undefined) { if (object.text === undefined) {
throw new Error('This object has not textual representation.'); throw new Error('This object has not textual representation.');
} }
const options: {font?: string} = {}; const options: {
let font = ''; fontStyle?: string,
fontSize?: string,
fontFamily?: string,
color?: string,
align?: string,
wordWrap?: {
width: number,
useAdvancedWrap?: boolean
}
} = {};
if (object.text.italic) { if (object.text.italic) {
font += 'italic '; options.fontStyle = 'italic';
} }
// Note: there is no support for "strikeout" and "underline" // Note: there is no support for "strikeout" and "underline"
let fontSize: number = 16; let fontSize: number = 16;
if (object.text.pixelsize) { if (object.text.pixelsize) {
font += object.text.pixelsize+'px ';
fontSize = object.text.pixelsize; fontSize = object.text.pixelsize;
} else {
font += '16px ';
} }
options.fontSize = fontSize + 'px';
if (object.text.fontfamily) { if (object.text.fontfamily) {
font += '"'+object.text.fontfamily+'"'; options.fontFamily = '"'+object.text.fontfamily+'"';
} }
if (font !== '') {
options.font = font;
}
const textElem = scene.add.text(object.x, object.y, object.text.text, options);
textElem.setFontSize(fontSize);
let color = '#000000'; let color = '#000000';
if (object.text.color !== undefined) { if (object.text.color !== undefined) {
color = object.text.color; color = object.text.color;
} }
textElem.setColor(color); options.color = color;
if (object.text.wrap) { if (object.text.wrap === true) {
textElem.setWordWrapWidth(textElem.width); options.wordWrap = {
width: object.width,
//useAdvancedWrap: true
}
} }
textElem.setAngle(object.rotation);
if (object.text.halign !== undefined) { if (object.text.halign !== undefined) {
textElem.setAlign(object.text.halign); options.align = object.text.halign;
} }
console.warn(options);
const textElem = scene.add.text(object.x, object.y, object.text.text, options);
textElem.setAngle(object.rotation);
} }
} }