[latex3-commits] [git/LaTeX3-latex3-luaotfload] variable-cff2: Fix #184 for HarfBuzz too (f5b1da3)

Marcel Fabian Krüger tex at 2krueger.de
Wed Aug 4 21:06:46 CEST 2021


Repository : https://github.com/latex3/luaotfload
On branch  : variable-cff2
Link       : https://github.com/latex3/luaotfload/commit/f5b1da37ca0f95f92e82d37a815ef08b584965a5

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

commit f5b1da37ca0f95f92e82d37a815ef08b584965a5
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Wed Aug 4 21:06:46 2021 +0200

    Fix #184 for HarfBuzz too


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

f5b1da37ca0f95f92e82d37a815ef08b584965a5
 src/luaotfload-harf-define.lua        |  2 +-
 src/luaotfload-harf-var-t2-writer.lua | 60 ++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index 29ff0ef..eceab41 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -105,7 +105,7 @@ local function loadfont(spec)
     if hbface:get_table(cff2tag):get_length() == 0 then
       error'Only CFF2 based Variable fonts are currently supported in harf mode'
     end
-    local instance = spec.features.raw.instance
+    local instance = spec.features.raw.instance or spec.features.raw.axis
     local assignments = instance and variable_pattern:match(instance)
     if assignments then
       local axes = hbface:ot_var_get_axis_infos()
diff --git a/src/luaotfload-harf-var-t2-writer.lua b/src/luaotfload-harf-var-t2-writer.lua
index a002efe..9375abe 100644
--- a/src/luaotfload-harf-var-t2-writer.lua
+++ b/src/luaotfload-harf-var-t2-writer.lua
@@ -53,7 +53,65 @@ local function convert_cs(cs, upem)
       end
     end
   end
-  for _, args in ipairs(cs) do if args then add(table.unpack(args)) end end
+  for _, args in ipairs(cs) do
+    if args then
+      local cmd = args[1]
+      local height = #args - 1
+      local i = 2
+      while height > 48 do
+        -- Special cases: hhcurveto, vvcurveto, rcurveline, rlinecurve
+        -- hhvurveto/vvcurveto: In odd argument case, the first argument must be
+        -- followed by a multiple of four arguments.
+        if cmd == 27 and i == 2 and height % 4 == 1 then -- hhcurveto
+          add(cmd, table.unpack(args, i, i + 44))
+          height = height - 45
+          i = i + 45
+        elseif cmd == 26 and i == 2 and height % 4 == 1 then -- vvcurveto
+          add(cmd, table.unpack(args, i, i + 44))
+          height = height - 45
+          i = i + 45
+        -- rcurveline/rlinecurve: At least 8 arguments must be preserved, all previous instances
+        -- need different commands
+        elseif cmd == 24 then -- rcurveline
+          height = height - 48
+          local count
+          if height >= 8 then
+            count = 48
+          else
+            count = 48 - 8 + height
+            height = 8
+          end
+          add(8, table.unpack(args, i, i + count - 1)) -- 8 = rrcurveto
+          i = i + count
+        elseif cmd == 25 then -- rlinecurve
+          height = height - 48
+          local count
+          if height >= 8 then
+            count = 48
+          else
+            count = 48 - 8 + height
+            height = 8
+          end
+          add(5, table.unpack(args, i, i + count - 1)) -- 5 = rlineto
+          i = i + count
+        else -- Some commands have an optional last argument which can appear after multiple of 48 arguments,
+             -- so it's safer to never leave a element alone in a line.
+          height = height - 48
+          local count
+          if height > 1 then
+            count = 48
+          else
+            -- assert(height == 1)
+            count = 24--48 - 25 + height
+            height = 25
+          end
+          add(cmd, table.unpack(args, i, i + count - 1))
+          i = i + count
+        end
+      end
+      add(cmd, table.unpack(args, i))
+    end
+  end
   return table.concat(cs_parts)
 end
 





More information about the latex3-commits mailing list.