Skip to content

Commit

Permalink
feat(shapers): Warn when asked to measure a character not shaped in a…
Browse files Browse the repository at this point in the history
… font
  • Loading branch information
alerque committed Dec 9, 2024
1 parent 2adf631 commit e550067
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions shapers/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ function shaper:measureChar (char)
local options = SILE.font.loadDefaults({})
options.tracking = SILE.settings:get("shaper.tracking")
local items = self:shapeToken(char, options)
if #items > 0 then
return { height = items[1].height, width = items[1].width, depth = items[1].depth }
SU.dump({ char, items })
if #items >= 1 then
local item = items[1]
if item.name == ".notdef" then
SU.warn(
("No glyph available for '%s' in %s, returning measurements of '.notdef' instead"):format(
char,
options.family
)
)
end
return { height = item.height, width = item.width, depth = item.depth, name = item.name }
else
SU.error("Unable to measure character", char)
end
Expand Down
2 changes: 1 addition & 1 deletion types/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ unittypes["zw"] = {
definition = function (v)
local zenkakuchar = SILE.settings:get("document.zenkakuchar")
local measurable, zenkaku = pcall(SILE.shaper.measureChar, SILE.shaper, zenkakuchar)
if not measurable then
if not measurable or zenkaku.name == ".notdef" then
SU.warn(([[
Zenkaku width (全角幅) unit zw is falling back to 1em == 1zw as we cannot measure %s
Expand Down

0 comments on commit e550067

Please sign in to comment.