@@ -510,7 +510,12 @@ function elements.stackbox:shape ()
510510 -- Handle stretchy operators
511511 for _ , elt in ipairs (self .children ) do
512512 if elt :is_a (elements .text ) and elt .kind == " operator" and SU .boolean (elt .stretchy , false ) then
513- elt :_vertStretchyReshape (self .depth , self .height )
513+ local stretched = elt :_vertStretchyReshape (self .depth , self .height )
514+ if stretched then
515+ -- Stretched elements may have altered height and depth
516+ self .height = maxLength (self .height , elt .height )
517+ self .depth = maxLength (self .depth , elt .depth )
518+ end
514519 end
515520 end
516521 -- Set self.width
@@ -1249,10 +1254,16 @@ function elements.text:_vertStretchyReshape (depth, height)
12491254 -- We only do it if the scaling logic found constructions on the vertical block axis.
12501255 -- It's a dirty hack until we properly implement assembly of glyphs in the case we couldn't
12511256 -- find a big enough variant.
1252- self .vertExpectedSz = height + depth
1253- self .vertScalingRatio = (depth + height ):tonumber () / (self .height :tonumber () + self .depth :tonumber ())
1254- self .height = height
1255- self .depth = depth
1257+ -- At output, We will peform a symmetric scaling of the glyphs, centered on the height axis.
1258+ local constants = self :getMathMetrics ().constants
1259+ local scaleDown = self :getScaleDown ()
1260+ axisHeight = constants .axisHeight * scaleDown
1261+
1262+ local midSz = maxLength (height - axisHeight , depth + axisHeight )
1263+ self .vertScalingRatio = 2 * midSz :tonumber () / (self .height + self .depth ):tonumber ()
1264+ self .vertScalingOffset = self .height - (midSz + axisHeight ) / self .vertScalingRatio
1265+ self .height = midSz + axisHeight
1266+ self .depth = midSz - axisHeight
12561267 end
12571268 return hasStretched
12581269end
@@ -1286,6 +1297,9 @@ function elements.text:output (x, y, line)
12861297 else
12871298 compensatedY = y
12881299 end
1300+ if self .vertScalingOffset then
1301+ compensatedY = compensatedY + self .vertScalingOffset
1302+ end
12891303 local xs = scaleWidth (x , line ) -- account for stretchability/shrinkability in line justification
12901304 SILE .outputter :setCursor (xs , compensatedY .length )
12911305 SILE .outputter :setFont (self .font )
0 commit comments