From 766978d24919fef28e12a8c4239c96e92dc349a5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 4 May 2016 21:06:52 +0200 Subject: [aux] fix units lookup prevent crash with AFM fonts With the new loader, the ``units_per_em`` field resides under the toplevel TFM structure with the key ``units``. For AFM fonts, it is not fount under the metadata table too, which we are currently querying. Thus we prefer the main value, falling back on metadata only in case it is missing. At this occasion, tidy up our unit lookup helper and use that wherever we need access to the values ourselves. --- src/luaotfload-auxiliary.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua index e544dd7..e482aba 100644 --- a/src/luaotfload-auxiliary.lua +++ b/src/luaotfload-auxiliary.lua @@ -100,17 +100,21 @@ luaotfload_callbacks [#luaotfload_callbacks + 1] = { "patch_font", set_sscale_dimens, "set_sscale_dimens", } +local default_units = 1000 + --- fontobj -> int local lookup_units = function (fontdata) - local metadata = fontdata.shared and fontdata.shared.rawdata.metadata - if metadata and metadata.units then - return metadata.units - elseif fontdata.parameters and fontdata.parameters.units then - return fontdata.parameters.units - elseif fontdata.units then --- v1.x - return fontdata.units + local units = fontdata.units + if units and units > 0 then return units end + local shared = fontdata.shared if not shared then return default_units end + local rawdata = shared.rawdata if not rawdata then return default_units end + local metadata = rawdata.metadata if not metadata then return default_units end + local capheight = metadata.capheight if not capheight then return default_units end + local units = metadata.units or fontdata.units + if not units or units == 0 then + return default_units end - return 1000 + return units end --[[doc-- @@ -213,8 +217,9 @@ local query_ascender = function (fontdata) local metadata = rawdata.metadata if not metadata then return false end local ascender = parameters.ascender or metadata.ascender if not ascender then return false end - local units = metadata.units if units == 0 then return false end local size = parameters.size if not size then return false end + local units = lookup_units (fontdata) + if not units or units == 0 then return false end return ascender * size / units end @@ -224,8 +229,9 @@ local query_capheight = function (fontdata) local rawdata = shared.rawdata if not rawdata then return false end local metadata = rawdata.metadata if not metadata then return false end local capheight = metadata.capheight if not capheight then return false end - local units = metadata.units if units == 0 then return false end local size = parameters.size if not size then return false end + local units = lookup_units (fontdata) + if not units or units == 0 then return false end return capheight * size / units end -- cgit v1.2.3