diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua')
-rw-r--r-- | Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua | 119 |
1 files changed, 113 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua index 0bd8c1441ca..c0262626181 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua @@ -1,5 +1,5 @@ --- Packageversion: 0.3 --- Packagedate: 2018/08/06 +-- Packageversion: 0.50 +-- Packagedate: 2019/01/04 -- tagpdf.lua -- Ulrike Fischer @@ -42,16 +42,21 @@ functions uftag.func.mark_shipout (): a wrapper around the core function which inserts the last EMC uftag.func.fill_parent_tree_line (page): outputs the entries of the parenttree for this page uftag.func.output_parenttree(): outputs the content of the parenttree + uftag.func.markspaceon(), uftag.func.markspaceoff(): (de)activates the marking of positions for space chars uftag.trace.show_mc_data (num): shows uftag.mc[num] uftag.trace.show_all_mc_data (max): shows a maximum about mc's uftag.trace.show_seq: shows a sequence (array) uftag.trace.show_struct_data (num): shows data of structure num uftag.trace.show_prop: shows a prop uftag.trace.log + uftag.trace.showspaces : boolean --]] -local mctypeattributeid = luatexbase.registernumber ("g__uftag_mc_type_attr") -local mccntattributeid = luatexbase.registernumber ("g__uftag_mc_cnt_attr") +local mctypeattributeid = luatexbase.registernumber ("g__uftag_mc_type_attr") +local mccntattributeid = luatexbase.registernumber ("g__uftag_mc_cnt_attr") +local iwspaceattributeid = luatexbase.registernumber ("g__uftag_interwordspace_attr") +local iwfontattributeid = luatexbase.registernumber ("g__uftag_interwordfont_attr") + local catlatex = luatexbase.registernumber("catcodetable@latex") local tagunmarkedbool= token.create("g__uftag_tagunmarked_bool") @@ -63,11 +68,13 @@ local tableinsert = table.insert local nodeid = node.id local nodecopy = node.copy local nodegetattribute = node.get_attribute +local nodesetattribute = node.set_attribute local nodenew = node.new local nodetail = node.tail local nodeslide = node.slide local noderemove = node.remove local nodetraverseid = node.traverse_id +local nodetraverse = node.traverse local nodeinsertafter = node.insert_after local nodeinsertbefore = node.insert_before local pdfpageref = pdf.pageref @@ -77,6 +84,7 @@ local VLIST = node.id("vlist") local RULE = node.id("rule") local DISC = node.id("disc") local GLUE = node.id("glue") +local GLYPH = node.id("glyph") local KERN = node.id("kern") local PENALTY = node.id("penalty") local LOCAL_PAR = node.id("local_par") @@ -146,6 +154,88 @@ local function __uftag_insert_bdc_node (head,current,tag,dict) return head end +-- this is for debugging the space chars +local function __uftag_show_spacemark (head,current,color,height) + local markcolor = color or "1 0 0" + local markheight = height or 10 + local pdfstring = node.new("whatsit","pdf_literal") + pdfstring.data = + string.format("q "..markcolor.." RG "..markcolor.." rg 0.4 w 0 %g m 0 %g l S Q",-3,markheight) + head = node.insert_after(head,current,pdfstring) + return head +end + +--[[ a function to mark up places where real space chars should be inserted + it only sets an attribute. +--]] + +local function __uftag_mark_spaces (head) + local inside_math = false + for n in nodetraverse(head) do + local id = n.id + if id == GLYPH then + local glyph = n + if glyph.next and (glyph.next.id == GLUE) + and not inside_math and (glyph.next.width >0) + then + nodesetattribute(glyph.next,iwspaceattributeid,1) + nodesetattribute(glyph.next,iwfontattributeid,glyph.font) + -- for debugging + if uftag.trace.showspaces then + __uftag_show_spacemark (head,glyph) + end + end + elseif id == PENALTY then + local glyph = n + -- uftag.trace.log ("PENALTY ".. n.subtype.."VALUE"..n.penalty,3) + if glyph.next and (glyph.next.id == GLUE) + and not inside_math and (glyph.next.width >0) and n.subtype==0 + then + nodesetattribute(glyph.next,iwspaceattributeid,1) + -- nodesetattribute(glyph.next,iwfontattributeid,glyph.font) + -- for debugging + if uftag.trace.showspaces then + __uftag_show_spacemark (head,glyph) + end + end + elseif id == MATH then + inside_math = (n.subtype == 0) + end + end + return head +end + +local function __uftag_activate_mark_space () + if not luatexbase.in_callback ("pre_linebreak_filter","markspaces") then + luatexbase.add_to_callback("pre_linebreak_filter",__uftag_mark_spaces,"markspaces") + luatexbase.add_to_callback("hpack_filter",__uftag_mark_spaces,"markspaces") + end +end + +uftag.func.markspaceon=__uftag_activate_mark_space + +local function __uftag_deactivate_mark_space () + if luatexbase.in_callback ("pre_linebreak_filter","markspaces") then + luatexbase.remove_from_callback("pre_linebreak_filter","markspaces") + luatexbase.remove_from_callback("hpack_filter","markspaces") + end +end +-- +uftag.func.markspaceoff=__uftag_deactivate_mark_space + +local default_space_char = node.new(GLYPH) +local default_fontid = font.id("TU/lmr/m/n/10") +default_space_char.char = 32 +default_space_char.font = default_fontid + +local function __uftag_insert_space_char (head,n,fontid) + if luaotfload.aux.slot_of_name(fontid,"space") then + local space + -- head, space = node.insert_before(head, n, ) -- Set the right font + -- n.width = n.width - space.width + -- space.attr = n.attr + end +end --[[ Now follows the core function @@ -179,6 +269,7 @@ function uftag.func.mark_page_elements (box,mcpagecnt,mccntprev,mcopen,name,mcty end for n in node.traverse(head) do local mccnt, mctype, tag = __uftag_get_mc_cnt_type_tag (n) + local spaceattr = nodegetattribute(n,iwspaceattributeid) or -1 uftag.trace.log ("NODE ".. node.type(node.getid(n)).." MC"..tostring(mccnt).." => TAG "..tostring(mctype).." => " .. tostring(tag),3) if n.id == HLIST then -- enter the hlist @@ -187,10 +278,26 @@ function uftag.func.mark_page_elements (box,mcpagecnt,mccntprev,mcopen,name,mcty elseif n.id == VLIST then -- enter the vlist mcopen,mcpagecnt,mccntprev,mctypeprev= uftag.func.mark_page_elements (n,mcpagecnt,mccntprev,mcopen,"INTERNAL VLIST",mctypeprev) - elseif n.id == GLUE then -- glue is ignored + elseif n.id == GLUE then -- at glue real space chars are inserted, for the rest it is ignored + -- for debugging + if uftag.trace.showspaces and spaceattr==1 then + __uftag_show_spacemark (head,n,"0 1 0") + end + if spaceattr==1 then + local space + local space_char = node.copy(default_space_char) + local curfont = nodegetattribute(n,iwfontattributeid) + uftag.trace.log ("FONT ".. tostring(curfont),3) + if curfont and luaotfload.aux.slot_of_name(curfont,"space") then + space_char.font=curfont + end + head, space = node.insert_before(head, n, space_char) -- + n.width = n.width - space.width + space.attr = n.attr + end elseif n.id == LOCAL_PAR then -- local_par is ignored elseif n.id == PENALTY then -- penalty is ignored - elseif n.id == KERN then -- kern is ignored + elseif n.id == KERN then -- kern is ignored else -- math is currently only logged. -- we could mark the whole as math |