Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize creation of hyphenation nodes #1971

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions core/hyphenator-liang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,25 @@ SILE.hyphenator = {}
SILE.hyphenator.languages = {}
SILE._hyphenators = {}

local function defaultHyphenateSegments (node, segments, _)
local hyphen = SILE.shaper:createNnodes(SILE.settings:get("font.hyphenchar"), node.options)
-- BUG ALERT: This implementation is known to not account for font.hyphenchar being changed midway through a document.
-- If the font also changed the node options would be different anyway so in 99%+ of cases this cheat is expected to
-- work but technically the memoization should include the setting or the ID of the current setting stack or something.

local lastoptions, lasthyphen

local _defaultHyphenateSegments = pl.utils.memoize(function (hash)
local hyphen = SILE.shaper:createNnodes(SILE.settings:get("font.hyphenchar"), lastoptions)
return SILE.nodefactory.discretionary({ prebreak = hyphen }), segments
end)

local function defaultHyphenateSegments (node, segments, _)
if lastoptions ~= node.options then
lastoptions = node.options
local hash = pl.pretty.write(node.options, "", true)
local discretionary = _defaultHyphenateSegments(hash)
lasthyphen = discretionary
end
return lasthyphen, segments
end

local initHyphenator = function (lang)
Expand Down
Loading