summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/luatexko/luatexko.lua
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-03-21 03:01:37 +0000
committerNorbert Preining <norbert@preining.info>2020-03-21 03:01:37 +0000
commit3e43bc594a14e8c4fc21d6a71f22a23dd78fe252 (patch)
tree19d1a8bb88da795b5317f91775f645e0b7bd9eb9 /macros/luatex/generic/luatexko/luatexko.lua
parentc720a4409b388fa706f3eb1ce275f76f7d49d996 (diff)
CTAN sync 202003210301
Diffstat (limited to 'macros/luatex/generic/luatexko/luatexko.lua')
-rw-r--r--macros/luatex/generic/luatexko/luatexko.lua236
1 files changed, 122 insertions, 114 deletions
diff --git a/macros/luatex/generic/luatexko/luatexko.lua b/macros/luatex/generic/luatexko/luatexko.lua
index 0720a4ecd9..95d8fc1a84 100644
--- a/macros/luatex/generic/luatexko/luatexko.lua
+++ b/macros/luatex/generic/luatexko/luatexko.lua
@@ -13,8 +13,8 @@
luatexbase.provides_module {
name = 'luatexko',
- date = '2020/03/14',
- version = '2.7',
+ date = '2020/03/20',
+ version = '2.8',
description = 'typesetting Korean with LuaTeX',
author = 'Dohyun Kim, Soojin Nam',
license = 'LPPL v1.3+',
@@ -73,7 +73,6 @@ local callback_descriptions = luatexbase.callback_descriptions
local create_callback = luatexbase.create_callback
local module_warning = luatexbase.module_warning
local new_user_whatsit = luatexbase.new_user_whatsit
-local new_user_whatsit_id = luatexbase.new_user_whatsit_id
local registernumber = luatexbase.registernumber
local remove_from_callback = luatexbase.remove_from_callback
@@ -93,7 +92,6 @@ local ruleid = node.id"rule"
local vlistid = node.id"vlist"
local whatsitid = node.id"whatsit"
local literal_whatsit = node.subtype"pdf_literal"
-local user_whatsit = node.subtype"user_defined"
local directmode = 2
local fontkern = 0
local userkern = 1
@@ -110,6 +108,7 @@ local fallbackfontattr = attributes.luatexkofallbackfontattr
local autojosaattr = attributes.luatexkoautojosaattr
local classicattr = attributes.luatexkoclassicattr
local dotemphattr = attributes.luatexkodotemphattr
+local ulineattr = attributes.luatexkoulineattr
local rubyattr = attributes.luatexkorubyattr
local hangulbyhangulattr = attributes.luatexkohangulbyhangulattr
local hanjabyhanjaattr = attributes.luatexkohanjabyhanjaattr
@@ -465,13 +464,12 @@ luatexko.forcehangulchars = force_hangul
local forcehf_f, forcehf_id = new_user_whatsit("forcehf","luatexko")
-local function update_force_hangul (value)
+function luatexko.updateforcehangul (value)
local what = forcehf_f()
what.type = lua_value -- function
what.value = value
nodewrite(what)
end
-luatexko.updateforcehangul = update_force_hangul
local function hangul_space_skip (curr, newfont)
if curr.lang ~= nohyphen and curr.font ~= newfont then
@@ -517,7 +515,6 @@ local function process_fonts (head)
is_not_harf(curr.font) and
option_in_font(curr.font, "script") == "hang" then
luatexko.activate("reorderTM") -- activate reorderTM here
- active_processes.reorderTM = true
end
else
@@ -556,10 +553,9 @@ local function process_fonts (head)
curr.replace = process_fonts(curr.replace)
elseif id == mathid then
curr = end_of_math(curr)
- elseif id == whatsitid
- and curr.subtype == user_whatsit
- and curr.user_id == forcehf_id
- and curr.type == lua_value then
+ elseif id == whatsitid and
+ curr.user_id == forcehf_id and
+ curr.type == lua_value then
local value = curr.value
if type(value) == "function" then
@@ -901,9 +897,7 @@ local function process_interhangul (head, par)
if c and not is_unicode_var_sel(c) then
head, pc = do_interhangul_option(head, curr, pc, c, curr.font, par)
- if is_chosong(c) then
- pc = 0
- elseif is_jungsong(c) or is_jongsong(c) or hangul_tonemark[c] then
+ if is_jungsong(c) or is_jongsong(c) or hangul_tonemark[c] then
pc = 1
end
end
@@ -1210,11 +1204,22 @@ end
local dotemphbox = {}
luatexko.dotemphbox = dotemphbox
-local function process_dotemph (head, tofree)
- local curr, outer, tofree = head, not tofree, tofree or {}
+local dotemph_f, dotemph_id = new_user_whatsit("dotemph","luatexko")
+
+function luatexko.dotemphboundary (i)
+ local what = dotemph_f()
+ what.type = lua_number
+ what.value = i
+ nodewrite(what)
+end
+
+local function process_dotemph (head)
+ local curr = head
while curr do
- local id = curr.id
- if id == glyphid then
+ if curr.list then
+ curr.list = process_dotemph(curr.list)
+
+ elseif curr.id == glyphid then
local dotattr = has_attribute(curr, dotemphattr)
if dotattr then
local c = my_node_props(curr).unicode or curr.char
@@ -1231,7 +1236,13 @@ local function process_dotemph (head, tofree)
local currwd = curr.width
if currwd >= font_options.en_size[curr.font] then
- local box = nodecopy(dotemphbox[dotattr])
+ local box = nodecopy(dotemphbox[dotattr]).list
+ -- bypass unwanted nodes injected by some other packages
+ while box.id ~= hlistid do
+ warning[[\dotemph should be an hbox]]
+ box = getnext(box)
+ end
+
local shift = (currwd - box.width)/2
if shift ~= 0 then
local list = box.list
@@ -1245,28 +1256,26 @@ local function process_dotemph (head, tofree)
box.width = 0
head = insert_before(head, curr, box)
- tofree[dotattr] = true
end
end
- unset_attribute(curr, dotemphattr)
- end
- elseif id == hlistid then
- local list = curr.list
- if list then
- curr.list, tofree = process_dotemph(list, tofree)
end
+
+ elseif curr.id == whatsitid and
+ curr.user_id == dotemph_id and
+ curr.type == lua_number then
+
+ local val = curr.value
+ nodefree(dotemphbox[val])
+ dotemphbox[val] = nil
end
curr = getnext(curr)
end
- if outer then
- for k in pairs(tofree) do nodefree(dotemphbox[k]) end
- end
- return head, tofree
+ return head
end
-- uline
-local function get_strike_out_down (box)
+function luatexko.get_strike_out_down (box)
local c, f = hbox_char_font(box, true, true) -- ignore blocking nodes
if c and f then
local down
@@ -1286,14 +1295,16 @@ local function get_strike_out_down (box)
end
return -texsp"0.5ex"
end
-luatexko.get_strike_out_down = get_strike_out_down
local uline_f, uline_id = new_user_whatsit("uline","luatexko")
-local no_uline_id = new_user_whatsit_id("no_uline","luatexko")
-local function ulboundary (i, n, subtype)
+function luatexko.ulboundary (i, n, subtype)
local what = uline_f()
if n then
+ while n.id ~= ruleid and n.id ~= hlistid and n.id ~= vlistid do
+ warning[[\markoverwith should be a rule or a box]]
+ n = getnext(n)
+ end
what.type = lua_value -- table
what.value = { i, nodecopy(n), subtype }
else
@@ -1302,7 +1313,6 @@ local function ulboundary (i, n, subtype)
end
nodewrite(what)
end
-luatexko.ulboundary = ulboundary
local white_nodes = {
[glueid] = true,
@@ -1311,7 +1321,7 @@ local white_nodes = {
[whatsitid] = true,
}
-function skip_white_nodes (n, ltr)
+local function skip_white_nodes (n, ltr)
local nextnode = ltr and getnext or getprev
while n do
if not white_nodes[n.id] then break end
@@ -1323,66 +1333,78 @@ end
local function draw_uline (head, curr, parent, t, final)
local start, list, subtype = t.start or head, t.list, t.subtype
start = skip_white_nodes(start, true)
- if final then
+ if final and start then
nodeslide(start) -- to get correct getprev.
end
curr = skip_white_nodes(curr)
- curr = getnext(curr) or curr
- local len = parent and rangedimensions(parent, start, curr)
- or dimensions(start, curr) -- it works?!
- if len and len ~= 0 then
- local g = nodenew(glueid)
- setglue(g, len)
- g.subtype = subtype
- g.leader = final and list or nodecopy(list)
- local k = nodenew(kernid)
- k.kern = -len
- head = insert_before(head, start, g)
- head = insert_before(head, start, k)
+ if start and curr then
+ curr = getnext(curr) or curr
+ local len = parent and rangedimensions(parent, start, curr)
+ or dimensions(start, curr)
+ if len and len ~= 0 then
+ local g = nodenew(glueid)
+ setglue(g, len)
+ g.subtype = subtype
+ g.leader = final and list or nodecopy(list)
+ local k = nodenew(kernid)
+ k.kern = -len
+ head = insert_before(head, start, g)
+ head = insert_before(head, start, k)
+ end
end
return head
end
-local function process_uline (head, parent, items, level)
- local curr, items, level = head, items or {}, level or 0
+local ulitems = {}
+
+local function process_uline (head, parent, level)
+ local curr, level, attr = head, level or 0
while curr do
- local id = curr.id
- if id == whatsitid
- and curr.subtype == user_whatsit
- and curr.user_id == uline_id then
+ if curr.list then
+ curr.list = process_uline(curr.list, curr, level+1)
+
+ elseif curr.id == whatsitid and curr.user_id == uline_id then
local value = curr.value
if curr.type == lua_value then
local count, list, subtype = tableunpack(value)
- items[count] = {
- start = curr,
+ ulitems[count] = {
list = list,
subtype = subtype,
level = level,
}
- elseif items[value] then
- head = draw_uline(head, curr, parent, items[value], true)
- items[value] = nil
+ else
+ local item = ulitems[value]
+ if item then
+ head = draw_uline(head, curr, parent, item, true)
+ ulitems[value] = nil
+ attr = nil
+ end
end
- curr.user_id = no_uline_id -- avoid multiple run
- elseif id == hlistid then
- local list = curr.list
- if list then
- curr.list, items = process_uline(list, curr, items, level+1)
+ else
+ local currattr = has_attribute(curr, ulineattr)
+ if currattr then
+ local item = ulitems[currattr]
+ if item and not item.start then
+ item.start = curr
+ attr = currattr
+ end
end
+
end
curr = getnext(curr)
end
- curr = nodeslide(head)
- for i, t in pairs(items) do
- if level == t.level then
- head = draw_uline(head, curr, parent, t)
- t.start = nil
+ if attr then
+ local item = ulitems[attr]
+ if item and item.level == level then
+ head = draw_uline(head, nodeslide(head), parent, item)
+ item.start = nil
end
end
- return head, items
+
+ return head
end
-- ruby
@@ -1390,7 +1412,7 @@ end
local rubybox = {}
luatexko.rubybox = rubybox
-local function getrubystretchfactor (box)
+function luatexko.getrubystretchfactor (box)
local _, fid = hbox_char_font(box, true, true)
local str = font_options.intercharstretch[fid]
if str then
@@ -1398,7 +1420,6 @@ local function getrubystretchfactor (box)
set_macro("luatexkostretchfactor", stringformat("%.4f", str/em/2))
end
end
-luatexko.getrubystretchfactor = getrubystretchfactor
local function process_ruby_pre_linebreak (head)
local curr = head
@@ -1458,13 +1479,11 @@ local function process_ruby_post_linebreak (head)
head = insert_before(head, curr, ruby)
end
ruby_t = nil
- unset_attribute(curr, rubyattr)
- else
- local list = curr.list
- if list then
- curr.list = process_ruby_post_linebreak(list)
- end
+ elseif curr.list then
+ curr.list = process_ruby_post_linebreak(curr.list)
end
+ elseif curr.list then
+ curr.list = process_ruby_post_linebreak(curr.list)
end
curr = getnext(curr)
end
@@ -1797,7 +1816,7 @@ local function process_vertical_font (fontdata)
end
end
-local function get_horizbox_moveleft ()
+function luatexko.gethorizboxmoveleft ()
for _, v in ipairs{ fontcurrent(),
texattribute.luatexkohangulfontattr,
texattribute.luatexkohanjafontattr,
@@ -1811,7 +1830,6 @@ local function get_horizbox_moveleft ()
end
end
end
-luatexko.gethorizboxmoveleft = get_horizbox_moveleft
-- charraise
@@ -1885,10 +1903,13 @@ local function process_fake_slant_font (fontdata)
local fsl = fontdata.slant
if fsl and fsl > 0 then
fsl = fsl/1000
+ local hb = is_harf(fontdata)
+
local params = fontdata.parameters or {}
- params.slant = (params.slant or 0) + fsl*65536 -- slant per point
+ if not hb then -- hb done by luaotfload
+ params.slant = (params.slant or 0) + fsl*65536 -- slant per point
+ end
- local hb = is_harf(fontdata)
local scale = hb and hb.scale or params.factor or 655.36
local shared = fontdata.shared or {}
@@ -1928,6 +1949,13 @@ create_callback("luatexko_hpack_first", "data", pass_fun)
create_callback("luatexko_prelinebreak_first", "data", pass_fun)
create_callback("luatexko_hpack_second", "data", pass_fun)
create_callback("luatexko_prelinebreak_second", "data", pass_fun)
+create_callback("luatexko_do_atbegshi", "data", pass_fun)
+
+function luatexko.process_atbegshi (box)
+ if box and box.list then
+ box.list = call_callback("luatexko_do_atbegshi", box.list)
+ end
+end
add_to_callback("hpack_filter", function(h)
h = process_fonts(h)
@@ -2058,17 +2086,14 @@ add_to_callback("luaotfload.patch_font_unsafe", process_patch_font,
local auxiliary_procs = {
dotemph = {
- hpack_filter = process_dotemph,
- post_linebreak_filter = process_dotemph,
+ luatexko_do_atbegshi = process_dotemph,
},
uline = {
- hpack_filter = process_uline,
- post_linebreak_filter = process_uline,
+ luatexko_do_atbegshi = process_uline,
},
ruby = {
- pre_linebreak_filter = process_ruby_pre_linebreak,
- hpack_filter = process_ruby_post_linebreak,
- post_linebreak_filter = process_ruby_post_linebreak,
+ pre_linebreak_filter = process_ruby_pre_linebreak,
+ luatexko_do_atbegshi = process_ruby_post_linebreak,
},
autojosa = {
luatexko_hpack_first = process_josa,
@@ -2080,26 +2105,12 @@ local auxiliary_procs = {
},
}
-local function activate (name)
+function luatexko.activate (name)
for cbnam, cbfun in pairs( auxiliary_procs[name] ) do
- local fun
- if cbnam == "hpack_filter" then
- fun = function(h, gc)
- if gc == "hbox" or gc == "adjusted_hbox" or gc == "align_set" then
- h = cbfun(h)
- end
- return h
- end
- else
- fun = function(h)
- h = cbfun(h)
- return h
- end
- end
- add_to_callback(cbnam, fun, "luatexko."..cbnam.."."..name)
+ add_to_callback(cbnam, cbfun, "luatexko."..cbnam.."."..name)
end
+ active_processes[name] = true
end
-luatexko.activate = activate
add_to_callback ("hyphenate",
function(head)
@@ -2129,12 +2140,12 @@ end,
-- aux functions
-local function deactivate_all (str)
+function luatexko.deactivateall (str)
luatexko.deactivated = {}
for _, name in ipairs{ "hpack_filter",
"pre_linebreak_filter",
- "post_linebreak_filter",
"hyphenate",
+ "luatexko_do_atbegshi", -- might not work properly
"luaotfload.patch_font_unsafe", -- added for harf
"luaotfload.patch_font" } do
local t = {}
@@ -2147,9 +2158,8 @@ local function deactivate_all (str)
luatexko.deactivated[name] = t
end
end
-luatexko.deactivateall = deactivate_all
-local function reactivate_all ()
+function luatexko.reactivateall ()
for name, v in pairs(luatexko.deactivated or {}) do
for _, vv in ipairs(v) do
add_to_callback(name, tableunpack(vv))
@@ -2157,10 +2167,8 @@ local function reactivate_all ()
end
luatexko.deactivated = nil
end
-luatexko.reactivateall = reactivate_all
-local function current_has_hangul_chars (cnt)
+function luatexko.currenthashangulchars (cnt)
texcount[cnt] = char_in_font(fontcurrent(), 0xAC00) and 1 or 0
end
-luatexko.currenthashangulchars = current_has_hangul_chars