| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3backend-header.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2019-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3backend bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\documentclass[full,kernel]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% \title{^^A |
| 34 |
% The \pkg{l3backend-header} module\\ Backend graphics support^^A |
| 35 |
% } |
| 36 |
% |
| 37 |
% \author{^^A |
| 38 |
% The \LaTeX{} Project\thanks |
| 39 |
% {^^A |
| 40 |
% E-mail: |
| 41 |
% \href{mailto:[email protected]} |
| 42 |
% {[email protected]}^^A |
| 43 |
% }^^A |
| 44 |
% } |
| 45 |
% |
| 46 |
% \date{Released 2026-02-18} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \begin{documentation} |
| 51 |
% |
| 52 |
% \end{documentation} |
| 53 |
% |
| 54 |
% \begin{implementation} |
| 55 |
% |
| 56 |
% \section{\pkg{l3backend-header} implementation} |
| 57 |
% |
| 58 |
% \begin{macrocode} |
| 59 |
%<*dvips&header> |
| 60 |
% \end{macrocode} |
| 61 |
% |
| 62 |
% \begin{macro}[no-user-doc]{color.sc} |
| 63 |
% Empty definition for color at the top level. |
| 64 |
% \begin{macrocode} |
| 65 |
/color.sc { } def |
| 66 |
% \end{macrocode} |
| 67 |
% \end{macro} |
| 68 |
% |
| 69 |
% \begin{macro}[int]{TeXcolorseparation, separation} |
| 70 |
% Support for separation/spot colors: this strange naming is so |
| 71 |
% things work with the color stack. |
| 72 |
% \begin{macrocode} |
| 73 |
TeXDict begin |
| 74 |
/TeXcolorseparation { setcolor } def |
| 75 |
end |
| 76 |
% \end{macrocode} |
| 77 |
% \end{macro} |
| 78 |
% |
| 79 |
% \begin{macro}[int]{pdf.globaldict} |
| 80 |
% A small global dictionary for backend use. |
| 81 |
% \begin{macrocode} |
| 82 |
true setglobal |
| 83 |
/pdf.globaldict 4 dict def |
| 84 |
false setglobal |
| 85 |
% \end{macrocode} |
| 86 |
% \end{macro} |
| 87 |
% |
| 88 |
% \begin{macro}[int] |
| 89 |
% { |
| 90 |
% pdf.cvs , |
| 91 |
% pdf.dvi.pt , |
| 92 |
% pdf.pt.dvi , |
| 93 |
% pdf.rect.ht |
| 94 |
% } |
| 95 |
% Small utilities for PostScript manipulations. Conversion to DVI dimensions |
| 96 |
% is done here to allow for |Resolution|. The total height of a rectangle |
| 97 |
% (an array) needs a little maths, in contrast to simply extracting a value. |
| 98 |
% \begin{macrocode} |
| 99 |
/pdf.cvs { 65534 string cvs } def |
| 100 |
/pdf.dvi.pt { 72.27 mul Resolution div } def |
| 101 |
/pdf.pt.dvi { 72.27 div Resolution mul } def |
| 102 |
/pdf.rect.ht { dup 1 get neg exch 3 get add } def |
| 103 |
% \end{macrocode} |
| 104 |
% \end{macro} |
| 105 |
% |
| 106 |
% \begin{macro}[int]{pdf.linkmargin, pdf.linkdp.pad, pdf.linkht.pad} |
| 107 |
% Settings which are defined up-front in |SDict|. |
| 108 |
% \begin{macrocode} |
| 109 |
/pdf.linkmargin { 1 pdf.pt.dvi } def |
| 110 |
/pdf.linkdp.pad { 0 } def |
| 111 |
/pdf.linkht.pad { 0 } def |
| 112 |
% \end{macrocode} |
| 113 |
% \end{macro} |
| 114 |
% |
| 115 |
% \begin{macro}[int] |
| 116 |
% { |
| 117 |
% pdf.rect , |
| 118 |
% pdf.save.ll , |
| 119 |
% pdf.save.ur , |
| 120 |
% pdf.save.linkll , |
| 121 |
% pdf.save.linkur , |
| 122 |
% pdf.llx , |
| 123 |
% pdf.lly , |
| 124 |
% pdf.urx , |
| 125 |
% pdf.ury |
| 126 |
% } |
| 127 |
% Functions for marking the limits of an annotation/link, plus drawing the |
| 128 |
% border. We separate links for generic annotations to support adding a |
| 129 |
% margin and setting a minimal size. |
| 130 |
% \begin{macrocode} |
| 131 |
/pdf.rect |
| 132 |
{ /Rect [ pdf.llx pdf.lly pdf.urx pdf.ury ] } def |
| 133 |
/pdf.save.ll |
| 134 |
{ |
| 135 |
currentpoint |
| 136 |
/pdf.lly exch def |
| 137 |
/pdf.llx exch def |
| 138 |
} |
| 139 |
def |
| 140 |
/pdf.save.ur |
| 141 |
{ |
| 142 |
currentpoint |
| 143 |
/pdf.ury exch def |
| 144 |
/pdf.urx exch def |
| 145 |
} |
| 146 |
def |
| 147 |
/pdf.save.linkll |
| 148 |
{ |
| 149 |
currentpoint |
| 150 |
pdf.linkmargin add |
| 151 |
pdf.linkdp.pad add |
| 152 |
/pdf.lly exch def |
| 153 |
pdf.linkmargin sub |
| 154 |
/pdf.llx exch def |
| 155 |
} |
| 156 |
def |
| 157 |
/pdf.save.linkur |
| 158 |
{ |
| 159 |
currentpoint |
| 160 |
pdf.linkmargin sub |
| 161 |
pdf.linkht.pad sub |
| 162 |
/pdf.ury exch def |
| 163 |
pdf.linkmargin add |
| 164 |
/pdf.urx exch def |
| 165 |
} |
| 166 |
def |
| 167 |
% \end{macrocode} |
| 168 |
% \end{macro} |
| 169 |
% |
| 170 |
% \begin{macro}[int] |
| 171 |
% { |
| 172 |
% pdf.dest.anchor , |
| 173 |
% pdf.dest.x , |
| 174 |
% pdf.dest.y , |
| 175 |
% pdf.dest.point , |
| 176 |
% pdf.dest2device , |
| 177 |
% pdf.dev.x , |
| 178 |
% pdf.dev.y , |
| 179 |
% pdf.tmpa , |
| 180 |
% pdf.tmpb , |
| 181 |
% pdf.tmpc , |
| 182 |
% pdf.tmpd |
| 183 |
% } |
| 184 |
% For finding the anchor point of a destination link. We make the use case |
| 185 |
% a separate function as it comes up a lot, and as this makes it easier to |
| 186 |
% adjust if we need additional effects. We also need a more complex approach |
| 187 |
% to convert a coordinate pair correctly when defining a rectangle: this |
| 188 |
% can otherwise be out when using a landscape page. (Thanks to Alexander |
| 189 |
% Grahn for the approach here.) |
| 190 |
% \begin{macrocode} |
| 191 |
/pdf.dest.anchor |
| 192 |
{ |
| 193 |
currentpoint exch |
| 194 |
pdf.dvi.pt 72 add |
| 195 |
/pdf.dest.x exch def |
| 196 |
pdf.dvi.pt |
| 197 |
vsize 72 sub exch sub |
| 198 |
/pdf.dest.y exch def |
| 199 |
} |
| 200 |
def |
| 201 |
/pdf.dest.point |
| 202 |
{ pdf.dest.x pdf.dest.y } def |
| 203 |
/pdf.dest2device |
| 204 |
{ |
| 205 |
/pdf.dest.y exch def |
| 206 |
/pdf.dest.x exch def |
| 207 |
matrix currentmatrix |
| 208 |
matrix defaultmatrix |
| 209 |
matrix invertmatrix |
| 210 |
matrix concatmatrix |
| 211 |
cvx exec |
| 212 |
/pdf.dev.y exch def |
| 213 |
/pdf.dev.x exch def |
| 214 |
/pdf.tmpd exch def |
| 215 |
/pdf.tmpc exch def |
| 216 |
/pdf.tmpb exch def |
| 217 |
/pdf.tmpa exch def |
| 218 |
pdf.dest.x pdf.tmpa mul |
| 219 |
pdf.dest.y pdf.tmpc mul add |
| 220 |
pdf.dev.x add |
| 221 |
pdf.dest.x pdf.tmpb mul |
| 222 |
pdf.dest.y pdf.tmpd mul add |
| 223 |
pdf.dev.y add |
| 224 |
} |
| 225 |
def |
| 226 |
% \end{macrocode} |
| 227 |
% \end{macro} |
| 228 |
% |
| 229 |
% \begin{macro}[int] |
| 230 |
% { |
| 231 |
% pdf.bordertracking , |
| 232 |
% pdf.bordertracking.begin , |
| 233 |
% pdf.bordertracking.end , |
| 234 |
% pdf.leftboundary , |
| 235 |
% pdf.rightboundary , |
| 236 |
% pdf.brokenlink.rect , |
| 237 |
% pdf.brokenlink.skip , |
| 238 |
% pdf.brokenlink.dict , |
| 239 |
% pdf.bordertracking.endpage , |
| 240 |
% pdf.bordertracking.continue , |
| 241 |
% pdf.originx , |
| 242 |
% pdf.originy |
| 243 |
% } |
| 244 |
% To know where a breakable link can go, we need to track the boundary |
| 245 |
% rectangle. That can be done by hooking into |a| and |x| operations: |
| 246 |
% those names have to be retained. The boundary is stored at the end of |
| 247 |
% the operation. Special effort is needed at the start and end of pages |
| 248 |
% (or rather galleys), such that everything works properly. |
| 249 |
% \begin{macrocode} |
| 250 |
/pdf.bordertracking false def |
| 251 |
/pdf.bordertracking.begin |
| 252 |
{ |
| 253 |
SDict /pdf.bordertracking true put |
| 254 |
SDict /pdf.leftboundary undef |
| 255 |
SDict /pdf.rightboundary undef |
| 256 |
/a where |
| 257 |
{ |
| 258 |
/a |
| 259 |
{ |
| 260 |
currentpoint pop |
| 261 |
SDict /pdf.rightboundary known dup |
| 262 |
{ |
| 263 |
SDict /pdf.rightboundary get 2 index lt |
| 264 |
{ not } |
| 265 |
if |
| 266 |
} |
| 267 |
if |
| 268 |
{ pop } |
| 269 |
{ SDict exch /pdf.rightboundary exch put } |
| 270 |
ifelse |
| 271 |
moveto |
| 272 |
currentpoint pop |
| 273 |
SDict /pdf.leftboundary known dup |
| 274 |
{ |
| 275 |
SDict /pdf.leftboundary get 2 index gt |
| 276 |
{ not } |
| 277 |
if |
| 278 |
} |
| 279 |
if |
| 280 |
{ pop } |
| 281 |
{ SDict exch /pdf.leftboundary exch put } |
| 282 |
ifelse |
| 283 |
} |
| 284 |
put |
| 285 |
} |
| 286 |
if |
| 287 |
} |
| 288 |
def |
| 289 |
/pdf.bordertracking.end |
| 290 |
{ |
| 291 |
/a where { /a { moveto } put } if |
| 292 |
/x where { /x { 0 exch rmoveto } put } if |
| 293 |
SDict /pdf.leftboundary known |
| 294 |
{ pdf.outerbox 0 pdf.leftboundary put } |
| 295 |
if |
| 296 |
SDict /pdf.rightboundary known |
| 297 |
{ pdf.outerbox 2 pdf.rightboundary put } |
| 298 |
if |
| 299 |
SDict /pdf.bordertracking false put |
| 300 |
} |
| 301 |
def |
| 302 |
/pdf.bordertracking.endpage |
| 303 |
{ |
| 304 |
pdf.bordertracking |
| 305 |
{ |
| 306 |
pdf.bordertracking.end |
| 307 |
true setglobal |
| 308 |
pdf.globaldict |
| 309 |
/pdf.brokenlink.rect [ pdf.outerbox aload pop ] put |
| 310 |
pdf.globaldict |
| 311 |
/pdf.brokenlink.skip pdf.baselineskip put |
| 312 |
pdf.globaldict |
| 313 |
/pdf.brokenlink.dict |
| 314 |
pdf.link.dict pdf.cvs put |
| 315 |
false setglobal |
| 316 |
mark pdf.link.dict cvx exec /Rect |
| 317 |
[ |
| 318 |
pdf.llx |
| 319 |
pdf.lly |
| 320 |
pdf.outerbox 2 get pdf.linkmargin add |
| 321 |
currentpoint exch pop |
| 322 |
pdf.outerbox pdf.rect.ht sub pdf.linkmargin sub |
| 323 |
] |
| 324 |
/ANN pdf.pdfmark |
| 325 |
} |
| 326 |
if |
| 327 |
} |
| 328 |
def |
| 329 |
/pdf.bordertracking.continue |
| 330 |
{ |
| 331 |
/pdf.link.dict pdf.globaldict |
| 332 |
/pdf.brokenlink.dict get def |
| 333 |
/pdf.outerbox pdf.globaldict |
| 334 |
/pdf.brokenlink.rect get def |
| 335 |
/pdf.baselineskip pdf.globaldict |
| 336 |
/pdf.brokenlink.skip get def |
| 337 |
pdf.globaldict dup dup |
| 338 |
/pdf.brokenlink.dict undef |
| 339 |
/pdf.brokenlink.skip undef |
| 340 |
/pdf.brokenlink.rect undef |
| 341 |
currentpoint |
| 342 |
/pdf.originy exch def |
| 343 |
/pdf.originx exch def |
| 344 |
/a where |
| 345 |
{ |
| 346 |
/a |
| 347 |
{ |
| 348 |
moveto |
| 349 |
SDict |
| 350 |
begin |
| 351 |
currentpoint pdf.originy ne exch |
| 352 |
pdf.originx ne or |
| 353 |
{ |
| 354 |
pdf.save.linkll |
| 355 |
/pdf.lly |
| 356 |
pdf.lly pdf.outerbox 1 get sub def |
| 357 |
pdf.bordertracking.begin |
| 358 |
} |
| 359 |
if |
| 360 |
end |
| 361 |
} |
| 362 |
put |
| 363 |
} |
| 364 |
if |
| 365 |
/x where |
| 366 |
{ |
| 367 |
/x |
| 368 |
{ |
| 369 |
0 exch rmoveto |
| 370 |
SDict |
| 371 |
begin |
| 372 |
currentpoint |
| 373 |
pdf.originy ne exch pdf.originx ne or |
| 374 |
{ |
| 375 |
pdf.save.linkll |
| 376 |
/pdf.lly |
| 377 |
pdf.lly pdf.outerbox 1 get sub def |
| 378 |
pdf.bordertracking.begin |
| 379 |
} |
| 380 |
if |
| 381 |
end |
| 382 |
} |
| 383 |
put |
| 384 |
} |
| 385 |
if |
| 386 |
} |
| 387 |
def |
| 388 |
% \end{macrocode} |
| 389 |
% \end{macro} |
| 390 |
% |
| 391 |
% \begin{macro}[int] |
| 392 |
% { |
| 393 |
% pdf.breaklink , |
| 394 |
% pdf.breaklink.write , |
| 395 |
% pdf.count , |
| 396 |
% pdf.currentrect |
| 397 |
% } |
| 398 |
% Dealing with link breaking itself has multiple stage. The first step is to |
| 399 |
% find the |Rect| entry in the dictionary, looping over key--value pairs. |
| 400 |
% The first line is handled first, adjusting the rectangle to stay inside the |
| 401 |
% text area. The second phase is a loop over the height of the bulk of the |
| 402 |
% link area, done on the basis of a number of baselines. Finally, the end of |
| 403 |
% the link area is tidied up, again from the boundary of the text area. |
| 404 |
% \begin{macrocode} |
| 405 |
/pdf.breaklink |
| 406 |
{ |
| 407 |
pop |
| 408 |
counttomark 2 mod 0 eq |
| 409 |
{ |
| 410 |
counttomark /pdf.count exch def |
| 411 |
{ |
| 412 |
pdf.count 0 eq { exit } if |
| 413 |
counttomark 2 roll |
| 414 |
1 index /Rect eq |
| 415 |
{ |
| 416 |
dup 4 array copy |
| 417 |
dup dup |
| 418 |
1 get |
| 419 |
pdf.outerbox pdf.rect.ht |
| 420 |
pdf.linkmargin 2 mul add sub |
| 421 |
3 exch put |
| 422 |
dup |
| 423 |
pdf.outerbox 2 get |
| 424 |
pdf.linkmargin add |
| 425 |
2 exch put |
| 426 |
dup dup |
| 427 |
3 get |
| 428 |
pdf.outerbox pdf.rect.ht |
| 429 |
pdf.linkmargin 2 mul add add |
| 430 |
1 exch put |
| 431 |
/pdf.currentrect exch def |
| 432 |
pdf.breaklink.write |
| 433 |
{ |
| 434 |
pdf.currentrect |
| 435 |
dup |
| 436 |
pdf.outerbox 0 get |
| 437 |
pdf.linkmargin sub |
| 438 |
0 exch put |
| 439 |
dup |
| 440 |
pdf.outerbox 2 get |
| 441 |
pdf.linkmargin add |
| 442 |
2 exch put |
| 443 |
dup dup |
| 444 |
1 get |
| 445 |
pdf.baselineskip add |
| 446 |
1 exch put |
| 447 |
dup dup |
| 448 |
3 get |
| 449 |
pdf.baselineskip add |
| 450 |
3 exch put |
| 451 |
/pdf.currentrect exch def |
| 452 |
pdf.breaklink.write |
| 453 |
} |
| 454 |
1 index 3 get |
| 455 |
pdf.linkmargin 2 mul add |
| 456 |
pdf.outerbox pdf.rect.ht add |
| 457 |
2 index 1 get sub |
| 458 |
pdf.baselineskip div round cvi 1 sub |
| 459 |
exch |
| 460 |
repeat |
| 461 |
pdf.currentrect |
| 462 |
dup |
| 463 |
pdf.outerbox 0 get |
| 464 |
pdf.linkmargin sub |
| 465 |
0 exch put |
| 466 |
dup dup |
| 467 |
1 get |
| 468 |
pdf.baselineskip add |
| 469 |
1 exch put |
| 470 |
dup dup |
| 471 |
3 get |
| 472 |
pdf.baselineskip add |
| 473 |
3 exch put |
| 474 |
dup 2 index 2 get 2 exch put |
| 475 |
/pdf.currentrect exch def |
| 476 |
pdf.breaklink.write |
| 477 |
SDict /pdf.pdfmark.good false put |
| 478 |
exit |
| 479 |
} |
| 480 |
{ pdf.count 2 sub /pdf.count exch def } |
| 481 |
ifelse |
| 482 |
} |
| 483 |
loop |
| 484 |
} |
| 485 |
if |
| 486 |
/ANN |
| 487 |
} |
| 488 |
def |
| 489 |
/pdf.breaklink.write |
| 490 |
{ |
| 491 |
counttomark 1 sub |
| 492 |
index /_objdef eq |
| 493 |
{ |
| 494 |
counttomark -2 roll |
| 495 |
dup wcheck |
| 496 |
{ |
| 497 |
readonly |
| 498 |
counttomark 2 roll |
| 499 |
} |
| 500 |
{ pop pop } |
| 501 |
ifelse |
| 502 |
} |
| 503 |
if |
| 504 |
counttomark 1 add copy |
| 505 |
pop pdf.currentrect |
| 506 |
/ANN pdfmark |
| 507 |
} |
| 508 |
def |
| 509 |
% \end{macrocode} |
| 510 |
% \end{macro} |
| 511 |
% |
| 512 |
% \begin{macro}[int] |
| 513 |
% { |
| 514 |
% pdf.pdfmark , |
| 515 |
% pdf.pdfmark.good , |
| 516 |
% pdf.outerbox , |
| 517 |
% pdf.baselineskip , |
| 518 |
% pdf.pdfmark.dict |
| 519 |
% } |
| 520 |
% The business end of breaking links starts by hooking into |pdfmarks|. |
| 521 |
% Unlike \pkg{hypdvips}, we avoid altering any links we have not created |
| 522 |
% by using a copy of the core |pdfmarks| function. Only mark types which |
| 523 |
% are known are altered. At present, this is purely |ANN| marks, which are |
| 524 |
% measured relative to the size of the baseline skip. If they are |
| 525 |
% more than one apparent line high, breaking is applied. |
| 526 |
% \begin{macrocode} |
| 527 |
/pdf.pdfmark |
| 528 |
{ |
| 529 |
SDict /pdf.pdfmark.good true put |
| 530 |
dup /ANN eq |
| 531 |
{ |
| 532 |
pdf.pdfmark.store |
| 533 |
pdf.pdfmark.dict |
| 534 |
begin |
| 535 |
Subtype /Link eq |
| 536 |
currentdict /Rect known and |
| 537 |
SDict /pdf.outerbox known and |
| 538 |
SDict /pdf.baselineskip known and |
| 539 |
{ |
| 540 |
Rect 3 get |
| 541 |
pdf.linkmargin 2 mul add |
| 542 |
pdf.outerbox pdf.rect.ht add |
| 543 |
Rect 1 get sub |
| 544 |
pdf.baselineskip div round cvi 0 gt |
| 545 |
{ pdf.breaklink } |
| 546 |
if |
| 547 |
} |
| 548 |
if |
| 549 |
end |
| 550 |
SDict /pdf.outerbox undef |
| 551 |
SDict /pdf.baselineskip undef |
| 552 |
currentdict /pdf.pdfmark.dict undef |
| 553 |
} |
| 554 |
if |
| 555 |
pdf.pdfmark.good |
| 556 |
{ pdfmark } |
| 557 |
{ cleartomark } |
| 558 |
ifelse |
| 559 |
} |
| 560 |
def |
| 561 |
/pdf.pdfmark.store |
| 562 |
{ |
| 563 |
/pdf.pdfmark.dict 65534 dict def |
| 564 |
counttomark 1 add copy |
| 565 |
pop |
| 566 |
{ |
| 567 |
dup mark eq |
| 568 |
{ |
| 569 |
pop |
| 570 |
exit |
| 571 |
} |
| 572 |
{ |
| 573 |
pdf.pdfmark.dict |
| 574 |
begin def end |
| 575 |
} |
| 576 |
ifelse |
| 577 |
} |
| 578 |
loop |
| 579 |
} |
| 580 |
def |
| 581 |
% \end{macrocode} |
| 582 |
% \end{macro} |
| 583 |
% |
| 584 |
% \begin{macrocode} |
| 585 |
%</dvips&header> |
| 586 |
% \end{macrocode} |
| 587 |
% |
| 588 |
% \end{implementation} |
| 589 |
% |
| 590 |
% \PrintIndex |