summaryrefslogtreecommitdiff
path: root/src/luaotfload-auxiliary.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2016-05-04 21:06:52 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2016-05-04 21:06:56 +0200
commit766978d24919fef28e12a8c4239c96e92dc349a5 (patch)
tree9332c3d1f0690e521aa00a4877edc76dc7da6345 /src/luaotfload-auxiliary.lua
parent109d0b5c76cf614385482b6efd52fca9c76c1cfa (diff)
downloadluaotfload-766978d24919fef28e12a8c4239c96e92dc349a5.tar.gz
[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.
Diffstat (limited to 'src/luaotfload-auxiliary.lua')
-rw-r--r--src/luaotfload-auxiliary.lua26
1 files changed, 16 insertions, 10 deletions
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