[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Take care of removing def. ignorables by ourself (87c4cd6)
Marcel Fabian Krüger
tex at 2krueger.de
Tue Mar 31 00:49:47 CEST 2020
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/87c4cd6929e3c3986e26e5e05856a259466fb656
>---------------------------------------------------------------
commit 87c4cd6929e3c3986e26e5e05856a259466fb656
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Tue Mar 31 00:49:47 2020 +0200
Take care of removing def. ignorables by ourself
>---------------------------------------------------------------
87c4cd6929e3c3986e26e5e05856a259466fb656
src/luaotfload-harf-define.lua | 4 +-
src/luaotfload-notdef.lua | 122 +++++++++++++++++++-----------------
testfiles-harf/fallback.tlg | 2 +-
testfiles-harf/multiscript-auto.tlg | 2 +-
testfiles/invisible-chars.tlg | 4 +-
5 files changed, 72 insertions(+), 62 deletions(-)
diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index caf08d4..8754358 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -308,7 +308,9 @@ local function scalefont(data, spec)
buf_flags = harf_settings.default_buf_flags,
},
specification = spec,
- shared = {},
+ shared = {
+ features = features,
+ },
properties = {},
resources = {
unicodes = data.name_to_char,
diff --git a/src/luaotfload-notdef.lua b/src/luaotfload-notdef.lua
index 88bb554..5c724cf 100644
--- a/src/luaotfload-notdef.lua
+++ b/src/luaotfload-notdef.lua
@@ -24,14 +24,20 @@ local getwhd = node.direct.getwhd
local insert = table.insert
local insert_after = node.direct.insert_after
local kern_id = node.id'kern'
+local disc_id = node.id'disc'
local nodenew = node.direct.new
+local nodecopy = node.direct.copy
local otfregister = fonts.constructors.features.otf.register
local protect_glyph = node.direct.protect_glyph
local remove = node.direct.remove
local setfont = node.direct.setfont
local traverse_char = node.direct.traverse_char
+local traverse_id = node.direct.traverse_id
local setchar = node.direct.setchar
local getwidth = node.direct.getwidth
+local setkern = node.direct.setkern
+local setattributelist = node.direct.setattributelist
+local getattributelist = node.direct.getattributelist
local setmove = luaotfload.fontloader.nodes.injections.setmove
-- According to DerivedCoreProperties.txt, Default_Ignorable_Code_Point
@@ -158,74 +164,76 @@ otfregister {
}
}
-function fonts.handlers.otf.handlers.gsub_remove(head,char,dataset,sequence,kind,rlmode,skiphash,step,injection)
- local replacement
- if kind ~= 'ignore' then
- replacement = false
- else
- replacement = tonumber(dataset[1])
+local cached_kern = setmetatable({}, {__index = function(t, i)
+ local n = nodenew(kern_id)
+ setkern(n, i)
+ setattributelist(n, nil)
+ t[i] = n
+ return n
+end})
+local font_invisible_replacement = setmetatable({}, {__index = function(t, fid)
+ local fontdata = font.getfont(fid)
+ local replacement = fontdata.shared.features.invisible
+ if replacement == "remove" then
+ t[fid] = false
+ return false
end
- if replacement then
- setchar(char, replacement)
- setmove(char, 1, rlmode, -getwidth(char), injection)
- return head, char, true
+ replacement = tonumber(replacement) or 32
+ local char = fontdata.characters[replacement]
+ if char then
+ t[fid] = {replacement, cached_kern[-char.width]}
+ return t[fid]
else
- local next
- head, next = remove(head, char)
- flush_node(char)
- if not head and not next then -- Avoid a double free if we were alone
- head = nodenew(kern_id)
- end
- return head, next, true, true
+ t[fid] = false
+ return false
end
-end
+end})
-local sequence = {
- features = {invisible = {["*"] = {["*"] = true}}},
- flags = {false, false, false, false},
- name = "invisible",
- order = {"invisible"},
- nofsteps = 1,
- steps = {{
- coverage = ignorable_codepoints,
- index = 1,
- }},
- type = "gsub_remove",
-}
-local function invisibleinitialiser(tfmdata, value, features)
- local resources = tfmdata.resources
- local sequences = resources and resources.sequences
- if value ~= 'remove' and not tonumber(value) then
- features.invisible = 32
+ignorable_replacement = {}
+
+local delayed_remove do
+ local delayed
+ function delayed_remove(n)
+ flush_node(delayed)
+ delayed = n
end
- if sequences then
- local alreadydone
- for i=1,#sequences do
- if sequence == sequences[i] then
- alreadydone = true
- break
+end
+
+local function ignorablehandler(head, fid, ...) -- FIXME: The arguments are probably wrong
+ local fontparam = font_invisible_replacement[fid]
+ local replacement = fontparam and fontparam[1]
+ local font_kern = fontparam and fontparam[2]
+ for n, c, f in traverse_char(head) do if f == fid then
+ local lookup = ignorable_codepoints[c]
+ if lookup then
+ if replacement then
+ setchar(n, replacement)
+ if font_kern then
+ local k = nodecopy(font_kern)
+ setattributelist(k, getattributelist(n))
+ head = insert_after(head, n, nodecopy(font_kern))
+ end
+ else
+ local after
+ head, after = remove(head, n)
+ delayed_remove(n)
end
end
- if not alreadydone then
- -- Now we get to the interesting part: At which point should our new sequence be inserted? Let's do it at the end, then they are still seen by all features.
- insert(sequences, sequence)
- end
+ end end
+ delayed_remove()
+ for n in traverse_id(head, disc_id) do
+ local a, b, c = getdisc(n)
+ setdisc(ignorablehandler(a, fid), ignorablehandler(b, fid), ignorablehandler(c, fid))
end
+ return head
end
-local invisibleinitialiserharf if harfbuzz then
+
+if harfbuzz then
local harf_settings = luaotfload.harf
local preserve_flag = harfbuzz.Buffer.FLAG_PRESERVE_DEFAULT_IGNORABLES or 0
local remove_flag = harfbuzz.Buffer.FLAG_REMOVE_DEFAULT_IGNORABLES or 0
local dotted_circle_flag = harfbuzz.Buffer.FLAG_DO_NOT_INSERT_DOTTED_CIRCLE or 0
harf_settings.default_buf_flags = (harf_settings.default_buf_flags & ~remove_flag) | preserve_flag | dotted_circle_flag
- function invisibleinitialiserharf(tfmdata, value)
- if not tfmdata.hb then return end
- local hb = tfmdata.hb
- hb.buf_flags = hb.buf_flags & ~preserve_flag
- if value == "remove" then
- hb.buf_flags = hb.buf_flags | remove_flag
- end
- end
local function dottedcircleinitialize(tfmdata, value)
if not tfmdata.hb then return end
local hb = tfmdata.hb
@@ -244,9 +252,9 @@ otfregister {
name = 'invisible',
description = 'Remove invisible control characters',
default = true,
- initializers = {
- node = invisibleinitialiser,
- plug = invisibleinitialiserharf,
+ processors = {
+ node = ignorablehandler,
+ plug = ignorablehandler,
},
}
diff --git a/testfiles-harf/fallback.tlg b/testfiles-harf/fallback.tlg
index 20dbd6d..1cac6e6 100644
--- a/testfiles-harf/fallback.tlg
+++ b/testfiles-harf/fallback.tlg
@@ -71,4 +71,4 @@ Completed box being shipped out [1]
...\glue 0.0 plus 1.0fil
...\TU/lmr/m/n/10 "1" 0031 +0:+0^^I[lmroman10-regular]:+tlig;
...\glue 0.0 plus 1.0fil
-2 hlist, 1 rule, 1 dir, 3 kern, 1 glyph, 2 attribute, 48 glue_spec, 2 attribute_list (fallback.aux)
+2 hlist, 1 rule, 1 dir, 5 kern, 1 glyph, 2 attribute, 48 glue_spec, 2 attribute_list (fallback.aux)
diff --git a/testfiles-harf/multiscript-auto.tlg b/testfiles-harf/multiscript-auto.tlg
index 3f281a9..8f42d3d 100644
--- a/testfiles-harf/multiscript-auto.tlg
+++ b/testfiles-harf/multiscript-auto.tlg
@@ -97,4 +97,4 @@ Completed box being shipped out [1]
...\glue 0.0 plus 1.0fil
...\TU/lmr/m/n/10 "1" 0031 +0:+0
...\glue 0.0 plus 1.0fil
-2 hlist, 1 rule, 1 dir, 3 kern, 1 glyph, 2 attribute, 48 glue_spec, 2 attribute_list (multiscript-auto.aux)
+2 hlist, 1 rule, 1 dir, 4 kern, 1 glyph, 2 attribute, 48 glue_spec, 2 attribute_list (multiscript-auto.aux)
diff --git a/testfiles/invisible-chars.tlg b/testfiles/invisible-chars.tlg
index 75c27ad..491202d 100644
--- a/testfiles/invisible-chars.tlg
+++ b/testfiles/invisible-chars.tlg
@@ -47,11 +47,11 @@ Completed box being shipped out [1]
.....\localleftbox=null
.....\localrightbox=null
....\hbox(0.0+0.0)x15.0, direction TLT
-....\kern-5.84 (font)
....\amiri
-....\amiri ي
....\kern-5.84 (font)
+....\amiri ي
....\amiri
+....\kern-5.84 (font)
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
More information about the latex3-commits
mailing list.