[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Add script marks in nullfont (cfef74d)

Marcel Fabian Krüger tex at 2krueger.de
Sun Feb 9 03:14:56 CET 2020


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/cfef74d3d02cc0edfd56613fe7be356de5a38152

>---------------------------------------------------------------

commit cfef74d3d02cc0edfd56613fe7be356de5a38152
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Feb 8 13:18:10 2020 +0100

    Add script marks in nullfont


>---------------------------------------------------------------

cfef74d3d02cc0edfd56613fe7be356de5a38152
 src/luaotfload-multiscript.lua  |  50 +++++++++++++++++++++++++++++++++++++++-
 trials/multiscript-fallback.pdf | Bin 88071 -> 88559 bytes
 trials/multiscript-fallback.tex |  12 +++++++++-
 3 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/luaotfload-multiscript.lua b/src/luaotfload-multiscript.lua
index cf2b330..c359dbf 100644
--- a/src/luaotfload-multiscript.lua
+++ b/src/luaotfload-multiscript.lua
@@ -23,6 +23,8 @@ local getwhd             = node.direct.getwhd
 local insert_after       = node.direct.insert_after
 local traverse_char      = node.direct.traverse_char
 local protect_glyph      = node.direct.protect_glyph
+local flush_node         = node.direct.flush_node
+local remove             = node.direct.remove
 local otffeatures        = fonts.constructors.newfeatures "otf"
 -- local normalize          = fonts.handlers.otf.features.normalize
 local definers           = fonts.definers
@@ -31,6 +33,20 @@ local scripts_lib        = require'luaotfload-scripts'.script
 local script_to_iso      = scripts_lib.to_iso
 local script_to_ot       = scripts_lib.to_ot
 
+local delayedremove, finishremove do
+  local removed
+  function finishremove()
+    if removed then
+      flush_node(removed)
+    end
+    removed = nil
+  end
+  function delayedremove(head, current)
+    finishremove()
+    removed = current
+    return remove(head, current)
+  end
+end
 local harf = luaotfload.harfbuzz
 local GSUBtag, GPOStag
 if harf then
@@ -63,6 +79,7 @@ local script_extensions do
     end
   end
 end
+local script_list = {}
 local script_mapping do
   -- We could extract these from PropertyValueAliases.txt...
   local script_aliases = {
@@ -121,6 +138,23 @@ local script_mapping do
   local f = io.open(kpse.find_file"Scripts.txt")
   script_mapping = file:match(f:read'*a')
   f:close()
+
+  for _, scr in next, script_aliases do
+    script_list[#script_list + 1] = scr
+  end
+end
+
+table.sort(script_list)
+local script_mark_offset = 0x200000
+local script_marks = {}
+do
+  for i=1,#script_list do
+    local codepoint = script_mark_offset - 1 + i
+    local scr = script_list[i]
+    -- script_mapping[codepoint] = scr
+    script_marks[scr] = codepoint
+    script_marks[codepoint] = scr
+  end
 end
 
 local function load_on_demand(specifications, size)
@@ -292,7 +326,7 @@ function domultiscript(head, _, _, _, direction)
   local last_fid, last_fonts, last_script
   for cur, cid, fid in traverse_char(head) do
     if fid ~= last_fid then
-      last_fid, last_fonts, last_script = fid, additional_scripts_fonts[fid]
+      last_fid, last_fonts = fid, additional_scripts_fonts[fid]
     end
     if last_fonts then
       local mapped_scr = script_mapping[cid]
@@ -321,8 +355,18 @@ function domultiscript(head, _, _, _, direction)
       if mapped_font then
         setfont(cur, mapped_font)
       end
+    elseif fid == 0 then
+      local script_mark = script_marks[cid]
+      if script_mark then
+        head = delayedremove(head, current)
+        last_script = script_mark
+      end
+    else
+      last_script = nil
     end
   end
+  finishremove() -- Cleanup
+  return head
 end
 
 function luaotfload.add_multiscript(name, fonts)
@@ -336,6 +380,10 @@ function luaotfload.add_multiscript(name, fonts)
   return name
 end
 
+function luaotfload.get_script_mark(scr)
+  return script_marks[scr]
+end
+
 otffeatures.register {
   name        = "multiscript",
   description = "Combine fonts for multiple scripts",
diff --git a/trials/multiscript-fallback.pdf b/trials/multiscript-fallback.pdf
index 08d49b7..7c4e92d 100644
Binary files a/trials/multiscript-fallback.pdf and b/trials/multiscript-fallback.pdf differ
diff --git a/trials/multiscript-fallback.tex b/trials/multiscript-fallback.tex
index 330923f..104224e 100644
--- a/trials/multiscript-fallback.tex
+++ b/trials/multiscript-fallback.tex
@@ -66,7 +66,17 @@ luaotfload.add_fallback
  )
 }
 
-\newcommand\testtext{1234 a^^^^0301 π^^^^0301 a!? π123!? a БѨ123!? a \char"1D6FC\ a \char"0995\char"09BF a „π“ a „Б“}
+\newcommand\testtext{1234 a^^^^0301 π^^^^0301 a!? π123!? a БѨ123!? a \char"1D6FC\ a \char"0995\char"09BF a\scriptmark grek „π“ a \scriptmark{cyrl}„Б“}
+\directlua{
+  local i = luatexbase.new_luafunction'scriptmark'
+  lua.get_functions_table()[i] = function()
+    local scr = token.scan_string()
+    local n = node.new'glyph'
+    n.char = luaotfload.get_script_mark(scr)
+    node.write(n)
+  end
+  token.set_lua('scriptmark', i, 'protected')
+}
 \begin{document}
 red= fallback, green = bng2 multiscript, blue= beng multiscript.
 %\showoutput





More information about the latex3-commits mailing list.