From f4204c1ea5fcc0368392c119530687681ab733c9 Mon Sep 17 00:00:00 2001 From: David Carlisle Date: Mon, 23 Nov 2015 18:50:00 +0000 Subject: define priority_in_callback (from luatexbase) --- src/luaotfload-colors.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua index 98549c8..576a432 100644 --- a/src/luaotfload-colors.lua +++ b/src/luaotfload-colors.lua @@ -315,7 +315,16 @@ end local color_callback_activated = 0 local add_to_callback = luatexbase.add_to_callback -local priority_in_callback = luatexbase.priority_in_callback +local function priority_in_callback (name,description) + for i,v in ipairs(luatexbase.callback_descriptions(name)) + do + if v == description then + return i + end + end + return false +end + --- unit -> unit add_color_callback = function ( ) -- cgit v1.2.3 From 54654688c8aa643ec9cc068eb25464d40ead84a0 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 26 Nov 2015 08:19:49 +0100 Subject: [colors] remove workaround for deprecated interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Luatexbase API was consolidated. Since the priority_in_callback functionality wasn’t used for anything but determining whether we need to convert to an hlist first, there’s not really any gain in keeping it around in the generic form. --- src/luaotfload-colors.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua index 576a432..ca5a067 100644 --- a/src/luaotfload-colors.lua +++ b/src/luaotfload-colors.lua @@ -313,18 +313,15 @@ local color_handler = function (head) return head end +local color_callback_name = "luaotfload.color_handler" local color_callback_activated = 0 local add_to_callback = luatexbase.add_to_callback -local function priority_in_callback (name,description) - for i,v in ipairs(luatexbase.callback_descriptions(name)) - do - if v == description then - return i - end - end - return false -end +--- unit -> bool +local mlist_to_hlist_initial = function () + local cdesc = luatexbase.callback_descriptions "mlist_to_hlist" + return cdesc and cdesc[1] == color_callback_name +end --- unit -> unit add_color_callback = function ( ) @@ -336,7 +333,7 @@ add_color_callback = function ( ) if color_callback_activated == 0 then add_to_callback(color_callback, color_handler, - "luaotfload.color_handler") + color_callback_name) add_to_callback("hpack_filter", function (head, groupcode) if groupcode == "hbox" or @@ -346,10 +343,10 @@ add_color_callback = function ( ) end return head end, - "luaotfload.color_handler") + color_callback_name) add_to_callback("mlist_to_hlist", function (head, display_type, need_penalties) - if priority_in_callback("mlist_to_hlist","luaotfload.color_handler") == 1 then + if mlist_to_hlist_initial () then head = mlist_to_hlist(head, display_type, need_penalties) end if display_type == "text" then @@ -357,7 +354,7 @@ add_color_callback = function ( ) end return color_handler(head) end, - "luaotfload.color_handler") + color_callback_name) color_callback_activated = 1 end end -- cgit v1.2.3 From fec6aa52281f689c7cfdd7b379f5dccbc2ce7cef Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 26 Nov 2015 23:12:49 +0100 Subject: [letterspace] fix handling of interword space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/lualatex/luaotfload/issues/297 Interword glue hasn’t been considered yet. This again adapts the relevant logic from Context to our letterspacing method. The code is deliberately simplistic and will most likely not address all constellations of a glue preceding a character. --- src/luaotfload-letterspace.lua | 94 +++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua index ab81881..5fa25f9 100644 --- a/src/luaotfload-letterspace.lua +++ b/src/luaotfload-letterspace.lua @@ -6,6 +6,9 @@ if not modules then modules = { } end modules ['letterspace'] = { license = "see context related readme files" } +--- This code diverged quite a bit from its origin in Context. Please +--- do *not* report bugs on the Context list. + local log = luaotfload.log local logreport = log.report @@ -39,7 +42,6 @@ local new_node = nodedirect.new local nodepool = nodedirect.pool local new_kern = nodepool.kern -local new_glue = nodepool.glue local nodecodes = nodes.nodecodes @@ -47,6 +49,7 @@ local glyph_code = nodecodes.glyph local kern_code = nodecodes.kern local disc_code = nodecodes.disc local math_code = nodecodes.math +local glue_code = nodecodes.glue local fonthashes = fonts.hashes local chardata = fonthashes.characters @@ -81,11 +84,17 @@ local kerncodes = bothways { [0] = "fontkern" , [1] = "userkern" , [2] = "accentkern" } +local skipcodes = bothways { [0] = "userskip" + , [13] = "spaceskip" + , [14] = "xspaceskip" + } -kerncodes.kerning = kerncodes.fontkern --- idiosyncrasy -local kerning_code = kerncodes.kerning -local userkern_code = kerncodes.userkern - +kerncodes.kerning = kerncodes.fontkern --- idiosyncrasy +local kerning_code = kerncodes.kerning +local userkern_code = kerncodes.userkern +local userskip_code = skipcodes.userskip +local spaceskip_code = skipcodes.spaceskip +local xspaceskip_code = skipcodes.xspaceskip ----------------------------------------------------------------------- --- node-res @@ -93,19 +102,30 @@ local userkern_code = kerncodes.userkern local glue_spec = new_node "glue_spec" -nodepool.glue = function (width, stretch, shrink, - stretch_order, shrink_order) +local new_gluespec = function (width, + stretch, shrink, + stretch_order, shrink_order) + local spec = copy_node(glue_spec) + if width then setfield(spec, "width" , width ) end + if stretch then setfield(spec, "stretch" , stretch ) end + if shrink then setfield(spec, "shrink" , shrink ) end + if stretch_order then setfield(spec, "stretch_order", stretch_order) end + if shrink_order then setfield(spec, "shrink_order" , shrink_order ) end + return spec +end + +local new_glue = function (width, stretch, shrink, + stretch_order, shrink_order) local n = new_node "glue" - if not width then + if not width then return n end -- no spec - elseif width == false or tonumber(width) then - local s = copy_node(glue_spec) - if width then setfield(s, "width" , width ) end - if stretch then setfield(s, "stretch" , stretch ) end - if shrink then setfield(s, "shrink" , shrink ) end - if stretch_order then setfield(s, "stretch_order", stretch_order) end - if shrink_order then setfield(s, "shrink_order" , shrink_order ) end - setfield(n, "spec", s) + if width == false then + local width = tonumber(width) + if width then + setfield(n, "spec", + new_gluespec(width, stretch, shrink, + stretch_order, shrink_order)) + end else -- shared setfield(n, "spec", copy_node(width)) @@ -198,6 +218,22 @@ local kern_injector = function (fillup, kern) return new_kern(kern) end +local kernable_skip = function (n) + local st = getsubtype (n) + return st == userskip_code + or st == spaceskip_code + or st == xspaceskip_code +end + +local function spec_injector (fillup, width, stretch, shrink) + if fillup then + local spec = new_gluespec(width, 2 * stretch, 2 * shrink) + setfield(spec, "stretch_order", 1) + return spec + end + return new_gluespec(width,stretch,shrink) +end + --[[doc-- Caveat lector. @@ -221,13 +257,11 @@ kerncharacters = function (head) local identifiers = fonthashes.identifiers local kernfactors = kernfactors - local firstkern = true while start do local id = getid(start) if id == glyph_code then - --- 1) look up kern factor (slow, but cached rudimentarily) local krn local fontid = getfont(start) @@ -304,6 +338,21 @@ kerncharacters = function (head) if not pid then -- nothing + elseif pid == glue_code and kernable_skip(prev) then + local spec = getfield(prev, "spec") + local wd = getfield(spec, "width") + if wd > 0 then + --- formula taken from Context + --- existing_width extended by four times the + --- width times the font’s kernfactor + local newwd = wd + --[[two en to a quad]] 4 * wd * krn + local stretched = (getfield(spec,"stretch") * newwd) / wd + local shrunk = (getfield(spec,"shrink") * newwd) / wd + setfield(prev, "spec", + spec_injector(fillup, newwd, stretched, shrunk)) + done = true + end + elseif pid == kern_code then local prev_subtype = getsubtype(prev) if prev_subtype == kerning_code --- context does this by means of an @@ -412,11 +461,10 @@ kerncharacters = function (head) krn = quaddata[lastfont]*krn -- here end setfield(disc, "replace", kern_injector(false, krn)) - end - - end - end - end + end --[[if replace and prv and nxt]] + end --[[if not pid]] + end --[[if prev]] + end --[[if id == glyph_code]] ::nextnode:: if start then -- cgit v1.2.3 From f0709824926bf19cf4eb638d9e3c2192bb9131b3 Mon Sep 17 00:00:00 2001 From: David Carlisle Date: Thu, 26 Nov 2015 22:24:52 +0000 Subject: @ may not be catcode 11 in plain --- src/luaotfload.sty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luaotfload.sty b/src/luaotfload.sty index 1b31b1d..ad4ef2d 100644 --- a/src/luaotfload.sty +++ b/src/luaotfload.sty @@ -33,7 +33,7 @@ %% \csname ifluaotfloadloaded\endcsname \let\ifluaotfloadloaded\endinput -\ifx\newluafunction\@undefined +\ifx\newluafunction\undefined \input ltluatex \fi \ifdefined\ProvidesPackage -- cgit v1.2.3