@ -207,45 +207,26 @@ const rescalePointsInElement = (
}
: { } ;
// This is not computationally ideal, but can't be helped.
const MIN_FONT_SIZE = 1 ;
const measureFontSizeFromWH = (
element : NonDeleted < ExcalidrawTextElement > ,
nextWidth : number ,
nextHeight : number ,
) : { size : number ; baseline : number } | null = > {
let scale = Math . min ( nextWidth / element . width , nextHeight / element . height ) ;
let nextFontSize = element . fontSize * scale ;
let metrics = measureText (
element . text ,
getFontString ( { fontSize : nextFontSize , fontFamily : element.fontFamily } ) ,
) ;
if ( metrics . width - nextWidth < 1 && metrics . height - nextHeight < 1 ) {
return { size : nextFontSize , baseline : metrics.baseline } ;
}
// second measurement
scale = Math . min (
Math . min ( nextWidth , metrics . width ) / element . width ,
Math . min ( nextHeight , metrics . height ) / element . height ,
) ;
nextFontSize = element . fontSize * scale ;
metrics = measureText (
element . text ,
getFontString ( { fontSize : nextFontSize , fontFamily : element.fontFamily } ) ,
) ;
if ( metrics . width - nextWidth < 1 && metrics . height - nextHeight < 1 ) {
return { size : nextFontSize , baseline : metrics.baseline } ;
// We only use width to scale font on resize
const nextFontSize = element . fontSize * ( nextWidth / element . width ) ;
if ( nextFontSize < MIN_FONT_SIZE ) {
return null ;
}
// third measurement
scale *= 0.99 ; // just heuristics
nextFontSize = element . fontSize * scale ;
metrics = measureText (
const metrics = measureText (
element . text ,
getFontString ( { fontSize : nextFontSize , fontFamily : element.fontFamily } ) ,
) ;
if ( metrics . width - nextWidth < 1 && metrics . height - nextHeight < 1 ) {
return { size : nextFontSize , baseline : metrics.baseline } ;
}
return null ;
return {
size : nextFontSize ,
baseline : metrics.baseline + ( nextHeight - metrics . height ) ,
} ;
} ;
const getSidesForResizeHandle = (