[latex3-commits] [git/LaTeX3-latex3-luaotfload] variable-cff2: Fix composite glyphs -- Requires engine changes (c190280)

Marcel Fabian Krüger tex at 2krueger.de
Sat Aug 7 04:50:05 CEST 2021


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

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

commit c1902805e3afc1cb5e802a22a93286f2329387c1
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Aug 7 04:41:42 2021 +0200

    Fix composite glyphs -- Requires engine changes


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

c1902805e3afc1cb5e802a22a93286f2329387c1
 src/luaotfload-harf-define.lua  | 25 ++++++++++++++++++++-----
 src/luaotfload-harf-var-ttf.lua | 12 ++++++------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index e054c31..eca2da4 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -426,7 +426,7 @@ local function scalefont(data, spec)
     resources = {
       unicodes = data.name_to_char,
     },
-    streamprovider = data.normalized and (data.fonttype == 'opentype' and 1 or 2) or nil,
+    streamprovider = data.normalized and (data.fonttype == 'opentype' and 1 or 3) or nil,
   }
   tfmdata.shared.processes = fonts.handlers.otf.setfeatures(tfmdata, features)
   fonts.constructors.applymanipulators("otf", tfmdata, features, false)
@@ -489,19 +489,34 @@ luatexbase.add_to_callback('find_truetype_file', function(name)
 end, 'luaotfload.harf.strip_prefix')
 
 local glyph_stream_data
+local glyph_stream_mapping, glyph_stream_mapping_inverse
+local extents_hbfont
 local cb = luatexbase.remove_from_callback('glyph_stream_provider', 'luaotfload.glyph_stream')
-luatexbase.add_to_callback('glyph_stream_provider', function(fid, cid, kind)
+luatexbase.add_to_callback('glyph_stream_provider', function(fid, cid, kind, ocid)
   if cid == 0 then -- Always the first call for a font
-    glyph_stream_data = nil
+    glyph_stream_data, extents_hbfont = nil
     collectgarbage()
     local fontdir = font.getfont(fid)
     if fontdir and fontdir.hb then
-      glyph_stream_data = (kind == 1 and cff2_handler or kind == 2 and ttf_handler)(fontdir.hb.shared.face, fontdir.hb.shared.font)
+      if kind == 3 then
+        glyph_stream_mapping = {[ocid] = cid}
+        glyph_stream_mapping_inverse = {[cid] = ocid}
+        extents_hbfont = fontdir.hb.shared.font
+      elseif kind == 2 then
+        glyph_stream_data = ttf_handler(fontdir.hb.shared.face, fontdir.hb.shared.font, glyph_stream_mapping, glyph_stream_mapping_inverse)
+      else
+        glyph_stream_data = cff2_handler(fontdir.hb.shared.face, fontdir.hb.shared.font)
+      end
     end
   end
   if glyph_stream_data then
     return glyph_stream_data(cid)
+  elseif extents_hbfont then
+    glyph_stream_mapping[ocid] = cid
+    glyph_stream_mapping_inverse[cid] = ocid
+    local extents = extents_hbfont:get_glyph_extents(ocid)
+    return extents.width, extents.x_bearing, extents.height, extents.y_bearing
   else
-    return cb(fid, cid, kind)
+    return cb(fid, cid, kind, ocid)
   end
 end, 'luaotfload.harf.glyphstream')
diff --git a/src/luaotfload-harf-var-ttf.lua b/src/luaotfload-harf-var-ttf.lua
index efe2a29..4e58d33 100644
--- a/src/luaotfload-harf-var-ttf.lua
+++ b/src/luaotfload-harf-var-ttf.lua
@@ -243,7 +243,7 @@ local function parse_glyf(loca, glyf, gid)
   end
 end
 
-local function serialize_glyf(points)
+local function serialize_glyf(points, map)
   local contours = points.contours
   if points.contours then
     local flagdata, xdata, ydata = {}, {}, {}
@@ -328,7 +328,7 @@ local function serialize_glyf(points)
           .. string.pack(component.flags & 0x2 == 0 and '>I2I2'
                       or component.flags & 0x1 == 0x1 and '>I2I2i2i2'
                       or '>I2I2i1i1',
-              component.flags, component.glyph, x, y)
+              component.flags, map[component.glyph], x, y)
           .. component.payload
     end
     return result
@@ -386,7 +386,7 @@ local function read_deltas(gvar_data, offset, count)
   return deltas, offset
 end
 
-local function interpolate_glyf(loca, gvar_index, gvar, glyf, gid, coords)
+local function interpolate_glyf(loca, gvar_index, gvar, glyf, gid, coords, map)
   local var = gvar_index[gid+1]
   if not var then
     local start = loca[gid+1] + 1
@@ -545,16 +545,16 @@ local function interpolate_glyf(loca, gvar_index, gvar, glyf, gid, coords)
     end
     offset = offset + size
   end
-  return serialize_glyf(points)
+  return serialize_glyf(points, map)
 end
 
-return function(face, font)
+return function(face, font, map, map_inv)
   local gvar = assert(face:get_table(gvar_tag):get_data())
   local gvar_index = assert(read_gvar(gvar))
   local loca = assert(read_loca(face))
   local glyf = assert(face:get_table(glyf_tag):get_data())
   local normalized = {font:get_var_coords_normalized()}
   return function(gid)
-    return interpolate_glyf(loca, gvar_index, gvar, glyf, gid, normalized)
+    return interpolate_glyf(loca, gvar_index, gvar, glyf, map_inv[gid], normalized, map)
   end
 end





More information about the latex3-commits mailing list.