From e5500679011f7d29a81e2aae38b3277f569c1ac0 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 9 Dec 2024 16:55:55 +0300 Subject: [PATCH] feat(shapers): Warn when asked to measure a character not shaped in a font --- shapers/base.lua | 14 ++++++++++++-- types/unit.lua | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/shapers/base.lua b/shapers/base.lua index 9a0a08063..2cae7b25a 100644 --- a/shapers/base.lua +++ b/shapers/base.lua @@ -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 diff --git a/types/unit.lua b/types/unit.lua index 169de78a9..5c9c3d1f3 100644 --- a/types/unit.lua +++ b/types/unit.lua @@ -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