Skip to content

Commit 589c058

Browse files
Omikhleiaalerque
authored andcommitted
fix(math): Stretchy symbols should work on large content (workaround)
The current stretchy "reshaping" picks the closest symbols in the math glyph variants, but when none exist or they are still not close enough (esp. far too small), OpenTypeand MathML Core say we should rely on complex glyph assembly rules from glyph parts. We don't have that yet: Here we fallback on re-scaling the glyph. It might not look always good, but at least it's stretched as it should around the content. It's a dirty compromise until something better can be done.
1 parent bde46cd commit 589c058

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

packages/math/base-elements.lua

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,26 @@ function elements.text:_stretchyReshape (target, direction)
10351035
return false
10361036
end
10371037

1038-
function elements.text:_vertStretchyReshape(depth, height)
1039-
return self:_stretchyReshape(depth + height, true)
1038+
function elements.text:_vertStretchyReshape (depth, height)
1039+
local hasStretched = self:_stretchyReshape(depth + height, true)
1040+
if hasStretched then
1041+
-- HACK: see output routine
1042+
self.vertExpectedSz = height + depth
1043+
self.vertScalingRatio = (depth + height):tonumber() / (self.height:tonumber() + self.depth:tonumber())
1044+
self.height = height
1045+
self.depth = depth
1046+
end
1047+
return hasStretched
10401048
end
10411049

1042-
function elements.text:_horizStretchyReshape(width)
1043-
return self:_stretchyReshape(width, false)
1050+
function elements.text:_horizStretchyReshape (width)
1051+
local hasStretched = self:_stretchyReshape(width, false)
1052+
if hasStretched then
1053+
-- HACK: see output routine
1054+
self.horizScalingRatio = width:tonumber() / self.width:tonumber()
1055+
self.width = width
1056+
end
1057+
return hasStretched
10441058
end
10451059

10461060
function elements.text:output (x, y, line)
@@ -1058,7 +1072,21 @@ function elements.text:output (x, y, line)
10581072
-- There should be no stretch or shrink on the width of a text
10591073
-- element.
10601074
local width = self.width.length
1061-
SILE.outputter:drawHbox(self.value, width)
1075+
-- HACK: For stretchy operators, MathML Core and OpenType define how to build large glyphs
1076+
-- from an assembly of smaller ones. It's fairly complex and idealistic...
1077+
-- Anyhow, we do not have that yet, so we just stretch the glyph artificially.
1078+
-- There are cases where this will not look very good.
1079+
-- Call that a compromise, so that long vectors or large matrices look "decent" without assembly.
1080+
if SILE.outputter.scaleFn and (self.horizScalingRatio or self.vertScalingRatio) then
1081+
local xratio = self.horizScalingRatio or 1
1082+
local yratio = self.vertScalingRatio or 1
1083+
SU.debug("math", "fake glyph stretch: xratio =", xratio, "yratio =", yratio)
1084+
SILE.outputter:scaleFn(x, y, xratio, yratio, function ()
1085+
SILE.outputter:drawHbox(self.value, width)
1086+
end)
1087+
else
1088+
SILE.outputter:drawHbox(self.value, width)
1089+
end
10621090
end
10631091

10641092
elements.fraction = pl.class(elements.mbox)

0 commit comments

Comments
 (0)