[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Add aux.provides_axis (e28c863)
Marcel Fabian Krüger
tex at 2krueger.de
Sat Oct 1 12:13:09 CEST 2022
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/e28c863ecd92c22027184339291d0285a9a62a6a
>---------------------------------------------------------------
commit e28c863ecd92c22027184339291d0285a9a62a6a
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sat Oct 1 12:13:09 2022 +0200
Add aux.provides_axis
>---------------------------------------------------------------
e28c863ecd92c22027184339291d0285a9a62a6a
src/luaotfload-auxiliary.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua
index 0c9551a..8130552 100644
--- a/src/luaotfload-auxiliary.lua
+++ b/src/luaotfload-auxiliary.lua
@@ -583,6 +583,62 @@ function aux.provides_language(font_id, asked_script, asked_language)
end
end
+--[[doc--
+A function to check if a font is a variabe font with a given axis.
+--doc]]--
+
+function aux.provides_axis(font_id, asked_axis)
+ if not font_id or type (font_id) ~= "number"
+ or not asked_axis or type (asked_axis) ~= "string"
+ then
+ logreport ("both", 0, "aux",
+ "invalid parameters to provides_axis(%s, %s)",
+ tostring (font_id), tostring (asked_axis))
+ return false
+ end
+ -- asked_axis = stringlower(asked_axis)
+ local tfmdata = identifiers[font_id]
+ if not tfmdata then
+ logreport ("log", 0, "aux", "no font with id %d", font_id)
+ return false
+ end
+ local hbface = get_hbface(tfmdata)
+ if hbface then
+ if not hbface:ot_var_has_data() then return false end
+
+ if #asked_axis <= 4 then
+ local tag = harf.Tag.new(asked_axis)
+ local info = hbface:ot_var_find_axis_info(tag)
+ if info then
+ return true -- TODO: More info?
+ end
+ end
+
+ asked_axis = stringlower(asked_axis)
+ local infos = hbface:ot_var_get_axis_infos()
+ for i=1, #infos do
+ local info = infos[i]
+ if hbface:get_name(info.name_id):lower() == asked_axis then
+ return true -- TODO: More info?
+ end
+ end
+ else
+ asked_axis = stringlower(asked_axis)
+ local resources = tfmdata.resources
+ local variabledata = resources and resources.variabledata
+ if not variabledata then return false end
+ local axes = variabledata.axis
+ if not axes then return false end -- Shouldn't happen
+ for i=1, #axes do
+ local axis = axes[i]
+ if axis.tag == asked_axis or axis.name == asked_axis then
+ return true -- TODO: More info?
+ end
+ end
+ end
+ return false
+end
+
--[[doc--
We strip the syntax elements from feature definitions (shouldn’t
actually be there in the first place, but who cares ...)
More information about the latex3-commits
mailing list.