diff options
author | Norbert Preining <norbert@preining.info> | 2023-08-08 03:00:52 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-08-08 03:00:52 +0000 |
commit | 313a3ccce8935aa26c29f2e430042cffee435454 (patch) | |
tree | 4538a4d48be5143222aea6ad75a473938e243c55 /macros/latex/contrib/tagpdf/tagpdf-backend.dtx | |
parent | aebf6a3b57eda6e22a8e5fb93958edbf6ad1b551 (diff) |
CTAN sync 202308080300
Diffstat (limited to 'macros/latex/contrib/tagpdf/tagpdf-backend.dtx')
-rw-r--r-- | macros/latex/contrib/tagpdf/tagpdf-backend.dtx | 148 |
1 files changed, 119 insertions, 29 deletions
diff --git a/macros/latex/contrib/tagpdf/tagpdf-backend.dtx b/macros/latex/contrib/tagpdf/tagpdf-backend.dtx index 66a6e7ff7c..761fb21a8b 100644 --- a/macros/latex/contrib/tagpdf/tagpdf-backend.dtx +++ b/macros/latex/contrib/tagpdf/tagpdf-backend.dtx @@ -47,13 +47,13 @@ % }^^A % } % -% \date{Version 0.98j, released 2023-07-08} +% \date{Version 0.98k, released 2023-08-04} % \maketitle % \begin{implementation} % \begin{macrocode} %<@@=tag> %<*luatex> -\ProvidesExplFile {tagpdf-luatex.def} {2023-07-08} {0.98j} +\ProvidesExplFile {tagpdf-luatex.def} {2023-08-04} {0.98k} {tagpdf~driver~for~luatex} % \end{macrocode} % \section{Loading the lua} @@ -158,8 +158,8 @@ local ProvidesLuaModule = { name = "tagpdf", - version = "0.98j", --TAGVERSION - date = "2023-07-08", --TAGDATE + version = "0.98k", --TAGVERSION + date = "2023-08-04", --TAGDATE description = "tagpdf lua code", license = "The LATEX Project Public License 1.3c" } @@ -263,6 +263,10 @@ local nodeinsertafter = node.insert_after local nodeinsertbefore = node.insert_before local pdfpageref = pdf.pageref +local fonthashes = fonts.hashes +local identifiers = fonthashes.identifiers +local fontid = font.id + local HLIST = node.id("hlist") local VLIST = node.id("vlist") local RULE = node.id("rule") @@ -584,39 +588,106 @@ end % \end{macrocode} % \end{macro} % \subsection{Functions to insert the pdf literals} -% \begin{macro}{@@_insert_emc_node} -% This insert the emc node. +% \begin{macro}{@@_backend_create_emc_node,@@_insert_emc_node} +% This insert the emc node. We support also dvips and dvipdfmx backend % \begin{macrocode} +local @@_backend_create_emc_node +if tex.outputmode == 0 then + if token.get_macro("c_sys_backend_str") == "dvipdfmx" then + function @@_backend_create_emc_node () + local emcnode = nodenew("whatsit","special") + emcnode.data = "pdf:code EMC" + return emcnode + end + else -- assume a dvips variant + function @@_backend_create_emc_node () + local emcnode = nodenew("whatsit","special") + emcnode.data = "ps:SDict begin mark /EMC pdfmark end" + return emcnode + end + end +else -- pdf mode + function @@_backend_create_emc_node () + local emcnode = nodenew("whatsit","pdf_literal") + emcnode.data = "EMC" + emcnode.mode=1 + return emcnode + end +end + local function @@_insert_emc_node (head,current) - local emcnode = nodenew("whatsit","pdf_literal") - emcnode.data = "EMC" - emcnode.mode=1 - head = node.insert_before(head,current,emcnode) - return head + local emcnode= @@_backend_create_emc_node() + head = node.insert_before(head,current,emcnode) + return head end % \end{macrocode} % \end{macro} -% \begin{macro}{@@_insert_bmc_node} +% \begin{macro}{@@_backend_create_bmc_node,@@_insert_bmc_node} % This inserts a simple bmc node % \begin{macrocode} +local @@_backend_create_bmc_node +if tex.outputmode == 0 then + if token.get_macro("c_sys_backend_str") == "dvipdfmx" then + function @@_backend_create_bmc_node (tag) + local bmcnode = nodenew("whatsit","special") + bmcnode.data = "pdf:code /"..tag.." BMC" + return bmcnode + end + else -- assume a dvips variant + function @@_backend_create_bmc_node (tag) + local bmcnode = nodenew("whatsit","special") + bmcnode.data = "ps:SDict begin mark/"..tag.." BMC pdfmark end" + return bmcnode + end + end +else -- pdf mode + function @@_backend_create_bmc_node (tag) + local bmcnode = nodenew("whatsit","pdf_literal") + bmcnode.data = "/"..tag.." BMC" + bmcnode.mode=1 + return bmcnode + end +end + local function @@_insert_bmc_node (head,current,tag) - local bmcnode = nodenew("whatsit","pdf_literal") - bmcnode.data = "/"..tag.." BMC" - bmcnode.mode=1 - head = node.insert_before(head,current,bmcnode) + local bmcnode = @@_backend_create_bmc_node (tag) + head = node.insert_before(head,current,bmcnode) return head end % \end{macrocode} % \end{macro} -% \begin{macro}{@@_insert_bdc_node} +% \begin{macro}{@@_backend_create_bdc_node,@@_insert_bdc_node} % This inserts a bcd node with a fix dict. % TODO: check if this is still used, now that we create properties. % \begin{macrocode} +local @@_backend_create_bdc_node + +if tex.outputmode == 0 then + if token.get_macro("c_sys_backend_str") == "dvipdfmx" then + function @@_backend_create_bdc_node (tag,dict) + local bdcnode = nodenew("whatsit","special") + bdcnode.data = "pdf:code /"..tag.."<<"..dict..">> BDC" + return bdcnode + end + else -- assume a dvips variant + function @@_backend_create_bdc_node (tag,dict) + local bdcnode = nodenew("whatsit","special") + bdcnode.data = "ps:SDict begin mark/"..tag.."<<"..dict..">> BDC pdfmark end" + return bdcnode + end + end +else -- pdf mode + function @@_backend_create_bdc_node (tag,dict) + local bdcnode = nodenew("whatsit","pdf_literal") + bdcnode.data = "/"..tag.."<<"..dict..">> BDC" + bdcnode.mode=1 + return bdcnode + end +end + local function @@_insert_bdc_node (head,current,tag,dict) - local bdcnode = nodenew("whatsit","pdf_literal") - bdcnode.data = "/"..tag.."<<"..dict..">> BDC" - bdcnode.mode=1 - head = node.insert_before(head,current,bdcnode) + bdcnode= @@_backend_create_bdc_node (tag,dict) + head = node.insert_before(head,current,bdcnode) return head end % \end{macrocode} @@ -644,11 +715,16 @@ ltx.@@.func.pdf_object_ref=@@_pdf_object_ref local function @@_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") + local pdfstring + if tex.outputmode == 0 then + -- ignore dvi mode for now + else + 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 + return head + end end % \end{macrocode} % \end{macro} @@ -760,11 +836,24 @@ ltx.@@.func.markspaceoff=@@_deactivate_mark_space % \end{macro} % We need two local variable to setup a default space char. % \begin{macrocode} -local default_space_char = node.new(GLYPH) -local default_fontid = font.id("TU/lmr/m/n/10") +local default_space_char = nodenew(GLYPH) +local default_fontid = fontid("TU/lmr/m/n/10") default_space_char.char = 32 default_space_char.font = default_fontid % \end{macrocode} +% And a function to check as best as possible if a font has a space: +% \begin{macrocode} +local function @@_font_has_space (fontid) + t= fonts.hashes.identifiers[fontid] + if luaotfload.aux.slot_of_name(fontid,"space") + or t.characters and t.characters[32] and t.characters[32]["unicode"]==32 + then + return true + else + return false + end +end +% \end{macrocode} % \begin{macro} % { % @@_space_chars_shipout, @@ -793,7 +882,10 @@ local function @@_space_chars_shipout (box) local space_char = node.copy(default_space_char) local curfont = nodegetattribute(n,iwfontattributeid) ltx.@@.trace.log ("INFO SPACE-FUNCTION-FONT: ".. tostring(curfont),3) - if curfont and luaotfload.aux.slot_of_name(curfont,"space") then + if curfont and + -- luaotfload.aux.slot_of_name(curfont,"space") + @@_font_has_space (curfont) + then space_char.font=curfont end head, space = node.insert_before(head, n, space_char) -- @@ -1074,10 +1166,8 @@ end function ltx.@@.func.mark_shipout (box) mcopen = ltx.@@.func.mark_page_elements (box,-1,-100,0,"Shipout",-1) if mcopen~=0 then -- there is a chunk open, close it (hope there is only one ... - local emcnode = nodenew("whatsit","pdf_literal") + local emcnode = @@_backend_create_emc_node () local list = box.list - emcnode.data = "EMC" - emcnode.mode=1 if list then list = node.insert_after (list,node.tail(list),emcnode) mcopen = mcopen - 1 |