@@ -267,6 +267,9 @@ const _approximateDimensionsInternal = (
267267const _getMeasurementContainer = memoize ( ( ) => {
268268 const element = document . createElementNS ( "http://www.w3.org/2000/svg" , "svg" ) ;
269269 element . setAttribute ( "xlink" , "http://www.w3.org/1999/xlink" ) ;
270+ element . setAttribute ( "width" , "300" ) ;
271+ element . setAttribute ( "height" , "300" ) ;
272+ element . setAttribute ( "viewBox" , "0 0 300 300" ) ;
270273
271274 const containerElement = document . createElementNS (
272275 "http://www.w3.org/2000/svg" ,
@@ -304,24 +307,31 @@ const _measureDimensionsInternal = memoize(
304307 ) ;
305308 const params = _prepareParams ( style , i ) ;
306309 textElement . style . fontFamily = params . fontFamily ;
307- textElement . style . transform = `rotate(${ params . angle } )` ;
308310 textElement . style . fontSize = `${ params . fontSize } px` ;
309311 textElement . style . lineHeight = params . lineHeight ;
310312 textElement . style . fontFamily = params . fontFamily ;
311313 textElement . style . letterSpacing = params . letterSpacing ;
312314 textElement . textContent = line ;
313315 textElement . setAttribute ( "x" , "0" ) ;
314316 textElement . setAttribute ( "y" , `${ heightAcc } ` ) ;
315- heightAcc += params . lineHeight * params . fontSize ;
316-
317317 containerElement . appendChild ( textElement ) ;
318+
319+ heightAcc +=
320+ params . lineHeight * textElement . getBoundingClientRect ( ) . height ;
318321 }
319322
320- const { width, height } = containerElement . getBoundingClientRect ( ) ;
323+ const { width } = containerElement . getBoundingClientRect ( ) ;
321324
322325 containerElement . innerHTML = "" ;
323326
324- return { width, height } ;
327+ return {
328+ width : style ?. angle
329+ ? _getSizeWithRotate ( width , heightAcc , style ?. angle )
330+ : width ,
331+ height : style ?. angle
332+ ? _getSizeWithRotate ( heightAcc , width , style ?. angle )
333+ : heightAcc ,
334+ } ;
325335 } ,
326336 ( text , style ) => {
327337 const totalText = Array . isArray ( text ) ? text . join ( ) : text ;
0 commit comments