[latex3-commits] [git/LaTeX3-latex3-luaotfload] harfnode-dev: Combine harf auxiliary functions with aux (3208006)
Marcel Fabian Krüger
tex at 2krueger.de
Tue Oct 15 19:55:48 CEST 2019
Repository : https://github.com/latex3/luaotfload
On branch : harfnode-dev
Link : https://github.com/latex3/luaotfload/commit/3208006b00f8a3033932a64b702886d3d1a3bb3c
>---------------------------------------------------------------
commit 3208006b00f8a3033932a64b702886d3d1a3bb3c
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Tue Oct 15 19:40:10 2019 +0200
Combine harf auxiliary functions with aux
>---------------------------------------------------------------
3208006b00f8a3033932a64b702886d3d1a3bb3c
src/luaotfload-auxiliary.lua | 125 ++++++++++++++++++++++++++++++++--------
src/luaotfload-harf.lua | 134 -------------------------------------------
src/luaotfload-main.lua | 1 -
3 files changed, 102 insertions(+), 158 deletions(-)
diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua
index 8fa55d3..dca89f0 100644
--- a/src/luaotfload-auxiliary.lua
+++ b/src/luaotfload-auxiliary.lua
@@ -39,6 +39,13 @@ local stringbyte = string.byte
local stringfind = string.find
local tablecopy = table.copy
+local harf = luaharfbuzz or require'luaharfbuzz'
+local GSUBtag, GPOStag
+if harf then
+ GSUBtag = harf.Tag.new("GSUB")
+ GPOStag = harf.Tag.new("GPOS")
+end
+
local aux = { }
local luaotfload_callbacks = { }
@@ -349,15 +356,27 @@ function aux.slot_of_name(font_id, glyphname, unsafe)
local tfmdata = identifiers [font_id]
if not tfmdata then return raw_slot_of_name (font_id, glyphname) end
- local resources = tfmdata.resources if not resources then return false end
- local unicodes = resources.unicodes if not unicodes then return false end
-
- local unicode = unicodes [glyphname]
- if unicode then
- if type (unicode) == "number" then
- return unicode
- else
- return unicode [1] --- for multiple components
+ local hbdata = fontdata.hb
+ if hbdata then
+ local hbshared = hbdata.shared
+ local nominals = hbshared.nominals
+ local hbfont = hbshared.font
+
+ local gid = hbfont:get_glyph_from_name(glyphname)
+ if gid ~= nil then
+ return nominals[gid] or gid + hbshared.gid_offset
+ end
+ else
+ local resources = tfmdata.resources if not resources then return false end
+ local unicodes = resources.unicodes if not unicodes then return false end
+
+ local unicode = unicodes [glyphname]
+ if unicode then
+ if type (unicode) == "number" then
+ return unicode
+ else
+ return unicode [1] --- for multiple components
+ end
end
end
return false
@@ -412,6 +431,11 @@ local function get_features(tfmdata)
return features
end
+local function get_hbface(tfmdata)
+ if not tfmdata.hb then return end
+ return tfmdata.hbshared.face
+end
+
--[[doc--
This function, modeled after “check_script()” from fontspec, returns
true if in the given font, the script “asked_script” is accounted for in at
@@ -429,9 +453,21 @@ function aux.provides_script(font_id, asked_script)
return false
end
asked_script = stringlower(asked_script)
- if font_id and font_id > 0 then
- local tfmdata = identifiers[font_id]
- if not tfmdata then return false end
+ 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
+ local script = harf.Tag.new(asked_script)
+ for _, tag in next, { GSUBtag, GPOStag } do
+ local scripts = hbface:ot_layout_get_script_tags(tag) or {}
+ for i = 1, #scripts do
+ if script == scripts[i] then return true end
+ end
+ end
+ else
local features = get_features (tfmdata)
if features == false then
logreport ("log", 1, "aux", "font no %d lacks a features table", font_id)
@@ -452,7 +488,6 @@ function aux.provides_script(font_id, asked_script)
"font no %d (%s) defines no feature for script %s",
font_id, fontname, asked_script)
end
- logreport ("log", 0, "aux", "no font with id %d", font_id)
return false
end
@@ -477,8 +512,36 @@ function aux.provides_language(font_id, asked_script, asked_language)
return false
end
asked_script = stringlower(asked_script)
- asked_language = stringlower(asked_language)
- if font_id and font_id > 0 then
+ 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
+ asked_language = stringupper(asked_language)
+ if asked_language == "DFLT" then
+ return aux.provides_script(font_id, asked_script)
+ end
+ local script = harf.Tag.new(asked_script)
+ -- HarfBuzz expects "DFLT" in lower-case
+ local language = harf.Tag.new(asked_language)
+ local feature = harf.Tag.new(feature)
+
+ for _, tag in next, { GSUBtag, GPOStag } do
+ local scripts = hbface:ot_layout_get_script_tags(tag) or {}
+ for i = 1, #scripts do
+ if script == scripts[i] then
+ local languages = hbface:ot_layout_get_language_tags(tag, i - 1) or {}
+ for j = 1, #languages do
+ if language == languages[j] then return true end
+ end
+ end
+ end
+ end
+ return false
+ else
+ asked_language = stringlower(asked_language)
local tfmdata = identifiers[font_id]
if not tfmdata then return false end
local features = get_features (tfmdata)
@@ -504,9 +567,8 @@ function aux.provides_language(font_id, asked_script, asked_language)
"font no %d (%s) defines no feature "
.. "for script %s with language %s",
font_id, fontname, asked_script, asked_language)
+ return false
end
- logreport ("log", 0, "aux", "no font with id %d", font_id)
- return false
end
--[[doc--
@@ -558,12 +620,31 @@ function aux.provides_feature(font_id, asked_script,
return false
end
asked_script = stringlower(asked_script)
- asked_language = stringlower(asked_language)
asked_feature = lpegmatch(strip_garbage, asked_feature)
- if font_id > 0 then
- local tfmdata = identifiers[font_id]
- if not tfmdata then return false end
+ 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
+ asked_language = stringupper(asked_language)
+ local script = harf.Tag.new(asked_script)
+ -- HarfBuzz expects "DFLT" in lower-case
+ local language = harf.Tag.new(asked_language == "DFLT" and "dflt" or asked_language)
+ local feature = harf.Tag.new(feature)
+
+ for _, tag in next, { GSUBtag, GPOStag } do
+ local _, script_idx = hbface:ot_layout_find_script(tag, script)
+ local _, language_idx = hbface:ot_layout_find_language(tag, script_idx, language)
+ if hbface:ot_layout_find_feature(tag, script_idx, language_idx, feature) then
+ return true
+ end
+ end
+ return false
+ else
+ asked_language = stringlower(asked_language)
local features = get_features (tfmdata)
if features == false then
logreport ("log", 1, "aux", "font no %d lacks a features table", font_id)
@@ -588,8 +669,6 @@ function aux.provides_feature(font_id, asked_script,
"font no %d (%s) does not define feature %s for script %s with language %s",
font_id, fontname, asked_feature, asked_script, asked_language)
end
- logreport ("log", 0, "aux", "no font with id %d", font_id)
- return false
end
-----------------------------------------------------------------------
diff --git a/src/luaotfload-harf.lua b/src/luaotfload-harf.lua
deleted file mode 100644
index 3b63a37..0000000
--- a/src/luaotfload-harf.lua
+++ /dev/null
@@ -1,134 +0,0 @@
-local harf = luaharfbuzz or require'luaharfbuzz'
-
-local GSUBtag = harf.Tag.new("GSUB")
-local GPOStag = harf.Tag.new("GPOS")
-local dflttag = harf.Tag.new("dflt")
-
-local aux = luaotfload.aux
-
-local aux_provides_script = aux.provides_script
-aux.provides_script = function(fontid, script)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local hbface = hbshared.face
-
- local script = harf.Tag.new(script)
- for _, tag in next, { GSUBtag, GPOStag } do
- local scripts = hbface:ot_layout_get_script_tags(tag) or {}
- for i = 1, #scripts do
- if script == scripts[i] then return true end
- end
- end
- return false
- end
- return aux_provides_script(fontid, script)
-end
-
-local aux_provides_language = aux.provides_language
-aux.provides_language = function(fontid, script, language)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local hbface = hbshared.face
-
- local script = harf.Tag.new(script)
- -- fontspec seems to incorrectly use “DFLT” for language instead of “dflt”.
- local language = harf.Tag.new(language == "DFLT" and "dflt" or language)
-
- for _, tag in next, { GSUBtag, GPOStag } do
- local scripts = hbface:ot_layout_get_script_tags(tag) or {}
- for i = 1, #scripts do
- if script == scripts[i] then
- if language == dflttag then
- -- By definition “dflt” language is always present.
- return true
- else
- local languages = hbface:ot_layout_get_language_tags(tag, i - 1) or {}
- for j = 1, #languages do
- if language == languages[j] then return true end
- end
- end
- end
- end
- end
- return false
- end
- return aux_provides_language(fontid, script, language)
-end
-
-local aux_provides_feature = aux.provides_feature
-aux.provides_feature = function(fontid, script, language, feature)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local hbface = hbshared.face
-
- local script = harf.Tag.new(script)
- -- fontspec seems to incorrectly use “DFLT” for language instead of “dflt”.
- local language = harf.Tag.new(language == "DFLT" and "dflt" or language)
- local feature = harf.Tag.new(feature)
-
- for _, tag in next, { GSUBtag, GPOStag } do
- local _, script_idx = hbface:ot_layout_find_script(tag, script)
- local _, language_idx = hbface:ot_layout_find_language(tag, script_idx, language)
- if hbface:ot_layout_find_feature(tag, script_idx, language_idx, feature) then
- return true
- end
- end
- return false
- end
- return aux_provides_feature(fontid, script, language, feature)
-end
-
-local aux_font_has_glyph = aux.font_has_glyph
-aux.font_has_glyph = function(fontid, codepoint)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local unicodes = hbshared.unicodes
- return unicodes[codepoint] ~= nil
- end
- return aux_font_has_glyph(fontid, codepoint)
-end
-
-local aux_slot_of_name = aux.slot_of_name
-aux.slot_of_name = function(fontid, glyphname, unsafe)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local nominals = hbshared.nominals
- local hbfont = hbshared.font
-
- local gid = hbfont:get_glyph_from_name(glyphname)
- if gid ~= nil then
- return nominals[gid] or gid + hbshared.gid_offset
- end
- return nil
- end
- return aux_slot_of_name(fontid, glyphname, unsafe)
-end
-
-local aux_name_of_slot = aux.name_of_slot
-aux.name_of_slot = function(fontid, codepoint)
- local fontdata = font.getfont(fontid)
- local hbdata = fontdata and fontdata.hb
- if hbdata then
- local hbshared = hbdata.shared
- local hbfont = hbshared.font
- local characters = fontdata.characters
- local character = characters[codepoint]
-
- if character then
- local gid = characters[codepoint].index
- return hbfont:get_glyph_name(gid)
- end
- return nil
- end
- return aux_name_of_slot(fontid, codepoint)
-end
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index cc0461a..6ee3cd7 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -303,7 +303,6 @@ luaotfload.main = function ()
loadmodule "notdef" --- missing glyph handling
initialize "auxiliary" --- additional high-level functionality
if pcall(require, 'luaharfbuzz') then
- loadmodule "harf"
loadmodule "harf-define"
loadmodule "harf-plug"
end
More information about the latex3-commits
mailing list