@@ -707,8 +707,8 @@ var Constants = {
707707 svg : "SVGRenderer" ,
708708 canvas : "CanvasRenderer"
709709 } ,
710- Version : "v0.8.10 " ,
711- PublishDate : "2022-06-09T16:09:22.888Z " ,
710+ Version : "v0.8.11 " ,
711+ PublishDate : "2022-08-15T20:06:30.856Z " ,
712712 Identifier : "two-" ,
713713 Resolution : 12 ,
714714 AutoCalculateImportedMatrices : true ,
@@ -3020,13 +3020,13 @@ function isDefaultMatrix(m) {
30203020var CanvasShim = {
30213021 Image : null ,
30223022 isHeadless : false ,
3023- shim : function ( canvas2 , Image ) {
3024- Renderer . Utils . shim ( canvas2 ) ;
3023+ shim : function ( canvas3 , Image ) {
3024+ Renderer . Utils . shim ( canvas3 ) ;
30253025 if ( typeof Image !== "undefined" ) {
30263026 CanvasShim . Image = Image ;
30273027 }
30283028 CanvasShim . isHeadless = true ;
3029- return canvas2 ;
3029+ return canvas3 ;
30303030 }
30313031} ;
30323032
@@ -5519,8 +5519,12 @@ function FlagRadius() {
55195519}
55205520
55215521// src/text.js
5522+ var canvas2 ;
55225523var min4 = Math . min ;
55235524var max4 = Math . max ;
5525+ if ( root . document ) {
5526+ canvas2 = document . createElement ( "canvas" ) ;
5527+ }
55245528var _Text = class extends Shape {
55255529 constructor ( message , x , y , styles ) {
55265530 super ( ) ;
@@ -5582,6 +5586,31 @@ var _Text = class extends Shape {
55825586 }
55835587 }
55845588 }
5589+ static Measure ( text ) {
5590+ if ( canvas2 ) {
5591+ const ctx = canvas2 . getContext ( "2d" ) ;
5592+ ctx . font = [
5593+ text . _style ,
5594+ text . _weight ,
5595+ `${ text . _size } px/${ text . _leading } px` ,
5596+ text . _family
5597+ ] . join ( " " ) ;
5598+ const metrics = ctx . measureText ( text . value , 0 , 0 ) ;
5599+ const height = metrics . actualBoundingBoxDescent + metrics . actualBoundingBoxAscent ;
5600+ return {
5601+ width : metrics . width ,
5602+ height
5603+ } ;
5604+ } else {
5605+ const width = this . value . length * this . size * _Text . Ratio ;
5606+ const height = this . leading ;
5607+ console . warn ( "Two.Text: unable to accurately measure text, so using an approximation." ) ;
5608+ return {
5609+ width,
5610+ height
5611+ } ;
5612+ }
5613+ }
55855614 clone ( parent ) {
55865615 const clone = new _Text ( this . value ) ;
55875616 clone . translation . copy ( this . translation ) ;
@@ -5628,8 +5657,7 @@ var _Text = class extends Shape {
56285657 let left , right , top , bottom ;
56295658 this . _update ( true ) ;
56305659 matrix3 = shallow ? this . _matrix : getComputedMatrix ( this ) ;
5631- const height = this . leading ;
5632- const width = this . value . length * this . size * _Text . Ratio ;
5660+ const { width, height } = _Text . Measure ( this ) ;
56335661 const border = ( this . _linewidth || 0 ) / 2 ;
56345662 switch ( this . alignment ) {
56355663 case "left" :
@@ -5645,17 +5673,13 @@ var _Text = class extends Shape {
56455673 right = width / 2 + border ;
56465674 }
56475675 switch ( this . baseline ) {
5648- case "top " :
5649- top = - border ;
5650- bottom = height + border ;
5676+ case "middle " :
5677+ top = - ( height / 2 + border ) ;
5678+ bottom = height / 2 + border ;
56515679 break ;
5652- case "bottom" :
5680+ default :
56535681 top = - ( height + border ) ;
56545682 bottom = border ;
5655- break ;
5656- default :
5657- top = - ( height / 2 + border ) ;
5658- bottom = height / 2 + border ;
56595683 }
56605684 a = matrix3 . multiply ( left , top , 1 ) ;
56615685 b = matrix3 . multiply ( left , bottom , 1 ) ;
@@ -8809,7 +8833,7 @@ var webgl = {
88098833 let prev , a , c , ux , uy , vx , vy , ar , bl , br , cl , x , y ;
88108834 let isOffset ;
88118835 const commands = elem . _renderer . vertices ;
8812- const canvas2 = this . canvas ;
8836+ const canvas3 = this . canvas ;
88138837 const ctx = this . ctx ;
88148838 const scale = elem . _renderer . scale ;
88158839 const stroke = elem . _stroke ;
@@ -8823,12 +8847,12 @@ var webgl = {
88238847 const dashes = elem . dashes ;
88248848 const length = commands . length ;
88258849 const last = length - 1 ;
8826- canvas2 . width = Math . max ( Math . ceil ( elem . _renderer . rect . width * scale . x ) , 1 ) ;
8827- canvas2 . height = Math . max ( Math . ceil ( elem . _renderer . rect . height * scale . y ) , 1 ) ;
8850+ canvas3 . width = Math . max ( Math . ceil ( elem . _renderer . rect . width * scale . x ) , 1 ) ;
8851+ canvas3 . height = Math . max ( Math . ceil ( elem . _renderer . rect . height * scale . y ) , 1 ) ;
88288852 const centroid = elem . _renderer . rect . centroid ;
88298853 const cx = centroid . x ;
88308854 const cy = centroid . y ;
8831- ctx . clearRect ( 0 , 0 , canvas2 . width , canvas2 . height ) ;
8855+ ctx . clearRect ( 0 , 0 , canvas3 . width , canvas3 . height ) ;
88328856 if ( fill ) {
88338857 if ( typeof fill === "string" ) {
88348858 ctx . fillStyle = fill ;
@@ -9108,7 +9132,7 @@ var webgl = {
91089132 points : {
91099133 updateCanvas : function ( elem ) {
91109134 let isOffset ;
9111- const canvas2 = this . canvas ;
9135+ const canvas3 = this . canvas ;
91129136 const ctx = this . ctx ;
91139137 const stroke = elem . _stroke ;
91149138 const linewidth = elem . _linewidth ;
@@ -9120,12 +9144,12 @@ var webgl = {
91209144 if ( ! webgl . isHidden . test ( stroke ) ) {
91219145 dimension += linewidth ;
91229146 }
9123- canvas2 . width = getPoT ( dimension ) ;
9124- canvas2 . height = canvas2 . width ;
9125- const aspect = dimension / canvas2 . width ;
9126- const cx = canvas2 . width / 2 ;
9127- const cy = canvas2 . height / 2 ;
9128- ctx . clearRect ( 0 , 0 , canvas2 . width , canvas2 . height ) ;
9147+ canvas3 . width = getPoT ( dimension ) ;
9148+ canvas3 . height = canvas3 . width ;
9149+ const aspect = dimension / canvas3 . width ;
9150+ const cx = canvas3 . width / 2 ;
9151+ const cy = canvas3 . height / 2 ;
9152+ ctx . clearRect ( 0 , 0 , canvas3 . width , canvas3 . height ) ;
91299153 if ( fill ) {
91309154 if ( typeof fill === "string" ) {
91319155 ctx . fillStyle = fill ;
@@ -9276,7 +9300,7 @@ var webgl = {
92769300 } ,
92779301 text : {
92789302 updateCanvas : function ( elem ) {
9279- const canvas2 = this . canvas ;
9303+ const canvas3 = this . canvas ;
92809304 const ctx = this . ctx ;
92819305 const scale = elem . _renderer . scale ;
92829306 const stroke = elem . _stroke ;
@@ -9285,14 +9309,14 @@ var webgl = {
92859309 const opacity = elem . _renderer . opacity || elem . _opacity ;
92869310 const dashes = elem . dashes ;
92879311 const decoration = elem . _decoration ;
9288- canvas2 . width = Math . max ( Math . ceil ( elem . _renderer . rect . width * scale . x ) , 1 ) ;
9289- canvas2 . height = Math . max ( Math . ceil ( elem . _renderer . rect . height * scale . y ) , 1 ) ;
9312+ canvas3 . width = Math . max ( Math . ceil ( elem . _renderer . rect . width * scale . x ) , 1 ) ;
9313+ canvas3 . height = Math . max ( Math . ceil ( elem . _renderer . rect . height * scale . y ) , 1 ) ;
92909314 const centroid = elem . _renderer . rect . centroid ;
92919315 const cx = centroid . x ;
92929316 const cy = centroid . y ;
92939317 let a , b , c , d , e , sx , sy , x1 , y1 , x2 , y2 ;
92949318 const isOffset = fill . _renderer && fill . _renderer . offset && stroke . _renderer && stroke . _renderer . offset ;
9295- ctx . clearRect ( 0 , 0 , canvas2 . width , canvas2 . height ) ;
9319+ ctx . clearRect ( 0 , 0 , canvas3 . width , canvas3 . height ) ;
92969320 if ( ! isOffset ) {
92979321 ctx . font = [ elem . _style , elem . _weight , elem . _size + "px/" + elem . _leading + "px" , elem . _family ] . join ( " " ) ;
92989322 }
0 commit comments