Skip to content

Commit e0b5cd8

Browse files
committed
feat(shapers): Warn when asked to measure a character not shaped in a font
1 parent 2adf631 commit e0b5cd8

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

packages/math/base-elements.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,10 @@ function elements.sqrt:shape ()
16251625
-- Note: In TeX, the radical sign extends a lot below the baseline,
16261626
-- and MathML Core also has a lot of layout text about it.
16271627
-- Not only it doesn't look good, but it's not very clear vs. OpenType.
1628-
local radicalGlyph = SILE.shaper:measureChar("")
1628+
local radicalGlyph, found = SILE.shaper:measureChar("")
1629+
if not found then
1630+
SU.error("Math font does not contain a square root glyph")
1631+
end
16291632
local ratio = (self.radicand.height:tonumber() + self.radicand.depth:tonumber())
16301633
/ (radicalGlyph.height + radicalGlyph.depth)
16311634
local vertAdHocOffset = (ratio > 1 and math.log(ratio) or 0) * self.radicalVerticalGap

shapers/base.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ function shaper:measureChar (char)
6767
local options = SILE.font.loadDefaults({})
6868
options.tracking = SILE.settings:get("shaper.tracking")
6969
local items = self:shapeToken(char, options)
70-
if #items > 0 then
71-
return { height = items[1].height, width = items[1].width, depth = items[1].depth }
70+
if items and items[1] then
71+
local item = items[1]
72+
return item, item.gid ~= 0
7273
else
7374
SU.error("Unable to measure character", char)
7475
end

types/unit.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,16 @@ unittypes["zw"] = {
223223
relative = true,
224224
definition = function (v)
225225
local zenkakuchar = SILE.settings:get("document.zenkakuchar")
226-
local measurable, zenkaku = pcall(SILE.shaper.measureChar, SILE.shaper, zenkakuchar)
227-
if not measurable then
226+
local measurable, zenkaku, found = pcall(SILE.shaper.measureChar, SILE.shaper, zenkakuchar)
227+
if not found or not measurable then
228228
SU.warn(([[
229229
Zenkaku width (全角幅) unit zw is falling back to 1em == 1zw as we cannot measure %s
230230
231231
Either change this char to one suitable for your language, or load a font that
232232
has it.
233233
]]):format(zenkakuchar))
234234
end
235-
local width = measurable and zenkaku.width or SILE.settings:get("font.size")
235+
local width = found and measurable and zenkaku.width or SILE.settings:get("font.size")
236236
return v * width
237237
end,
238238
}

0 commit comments

Comments
 (0)