diff options
author | Karl Berry <karl@freefriends.org> | 2021-06-02 21:00:28 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-06-02 21:00:28 +0000 |
commit | 5a9ffa846c76f109c6015145217e1e593bb30777 (patch) | |
tree | c9c1528fe51985b76693939fd042db5d47e81d2e /Master/texmf-dist/tex/generic/babel/luababel.def | |
parent | 602bf0a5286f05673b2a8c4d79688a36cfa5a495 (diff) |
babel (2jun21)
git-svn-id: svn://tug.org/texlive/trunk@59439 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/babel/luababel.def')
-rw-r--r-- | Master/texmf-dist/tex/generic/babel/luababel.def | 197 |
1 files changed, 110 insertions, 87 deletions
diff --git a/Master/texmf-dist/tex/generic/babel/luababel.def b/Master/texmf-dist/tex/generic/babel/luababel.def index 51225cfa08a..62687deafa9 100644 --- a/Master/texmf-dist/tex/generic/babel/luababel.def +++ b/Master/texmf-dist/tex/generic/babel/luababel.def @@ -26,6 +26,7 @@ %% This work has the LPPL maintenance status "maintained". %% %% The Current Maintainer of this work is Javier Bezos. + %% %% The list of derived (unpacked) files belonging to the distribution %% and covered by LPPL is defined by the unpacking scripts (with @@ -621,9 +622,23 @@ Babel.arabic.justify_enabled = true function Babel.arabic.justify(head) if not Babel.arabic.justify_enabled then return head end + for line in node.traverse_id(node.id'hlist', head) do + Babel.arabic.justify_hlist(head, line) + end + return head +end + +function Babel.arabic.justify_hbox(head, gc, size, pack) + if Babel.arabic.justify_enabled and pack == 'exactly' then + Babel.arabic.justify_hlist(head, nil, gc, size, pack) + end + return head +end + +function Babel.arabic.justify_hlist(head, line, gc, size, pack) local d, new local k_list, k_item, pos_inline - local width, width_new, full, k_curr, wt_pos, goal + local width, width_new, full, k_curr, wt_pos, goal, shift local subst_done = false local elong_map = Babel.arabic.elong_map local last_line @@ -631,102 +646,110 @@ function Babel.arabic.justify(head) local KASHIDA = luatexbase.registernumber'bblar@kashida' local LOCALE = luatexbase.registernumber'bbl@attr@locale' - for line in node.traverse_id(node.id'hlist', head) do - % Exclude last line. todo. But-- it discards one-word lines, too! - % ? Look for glue = 12:15 - if (line.glue_sign == 1 and line.glue_order == 0) then - elongs = {} % Stores elongated candidates of each line - k_list = {} % And all letters with kashida - pos_inline = 0 % Not yet used - - for n in node.traverse_id(GLYPH, line.head) do - pos_inline = pos_inline + 1 % To find where it is. Not used. - - % Elongated glyphs - if elong_map then - local locale = node.get_attribute(n, LOCALE) - if elong_map[locale] and elong_map[locale][n.font] and - elong_map[locale][n.font][n.char] then - table.insert(elongs, {node = n, locale = locale} ) - node.set_attribute(n.prev, KASHIDA, 0) - end - end + if line == nil then + line = {} + line.glue_sign = 1 + line.glue_order = 0 + line.head = head + line.shift = 0 + line.width = size + end - % Tatwil - if Babel.kashida_wts then - local k_wt = node.get_attribute(n, KASHIDA) - if k_wt > 0 then % todo. parameter for multi inserts - table.insert(k_list, {node = n, weight = k_wt, pos = pos_inline}) - end + % Exclude last line. todo. But-- it discards one-word lines, too! + % ? Look for glue = 12:15 + if (line.glue_sign == 1 and line.glue_order == 0) then + elongs = {} % Stores elongated candidates of each line + k_list = {} % And all letters with kashida + pos_inline = 0 % Not yet used + + for n in node.traverse_id(GLYPH, line.head) do + pos_inline = pos_inline + 1 % To find where it is. Not used. + + % Elongated glyphs + if elong_map then + local locale = node.get_attribute(n, LOCALE) + if elong_map[locale] and elong_map[locale][n.font] and + elong_map[locale][n.font][n.char] then + table.insert(elongs, {node = n, locale = locale} ) + node.set_attribute(n.prev, KASHIDA, 0) end + end - end % of node.traverse_id - - if #elongs == 0 and #k_list == 0 then goto next_line end - - full = line.width - goal = full * Babel.arabic.justify_factor % A bit crude - width = node.dimensions(line.head) % The 'natural' width - - % == Elongated == - % Original idea taken from 'chikenize' - while (#elongs > 0 and width < goal) do - subst_done = true - local x = #elongs - local curr = elongs[x].node - local oldchar = curr.char - curr.char = elong_map[elongs[x].locale][curr.font][curr.char] - width = node.dimensions(line.head) % Check if the line is too wide - % Substitute back if the line would be too wide and break: - if width > goal then - curr.char = oldchar - break + % Tatwil + if Babel.kashida_wts then + local k_wt = node.get_attribute(n, KASHIDA) + if k_wt > 0 then % todo. parameter for multi inserts + table.insert(k_list, {node = n, weight = k_wt, pos = pos_inline}) end - % If continue, pop the just substituted node from the list: - table.remove(elongs, x) end - % == Tatwil == - if #k_list == 0 then goto next_line end - - width = node.dimensions(line.head) % The 'natural' width - k_curr = #k_list - wt_pos = 1 - - while width < goal do - subst_done = true - k_item = k_list[k_curr].node - if k_list[k_curr].weight == Babel.kashida_wts[wt_pos] then - d = node.copy(k_item) - d.char = 0x0640 - line.head, new = node.insert_after(line.head, k_item, d) - width_new = node.dimensions(line.head) - if width > goal or width == width_new then - node.remove(line.head, new) % Better compute before - break - end - width = width_new - end - if k_curr == 1 then - k_curr = #k_list - wt_pos = (wt_pos >= table.getn(Babel.kashida_wts)) and 1 or wt_pos+1 - else - k_curr = k_curr - 1 + end % of node.traverse_id + + if #elongs == 0 and #k_list == 0 then goto next_line end + full = line.width + shift = line.shift + goal = full * Babel.arabic.justify_factor % A bit crude + width = node.dimensions(line.head) % The 'natural' width + + % == Elongated == + % Original idea taken from 'chikenize' + while (#elongs > 0 and width < goal) do + subst_done = true + local x = #elongs + local curr = elongs[x].node + local oldchar = curr.char + curr.char = elong_map[elongs[x].locale][curr.font][curr.char] + width = node.dimensions(line.head) % Check if the line is too wide + % Substitute back if the line would be too wide and break: + if width > goal then + curr.char = oldchar + break + end + % If continue, pop the just substituted node from the list: + table.remove(elongs, x) + end + + % == Tatwil == + if #k_list == 0 then goto next_line end + + width = node.dimensions(line.head) % The 'natural' width + k_curr = #k_list + wt_pos = 1 + + while width < goal do + subst_done = true + k_item = k_list[k_curr].node + if k_list[k_curr].weight == Babel.kashida_wts[wt_pos] then + d = node.copy(k_item) + d.char = 0x0640 + line.head, new = node.insert_after(line.head, k_item, d) + width_new = node.dimensions(line.head) + if width > goal or width == width_new then + node.remove(line.head, new) % Better compute before + break end + width = width_new + end + if k_curr == 1 then + k_curr = #k_list + wt_pos = (wt_pos >= table.getn(Babel.kashida_wts)) and 1 or wt_pos+1 + else + k_curr = k_curr - 1 end + end - ::next_line:: + ::next_line:: - % Must take into account marks and ins, see luatex manual. - % Have to be executed only if there are changes. Investigate - % what's going on exactly. - if subst_done then - node.insert_before(head, line, node.hpack(line.head, full, 'exactly')) - node.remove(head, line) - end - end % if process line - end % for lines - return head + % Must take into account marks and ins, see luatex manual. + % Have to be executed only if there are changes. Investigate + % what's going on exactly. + if subst_done and not gc then + d = node.hpack(line.head, full, 'exactly') + d.shift = shift + node.insert_before(head, line, d) + node.remove(head, line) + end + end % if process line end } \endgroup |