File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -2519,14 +2519,18 @@ function textCore(p5, fn) {
25192519 } ;
25202520
25212521 Renderer . prototype . _middleAlignOffset = function ( ) {
2522+ const { textFont, textSize } = this . states ;
2523+ const font = textFont ?. font ;
25222524 const ctx = this . textDrawingContext ( ) ;
25232525 const metrics = ctx . measureText ( 'X' ) ;
2524- return (
2525- ( metrics . fontBoundingBoxDescent +
2526- ( metrics . alphabeticBaseline || - metrics . fontBoundingBoxAscent / 2 ) ) /
2527- 2 -
2528- ( metrics . fontBoundingBoxAscent - metrics . fontBoundingBoxDescent ) / 2
2529- ) ;
2526+ let sCapHeight = ( font ?. data || { } ) [ 'OS/2' ] ?. sCapHeight ;
2527+ if ( sCapHeight ) {
2528+ const unitsPerEm = font . data . head . unitsPerEm ;
2529+ sCapHeight *= textSize / unitsPerEm ;
2530+ } else {
2531+ sCapHeight = metrics . fontBoundingBoxAscent ;
2532+ }
2533+ return metrics . alphabeticBaseline + sCapHeight / 2 ;
25302534 } ;
25312535
25322536 if ( p5 . Renderer2D ) {
You can’t perform that action at this time.
0 commit comments