@@ -312,14 +312,14 @@ BRp.applyPrefixedLabelDimensions = function( ele, prefix ){
312312
313313 let labelDims = this . calculateLabelDimensions ( ele , text ) ;
314314 let lineHeight = ele . pstyle ( 'line-height' ) . pfValue ;
315+ let size = ele . pstyle ( 'font-size' ) . pfValue ;
315316 let textWrap = ele . pstyle ( 'text-wrap' ) . strValue ;
316317 let lines = util . getPrefixedProperty ( _p . rscratch , 'labelWrapCachedLines' , prefix ) || [ ] ;
317318 let numLines = textWrap !== 'wrap' ? 1 : Math . max ( lines . length , 1 ) ;
318- let normPerLineHeight = labelDims . height / numLines ;
319- let labelLineHeight = normPerLineHeight * lineHeight ;
319+ let labelLineHeight = size * lineHeight ;
320320
321321 let width = labelDims . width ;
322- let height = labelDims . height + ( numLines - 1 ) * ( lineHeight - 1 ) * normPerLineHeight ;
322+ let height = labelDims . height + ( numLines - 1 ) * ( lineHeight - 1 ) * size ;
323323
324324 util . setPrefixedProperty ( _p . rstyle , 'labelWidth' , prefix , width ) ;
325325 util . setPrefixedProperty ( _p . rscratch , 'labelWidth' , prefix , width ) ;
@@ -328,6 +328,7 @@ BRp.applyPrefixedLabelDimensions = function( ele, prefix ){
328328 util . setPrefixedProperty ( _p . rscratch , 'labelHeight' , prefix , height ) ;
329329
330330 util . setPrefixedProperty ( _p . rscratch , 'labelLineHeight' , prefix , labelLineHeight ) ;
331+ util . setPrefixedProperty ( _p . rscratch , 'labelActualDescent' , prefix , labelDims . labelActualDescent ) ;
331332} ;
332333
333334BRp . getLabelText = function ( ele , prefix ) {
@@ -487,6 +488,7 @@ BRp.calculateLabelDimensions = function( ele, text ){
487488 let size = ele . pstyle ( 'font-size' ) . pfValue ;
488489 let family = ele . pstyle ( 'font-family' ) . strValue ;
489490 let weight = ele . pstyle ( 'font-weight' ) . strValue ;
491+ let textMetrics = ele . pstyle ( 'text-metrics' ) . strValue || "default" ;
490492
491493 let canvas = this . labelCalcCanvas ;
492494 let c2d = this . labelCalcCanvasContext ;
@@ -509,23 +511,38 @@ BRp.calculateLabelDimensions = function( ele, text ){
509511 let width = 0 ;
510512 let height = 0 ;
511513 let lines = text . split ( '\n' ) ;
514+ let lineCount = lines . length ;
515+ let labelActualDescent = 0 ;
516+ let labelActualAscent = 0 ;
512517
513- for ( let i = 0 ; i < lines . length ; i ++ ) {
518+ for ( let i = 0 ; i < lineCount ; i ++ ) {
514519 let line = lines [ i ] ;
515520 let metrics = c2d . measureText ( line ) ;
516521 let w = Math . ceil ( metrics . width ) ;
517522 let h = size ;
523+ if ( textMetrics === "actual" ) {
524+ if ( i === 0 ) {
525+ labelActualAscent = metrics . actualBoundingBoxAscent ;
526+ }
527+ if ( i === lineCount - 1 ) {
528+ labelActualDescent = metrics . actualBoundingBoxDescent ;
529+ }
530+ }
518531
519532 width = Math . max ( w , width ) ;
520533 height += h ;
521534 }
522-
535+ if ( textMetrics === "actual" ) {
536+ height -= size - labelActualAscent - labelActualDescent ;
537+ }
523538 width += padding ;
524539 height += padding ;
525540
526541 return {
527542 width,
528- height
543+ height,
544+ labelActualAscent,
545+ labelActualDescent
529546 } ;
530547} ;
531548
0 commit comments