From b717bea7d6fb8521bbc578148834022cd6d0d03f 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 | 9 +++++++-- types/unit.lua | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/shapers/base.lua b/shapers/base.lua index 9a0a08063..a78fb90eb 100644 --- a/shapers/base.lua +++ b/shapers/base.lua @@ -67,8 +67,13 @@ 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