Skip to content

Commit f886fff

Browse files
committed
fix(textsize): fix one line mini fontsize texté
1 parent fd298f5 commit f886fff

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/shapes.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ export class Text extends Shape {
155155
let fontsize = Math.min(this.boundingBox.size.y ?? Number.POSITIVE_INFINITY, this.fontsize ?? Number.POSITIVE_INFINITY);
156156
if (fontsize == Number.POSITIVE_INFINITY) fontsize = C.DEFAULT_FONTSIZE;
157157
context.font = Text.buildFont(this.style, fontsize, this.font);
158-
if (context.measureText(this.text).width >= this.boundingBox.size.x) fontsize = fontsize * this.boundingBox.size.x / context.measureText(this.text).width;
158+
const defaultTextWidth = context.measureText(this.text).width;
159+
if (defaultTextWidth >= this.boundingBox.size.x) fontsize = fontsize * this.boundingBox.size.x / defaultTextWidth;
159160
return fontsize
160161
}
161162

@@ -223,7 +224,13 @@ export class Text extends Shape {
223224
context.resetTransform();
224225
context.translate(origin.x, origin.y);
225226
context.rotate(Math.PI / 180 * this.orientation);
226-
if (this.isScaled) context.scale(Math.abs(contextMatrix.a), Math.abs(contextMatrix.d));
227+
if (this.isScaled) {
228+
if (this.fontsize < 1) {
229+
context.scale(Math.abs(contextMatrix.a * this.fontsize), Math.abs(contextMatrix.d * this.fontsize));
230+
context.font = Text.buildFont(this.style, 1, this.font);
231+
}
232+
else context.scale(Math.abs(contextMatrix.a), Math.abs(contextMatrix.d));
233+
}
227234
this.write(this.writtenText, context);
228235
}
229236

0 commit comments

Comments
 (0)