[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Move tlig feature into feature too (963ec17)

Marcel Fabian Krüger tex at 2krueger.de
Sun Feb 23 11:57:57 CET 2020


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

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

commit 963ec176a802a2ea623face10d1ed738d7e383f4
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sun Feb 23 11:57:57 2020 +0100

    Move tlig feature into feature too


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

963ec176a802a2ea623face10d1ed738d7e383f4
 src/luaotfload-harf-define.lua | 28 -----------------
 src/luaotfload-harf-plug.lua   | 18 -----------
 src/luaotfload-szss.lua        | 68 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index 26e1fe7..1050e0b 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -219,20 +219,6 @@ local function sanitize(psname)
   return psname:gsub('[][\0-\32\127-\255(){}<>/%%]', '-')
 end
 
--- Ligatures. The value is a character "ligature" table as described in the
--- manual.
-local tlig ={
-  [0x2013] = { [0x002D] = { char = 0x2014 } }, -- [---]
-  [0x002D] = { [0x002D] = { char = 0x2013 } }, -- [--]
-  [0x0060] = { [0x0060] = { char = 0x201C } }, -- [``]
-  [0x0027] = { [0x0027] = { char = 0x201D } }, -- ['']
-  [0x0021] = { [0x0060] = { char = 0x00A1 } }, -- [!`]
-  [0x003F] = { [0x0060] = { char = 0x00BF } }, -- [?`]
-  [0x002C] = { [0x002C] = { char = 0x201E } }, -- [,,]
-  [0x003C] = { [0x003C] = { char = 0x00AB } }, -- [<<]
-  [0x003E] = { [0x003E] = { char = 0x00BB } }, -- [>>]
-}
-
 local function scalefont(data, spec)
   if not data then return data, spec end
   local size = spec.size
@@ -285,20 +271,6 @@ local function scalefont(data, spec)
     end
   end
 
-  local slantfactor = nil
-  if features.slant then
-    slantfactor = tonumber(features.slant) * 1000
-  end
-
-  if features.tlig then
-    for char in next, characters do
-      local ligatures = tlig[char]
-      if ligatures then
-        characters[char].ligatures = ligatures
-      end
-    end
-  end
-
   local tfmdata = {
     name = spec.specification,
     filename = 'harfloaded:' .. spec.resolved,
diff --git a/src/luaotfload-harf-plug.lua b/src/luaotfload-harf-plug.lua
index e148c97..9d0e730 100644
--- a/src/luaotfload-harf-plug.lua
+++ b/src/luaotfload-harf-plug.lua
@@ -166,22 +166,11 @@ end
 
 local process
 
--- Legacy TeX Input Method Disguised as Font Ligatures hack.
---
--- Single replacements, keyed by character to replace. Handled separately
--- because TeX ligaturing mechanism does not support one-to-one replacements.
-local trep = {
-  [0x0022] = 0x201D, -- ["]
-  [0x0027] = 0x2019, -- [']
-  [0x0060] = 0x2018, -- [`]
-}
-
 local function itemize(head, fontid, direction)
   local fontdata = font.getfont(fontid)
   local hbdata   = fontdata and fontdata.hb
   local spec     = fontdata and fontdata.specification
   local options  = spec and spec.features.raw
-  local texlig   = options and options.tlig
 
   local runs, codes = {}, {}
   local dirstack = {}
@@ -224,13 +213,6 @@ local function itemize(head, fontid, direction)
       currdir = getdir(n)
     end
 
-    if not skip and texlig then
-      local replacement = trep[code]
-      if replacement then
-        code = replacement
-      end
-    end
-
     codes[#codes + 1] = code
 
     if lastdir ~= currdir or lastskip ~= skip then
diff --git a/src/luaotfload-szss.lua b/src/luaotfload-szss.lua
index 55b5553..9049037 100644
--- a/src/luaotfload-szss.lua
+++ b/src/luaotfload-szss.lua
@@ -160,13 +160,65 @@ otfregister {
     end,
   },
 }
-  -- if features.tlig then
-  --   for char in next, characters do
-  --     local ligatures = tlig[char]
-  --     if ligatures then
-  --       characters[char].ligatures = ligatures
-  --     end
-  --   end
-  -- end
+
+-- Legacy TeX Input Method Disguised as Font Ligatures hack.
+--
+-- Single replacements, keyed by character to replace. Handled separately
+-- because TeX ligaturing mechanism does not support one-to-one replacements.
+local trep = {
+  [0x0022] = 0x201D, -- ["]
+  [0x0027] = 0x2019, -- [']
+  [0x0060] = 0x2018, -- [`]
+}
+
+-- Ligatures. The value is a character "ligature" table as described in the
+-- manual.
+local tlig ={
+  [0x2013] = { [0x002D] = { char = 0x2014 } }, -- [---]
+  [0x002D] = { [0x002D] = { char = 0x2013 } }, -- [--]
+  [0x0060] = { [0x0060] = { char = 0x201C } }, -- [``]
+  [0x0027] = { [0x0027] = { char = 0x201D } }, -- ['']
+  [0x0021] = { [0x0060] = { char = 0x00A1 } }, -- [!`]
+  [0x003F] = { [0x0060] = { char = 0x00BF } }, -- [?`]
+  [0x002C] = { [0x002C] = { char = 0x201E } }, -- [,,]
+  [0x003C] = { [0x003C] = { char = 0x00AB } }, -- [<<]
+  [0x003E] = { [0x003E] = { char = 0x00BB } }, -- [>>]
+}
+
+otfregister {
+  name = 'tlig',
+  description = 'Traditional TeX ligatures',
+  default = false,
+  manipulators = {
+    plug = function(tfmdata, _, value)
+      local characters = tfmdata.characters
+      for codepoint, ligatures in next, tlig do
+        local char = characters[codepoint]
+        if char then
+          char.ligatures = ligatures
+        end
+      end
+    end,
+  },
+  processors = {
+    plug = function(head, font)
+      local n = head
+      while n do
+        local c, id = is_char(n, font)
+        local rep = trep[c]
+        if rep then
+          setchar(n, rep)
+        elseif id == disc_t then
+          local pre, post, replace = getdisc(n)
+          pre = szssprocessor(pre, font)
+          post = szssprocessor(post, font)
+          replace = szssprocessor(replace, font)
+          setdisc(n, pre, post, replace)
+        end
+        n = getnext(n)
+      end
+    end,
+  },
+}
 
 --- vim:sw=2:ts=2:expandtab:tw=71





More information about the latex3-commits mailing list.