[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Let HarfBuzz handle all scaling (0c7945c)
Marcel Fabian Krüger
tex at 2krueger.de
Tue Feb 11 11:18:09 CET 2020
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/0c7945cb4bccc9083450d53751d655f9f7336d4c
>---------------------------------------------------------------
commit 0c7945cb4bccc9083450d53751d655f9f7336d4c
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Tue Feb 11 01:25:47 2020 +0100
Let HarfBuzz handle all scaling
More reliable handling of extend, squeeze and slant handling
>---------------------------------------------------------------
0c7945cb4bccc9083450d53751d655f9f7336d4c
src/luaotfload-harf-define.lua | 63 +++++++++++++++++++++---------------------
src/luaotfload-harf-plug.lua | 16 ++++-------
2 files changed, 37 insertions(+), 42 deletions(-)
diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index 6a19ffc..da388ca 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -112,7 +112,6 @@ 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
@@ -123,7 +122,6 @@ local function loadfont(spec)
end
end
glyphs[gid] = {
- width = width,
height = height or ascender,
depth = -(depth or descender),
italic = italic or 0,
@@ -247,7 +245,22 @@ 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
- hbfont:set_scale(upem, 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)
-- Populate font’s characters table.
local glyphs = data.glyphs
@@ -255,10 +268,10 @@ local function scalefont(data, spec)
for gid, glyph in next, glyphs do
characters[gid_offset + gid] = {
index = gid,
- width = glyph.width * scale,
- height = glyph.height * scale,
- depth = glyph.depth * scale,
- italic = glyph.italic * scale,
+ width = hbfont:get_glyph_h_advance(gid),
+ height = glyph.height * vscale,
+ depth = glyph.depth * vscale,
+ italic = glyph.italic * hscale,
}
end
@@ -285,20 +298,6 @@ 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]
@@ -327,22 +326,22 @@ local function scalefont(data, spec)
squeeze = squeezefactor,
characters = characters,
parameters = {
- 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.
+ 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.
},
hb = {
- scale = scale,
+ -- scale = scale,
spec = spec,
palette = palette,
shared = data,
- hscale = hscale,
- vscale = vscale,
+ hscale = hscale * upem,
+ vscale = vscale * upem,
},
specification = spec,
shared = {},
diff --git a/src/luaotfload-harf-plug.lua b/src/luaotfload-harf-plug.lua
index c538309..bd0b823 100644
--- a/src/luaotfload-harf-plug.lua
+++ b/src/luaotfload-harf-plug.lua
@@ -330,9 +330,7 @@ function shape(head, node, run)
buf:set_cluster_level(buf.CLUSTER_LEVEL_MONOTONE_CHARACTERS)
buf:add_codepoints(codes, offset - 1, len)
- local hscale = hbdata.hscale
- local vscale = hbdata.vscale
- hbfont:set_scale(hscale, vscale)
+ hbfont:set_scale(hbdata.hscale, hbdata.vscale)
if hb.shape_full(hbfont, buf, features, shapers) then
-- The engine wants the glyphs in logical order, but HarfBuzz outputs them
@@ -595,8 +593,6 @@ 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
@@ -752,8 +748,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) * scale
- local yoffset = glyph.y_offset * scale
+ local xoffset = rtl and -glyph.x_offset or glyph.x_offset
+ local yoffset = glyph.y_offset
setoffsets(node, xoffset, yoffset)
fontglyph.used = fonttype and true
@@ -795,11 +791,11 @@ local function tonodes(head, node, run, glyphs)
setprop(node, endactual_p, true)
end
local x_advance = glyph.x_advance
- local width = fontglyph.width
+ local width = character.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) * scale, node)
+ local kern = newkern(x_advance - width, node)
head, node = insertkern(head, node, kern, rtl)
end
end
@@ -809,7 +805,7 @@ local function tonodes(head, node, run, glyphs)
-- it from the default, so reset the glue using the new advance.
-- 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 * scale
+ local width = glyph.x_advance
if fontdata.parameters.space ~= width then
setwidth(node, width)
setfield(node, "stretch", width / 2)
More information about the latex3-commits
mailing list.