@@ -128,6 +128,7 @@ class TextLayer {
128128 this . #pageHeight = pageHeight ;
129129
130130 TextLayer . #ensureMinFontSizeComputed( ) ;
131+ container . style . setProperty ( "--min-font-size" , TextLayer . #minFontSize) ;
131132
132133 setLayerDimensions ( container , viewport ) ;
133134
@@ -342,7 +343,6 @@ class TextLayer {
342343 top = tx [ 5 ] - fontAscent * Math . cos ( angle ) ;
343344 }
344345
345- const scaleFactorStr = "calc(var(--total-scale-factor) *" ;
346346 const divStyle = textDiv . style ;
347347 // Setting the style properties individually, rather than all at once,
348348 // should be OK since the `textDiv` isn't appended to the document yet.
@@ -351,14 +351,10 @@ class TextLayer {
351351 divStyle . top = `${ ( ( 100 * top ) / this . #pageHeight) . toFixed ( 2 ) } %` ;
352352 } else {
353353 // We're in a marked content span, hence we can't use percents.
354- divStyle . left = `${ scaleFactorStr } ${ left . toFixed ( 2 ) } px)` ;
355- divStyle . top = `${ scaleFactorStr } ${ top . toFixed ( 2 ) } px)` ;
354+ divStyle . left = `calc(var(--total-scale-factor) * ${ left . toFixed ( 2 ) } px)` ;
355+ divStyle . top = `calc(var(--total-scale-factor) * ${ top . toFixed ( 2 ) } px)` ;
356356 }
357- // We multiply the font size by #minFontSize, and then #layout will
358- // scale the element by 1/#minFontSize. This allows us to effectively
359- // ignore the minimum font size enforced by the browser, so that the text
360- // layer <span>s can always match the size of the text in the canvas.
361- divStyle . fontSize = `${ scaleFactorStr } ${ ( TextLayer . #minFontSize * fontHeight ) . toFixed ( 2 ) } px)` ;
357+ divStyle . setProperty ( "--font-height" , `${ fontHeight . toFixed ( 2 ) } px` ) ;
362358 divStyle . fontFamily = fontFamily ;
363359
364360 textDivProperties . fontSize = fontHeight ;
@@ -421,11 +417,6 @@ class TextLayer {
421417 const { div, properties, ctx } = params ;
422418 const { style } = div ;
423419
424- let transform = "" ;
425- if ( TextLayer . #minFontSize > 1 ) {
426- transform = `scale(${ 1 / TextLayer . #minFontSize} )` ;
427- }
428-
429420 if ( properties . canvasWidth !== 0 && properties . hasText ) {
430421 const { fontFamily } = style ;
431422 const { canvasWidth, fontSize } = properties ;
@@ -435,14 +426,11 @@ class TextLayer {
435426 const { width } = ctx . measureText ( div . textContent ) ;
436427
437428 if ( width > 0 ) {
438- transform = `scaleX( ${ ( canvasWidth * this . #scale) / width } ) ${ transform } ` ;
429+ style . setProperty ( "--scale-x" , ( canvasWidth * this . #scale) / width ) ;
439430 }
440431 }
441432 if ( properties . angle !== 0 ) {
442- transform = `rotate(${ properties . angle } deg) ${ transform } ` ;
443- }
444- if ( transform . length > 0 ) {
445- style . transform = transform ;
433+ style . setProperty ( "--rotate" , `${ properties . angle } deg` ) ;
446434 }
447435 }
448436
0 commit comments