[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Revert "Let HarfBuzz handle all scaling" (d6f8796)

Marcel Fabian Krüger tex at 2krueger.de
Sat Feb 15 09:17:01 CET 2020


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

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

commit d6f8796ea09e965ab1a3eb48c342bc7c27c78df5
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Feb 15 09:17:01 2020 +0100

    Revert "Let HarfBuzz handle all scaling"
    
    This reverts commit 0c7945cb4bccc9083450d53751d655f9f7336d4c.


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

d6f8796ea09e965ab1a3eb48c342bc7c27c78df5
 src/luaotfload-harf-define.lua | 63 +++++++++++++++++++++---------------------
 src/luaotfload-harf-plug.lua   | 16 +++++++----
 2 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index da388ca..6a19ffc 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -112,6 +112,7 @@ local function loadfont(spec)
     local glyphcount = hbface:get_glyph_count()
     local glyphs = {}
     for gid = 0, glyphcount - 1 do
+      local width = hbfont:get_glyph_h_advance(gid)
       local height, depth, italic = nil, nil, nil
       local extents = hbfont:get_glyph_extents(gid)
       if extents then
@@ -122,6 +123,7 @@ local function loadfont(spec)
         end
       end
       glyphs[gid] = {
+        width  = width,
         height = height or ascender,
         depth  = -(depth or descender),
         italic = italic or 0,
@@ -245,22 +247,7 @@ local function scalefont(data, spec)
   -- We shape in font units (at UPEM) and then scale output with the desired
   -- sfont size.
   local scale = size / upem
-
-  local hscale = scale
-  local extendfactor = nil
-  if features.extend then
-    extendfactor = tonumber(features.extend) * 1000
-    hscale = hscale * tonumber(features.extend)
-  end
-
-  local vscale = scale
-  local squeezefactor = nil
-  if features.squeeze then
-    squeezefactor = tonumber(features.squeeze) * 1000
-    vscale = vscale * tonumber(features.squeeze)
-  end
-
-  hbfont:set_scale(hscale * upem, vscale * upem)
+  hbfont:set_scale(upem, upem)
 
   -- Populate font’s characters table.
   local glyphs = data.glyphs
@@ -268,10 +255,10 @@ local function scalefont(data, spec)
   for gid, glyph in next, glyphs do
     characters[gid_offset + gid] = {
       index  = gid,
-      width  = hbfont:get_glyph_h_advance(gid),
-      height = glyph.height * vscale,
-      depth  = glyph.depth  * vscale,
-      italic = glyph.italic * hscale,
+      width  = glyph.width  * scale,
+      height = glyph.height * scale,
+      depth  = glyph.depth  * scale,
+      italic = glyph.italic * scale,
     }
   end
 
@@ -298,6 +285,20 @@ local function scalefont(data, spec)
     slantfactor = tonumber(features.slant) * 1000
   end
 
+  local hscale = upem
+  local extendfactor = nil
+  if features.extend then
+    extendfactor = tonumber(features.extend) * 1000
+    hscale = hscale * tonumber(features.extend)
+  end
+
+  local vscale = upem
+  local squeezefactor = nil
+  if features.squeeze then
+    squeezefactor = tonumber(features.squeeze) * 1000
+    vscale = vscale * tonumber(features.squeeze)
+  end
+
   if features.tlig then
     for char in next, characters do
       local ligatures = tlig[char]
@@ -326,22 +327,22 @@ local function scalefont(data, spec)
     squeeze = squeezefactor,
     characters = characters,
     parameters = {
-      slant = (data.slant + (slantfactor or 0) * 65.536) * hscale / vscale,
-      space = space * hscale,
-      space_stretch = space * hscale / 2,
-      space_shrink = space * hscale / 3,
-      x_height = data.xheight * vscale,
-      quad = hscale * upem,
-      extra_space = space * hscale / 3,
-      [8] = data.capheight * vscale, -- for XeTeX compatibility.
+      slant = data.slant,
+      space = space * scale,
+      space_stretch = space * scale / 2,
+      space_shrink = space * scale / 3,
+      x_height = data.xheight * scale,
+      quad = size,
+      extra_space = space * scale / 3,
+      [8] = data.capheight * scale, -- for XeTeX compatibility.
     },
     hb = {
-      -- scale = scale,
+      scale = scale,
       spec = spec,
       palette = palette,
       shared = data,
-      hscale = hscale * upem,
-      vscale = vscale * upem,
+      hscale = hscale,
+      vscale = vscale,
     },
     specification = spec,
     shared = {},
diff --git a/src/luaotfload-harf-plug.lua b/src/luaotfload-harf-plug.lua
index 51e64b0..93a4261 100644
--- a/src/luaotfload-harf-plug.lua
+++ b/src/luaotfload-harf-plug.lua
@@ -330,7 +330,9 @@ function shape(head, node, run)
   buf:set_cluster_level(buf.CLUSTER_LEVEL_MONOTONE_CHARACTERS)
   buf:add_codepoints(codes, offset - 1, len)
 
-  hbfont:set_scale(hbdata.hscale, hbdata.vscale)
+  local hscale = hbdata.hscale
+  local vscale = hbdata.vscale
+  hbfont:set_scale(hscale, vscale)
 
   if hb.shape_full(hbfont, buf, features, shapers) then
     -- The engine wants the glyphs in logical order, but HarfBuzz outputs them
@@ -594,6 +596,8 @@ local function tonodes(head, node, run, glyphs)
   local rtl = dir:is_backward()
   local lastprops
 
+  local scale = hbdata.scale
+
   local haspng = hbshared.haspng
   local fonttype = hbshared.fonttype
 
@@ -749,8 +753,8 @@ local function tonodes(head, node, run, glyphs)
                                 or character.index ~= oldcharacter.index then
             setchar(node, char)
           end
-          local xoffset = rtl and -glyph.x_offset or glyph.x_offset
-          local yoffset = glyph.y_offset
+          local xoffset = (rtl and -glyph.x_offset or glyph.x_offset) * scale
+          local yoffset = glyph.y_offset * scale
           setoffsets(node, xoffset, yoffset)
 
           fontglyph.used = fonttype and true
@@ -792,11 +796,11 @@ local function tonodes(head, node, run, glyphs)
             setprop(node, endactual_p, true)
           end
           local x_advance = glyph.x_advance
-          local width = character.width
+          local width = fontglyph.width
           if width ~= x_advance then
             -- The engine always uses the glyph width from the font, so we need
             -- to insert a kern node if the x advance is different.
-            local kern = newkern(x_advance - width, node)
+            local kern = newkern((x_advance - width) * scale, node)
             head, node = insertkern(head, node, kern, rtl)
           end
         end
@@ -809,7 +813,7 @@ local function tonodes(head, node, run, glyphs)
         -- we became a glyph in the process.
         -- We are intentionally not comparing with the existing glue width as
         -- spacing after the period is larger by default in TeX.
-        local width = glyph.x_advance
+        local width = glyph.x_advance * scale
         -- if space > width + 2 or width > space + 2 then
         if space ~= width then
           setwidth(node, getwidth(node) - space + width)





More information about the latex3-commits mailing list.