From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Mon, 2 Sep 2019 13:46:59 +0900
Subject: Initial commit

---
 macros/latex/contrib/l3backend/l3backend-pdf.dtx | 2106 ++++++++++++++++++++++
 1 file changed, 2106 insertions(+)
 create mode 100644 macros/latex/contrib/l3backend/l3backend-pdf.dtx

(limited to 'macros/latex/contrib/l3backend/l3backend-pdf.dtx')

diff --git a/macros/latex/contrib/l3backend/l3backend-pdf.dtx b/macros/latex/contrib/l3backend/l3backend-pdf.dtx
new file mode 100644
index 0000000000..fc75aae39b
--- /dev/null
+++ b/macros/latex/contrib/l3backend/l3backend-pdf.dtx
@@ -0,0 +1,2106 @@
+% \iffalse meta-comment
+%
+%% File: l3backend-pdf.dtx
+%
+% Copyright (C) 2019 The LaTeX3 Project
+%
+% It may be distributed and/or modified under the conditions of the
+% LaTeX Project Public License (LPPL), either version 1.3c of this
+% license or (at your option) any later version.  The latest version
+% of this license is in the file
+%
+%    https://www.latex-project.org/lppl.txt
+%
+% This file is part of the "l3backend bundle" (The Work in LPPL)
+% and all files in that bundle must be distributed together.
+%
+% -----------------------------------------------------------------------
+%
+% The development version of the bundle can be found at
+%
+%    https://github.com/latex3/latex3
+%
+% for those people who are interested.
+%
+%<*driver>
+\documentclass[full,kernel]{l3doc}
+\begin{document}
+  \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \title{^^A
+%   The \textsf{l3backend-pdf} package\\ Backend PDF features^^A
+% }
+%
+% \author{^^A
+%  The \LaTeX3 Project\thanks
+%    {^^A
+%      E-mail:
+%        \href{mailto:latex-team@latex-project.org}
+%          {latex-team@latex-project.org}^^A
+%    }^^A
+% }
+%
+% \date{Released 2019-08-25}
+%
+% \maketitle
+%
+% \begin{documentation}
+%
+% \end{documentation}
+%
+% \begin{implementation}
+%
+% \section{\pkg{l3backend-pdf} Implementation}
+%
+%    \begin{macrocode}
+%<*initex|package>
+%<@@=pdf>
+%    \end{macrocode}
+%
+% Setting up PDF resources is a complex area with only limited documentation
+% in the engine manuals. The following code builds heavily on existing ideas
+% from \pkg{hyperref} work by Sebastian Rahtz and Heiko Oberdiek, and
+% significant contributions by Alexander Grahn, in addition to the specific
+% code referenced a various points.
+%
+% \subsection{Shared code}
+%
+% A very small number of items that belong at the backend level but which
+% are common to all backends.
+%
+% \begin{variable}{\l_@@_internal_boxf}
+%    \begin{macrocode}
+\box_new:N \l_@@_internal_box
+%    \end{macrocode}
+% \end{variable}
+%
+% \subsection{\texttt{dvips} backend}
+%
+%    \begin{macrocode}
+%<*dvips>
+%    \end{macrocode}
+%
+% \begin{macro}{\@@_backend_pdfmark:n, \@@_backend_pdfmark:x}
+%   Used often enough it should be a separate function.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_pdfmark:n #1
+  { \__kernel_backend_postscript:n { mark #1 ~ pdfmark } }
+\cs_generate_variant:Nn \@@_backend_pdfmark:n { x }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Catalogue entries}
+%
+% \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2
+  { \@@_backend_pdfmark:n { { Catalog } << /#1 ~ #2 >> /PUT } }
+\cs_new_protected:Npn \@@_backend_info_gput:nn #1#2
+  { \@@_backend_pdfmark:n { /#1 ~ #2 /DOCINFO } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Objects}
+%
+% \begin{variable}{\g_@@_backend_object_int, \g_@@_backend_object_prop}
+%   For tracking objects to allow finalisation.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_object_int
+\prop_new:N \g_@@_backend_object_prop
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_backend_object_new:nn}
+% \begin{macro}[EXP]{\@@_backend_object_ref:n}
+%   Tracking objects is similar to \texttt{dvipdfmx}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_new:nn #1#2
+  {
+    \int_gincr:N \g_@@_backend_object_int
+    \int_const:cn
+      { c_@@_backend_object_ \tl_to_str:n {#1} _int }
+      { \g_@@_backend_object_int }
+    \prop_gput:Nnn \g_@@_backend_object_prop {#1} {#2}
+  }
+\cs_new:Npn \@@_backend_object_ref:n #1
+  { { pdf.obj \int_use:c { c_@@_backend_object_ \tl_to_str:n {#1} _int } } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_write:nn, \@@_backend_object_write:nx}
+% \begin{macro}
+%   {
+%     \@@_backend_object_write_array:nn ,
+%     \@@_backend_object_write_dict:nn  ,
+%     \@@_backend_object_write_stream:nn
+%   }
+% \begin{macro}{\@@_backend_object_write_stream:nnn}
+%   This is where we choose the actual type: some work to get things
+%   right.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_write:nn #1#2
+  {
+    \@@_backend_pdfmark:x
+      {
+        /_objdef ~ \@@_backend_object_ref:n {#1}
+        /type
+        \str_case_e:nn
+          { \prop_item:Nn \g_@@_backend_object_prop {#1} }
+          {
+            { array }   { /array }
+            { dict }    { /dict }
+            { fstream } { /stream }
+            { stream }  { /stream }
+          }
+        /OBJ
+      }
+    \use:c
+      { @@_backend_object_write_ \prop_item:Nn \g_@@_backend_object_prop {#1} :nn }
+      { \@@_backend_object_ref:n {#1} } {#2}
+  }
+\cs_generate_variant:Nn \@@_backend_object_write:nn { nx }
+\cs_new_protected:Npn \@@_backend_object_write_array:nn #1#2
+  {
+    \@@_backend_pdfmark:x
+      { #1 [ ~ \exp_not:n {#2} ~ ] ~ /PUTINTERVAL }
+  }
+\cs_new_protected:Npn \@@_backend_object_write_dict:nn #1#2
+  {
+    \@@_backend_pdfmark:x
+      { #1 << \exp_not:n {#2} >> /PUT }
+  }
+\cs_new_protected:Npn \@@_backend_object_write_stream:nn #1#2
+  {
+    \exp_args:Nx
+      \@@_backend_object_write_stream:nnn {#1} #2
+  }
+\cs_new_protected:Npn \@@_backend_object_write_stream:nnn #1#2#3
+  {
+    \@@_postscript:n
+      {
+        [nobreak]
+        mark ~ #1 ~ ( #3 ) /PUT ~ pdfmark ~
+        mark ~ #1 ~ << #2 >> /PUT ~ pdfmark
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:nx}
+%   No anonymous objects, so things are done manually.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_now:nn #1#2
+  {
+    \int_gincr:N \g_@@_backend_object_int
+    \@@_backend_pdfmark:x
+      {
+        /_objdef ~ { pdf.obj \int_use:N \g_@@_backend_object_int }
+        /type
+        \str_case:nn
+          {#1}
+          {
+            { array }   { /array }
+            { dict }    { /dict }
+            { fstream } { /stream }
+            { stream }  { /stream }
+          }
+        /OBJ
+      }
+    \exp_args:Nnx \use:c { @@_backend_object_write_ #1 :nn }
+      { { pdf.obj \int_use:N \g_@@_backend_object_int } } {#2}
+  }
+\cs_generate_variant:Nn \@@_backend_object_now:nn { nx }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_object_last:}
+%   Much like the annotation version.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_object_last:
+  { { pdf.obj \int_use:N \g_@@_backend_object_int } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Annotations}
+%
+% In \texttt{dvips}, annotations have to be constructed manually. As such,
+% we need the object code above for some definitions.
+%
+% \begin{macro}{pdf.globaldict}
+%   A small global dictionary for backend use.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    true ~ setglobal ~
+    /pdf.globaldict ~ 4 ~ dict ~ def ~
+    false ~ setglobal
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.cvs     ,
+%     pdf.dvi.pt  ,
+%     pdf.pt.dvi  ,
+%     pdf.rect.ht
+%   }
+%   Small utilities for PostScript manipulations. Conversion to DVI dimensions
+%   is done here to allow for |Resolution|. The total height of a rectangle
+%   (an array) needs a little maths, in contrast to simply extracting a value.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.cvs { 65534 ~ string ~ cvs } def
+    /pdf.dvi.pt { 72.27 ~ mul ~ Resolution ~ div } def
+    /pdf.pt.dvi { 72.27 ~ div ~ Resolution ~ mul } def
+    /pdf.rect.ht { dup ~ 1 ~ get ~ neg ~ exch ~ 3 ~ get ~ add } def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{pdf.linkmargin, pdf.linkdp.pad, pdf.linkht.pad}
+%   Settings which are defined up-front in |SDict|.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.linkmargin { 1 ~ pdf.pt.dvi } def
+    /pdf.linkdp.pad { 0 } def
+    /pdf.linkht.pad { 0 } def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.rect        ,
+%     pdf.save.ll     ,
+%     pdf.save.ur     ,
+%     pdf.save.linkll ,
+%     pdf.save.linkur ,
+%     pdf.llx         ,
+%     pdf.lly         ,
+%     pdf.urx         ,
+%     pdf.ury
+%   }
+%   Functions for marking the limits of an annotation/link, plus drawing the
+%   border. We separate links for generic annotations to support adding a
+%   margin and setting a minimal size.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.rect
+      { /Rect [ pdf.llx ~ pdf.lly ~ pdf.urx ~ pdf.ury ] } def
+    /pdf.save.ll
+      {
+        currentpoint
+        /pdf.lly ~ exch ~ def
+        /pdf.llx ~ exch ~ def
+      }
+        def
+    /pdf.save.ur
+      {
+        currentpoint
+        /pdf.ury ~ exch ~ def
+        /pdf.urx ~ exch ~ def
+      }
+        def
+    /pdf.save.linkll
+      {
+        currentpoint ~
+        pdf.linkmargin ~ add ~
+        pdf.linkdp.pad ~ add
+        /pdf.lly ~ exch ~ def ~
+        pdf.linkmargin ~ sub
+        /pdf.llx ~ exch ~ def
+      }
+        def
+    /pdf.save.linkur
+      {
+        currentpoint ~
+        pdf.linkmargin ~ sub ~
+        pdf.linkht.pad ~ sub
+        /pdf.ury ~ exch ~ def ~
+        pdf.linkmargin ~ add
+        /pdf.urx ~ exch ~ def
+      }
+        def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.dest.anchor ,
+%     pdf.dest.x      ,
+%     pdf.dest.y      ,
+%     pdf.dest.point  ,
+%     pdf.dest2device ,
+%     pdf.dev.x       ,
+%     pdf.dev.y       ,
+%     pdf.tmpa        ,
+%     pdf.tmpb        ,
+%     pdf.tmpc        ,
+%     pdf.tmpd
+%   }
+%   For finding the anchor point of a destination link. We make the use case
+%   a separate function as it comes up a lot, and as this makes it easier to
+%   adjust if we need additional effects. We also need a more complex approach
+%   to convert a co-ordinate pair correctly when defining a rectangle: this
+%   can otherwise be out when using a landscape page. (Thanks to Alexander
+%   Grahn for the approach here.)
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.dest.anchor
+      {
+        currentpoint ~ exch ~
+        pdf.dvi.pt ~ 72 ~ add ~
+        /pdf.dest.x ~ exch ~ def ~
+        pdf.dvi.pt ~
+        vsize ~ 72 ~ sub ~ exch ~ sub ~
+        /pdf.dest.y ~ exch ~ def
+      }
+        def
+    /pdf.dest.point
+      { pdf.dest.x ~ pdf.dest.y } def
+   /pdf.dest2device
+     {
+       /pdf.dest.y ~ exch ~ def
+       /pdf.dest.x ~ exch ~ def ~
+       matrix ~ currentmatrix ~
+       matrix ~ defaultmatrix ~
+       matrix ~ invertmatrix ~
+       matrix ~ concatmatrix ~
+       cvx ~ exec
+       /pdf.dev.y ~ exch ~ def
+       /pdf.dev.x ~ exch ~ def
+       /pdf.tmpd ~ exch ~ def
+       /pdf.tmpc ~ exch ~ def
+       /pdf.tmpb ~ exch ~ def
+       /pdf.tmpa ~ exch ~ def ~
+       pdf.dest.x ~ pdf.tmpa ~ mul ~
+         pdf.dest.y ~ pdf.tmpc ~ mul ~ add ~
+         pdf.dev.x ~ add ~
+       pdf.dest.x ~ pdf.tmpb ~ mul ~
+         pdf.dest.y ~ pdf.tmpd ~ mul ~ add ~
+         pdf.dev.y ~ add
+     }
+       def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.bordertracking          ,
+%     pdf.bordertracking.begin    ,
+%     pdf.bordertracking.end      ,
+%     pdf.leftboundary            ,
+%     pdf.rightboundary           ,
+%     pdf.brokenlink.rect         ,
+%     pdf.brokenlink.skip         ,
+%     pdf.brokenlink.dict         ,
+%     pdf.bordertracking.endpage  ,
+%     pdf.bordertracking.continue ,
+%     pdf.originx                 ,
+%     pdf.originy
+%   }
+%    To know where a breakable link can go, we need to track the boundary
+%    rectangle. That can be done by hooking into |a| and |x| operations:
+%    those names have to be retained. The boundary is stored at the end of
+%    the operation. Special effort is needed at the start and end of pages
+%    (or rather galleys), such that everything works properly.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.bordertracking ~ false ~ def
+    /pdf.bordertracking.begin
+      {
+        SDict ~ /pdf.bordertracking ~ true ~ put ~
+        SDict ~ /pdf.leftboundary ~ undef ~
+        SDict ~ /pdf.rightboundary ~ undef ~
+        /a ~ where
+          {
+            /a
+              {
+                currentpoint ~ pop ~
+                SDict /pdf.rightboundary ~ known ~ dup
+                  {
+                    SDict /pdf.rightboundary ~ get ~ 2 ~ index ~ lt
+                      { not }
+                    if
+                  }
+                if
+                  { pop }
+                  { SDict ~ exch /pdf.rightboundary ~ exch ~ put }
+                ifelse ~
+                moveto ~
+                currentpoint ~ pop ~
+                SDict /pdf.leftboundary ~ known ~ dup
+                  {
+                    SDict /pdf.leftboundary ~ get ~ 2 ~ index ~ gt
+                      { not }
+                    if
+                  }
+                if
+                  { pop }
+                  { SDict ~ exch /pdf.leftboundary ~ exch ~ put }
+                ifelse
+              }
+            put
+          }
+        if
+      }
+        def
+    /pdf.bordertracking.end
+      {
+        /a ~ where { /a { moveto } put } if
+        /x ~ where { /x { 0 ~ exch ~ rmoveto } put } if ~
+        SDict /pdf.leftboundary ~ known
+          { pdf.outerbox ~ 0 ~ pdf.leftboundary ~ put }
+        if ~
+        SDict /pdf.rightboundary ~ known
+          { pdf.outerbox ~ 2 ~ pdf.rightboundary ~ put }
+        if ~
+        SDict /pdf.bordertracking ~ false ~ put
+      }
+        def
+  /pdf.bordertracking.endpage
+    {
+      pdf.bordertracking
+        {
+          pdf.bordertracking.end ~
+          true ~ setglobal ~
+          pdf.globaldict
+            /pdf.brokenlink.rect [ pdf.outerbox ~ aload ~ pop ] put ~
+          pdf.globaldict
+            /pdf.brokenlink.skip ~ pdf.baselineskip ~ put ~
+          pdf.globaldict
+            /pdf.brokenlink.dict ~
+              pdf.link.dict ~ pdf.cvs ~ put ~
+          false ~ setglobal ~
+          mark ~ pdf.link.dict ~ cvx ~ exec ~ /Rect
+            [
+              pdf.llx ~
+              pdf.lly ~
+              pdf.outerbox ~ 2 ~ get ~ pdf.linkmargin ~ add ~
+              currentpoint ~ exch ~ pop ~
+              pdf.outerbox ~ pdf.rect.ht ~ sub ~ pdf.linkmargin ~ sub
+            ]
+          /ANN ~ pdf.pdfmark
+        }
+      if
+    }
+      def
+    /pdf.bordertracking.continue
+      {
+        /pdf.link.dict ~ pdf.globaldict
+          /pdf.brokenlink.dict ~ get ~ def
+        /pdf.outerbox ~ pdf.globaldict
+          /pdf.brokenlink.rect ~ get ~ def
+        /pdf.baselineskip ~ pdf.globaldict
+          /pdf.brokenlink.skip ~ get ~ def ~
+        pdf.globaldict ~ dup ~ dup
+        /pdf.brokenlink.dict ~ undef
+        /pdf.brokenlink.skip ~ undef
+        /pdf.brokenlink.rect ~ undef ~
+        currentpoint
+        /pdf.originy ~ exch ~ def
+        /pdf.originx ~ exch ~ def
+        /a ~ where
+          {
+            /a
+              {
+                moveto ~
+                SDict ~
+                begin ~
+                currentpoint ~ pdf.originy ~ ne ~ exch ~
+                  pdf.originx ~ ne ~ or
+                  {
+                    pdf.save.linkll
+                    /pdf.lly ~
+                      pdf.lly ~ pdf.outerbox ~ 1 ~ get ~ sub ~ def ~
+                    pdf.bordertracking.begin
+                  }
+                if ~
+                end
+              }
+            put
+          }
+        if
+        /x ~ where
+          {
+            /x
+              {
+                0 ~ exch ~ rmoveto ~
+                SDict~
+                begin ~
+                currentpoint ~
+                pdf.originy ~ ne ~ exch ~ pdf.originx ~ ne ~ or
+                  {
+                    pdf.save.linkll
+                    /pdf.lly ~
+                      pdf.lly ~ pdf.outerbox ~ 1 ~ get ~ sub ~ def ~
+                    pdf.bordertracking.begin
+                  }
+                if ~
+                end
+              }
+            put
+          }
+        if
+      }
+        def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.breaklink       ,
+%     pdf.breaklink.write ,
+%     pdf.count           ,
+%     pdf.currentrect
+%   }
+%   Dealing with link breaking itself has multiple stage. The first step is to
+%   find the |Rect| entry in the dictionary, looping over key--value pairs.
+%   The first line is handled first, adjusting the rectangle to stay inside the
+%   text area. The second phase is a loop over the height of the bulk of the
+%   link area, done on the basis of a number of baselines. Finally, the end of
+%   the link area is tidied up, again from the boundary of the text area.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.breaklink
+      {
+        pop ~
+        counttomark ~ 2 ~ mod ~ 0 ~ eq
+          {
+            counttomark /pdf.count ~ exch ~ def
+              {
+               pdf.count ~ 0 ~ eq { exit } if ~
+               counttomark ~ 2 ~ roll ~
+               1 ~ index ~ /Rect ~ eq
+                 {
+                   dup ~ 4 ~ array ~ copy ~
+                   dup ~ dup ~
+                     1 ~ get ~
+                     pdf.outerbox ~ pdf.rect.ht ~
+                     pdf.linkmargin ~ 2 ~ mul ~ add ~ sub ~
+                     3 ~ exch ~ put ~
+                   dup ~
+                     pdf.outerbox ~ 2 ~ get ~
+                     pdf.linkmargin ~ add ~
+                     2 ~ exch ~ put ~
+                   dup ~ dup ~
+                     3 ~ get ~
+                     pdf.outerbox ~ pdf.rect.ht ~
+                     pdf.linkmargin ~ 2 ~ mul ~ add ~ add ~
+                     1 ~ exch ~ put
+                   /pdf.currentrect ~ exch ~  def ~
+                   pdf.breaklink.write
+                     {
+                       pdf.currentrect ~
+                       dup ~
+                         pdf.outerbox ~ 0 ~ get ~
+                         pdf.linkmargin ~ sub ~
+                         0 ~ exch ~ put ~
+                       dup ~
+                         pdf.outerbox ~ 2 ~ get ~
+                         pdf.linkmargin ~ add ~
+                         2 ~ exch ~ put ~
+                       dup ~ dup ~
+                         1 ~ get ~
+                         pdf.baselineskip ~ add ~
+                         1 ~ exch ~ put ~
+                       dup ~ dup ~
+                         3 ~ get ~
+                         pdf.baselineskip ~ add ~
+                         3 ~ exch ~ put ~
+                       /pdf.currentrect ~ exch ~ def ~
+                       pdf.breaklink.write
+                      }
+                    1 ~ index ~ 3 ~ get ~
+                    pdf.linkmargin ~ 2 ~ mul ~ add ~
+                    pdf.outerbox ~ pdf.rect.ht ~ add ~
+                    2 ~ index ~ 1 ~ get ~ sub ~
+                    pdf.baselineskip ~ div ~ round ~ cvi ~ 1 ~ sub ~
+                    exch ~
+                  repeat ~
+                  pdf.currentrect ~
+                  dup ~
+                    pdf.outerbox ~ 0 ~ get ~
+                    pdf.linkmargin ~ sub ~
+                    0 ~ exch ~ put ~
+                  dup ~ dup ~
+                    1 ~ get ~
+                    pdf.baselineskip ~ add ~
+                    1 ~ exch ~ put ~
+                  dup ~ dup ~
+                    3 ~ get ~
+                    pdf.baselineskip ~ add ~
+                    3 ~ exch ~ put ~
+                  dup ~ 2 ~ index ~ 2 ~ get ~  2 ~ exch ~ put
+                  /pdf.currentrect ~ exch ~ def ~
+                  pdf.breaklink.write ~
+                  SDict /pdf.pdfmark.good ~ false ~ put ~
+                  exit
+                }
+                { pdf.count ~ 2 ~ sub /pdf.count ~ exch ~ def }
+              ifelse
+            }
+          loop
+        }
+      if
+      /ANN
+    }
+      def
+    /pdf.breaklink.write
+      {
+        counttomark ~ 1 ~ sub ~
+        index /_objdef ~ eq
+          {
+            counttomark ~ -2 ~ roll ~
+            dup ~ wcheck ~
+              {
+                readonly ~
+                counttomark ~ 2 ~ roll
+              }
+              { pop ~ pop }
+            ifelse
+          }
+        if ~
+        counttomark ~ 1 ~ add ~ copy ~
+        pop ~ pdf.currentrect
+        /ANN ~ pdfmark
+      }
+        def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {
+%     pdf.pdfmark      ,
+%     pdf.pdfmark.good ,
+%     pdf.outerbox     ,
+%     pdf.baselineskip ,
+%     pdf.pdfmark.dict
+%   }
+%   The business end of breaking links starts by hooking into |pdfmarks|.
+%   Unlike \pkg{hypdvips}, we avoid altering any links we have not created
+%   by using a copy of the core |pdfmarks| function. Only mark types which
+%   are known are altered. At present, this is purely |ANN| marks, which are
+%   measured relative to the size of the baseline skip. If they are
+%   more than one apparent line high, breaking is applied.
+%    \begin{macrocode}
+\__kernel_backend_postscript_header:n
+  {
+    /pdf.pdfmark
+      {
+        SDict /pdf.pdfmark.good ~ true ~ put ~
+        dup /ANN ~ eq
+          {
+            pdf.pdfmark.store ~
+            pdf.pdfmark.dict ~
+              begin ~
+                Subtype /Link ~ eq ~
+                currentdict /Rect ~ known ~ and ~
+                SDict /pdf.outerbox ~ known ~ and ~
+                SDict /pdf.baselineskip ~ known ~ and ~
+                  {
+                    Rect ~ 3 ~ get ~
+                    pdf.linkmargin ~ 2 ~ mul ~ add ~
+                    pdf.outerbox ~ pdf.rect.ht ~ add ~
+                    Rect ~ 1 ~ get ~ sub ~
+                    pdf.baselineskip ~ div ~ round ~ cvi ~ 0 ~ gt
+                      { pdf.breaklink }
+                    if
+                  }
+                if ~
+              end ~
+            SDict /pdf.outerbox ~ undef ~
+            SDict /pdf.baselineskip ~ undef ~
+            currentdict /pdf.pdfmark.dict ~ undef ~
+          }
+        if ~
+        pdf.pdfmark.good
+          { pdfmark }
+          { cleartomark }
+        ifelse
+      }
+        def
+    /pdf.pdfmark.store
+      {
+        /pdf.pdfmark.dict ~ 65534 ~ dict ~ def ~
+        counttomark ~ 1 ~ add ~ copy ~
+        pop
+          {
+            dup ~ mark ~ eq
+              {
+                pop ~
+                exit
+              }
+              {
+                pdf.pdfmark.dict ~
+                begin ~ def ~ end
+              }
+            ifelse
+          }
+        loop
+    }
+      def
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{variable}{\l_@@_backend_content_box}
+%   The content of an annotation.
+%    \begin{macrocode}
+\box_new:N \l_@@_backend_content_box
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_@@_backend_model_box}
+%   For creating model sizing for links.
+%    \begin{macrocode}
+\box_new:N \l_@@_backend_model_box
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_annotation_int}
+%   Needed as objects which are not annotations could be created.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_annotation_int
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_backend_annotation:nnnn, \@@_backend_annotation_aux:nnnn}
+% \begin{macro}{pdf.llx, pdf.lly, pdf.urx, pdf.ury}
+%   Annotations are objects, but we track them separately. Notably, they are
+%   not in the object data lists. Here, to get the co-ordinates of the
+%   annotation, we need to have the data collected at the PostScript level.
+%   That requires a bit of box trickery (effectively a \LaTeXe{} |picture|
+%   of zero size). Once the data is collected, use it to set up the annotation
+%   border. There is a split into two parts here to allow an easy way of
+%   applying the Adobe Reader fix.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_annotation:nnnn #1#2#3#4
+  {
+    \@@_backend_annotation_aux:nnnn {#1} {#2} {#3} {#4}
+    \int_gincr:N \g_@@_backend_object_int
+    \int_gset_eq:NN \g_@@_backend_annotation_int \g_@@_backend_object_int
+    \@@_backend_pdfmark:x
+      {
+
+        /_objdef { pdf.obj \int_use:N \g_@@_backend_object_int }
+        pdf.rect ~
+        #4 ~
+        /ANN
+      }
+  }
+\cs_new_protected:Npn \@@_backend_annotation_aux:nnnn #1#2#3#4
+  {
+    \box_move_down:nn {#3}
+      { \hbox:n { \@@_postscript:n { pdf.save.ll } } }
+    \hbox:n {#4}
+    \box_move_up:nn {#2}
+      {
+        \hbox:n
+          {
+            \tex_kern:D \dim_eval:n {#1} \scan_stop:
+            \@@_postscript:n { pdf.save.ur }
+          }
+      }
+    \int_gincr:N \g_@@_backend_object_int
+    \int_gset_eq:NN \g_@@_backend_annotation_int \g_@@_backend_object_int
+    \@@_backend_pdfmark:x
+      {
+        /_objdef { pdf.obj \int_use:N \g_@@_backend_object_int }
+        pdf.rect
+        /ANN
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_annotation_last:}
+%   Provide the last annotation we created: could get tricky of course if
+%   other packages are loaded.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_annotation_last:
+  { { pdf.obj \int_use:N \g_@@_backend_annotation_int } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{variable}{\g_@@_backend_link_int}
+%   To track annotations which are links.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_link_int
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_link_dict_tl}
+%   To pass information to the end-of-link function.
+%    \begin{macrocode}
+\tl_new:N \g_@@_backend_link_dict_tl
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_link_sf_int}
+%   Needed to save/restore space factor, which is needed to deal with the face
+%   we need a box.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_link_sf_int
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_link_math_bool}
+%   Needed to save/restore math mode.
+%    \begin{macrocode}
+\bool_new:N \g_@@_backend_link_math_bool
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_link_bool}
+%   Track link formation: we cannot nest at all.
+%    \begin{macrocode}
+\bool_new:N \g_@@_backend_link_bool
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_@@_breaklink_pdfmark_tl}
+%   Swappable content for link breaking.
+%    \begin{macrocode}
+\tl_new:N \l_@@_breaklink_pdfmark_tl
+\tl_set:Nn \l_@@_breaklink_pdfmark_tl { pdfmark }
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_breaklink_postscript:n}
+%   To allow dropping material unless link breaking is active.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_breaklink_postscript:n #1 { }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_breaklink_usebox:N}
+%   Swappable box unpacking or use.
+%    \begin{macrocode}
+\cs_new_eq:NN \@@_breaklink_usebox:N \box_use:N
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw}
+% \begin{macro}{\@@_backend_link:nw, \@@_backend_link_aux:nw}
+% \begin{macro}{\@@_backend_link_end:, \@@_backend_link_end_aux:}
+% \begin{macro}{\@@_backend_link_minima:}
+% \begin{macro}{\@@_backend_link_outerbox:n}
+% \begin{macro}{\@@_backend_link_sf_save:, \@@_backend_link_sf_restore:}
+% \begin{macro}
+%   {
+%     pdf.linkdp.pad      ,
+%     pdf.linkht.pad      ,
+%     pdf.llx, pdf.lly ,
+%     pdf.ury, pdf.ury ,
+%     pdf.link.dict       ,
+%     pdf.outerbox        ,
+%     pdf.baselineskip
+%   }
+%   Links are crated like annotations but with dedicated code to allow for
+%   adjusting the size of the rectangle. In contrast to \pkg{hyperref}, we
+%   grab the link content as a box which can then unbox: this allows the same
+%   interface as for \pdfTeX{}.
+%
+%   Taking the idea of |evenboxes| from \pkg{hypdvips}, we implement a minimum
+%   box height and depth for link placement. This means that \enquote{underlining}
+%   with a hyperlink will generally give an even appearance. However, to ensure
+%   that the full content is always above the link border, we do not allow
+%   this to be negative (contrast \pkg{hypdvips} approach). The result should
+%   be similar to \pdfTeX{} in the vast majority of foreseeable cases.
+%
+%   The object number for a link is saved separately from the rest of the
+%   dictionary as this allows us to insert it just once, at either an
+%   unbroken link or only in the first line of a broken one. That makes the
+%   code clearer but also avoids a low-level PostScript error with the code
+%   as taken from \pkg{hypdvips}.
+%
+%   Getting the outer dimensions of the text area may be better using a two-pass
+%   approach and |\tex_savepos:D|. That plus format mode are still to re-examine.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2
+  { \@@_backend_link_begin:nw { #1 /Subtype /Link /A << /S /GoTo /D ( #2 ) >> } }
+\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2
+  { \@@_backend_link_begin:nw {#1#2} }
+\cs_new_protected:Npn \@@_backend_link_begin:nw #1
+  {
+    \bool_if:NF \g_@@_backend_link_bool
+      { \@@_backend_link_begin_aux:nw {#1} }
+  }
+\cs_new_protected:Npn \@@_backend_link_begin_aux:nw #1
+  {
+    \bool_gset_true:N \g_@@_backend_link_bool
+    \@@_postscript:n
+      { /pdf.link.dict ( #1 ) def }
+    \tl_gset:Nn \g_@@_backend_link_dict_tl {#1}
+    \@@_backend_link_sf_save:
+    \mode_if_math:TF
+      { \bool_gset_true:N \g_@@_backend_link_math_bool }
+      { \bool_gset_false:N \g_@@_backend_link_math_bool }
+    \hbox_set:Nw \l_@@_backend_content_box
+      \@@_backend_link_sf_restore:
+      \bool_if:NT \g_@@_backend_link_math_bool
+        { \c_math_toggle_token }
+  }
+\cs_new_protected:Npn \@@_backend_link_end:
+  {
+    \bool_if:NT \g_@@_backend_link_bool
+      { \@@_backend_link_end_aux: }
+  }
+\cs_new_protected:Npn \@@_backend_link_end_aux:
+  {
+      \bool_if:NT \g_@@_backend_link_math_bool
+        { \c_math_toggle_token }
+      \@@_backend_link_sf_save:
+    \hbox_set_end:
+    \@@_backend_link_minima:
+    \hbox_set:Nn \l_@@_backend_model_box { Gg }
+    \exp_args:Nx \@@_backend_link_outerbox:n
+      {
+%<*initex>
+         \l_galley_total_left_margin_dim
+%</initex>
+%<*package>
+         \int_if_odd:nTF { \value { page } }
+           { \oddsidemargin }
+           { \evensidemargin }
+%</package>
+      }
+    \box_move_down:nn { \box_dp:N \l_@@_backend_content_box }
+      { \hbox:n { \@@_postscript:n { pdf.save.linkll } } }
+    \@@_breaklink_postscript:n { pdf.bordertracking.begin }
+    \@@_breaklink_usebox:N \l_@@_backend_content_box
+    \@@_breaklink_postscript:n { pdf.bordertracking.end }
+    \box_move_up:nn { \box_ht:N \l_@@_backend_content_box }
+      {
+        \hbox:n
+          { \@@_postscript:n { pdf.save.linkur } }
+      }
+    \int_gincr:N \g_@@_backend_object_int
+    \int_gset_eq:NN \g_@@_backend_link_int \g_@@_backend_object_int
+    \@@_postscript:x
+      {
+        mark
+        /_objdef { pdf.obj \int_use:N \g_@@_backend_link_int }
+        \g_@@_backend_link_dict_tl \c_space_tl
+        pdf.rect
+        /ANN ~ \l_@@_breaklink_pdfmark_tl
+      }
+    \@@_backend_link_sf_restore:
+    \bool_gset_false:N \g_@@_backend_link_bool
+  }
+\cs_new_protected:Npn \@@_backend_link_minima:
+  {
+    \hbox_set:Nn \l_@@_backend_model_box { Gg }
+    \@@_postscript:x
+      {
+        /pdf.linkdp.pad ~
+          \dim_to_decimal:n
+            {
+              \dim_max:nn
+                {
+                    \box_dp:N \l_@@_backend_model_box
+                  - \box_dp:N \l_@@_backend_content_box
+                }
+                { 0pt }
+            } ~
+              pdf.pt.dvi ~ def
+        /pdf.linkht.pad ~
+          \dim_to_decimal:n
+            {
+              \dim_max:nn
+                {
+                    \box_ht:N \l_@@_backend_model_box
+                  - \box_ht:N \l_@@_backend_content_box
+                }
+                { 0pt }
+            } ~
+              pdf.pt.dvi ~ def
+      }
+  }
+\cs_new_protected:Npn \@@_backend_link_outerbox:n #1
+  {
+    \@@_postscript:x
+      {
+        /pdf.outerbox
+          [
+            \dim_to_decimal:n {#1} ~
+            \dim_to_decimal:n { -\box_dp:N \l_@@_backend_model_box } ~
+%<*initex>
+            \dim_to_decimal:n { #1 + \l_galley_text_width_dim } ~
+%</initex>
+%<*package>
+            \dim_to_decimal:n { #1 + \textwidth } ~
+%</package>
+            \dim_to_decimal:n { \box_ht:N \l_@@_backend_model_box }
+          ]
+          [ exch { pdf.pt.dvi } forall ] def
+        /pdf.baselineskip ~
+          \dim_to_decimal:n { \tex_baselineskip:D } ~ dup ~ 0 ~ gt
+            { pdf.pt.dvi ~ def }
+            { pop ~ pop }
+          ifelse
+      }
+  }
+\cs_new_protected:Npn \@@_backend_link_sf_save:
+  {
+    \int_gset:Nn \g_@@_backend_link_sf_int
+      {
+        \mode_if_horizontal:TF
+          { \tex_spacefactor:D }
+          { 0 }
+      }
+  }
+\cs_new_protected:Npn \@@_backend_link_sf_restore:
+  {
+    \mode_if_horizontal:T
+      {
+        \int_compare:nNnT \g_@@_backend_link_sf_int > { 0 }
+          { \int_set_eq:NN \tex_spacefactor:D \g_@@_backend_link_sf_int }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@makecol@hook}
+%   Hooks to allow link breaking: something will be needed in format mode
+%   at some stage. At present this code is disabled as there is an open
+%   question about the name of the hook: to be resolved at the \LaTeXe{}
+%   end.
+%    \begin{macrocode}
+%<*package>
+\use_none:n
+  {
+    \cs_if_exist:NT \@makecol@hook
+      {
+        \tl_put_right:Nn \@makecol@hook
+          {
+            \box_if_empty:NF \@cclv
+              {
+                \vbox_set:Nn \@cclv
+                  {
+                    \@@_postscript:n
+                      {
+                        pdf.globaldict /pdf.brokenlink.rect ~ known
+                          { pdf.bordertracking.continue }
+                        if
+                      }
+                    \vbox_unpack_drop:N \@cclv
+                    \@@_postscript:n
+                      { pdf.bordertracking.endpage }
+                  }
+              }
+          }
+        \tl_set:Nn \l_@@_breaklink_pdfmark_tl { pdf.pdfmark }
+        \cs_set_eq:NN \@@_breaklink_postscript:n \@@_postscript:n
+        \cs_set_eq:NN \@@_breaklink_usebox:N \hbox_unpack:N
+      }
+  }
+%</package>
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_last:}
+%   The same as annotations, but with a custom integer.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_link_last:
+  { { pdf.obj \int_use:N \g_@@_backend_link_int } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_margin:n}
+%   Convert to big points and pass to PostScript.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_link_margin:n #1
+  {
+    \@@_postscript:x
+      {
+        /pdf.linkmargin { \dim_to_decimal:n {#1} ~ pdf.pt.dvi } def
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_destination:nn, \@@_backend_destination_rectangle:nn}
+%   Here, we need to turn the zoom into a scale. We also need to know where
+%   the current anchor point actually is: worked out in PostScript. For the
+%   rectangle version, we have a bit more PostScript: we need two points.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_destination:nn #1#2
+  {
+    \@@_postscript:n { pdf.dest.anchor }
+    \@@_backend_pdfmark:x
+      {
+        /View
+        [
+          \str_case:nnF {#2}
+            {
+              { xyz }   { /XYZ ~ pdf.dest.point ~ null }
+              { fit }   { /Fit }
+              { fitb }  { /FitB }
+              { fitbh } { /FitBH ~ pdf.dest.y }
+              { fitbv } { /FitBV ~ pdf.dest.x }
+              { fith }  { /FitH ~ pdf.dest.y }
+              { fitv }  { /FitV ~ pdf.dest.x }
+            }
+            {
+              /XYZ ~ pdf.dest.point ~ \fp_eval:n { (#2) / 100 }
+            }
+        ]
+        /Dest ( \exp_not:n {#1} ) cvn
+        /DEST
+      }
+  }
+\cs_new_protected:Npn \@@_backend_destination_rectangle:nn #1#2
+  {
+    \group_begin:
+      \hbox_set:Nn \l_@@_internal_box {#2}
+      \box_move_down:nn
+        { \box_dp:N \l_@@_internal_box }
+        { \hbox:n { \@@_postscript:n { pdf.save.ll } } }
+      \box_use:N \l_@@_internal_box
+      \box_move_up:nn
+        { \box_ht:N \l_@@_internal_box }
+        { \hbox:n { \@@_postscript:n { pdf.save.ur } } }
+      \@@_backend_pdfmark:n
+        {
+          /View
+          [
+            /FitR ~
+              pdf.llx ~ pdf.lly ~ pdf.dest2device ~
+              pdf.urx ~ pdf.ury ~ pdf.dest2device
+          ]
+          /Dest ( #1 ) cvn
+          /DEST
+        }
+    \group_end:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Structure}
+%
+% \begin{macro}{\@@_backend_compresslevel:n}
+% \begin{macro}{\@@_backend_compress_objects:n}
+%   These are all no-ops.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_compresslevel:n #1 { }
+\cs_new_protected:Npn \@@_backend_compress_objects:n #1 { }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
+%   Data not available!
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_version_major_gset:n #1 { }
+\cs_new_protected:Npn \@@_backend_version_minor_gset:n #1 { }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
+%   Data not available!
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_version_major: { -1 }
+\cs_new:Npn \@@_backend_version_minor: { -1 }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Marked content}
+%
+% \begin{macro}{\@@_backend_bdc:nn}
+% \begin{macro}{\@@_backend_emc:}
+%   Simple wrappers.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_bdc:nn #1#2
+  { \@@_backend_pdfmark:n { /#1 ~ #2 /BDC } }
+\cs_new_protected:Npn \@@_backend_emc:
+  { \@@_backend_pdfmark:n { /EMC } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+%    \begin{macrocode}
+%</dvips>
+%    \end{macrocode}
+%
+% \subsection{\texttt{pdfmode} backend}
+%
+%    \begin{macrocode}
+%<*pdfmode>
+%    \end{macrocode}
+%
+% \subsubsection{Annotations}
+%
+% \begin{macro}{\@@_backend_annotation:nnnn}
+%   Simply pass the raw data through, just dealing with evaluation of dimensions.
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_annotation:nnnn #1#2#3#4
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \tex_pdfextension:D annot ~ }
+      { \tex_pdfannot:D }
+      width  ~ \exp_not:N \dim_eval:n {#1} ~
+      height ~ \exp_not:N \dim_eval:n {#2} ~
+      depth  ~ \exp_not:N \dim_eval:n {#3} ~
+      {#4}
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_annotation_last:}
+%   A tiny amount of extra data gets added here.
+%    \begin{macrocode}
+\cs_new:Npx \@@_backend_annotation_last:
+  {
+    \exp_not:N \int_value:w
+    \cs_if_exist:NTF \tex_pdffeedback:D
+      { \exp_not:N \tex_pdffeedback:D lastannot ~ }
+      { \exp_not:N \tex_pdflastannot:D }
+      \c_space_tl 0 ~ R
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw}
+% \begin{macro}{\@@_backend_link_begin:nnnw}
+% \begin{macro}{\@@_backend_link_end:}
+%   Links are all created using the same internals.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2
+  { \@@_backend_link_begin:nnnw {#1} { goto~name } {#2} }
+\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2
+  { \@@_backend_link_begin:nnnw {#1} { user } {#2} }
+\cs_new_protected:Npx \@@_backend_link_begin:nnnw #1#2#3
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \tex_pdfextension:D startlink ~ }
+      { \tex_pdfstartlink:D }
+        attr {#1}
+        #2 {#3}
+  }
+\cs_new_protected:Npx \@@_backend_link_end:
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \tex_pdfextension:D endlink \scan_stop: }
+      { \tex_pdfendlink:D }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_last:}
+%   Formatted for direct use.
+%    \begin{macrocode}
+\cs_new:Npx \@@_backend_link_last:
+  {
+    \exp_not:N \int_value:w
+    \cs_if_exist:NTF \tex_pdffeedback:D
+      { \exp_not:N \tex_pdffeedback:D lastlink ~ }
+      { \exp_not:N \tex_pdflastlink:D }
+      \c_space_tl 0 ~ R
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_margin:n}
+%   A simple task: pass the data to the primitive.
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_link_margin:n #1
+  {
+    \cs_if_exist:NTF \tex_pdfvariable:D
+      { \exp_not:N \tex_pdfvariable:D linkmargin }
+      { \exp_not:N \tex_pdflinkmargin:D }
+        \exp_not:N \dim_eval:n {#1} \scan_stop:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_destination:nn, \@@_backend_destination_rectangle:nn}
+%   A simple task: pass the data to the primitive. The |\scan_stop:| deals
+%   with the danger of an unterminated keyword. The zoom given here is a
+%   percentage, but we need to pass it as \emph{per mille}. The rectangle
+%   version is also easy as everything is build in.
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_destination:nn #1#2
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \exp_not:N \tex_pdfextension:D dest ~ }
+      { \exp_not:N \tex_pdfdest:D }
+        name {#1}
+        \exp_not:N \str_case:nnF {#2}
+          {
+            { xyz }   { xyz }
+            { fit }   { fit }
+            { fitb }  { fitb }
+            { fitbh } { fitbh }
+            { fitbv } { fitbv }
+            { fith }  { fith }
+            { fitv }  { fitv }
+          }
+          { xyz ~ zoom \exp_not:N \fp_eval:n { #2 * 10 } }
+        \scan_stop:
+  }
+\cs_new_protected:Npx \@@_backend_destination_rectangle:nn #1#2
+  {
+    \group_begin:
+      \hbox_set:Nn \l_@@_internal_box {#2}
+     \cs_if_exist:NTF \tex_pdfextension:D
+      { \exp_not:N \tex_pdfextension:D dest ~ }
+      { \exp_not:N \tex_pdfdest:D }
+      name {#1}
+      fitr ~
+        width  \exp_not:N \box_wd:N \l_@@_internal_box
+        height \exp_not:N \box_ht:N \l_@@_internal_box
+        depth  \exp_not:N \box_dp:N \l_@@_internal_box
+      \box_use:N \l_@@_internal_box
+    \group_end:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Catalogue entries}
+%
+% \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_catalog_gput:nn #1#2
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \tex_pdfextension:D catalog }
+      { \tex_pdfcatalog:D }
+        { / #1 ~ #2 }
+  }
+\cs_new_protected:Npx \@@_backend_info_gput:nn #1#2
+  {
+    \cs_if_exist:NTF \tex_pdfextension:D
+      { \tex_pdfextension:D info }
+      { \tex_pdfinfo:D }
+        { / #1 ~ #2 }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Objects}
+%
+% \begin{variable}{\g_@@_backend_object_prop}
+%   For tracking objects to allow finalisation.
+%    \begin{macrocode}
+\prop_new:N \g_@@_backend_object_prop
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_backend_object_new:nn}
+% \begin{macro}[EXP]{\@@_backend_object_ref:n}
+%   Declaring objects means reserving at the PDF level plus starting
+%   tracking.
+%    \begin{macrocode}
+\group_begin:
+  \cs_set_protected:Npn \@@_tmp:w #1#2
+    {
+      \cs_new_protected:Npx \@@_backend_object_new:nn ##1##2
+        {
+          #1 reserveobjnum ~
+          \int_const:cn
+            { c_@@_backend_object_ \exp_not:N \tl_to_str:n {##1} _int }
+            {#2}
+          \prop_gput:Nnn \exp_not:N \g_@@_backend_object_prop {##1} {##2}
+        }
+    }
+  \cs_if_exist:NTF \tex_pdfextension:D
+    {
+      \@@_tmp:w
+        { \tex_pdfextension:D obj ~ }
+        { \exp_not:N \tex_pdffeedback:D lastobj }
+    }
+    { \@@_tmp:w { \tex_pdfobj:D } { \tex_pdflastobj:D } }
+\group_end:
+\cs_new:Npn \@@_backend_object_ref:n #1
+  { \int_use:c { c_@@_backend_object_ \tl_to_str:n {#1} _int } ~ 0 ~ R }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_write:nn,\@@_backend_object_write:nx}
+% \begin{macro}[EXP]{\@@_exp_not_i:nn, \@@_exp_not_ii:nn}
+%   Writing the data needs a little information about the structure of the
+%   object.
+%    \begin{macrocode}
+\group_begin:
+  \cs_set_protected:Npn \@@_tmp:w #1
+    {
+      \cs_new_protected:Npn \@@_backend_object_write:nn ##1##2
+        {
+          \tex_immediate:D #1 useobjnum ~
+          \int_use:c
+            { c_@@_backend_object_ \tl_to_str:n {##1} _int }
+            \str_case_e:nn
+              { \prop_item:Nn \g_@@_backend_object_prop {##1} }
+              {
+                { array } { { [ ~ \exp_not:n {##2} ~ ] } }
+                { dict }  { { << ~ \exp_not:n {##2} ~ >> } }
+                { fstream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~
+                      file ~ { \@@_exp_not_ii:nn ##2 }
+                  }
+                { stream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~
+                      { \@@_exp_not_ii:nn ##2 }
+                  }
+              }
+        }
+    }
+  \cs_if_exist:NTF \tex_pdfextension:D
+    { \@@_tmp:w { \tex_pdfextension:D obj ~ } }
+    { \@@_tmp:w { \tex_pdfobj:D } }
+\group_end:
+\cs_generate_variant:Nn \@@_backend_object_write:nn { nx }
+\cs_new:Npn \@@_exp_not_i:nn #1#2 { \exp_not:n {#1} }
+\cs_new:Npn \@@_exp_not_ii:nn #1#2 { \exp_not:n {#2} }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:nx}
+%   Much like writing, but direct creation.
+%    \begin{macrocode}
+\group_begin:
+  \cs_set_protected:Npn \@@_tmp:w #1
+    {
+      \cs_new_protected:Npn \@@_backend_object_now:nn ##1##2
+        {
+          \tex_immediate:D #1
+            \str_case:nn
+              {##1}
+              {
+                { array } { { [ ~ \exp_not:n {##2} ~ ] } }
+                { dict }  { { << ~ \exp_not:n {##2} ~ >> } }
+                { fstream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~
+                      file ~ { \@@_exp_not_ii:nn ##2 }
+                  }
+                { stream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~
+                      { \@@_exp_not_ii:nn ##2 }
+                  }
+              }
+        }
+    }
+  \cs_if_exist:NTF \tex_pdfextension:D
+    { \@@_tmp:w { \tex_pdfextension:D obj ~ } }
+    { \@@_tmp:w { \tex_pdfobj:D } }
+\group_end:
+\cs_generate_variant:Nn \@@_backend_object_now:nn { nx }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_object_last:}
+%   Much like annotation.
+%    \begin{macrocode}
+\cs_new:Npx \@@_backend_object_last:
+  {
+    \exp_not:N \int_value:w
+    \cs_if_exist:NTF \tex_pdffeedback:D
+      { \exp_not:N \tex_pdffeedback:D lastobj ~ }
+      { \exp_not:N \tex_pdflastobj:D }
+      \c_space_tl 0 ~ R
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Structure}
+%
+% \begin{macro}{\@@_backend_compresslevel:n}
+% \begin{macro}{\@@_backend_compress_objects:n}
+% \begin{macro}{\@@_backend_objcompresslevel:n}
+%   Simply pass data to the engine.
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_compresslevel:n #1
+  {
+    \exp_not:N \tex_global:D
+    \cs_if_exist:NTF \tex_pdfcompresslevel:D
+      { \tex_pdfcompresslevel:D }
+      { \tex_pdfvariable:D compresslevel }
+      \exp_not:N \int_value:w \exp_not:N \int_eval:n {#1} \scan_stop:
+  }
+\cs_new_protected:Npn \@@_backend_compress_objects:n #1
+  {
+    \bool_if:nTF {#1}
+      { \@@_backend_objcompresslevel:n { 2 } }
+      { \@@_backend_objcompresslevel:n { 0 } }
+  }
+\cs_new_protected:Npx \@@_backend_objcompresslevel:n #1
+  {
+    \exp_not:N \tex_global:D
+    \cs_if_exist:NTF \tex_pdfobjcompresslevel:D
+      { \tex_pdfobjcompresslevel:D }
+      { \tex_pdfvariable:D objcompresslevel }
+      #1 \scan_stop:
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
+%   At present, we don't have a primitive for the major version in \pdfTeX{},
+%   but we anticipate one \ldots
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend_version_major_gset:n #1
+  {
+    \cs_if_exist:NTF \tex_pdfvariable:D
+      {
+        \int_compare:nNnT \tex_luatexversion:D > { 106 }
+          {
+            \exp_not:N \tex_global:D \tex_pdfvariable:D majorversion
+              \exp_not:N \int_eval:n {#1} \scan_stop:
+          }
+      }
+      {
+        \cs_if_exist:NT \tex_pdfmajorversion:D
+          {
+            \exp_not:N \tex_global:D \tex_pdfmajorversion:D
+              \exp_not:N \int_eval:n {#1} \scan_stop:
+          }
+      }
+  }
+\cs_new_protected:Npx \@@_backend_version_minor_gset:n #1
+  {
+    \exp_not:N \tex_global:D
+    \cs_if_exist:NTF \tex_pdfminorversion:D
+      { \exp_not:N \tex_pdfminorversion:D }
+      { \tex_pdfvariable:D minorversion }
+        \exp_not:N \int_eval:n {#1} \scan_stop:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
+%   At present, we don't have a primitive for the major version!
+%    \begin{macrocode}
+\cs_new:Npx \@@_backend_version_major:
+  {
+    \cs_if_exist:NTF \tex_pdfvariable:D
+      {
+        \int_compare:nNnTF \tex_luatexversion:D > { 106 }
+          { \exp_not:N \tex_the:D \tex_pdfvariable:D majorversion }
+          { 1 }
+      }
+      {
+        \cs_if_exist:NTF \tex_pdfmajorversion:D
+          { \exp_not:N \tex_the:D \tex_pdfmajorversion:D }
+          { 1 }
+      }
+  }
+\cs_new:Npx \@@_backend_version_minor:
+  {
+    \exp_not:N \tex_the:D
+    \cs_if_exist:NTF \tex_pdfminorversion:D
+      { \exp_not:N \tex_pdfminorversion:D }
+      { \tex_pdfvariable:D minorversion }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Marked content}
+%
+% \begin{macro}{\@@_backend_bdc:nn}
+% \begin{macro}{\@@_backend_emc:}
+%   Simple wrappers. May need refinement: see
+%   \url{https://chat.stackexchange.com/transcript/message/49970158#49970158}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_bdc:nn #1#2
+  { \__kernel_backend_literal_page:n { /#1 ~ #2 ~ BDC } }
+\cs_new_protected:Npn \@@_backend_emc:
+  { \__kernel_backend_literal_page:n { EMC } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+%    \begin{macrocode}
+%</pdfmode>
+%    \end{macrocode}
+%
+% \subsection{\texttt{dvipdfmx} backend}
+%
+%    \begin{macrocode}
+%<*dvipdfmx|xdvipdfmx>
+%    \end{macrocode}
+%
+% \begin{macro}{\@@_backend:n, \@@_backend:x}
+%   A generic function for the backend PDF specials: used where we can.
+%    \begin{macrocode}
+\cs_new_protected:Npx \@@_backend:n #1
+  { \__kernel_backend_literal:n { pdf: #1 } }
+\cs_generate_variant:Nn \@@_backend:n { x }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Catalogue entries}
+%
+% \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2
+  { \@@_backend:n { put ~ @catalog << /#1 ~ #2 >> } }
+\cs_new_protected:Npn \@@_backend_info_gput:nn #1#2
+  { \@@_backend:n { docinfo << /#1 ~ #2 >> } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Objects}
+%
+% \begin{variable}{\g_@@_backend_object_int, \g_@@_backend_object_prop}
+%   For tracking objects to allow finalisation.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_object_int
+\prop_new:N \g_@@_backend_object_prop
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_backend_object_new:nn}
+% \begin{macro}[EXP]{\@@_backend_object_ref:n}
+%   Objects are tracked at the macro level, but we don't have to do anything
+%   at this stage.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_new:nn #1#2
+  {
+    \int_gincr:N \g_@@_backend_object_int
+    \int_const:cn
+      { c_@@_backend_object_ \tl_to_str:n {#1} _int }
+      { \g_@@_backend_object_int }
+    \prop_gput:Nnn \g_@@_backend_object_prop {#1} {#2}
+  }
+\cs_new:Npn \@@_backend_object_ref:n #1
+  { @pdf.obj \int_use:c { c_@@_backend_object_ \tl_to_str:n {#1} _int } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_write:nn, \@@_backend_object_write:nx}
+% \begin{macro}{\@@_backend_object_write:nnn}
+% \begin{macro}
+%   {
+%     \@@_backend_object_write_array:nn   ,
+%     \@@_backend_object_write_dict:nn    ,
+%     \@@_backend_object_write_fstream:nn ,
+%     \@@_backend_object_write_stream:nn
+%   }
+% \begin{macro}{\@@_backend_object_write_stream:nnnn}
+%   This is where we choose the actual type.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_write:nn #1#2
+  {
+    \exp_args:Nx \@@_backend_object_write:nnn
+      { \prop_item:Nn \g_@@_backend_object_prop {#1} } {#1} {#2}
+  }
+\cs_generate_variant:Nn \@@_backend_object_write:nn { nx }
+\cs_new_protected:Npn \@@_backend_object_write:nnn #1#2#3
+  {
+    \use:c { @@_backend_object_write_ #1 :nn }
+      { \@@_backend_object_ref:n {#2} } {#3}
+  }
+\cs_new_protected:Npn \@@_backend_object_write_array:nn #1#2
+  {
+    \@@_backend:x
+      { obj ~ #1 ~ [ ~ \exp_not:n {#2} ~ ] }
+  }
+\cs_new_protected:Npn \@@_backend_object_write_dict:nn #1#2
+  {
+    \@@_backend:x
+      { obj ~ #1 ~ << ~ \exp_not:n {#2} ~ >> }
+  }
+\cs_new_protected:Npn \@@_backend_object_write_fstream:nn #1#2
+  { \@@_backend_object_write_stream:nnnn { f } {#1} #2 }
+\cs_new_protected:Npn \@@_backend_object_write_stream:nn #1#2
+  { \@@_backend_object_write_stream:nnnn { } {#1} #2 }
+\cs_new_protected:Npn \@@_backend_object_write_stream:nnnn #1#2#3#4
+  {
+    \@@_backend:x
+      {
+        #1 stream ~ #2 ~
+          ( \exp_not:n {#4} ) ~ << \exp_not:n {#3} >>
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:nx}
+%   No anonymous objects with \texttt{dvipdfmx} so we have to give an
+%   object name.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_now:nn #1#2
+  {
+    \int_gincr:N \g_@@_backend_object_int
+    \exp_args:Nnx \use:c { @@_backend_object_write_ #1 :nn }
+      { @pdf.obj \int_use:N \g_@@_backend_object_int }
+      {#2}
+  }
+\cs_generate_variant:Nn \@@_backend_object_now:nn { nx }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_object_last:}
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_object_last:
+ { @pdf.obj \int_use:N \g_@@_backend_object_int }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Annotations}
+%
+% \begin{variable}{\g_@@_landscape_bool}
+%   There is a bug in \texttt{(x)dvipdfmx} which means annotations do
+%   not rotate. As such, we need to know if landscape is active.
+%    \begin{macrocode}
+\bool_new:N \g_@@_landscape_bool
+%<*package>
+\AtBeginDocument
+  {
+    \cs_if_exist:NT \landscape
+      {
+        \tl_put_right:Nn \landscape
+          { \bool_gset_true:N \g_@@_landscape_bool }
+        \tl_put_left:Nn \endlandscape
+          { \bool_gset_false:N \g_@@_landscape_bool }
+      }
+  }
+%</package>
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_backend_annotation_int}
+%   Needed as objects which are not annotations could be created.
+%    \begin{macrocode}
+\int_new:N \g_@@_backend_annotation_int
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_backend_annotation:nnnn, \@@_backend_annotation_aux:nnnn}
+%   Simply pass the raw data through, just dealing with evaluation of dimensions.
+%   The only wrinkle is landscape: we have to adjust by hand.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_annotation:nnnn #1#2#3#4
+  {
+    \bool_if:NTF \g_@@_landscape_bool
+      {
+         \box_move_up:nn {#2}
+           {
+             \vbox:n
+               {
+                 \@@_backend_annotation_aux:nnnn
+                   { #2 + #3 } {#1} { 0pt } {#4}
+               }
+           }
+      }
+      { \@@_backend_annotation_aux:nnnn {#1} {#2} {#3} {#4} }
+  }
+\cs_new_protected:Npn \@@_backend_annotation_aux:nnnn #1#2#3#4
+  {
+    \int_gincr:N \g_@@_backend_object_int
+    \int_gset_eq:NN \g_@@_backend_annotation_int \g_@@_backend_object_int
+    \@@_backend:x
+      {
+        ann ~ @pdf.obj \int_use:N \g_@@_backend_object_int \c_space_tl
+        width  ~ \dim_eval:n {#1} ~
+        height ~ \dim_eval:n {#2} ~
+        depth  ~ \dim_eval:n {#3} ~
+        << #4 >>
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_annotation_last:}
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_annotation_last:
+ { @pdf.obj \int_use:N \g_@@_backend_annotation_int }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw}
+% \begin{macro}{\@@_backend_link_begin:n}
+% \begin{macro}{\@@_backend_link_end:}
+%   All created using the same internals.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2
+  { \@@_backend_link_begin:n { #1 /Subtype /Link /A << /S /GoTo /D ( #2 ) >> } }
+\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2
+  { \@@_backend_link_begin:n {#1#2} }
+\cs_new_protected:Npn \@@_backend_link_begin:n #1
+  {
+    \@@_backend:n
+      {
+         bann
+         <<
+           /Type /Annot
+           #1
+         >>
+      }
+  }
+\cs_new_protected:Npn \@@_backend_link_end:
+  { \@@_backend:n { eann } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_last:}
+%   Data not available.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_link_last: { }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_link_margin:n}
+%   Pass to \texttt{dvipdfmx}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_link_margin:n #1
+  { \__kernel_backend_literal:x { dvipdfmx:config~g~ \dim_eval:n {#1} } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_destination:nn, \@@_backend_destination_rectangle:nn}
+%   Here, we need to turn the zoom into a scale. The method for \texttt{FitR}
+%   is from Alexander Grahn: the idea is to avoid needing to do any calculations
+%   in \TeX{} by using the backend data for \texttt{@xpos} and \texttt{@ypos}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_destination:nn #1#2
+  {
+    \@@_backend:x
+      {
+        dest ~ ( \exp_not:n {#1} )
+        [
+          @thispage
+          \str_case:nnF {#2}
+            {
+              { xyz }   { /XYZ ~ @xpos ~ @ypos ~ null }
+              { fit }   { /Fit }
+              { fitb }  { /FitB }
+              { fitbh } { /FitBH }
+              { fitbv } { /FitBV ~ @xpos }
+              { fith }  { /FitH ~ @ypos }
+              { fitv }  { /FitV ~ @xpos }
+            }
+            { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
+        ]
+      }
+  }
+\cs_new_protected:Npn \@@_backend_destination_rectangle:nn #1#2
+  {
+    \group_begin:
+      \hbox_set:Nn \l_@@_internal_box {#2}
+      \box_move_down:nn { \box_dp:N \l_@@_internal_box }
+        {
+          \hbox:n
+            {
+              \@@_backend:n { obj ~ @pdf_ #1 _llx ~ @xpos }
+              \@@_backend:n { obj ~ @pdf_ #1 _lly ~ @ypos }
+            }
+        }
+      \box_use:N \l_@@_internal_box
+      \box_move_up:nn { \box_ht:N \l_@@_internal_box }
+        {
+          \hbox:n
+            {
+              \@@_backend:n
+                {
+                  dest ~ (#1)
+                  [
+                    @thispage
+                    /FitR ~
+                      @pdf_ #1 _llx ~ @pdf_ #1 _lly ~
+                      @xpos ~ @ypos
+                  ]
+                }
+            }
+        }
+    \group_end:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Structure}
+%
+% \begin{macro}{\@@_backend_compresslevel:n}
+% \begin{macro}{\@@_backend_compress_objects:n}
+%   Pass data to the backend: these are a one-shot.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_compresslevel:n #1
+  { \__kernel_backend_literal:x { dvipdfmx:config~z~ \int_eval:n {#1} } }
+\cs_new_protected:Npn \@@_backend_compress_objects:n #1
+  {
+    \bool_if:nF {#1}
+      { \__kernel_backend_literal:n { dvipdfmx:config~C~0x40 } }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
+%   We start with the assumption that the default is active.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_version_major_gset:n #1
+  {
+    \cs_gset:Npx \@@_backend_version_major: { \int_eval:n {#1} }
+    \__kernel_backend_literal:x { pdf:majorversion~ \@@_backend_version_major: }
+  }
+\cs_new_protected:Npn \@@_backend_version_minor_gset:n #1
+  {
+    \cs_gset:Npx \@@_backend_version_minor: { \int_eval:n {#1} }
+    \__kernel_backend_literal:x { pdf:minorversion~ \@@_backend_version_minor: }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
+%   We start with the assumption that the default is active.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_version_major: { 1 }
+\cs_new:Npn \@@_backend_version_minor: { 5 }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Marked content}
+%
+% \begin{macro}{\@@_backend_bdc:nn}
+% \begin{macro}{\@@_backend_emc:}
+%   Simple wrappers. May need refinement: see
+%   \url{https://chat.stackexchange.com/transcript/message/49970158#49970158}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_bdc:nn #1#2
+  { \__kernel_backend_literal_page:n { /#1 ~ #2 ~ BDC } }
+\cs_new_protected:Npn \@@_backend_emc:
+  { \__kernel_backend_literal_page:n { EMC } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+%    \begin{macrocode}
+%</dvipdfmx|xdvipdfmx>
+%    \end{macrocode}
+%
+% \subsection{\texttt{dvisvgm} backend}
+%
+%    \begin{macrocode}
+%<*dvisvgm>
+%    \end{macrocode}
+%
+% \subsubsection{Catalogue entries}
+%
+% \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
+%   No-op.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2 { }
+\cs_new_protected:Npn \@@_backend_info_gput:nn #1#2 { }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection{Objects}
+%
+% \begin{macro}{\@@_backend_object_new:nn}
+% \begin{macro}[EXP]{\@@_backend_object_ref:n}
+% \begin{macro}{\@@_backend_object_write:nn, , \@@_backend_object_write:nx}
+% \begin{macro}{\@@_backend_object_now:nn, , \@@_backend_object_now:nx}
+% \begin{macro}{\@@_backend_object_last:}
+%   All no-ops here.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_object_new:nn #1#2 { }
+\cs_new:Npn \@@_backend_object_ref:n #1 { }
+\cs_new_protected:Npn \@@_backend_object_write:nn #1#2 { }
+\cs_new_protected:Npn \@@_backend_object_write:nx #1#2 { }
+\cs_new_protected:Npn \@@_backend_object_now:nn #1#2 { }
+\cs_new_protected:Npn \@@_backend_object_now:nx #1#2 { }
+\cs_new:Npn \@@_backend_object_last: { }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsubsection{Structure}
+%
+% \begin{macro}{\@@_backend_compresslevel:n}
+% \begin{macro}{\@@_backend_compress_objects:n}
+%   These are all no-ops.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_compresslevel:n #1 { }
+\cs_new_protected:Npn \@@_backend_compress_objects:n #1 { }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}
+%   {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
+%   Data not available!
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_version_major_gset:n #1 { }
+\cs_new_protected:Npn \@@_backend_version_minor_gset:n #1 { }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
+%   Data not available!
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_version_major: { -1 }
+\cs_new:Npn \@@_backend_version_minor: { -1 }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_backend_bdc:nn}
+% \begin{macro}{\@@_backend_emc:}
+%   More no-ops.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_bdc:nn #1#2 { }
+\cs_new_protected:Npn \@@_backend_emc: { }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+%    \begin{macrocode}
+%</dvisvgm>
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+%</initex|package>
+%    \end{macrocode}
+%
+% \end{implementation}
+%
+% \PrintIndex
-- 
cgit v1.2.3

