summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-17 15:39:51 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-17 15:39:51 +0200
commitaceb8a22bd3e7c53de492d3e806ae265942ccfa6 (patch)
tree52e30f45d945369b072893f029e0f5e59b5b116f
parentad95948e09bde3357faf57b6b13e63ae74fe60bb (diff)
downloadluaotfload-aceb8a22bd3e7c53de492d3e806ae265942ccfa6.tar.gz
add ``get_quad()``
-rw-r--r--luaotfload-auxiliary.lua52
1 files changed, 51 insertions, 1 deletions
diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua
index 1a48914..2bfcbf0 100644
--- a/luaotfload-auxiliary.lua
+++ b/luaotfload-auxiliary.lua
@@ -21,7 +21,8 @@ config.luaotfload = config.luaotfload or { }
local aux = luaotfload.aux
local log = luaotfload.log
local warning = luaotfload.log
-local identifiers = fonts.hashes.identifiers
+local fonthashes = fonts.hashes
+local identifiers = fonthashes.identifiers
local fontid = font.id
local texsprint = tex.sprint
@@ -680,4 +681,53 @@ end
aux.get_raw_fonts = get_raw_fonts
+-----------------------------------------------------------------------
+--- font parameters
+-----------------------------------------------------------------------
+--- analogy of font-hsh
+
+fonthashes.parameters = fonthashes.parameters or { }
+fonthashes.quads = fonthashes.quads or { }
+
+local parameters = fonthashes.parameters or { }
+local quads = fonthashes.quads or { }
+
+setmetatable(parameters, { __index = function (t, font_id)
+ local tfmdata = identifiers[font_id]
+ if not tfmdata then --- unsafe; avoid
+ tfmdata = font.fonts[font_id]
+ end
+ if tfmdata and type(tfmdata) == "table" then
+ local fontparameters = tfmdata.parameters
+ t[font_id] = fontparameters
+ return fontparameters
+ end
+ return nil
+end})
+
+--[[doc--
+
+ Note that the reason as to why we prefer functions over table indices
+ is that functions are much safer against unintended manipulation.
+ This justifies the overhead they cost.
+
+--doc]]--
+
+--- int -> (number | false)
+local get_quad = function (font_id)
+ local quad = quads[font_id]
+ if quad then
+ return quad
+ end
+ local fontparameters = parameters[font_id]
+ if fontparameters then
+ local quad = fontparameters.quad or 0
+ quads[font_id] = quad
+ return quad
+ end
+ return false
+end
+
+aux.get_quad = get_quad
+
-- vim:tw=71:sw=2:ts=2:expandtab