Adapt contrib/pdfmark
[s-roff.git] / contrib / pdfmark / pdfmark.tmac
blob312baaa9f51619e6d40a74c709948d19337b8624
1 .ig
2 @ pdfmark.tmac
4 Copyright (c) 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
6 Copyright (C) 2004, 2005, 2006, 2007
7   Free Software Foundation, Inc.
8      Written by Keith Marshall (keith.d.marshall@ntlworld.com)
10 groff is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License along
21 with groff; see the file COPYING.  If not, write to the Free Software
22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
24 Author's Note
25 =============
27 While I have written this macro package from scratch, much of my
28 inspiration has come from discussion on the groff mailing list
29 (mailto:groff@gnu.org).  I am particularly indebted to:
31    Kees Zeelenberg, for an earlier macro package he posted,
32    a study of which helped me to get started.
34    Carlos J. G. Duarte and Werner Lemberg, whose discussion
35    on computation of the bounding boxes for link "hot-spots"
36    forms the basis of such computations in this package.
38 .if !\n(.g .ab These pdfmark macros require groff.
39 .\"
40 .\" Check if we have already been loaded -- do not reload
41 .if d pdfmark .nx
42 .\"
43 .\" ======================================================================
44 .\" Module PDFMARK: Insert Arbitrary PDFMARK Code in the Postscript Stream
45 .\" ======================================================================
46 .\"
47 .\" PDFMARK output may be disabled, by zeroing the PDFOPMODE register,
48 .\" ( which mimics a more generic OPMODE, if it is defined ).
49 .\"
50 .if rOPMODE .aln PDFOPMODE OPMODE
51 .\"
52 .\" but if OPMODE wasn't defined,
53 .\" then make the default PDFMARK mode ENABLED.
54 .\"
55 .if !rPDFOPMODE .nr PDFOPMODE 1
56 .\"
57 .\" PDFMARK output must be constrained to a maximum line length limit,
58 .\" for strict compliance with the Postscript DSC.  This limit is defined
59 .\" in register "PDFMARK.FOLDWIDTH.MAX".  This is user definable, up to a
60 .\" ceiling value of 255, which is also its default value;  this limit
61 .\" is enforced for each PDFMARK, by macro "pdf*pdfmark.limit".
62 .\"
63 .de pdf*pdfmark.limit
64 .\" ----------------------------------------------------------------
65 .\" Usage:
66 .\"   .pdf*pdfmark.limit  REGISTER-NAME  DEFAULT-MAXIMUM-VALUE
67 .\" ----------------------------------------------------------------
68 .\"
69 .\" If a register named REGISTER-NAME has not been defined, then
70 .\" define it now, with default value = DEFAULT-MAXIMUM-VALUE.
71 .\"
72 .if !r\\$1 .nr \\$1 \\$2
73 .\"
74 .\" But when it has already been defined, ensure that its value does
75 .\" not exceed DEFAULT-MAXIMUM-VALUE; if value does exceed this ceiling,
76 .\" then redefine it, to enforce the limit.
77 .\"
78 .if (\\n[\\$1] > \\$2) .nr \\$1 \\$2
80 .\" The "pdfmark" macro is responsible for emitting the appropriate
81 .\" Postscript code.
82 .\"
83 .de pdfmark
84 .\" ----------------------------------------------------------------
85 .\" Usage:
86 .\"   .pdfmark  text of pdfmark instruction
87 .\" Macro supplies the required opening "[" and closing "pdfmark"
88 .\" operator; DO NOT include them in the instruction text!
89 .\" ----------------------------------------------------------------
90 .\"
91 .if \\n[PDFOPMODE] \{\
92 .\"
93 .\" Strict DSC compliance forbids emission of ps:exec lines which
94 .\" exceed 255 characters in length.  We will allow the user to specify
95 .\" an alternative lesser limit ...
96 .\"
97 .   pdf*pdfmark.limit PDFMARK.FOLDWIDTH.MAX 255
98 .\"
99 .\" ... and we will also support a second lesser limit, which will be
100 .\" applied to literal text parenthetically embedded within the PDFMARK.
102 .   pdf*pdfmark.limit PDFMARK.FOLDWIDTH \\n[PDFMARK.FOLDWIDTH.MAX]
104 .\" We will push out the entire PDFMARK in one chunk, provided it fits
105 .\" within this limit.
107 .   length pdf:length "[\\$* pdfmark\"
108 .   ie !(\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH]) \{\
109 .   \"
110 .   \" This PDFMARK is suitable for single chunk output ...
111 .   \"
112 .      nop \X'ps:exec [\\$* pdfmark'\c
113 .      \}
114 .   el \{\
115 .   \" ... but, when the limit would be violated, then we must
116 .   \" recompose the specified PDFMARK, spreading it over as many
117 .   \" continuation lines as are necessary.
118 .   \"
119 .      als pdf*compose pdf*compose.first
120 .      while \\n(.$ \{\
121 .         pdf*compose \\$1
122 .         shift
123 .         \}
124 .   \"
125 .   \" Complete the PDFMARK recomposition, by appending a
126 .   \" "pdfmark" operator, and push it out to the intermediate
127 .   \" output stream, (excluding its final line break).
128 .   \"
129 .      pdf*compose pdfmark
130 .      pdf*pdfmark.dispatch
131 .      chop pdf:composed
132 .      nop \Y[pdf:composed]\c
133 .   \"
134 .   \" And clean up when done.
135 .   \"
136 .      rm pdf*compose pdf*pdfmark.post
137 .      rm pdf:compose.test pdf:composed pdf:composed.literal
138 .      \}
139 .   rr pdf:length
140 .   \}
142 .\" When a PDFMARK exceeds the specified output record length limit,
143 .\" then we decompose it, subsequently using the dynamically overloaded
144 .\" macro, "pdf*compose", to reassemble it into as many continuation
145 .\" records as it may require.
147 .\" Each call to "pdf*compose" uses macro "pdf*length.increment" to
148 .\" keep track of the current output record length, so ensuring that
149 .\" the active maximum length limit is not violated.
151 .de pdf*length.increment
152 .\" ----------------------------------------------------------------
153 .\" Usage:
154 .\"   .pdf*length.increment  NEXT-ADDITION
155 .\" ----------------------------------------------------------------
157 .ie d pdf:composed.line \
158 .   length pdf:length "\\*[pdf:composed.line] \\$*\"
159 .el .length pdf:length "\\$*\"
161 .\" The first call to "pdf*compose" for each PDFMARK is directed
162 .\" to "pdf*compose.first";  this initialises the local strings
163 .\" and macros used to compose the eventual PDFMARK output.
165 .de pdf*compose.first
166 .\" ----------------------------------------------------------------
167 .\" Usage:
168 .\"   .als  pdf*compose  pdf*compose.first
169 .\"   .     pdf*compose  TOKEN
170 .\" ----------------------------------------------------------------
172 .\" Ensure that the output record accumulator will be initialised
173 .\" on posting of the first composed PDFMARK record.
175 .als pdf*pdfmark.post pdf*pdfmark.post.first
177 .\" The first token passed to "pdf*compose" should not be a
178 .\" literal, but be prepared to handle one, just in case.
180 .ds pdf:compose.test \\$1
181 .substring pdf:compose.test 0 0
182 .ie '('\\*[pdf:compose.test]' \{\
184 .\" We found a literal, even though we didn't expect it;
185 .\" if it's a single element literal, we can just handle it
186 .\" as if it is a regular token anyway.
188 .   ds pdf:compose.test "\\$\\n(.$\"
189 .   substring pdf:compose.test -1
190 .   if !')'\\*[pdf:compose.test]' \{\
191 .   \"
192 .   \" But when it is the first of a literal sequence,
193 .   \" then we need to set up "pdf*compose" to handle it.
194 .   \"
195 .      ds pdf:composed.literal "[\\$*\"
196 .      als pdf*compose pdf*compose.literal
197 .      \}
198 .   \}
199 .el .ds pdf:compose.test )
200 .if ')'\\*[pdf:compose.test]' \{\
202 .\" In the normal case, we start each new PDFMARK with a
203 .\" regular token; save it as the first in the composed output
204 .\" line sequence, and set up "pdf*compose" to collect
205 .\" the rest of the sequence.
207 .   ds pdf:composed.line "[\\$*\"
208 .   als pdf*compose pdf*compose.next
209 .   \}
211 .\" Subsequent calls to "pdf*compose", while collecting
212 .\" regular tokens, are then directed to "pdf*compose.next".
214 .de pdf*compose.next
215 .\" ----------------------------------------------------------------
216 .\" Usage:
217 .\"   .als  pdf*compose  pdf*compose.next
218 .\"   .     pdf*compose  TOKEN
219 .\" ----------------------------------------------------------------
221 .\" This first checks to ensure that the supplied token really is
222 .\" a regular token, and not the first element in a literal.
224 .ds pdf:compose.test \\$1
225 .substring pdf:compose.test 0 0
226 .ie '('\\*[pdf:compose.test]' \{\
228 .\" The supplied token represents the first element of a literal,
229 .\" but it may be a single element literal, which we simply handle
230 .\" as a regular token anyway.
232 .   ds pdf:compose.test "\\$\\n(.$\"
233 .   substring pdf:compose.test -1
234 .   if !')'\\*[pdf:compose.test]' \{\
235 .   \"
236 .   \" The supplied token is the first of a sequence of elements
237 .   \" which collectively define a literal, so start collecting a
238 .   \" composite literal token, and change the "pdf*compose"
239 .   \" state, to collect and append the remaining elements.
240 .   \"
241 .      ds pdf:composed.literal "\\$*\"
242 .      als pdf*compose pdf*compose.literal
243 .      \}
244 .   \}
245 .el .ds pdf:compose.test )
246 .if ')'\\*[pdf:compose.test]' \{\
248 .\" The supplied token IS a regular token; add it, but ensure that
249 .\" the active maximum record length limit is honoured.
251 .   pdf*length.increment "\\$*\"
252 .   ie (\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH.MAX]) \{\
253 .   \"
254 .   \" Adding this token would cause the current PDFMARK record, in
255 .   \" groff's intermediate output file, to overflow the active record
256 .   \" length limit, so post the current record and start another.
257 .   \"
258 .      pdf*pdfmark.dispatch
259 .      ds pdf:composed.line "\\$*\"
260 .      \}
261 .   el \{\
262 .   \"
263 .   \" This token will fit in the current PDFMARK record, without
264 .   \" violating the active length limit, so simply add it.
265 .   \"
266 .      ie d pdf:composed.line .as pdf:composed.line " \\$*\"
267 .      el .ds pdf:composed.line "\\$*\"
268 .      \}
269 .   \}
271 .\" While assembling a multiple token literal sequence into a single
272 .\" literal token, successive calls to "pdf*compose" are directed
273 .\" to "pdf*compose.literal".
275 .de pdf*compose.literal
276 .\" ----------------------------------------------------------------
277 .\" Usage:
278 .\"   .als  pdf*compose  pdf*compose.literal
279 .\"   .     pdf*compose  TOKEN
280 .\" ----------------------------------------------------------------
282 .\" First, check to ensure that the current token can be appended to
283 .\" the accumulated literal, without extending it beyond the maximum
284 .\" allowed literal token length.
286 .length pdf:length "\\*[pdf:composed.literal] \\$*\"
287 .ie (\\n[pdf:length] > (\\n[PDFMARK.FOLDWIDTH] - 2)) \{\
289 .\" If it has grown too long, then it must be folded across two
290 .\" physical PDFMARK output records, so check if we can accommodate
291 .\" the portion collected so far within the current output record.
293 .   pdf*length.increment "\\*[pdf:composed.literal]\"
294 .   if (\\n[pdf:length] > (\\n[PDFMARK.FOLDWIDTH.MAX] - 2)) \{\
295 .   \"
296 .   \" The current output record CAN'T accommodate the currently
297 .   \" composed portion of the literal, so flush out the current
298 .   \" record, to make way for the accumulated literal, and mark
299 .   \" the dispatch mode as "wrapped", for the fragments of the
300 .   \" folded literal string, which are to follow.
301 .   \"
302 .      pdf*pdfmark.dispatch
303 .      ds pdf*pdfmark.dispatch.wrapped
304 .      \}
305 .   ie d pdf:composed.line \{\
306 .   \"
307 .   \" If we DIDN'T need to flush the current output record,
308 .   \" then we can simply append the accumulated literal to it...
309 .   \"
310 .      as pdf:composed.line " \\*[pdf:composed.literal]\"
311 .      \}
312 .   el \{\
313 .   \"
314 .   \" otherwise, when the current record has been flushed, or is
315 .   \" empty, then we promote the accumulated literal, to make it
316 .   \" the next output record...
317 .   \"
318 .      rn pdf:composed.literal pdf:composed.line
319 .      \}
321 .\" Now, to complete the fold, flush out any accumulated partial
322 .\" output record, and continue accumulating the literal, starting
323 .\" with the current token.
325 .   pdf*pdfmark.dispatch
326 .   ds pdf:composed.literal "\\$*\"
327 .   \}
328 .el \{\
330 .\" Alternatively, when we HAVEN'T identified a need to fold the
331 .\" current output record, then we simply append the current token
332 .\" to the accumulated literal token buffer string.
334 .   as pdf:composed.literal " \\$*\"
335 .   \}
337 .\" Having ensured that we have sufficient space, in which to
338 .\" append the current token to the currently accumulated literal,
339 .\" we check its rightmost character, to see if is the closing
340 .\" parenthesis, which completes the literal.
342 .ds pdf:compose.test \\$\\n(.$
343 .substring pdf:compose.test -1
344 .if ')'\\*[pdf:compose.test]' \{\
346 .\" The literal has been completely collected, so we may now append
347 .\" it to the current output record, as a single literal token, but
348 .\" subject to the constraint that it must not extend the output
349 .\" record beyond the maximum permitted length.
351 .   pdf*length.increment "\\*[pdf:composed.literal]\"
352 .   ie (\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH.MAX]) \{\
353 .   \"
354 .   \" So, when the literal cannot be accommodated within the maximum
355 .   \" length constraint, then we flush the current record, and start
356 .   \" a new one, with the literal token as its first entry.
357 .   \"
358 .      pdf*pdfmark.dispatch
359 .      rn pdf:composed.literal pdf:composed.line
360 .      \}
361 .   el \{\
362 .   \"
363 .   \" When the literal CAN be accommodated within the maximum length
364 .   \" constraint, then ...
365 .   \"
366 .      ie d pdf:composed.line \{\
367 .      \"
368 .      \" When an output record has already been instantiated, we
369 .      \" append the literal token to it, and discard the accumulator
370 .      \" string, which is no longer required.
371 .      \"
372 .         as pdf:composed.line " \\*[pdf:composed.literal]\"
373 .         rm pdf:composed.literal
374 .         \}
375 .      el \{\
376 .      \"
377 .      \" But when no output record yet exists, then we simply
378 .      \" reassign the accumulated literal token, to instantiate a
379 .      \" new output record.
380 .      \"
381 .         rn pdf:composed.literal pdf:composed.line
382 .         \}
383 .      \}
385 .\" Finally, since we have completed the accumulation of the literal, we
386 .\" revert to the "unwrapped" mode of operation for "pdf*pdfmark.dispatch",
387 .\" and restore the normal "pdf*compose" action, for collection of the next
388 .\" token (if any).
390 .   rm pdf*pdfmark.dispatch.wrapped
391 .   als pdf*compose pdf*compose.next
392 .   \}
394 .\" While composing a multiple record PDFMARK, each composed record
395 .\" must be added to the collection, whenever the partially composed
396 .\" output record has been filled;  this is handled when necessary,
397 .\" by calling the "pdf*pdfmark.dispatch" macro.
399 .de pdf*pdfmark.dispatch
400 .\" ----------------------------------------------------------------
401 .\" Usage:
402 .\"   .pdf*pdfmark.dispatch
403 .\" ----------------------------------------------------------------
405 .if d pdf:composed.line \{\
407 .\" This is simply a wrapper around the overloaded "pdf*pdfmark.post"
408 .\" macro, ensuring that an output record has actually been collected
409 .\" before attempting to post it; it then cleans up after posting, to
410 .\" ensure that each collected record is posted only once.
412 .   if d pdf*pdfmark.dispatch.wrapped \{\
413 .   \"
414 .   \" When dispatching an excessively long literal string, which
415 .   \" must be wrapped over multiple records, this mode is active
416 .   \" for all but the closing record; we must escape the newline
417 .   \" at the end of each such unclosed literal record.
418 .   \"
419 .      as pdf:composed.line " \\\\\\\\\"
420 .      \}
421 .   pdf*pdfmark.post
422 .   rm pdf:composed.line
423 .   \}
425 .\" For each PDFMARK, the first call of "pdf*pdfmark.post" is directed
426 .\" to the "pdf*pdfmark.post.first" macro;  this initialises the state
427 .\" of the "pdf:composed" macro, for assembly of a new PDFMARK.
429 .de pdf*pdfmark.post.first
430 .de pdf:composed pdf*end
431 ps:exec \\*[pdf:composed.line]
432 .pdf*end
434 .\" Subsequent calls to "pdf*pdfmark.post" are redirected to the
435 .\" alternative "pdf*pdfmark.post.next" macro, which simply appends
436 .\" additional PDFMARK records to the "pdf:composed" macro.
438 .als pdf*pdfmark.post pdf*pdfmark.post.next
440 .de pdf*pdfmark.post.next
441 .am pdf:composed pdf*end
442 \\*[pdf:composed.line]
443 .pdf*end
445 .\" "pdf*end" is a dummy macro.  It is required to mark the end
446 .\" of each individual fragment which is added to "pdf:composed";
447 .\" other than this, it does nothing.
449 .de pdf*end
452 .\" Some supporting macros defer actual pdfmark output until an
453 .\" appropriate time for it to be written; the "pdfsync" macro
454 .\" provides a mechanism for flushing such deferred output;
455 .\" it should be called from an end macro, and at any other time
456 .\" when it may be deemed necessary to flush pdfmark context.
458 .de pdfsync
459 .\" ----------------------------------------------------------------
460 .\" Usage:
461 .\"   .pdfsync buffer ...
462 .\" Arguments indicate which "buffer(s)" to flush:
463 .\"   O -> bookmark (outline) cache
464 .\"   M -> document metadata diversion
465 .\" If no argument, flush ALL buffers
466 .\" ----------------------------------------------------------------
468 .ie \\n(.$ \{\
469 .   while \\n(.$ \{\
470 .      if '\\$1'O' .pdf:bm.sync 1
471 .      if '\\$1'M' \{\
472 .         if dpdf:metadata .pdf:metadata
473 .         rm pdf:metadata
474 .         \}
475 .      shift
476 .      \}
477 .   \}
478 .el .pdfsync O M
481 .\" some helper functions ...
483 .\" "pdf:warn" and "pdf:error" write diagnostic messages to stderr
485 .de pdf:warn
486 .\" ----------------------------------------------------------
487 .\" Usage:
488 .\"   .pdf:warn text of message
489 .\" ----------------------------------------------------------
491 .tm \\n(.F:\\n(.c: macro warning: \\$*
493 .de pdf:error
494 .\" ----------------------------------------------------------
495 .\" Usage:
496 .\"   .pdf:error text of message
497 .\" ----------------------------------------------------------
499 .tm \\n(.F:\\n(.c: macro error: \\$*
501 .\" "pdf:pop", assisted by "pdf*pop", allows us to retrieve register,
502 .\" or string values, from a string masquerading as a data queue,
503 .\" or as a stack.
505 .de pdf:pop
506 .\" ----------------------------------------------------------------
507 .\" Usage:
508 .\"   .pdf:pop <type> <to-name> <from-name>
509 .\"   $1 = nr for numeric register, ds for string
510 .\"   $2 = name of register or string to be assigned
511 .\"   $3 = name of string, from which data is to be retrieved
512 .\" ----------------------------------------------------------------
514 .pdf*pop \\$* \\*[\\$3]
516 .de pdf*pop
517 .ds pdf:stack \\$3
518 .\\$1 \\$2 \\$4
519 .shift 4
520 .ie \\n(.$ .ds \\*[pdf:stack] \\$*
521 .el .rm \\*[pdf:stack]
522 .rm pdf:stack
526 .\" ===========================================================
527 .\" Module PDFINFO: Insert MetaData Entries into a PDF Document
528 .\" ===========================================================
530 .\" N.B.
531 .\"   Output from the macros in this module is deferred, until
532 .\"   subsequent invocation of .pdfsync, or .pdfexit
534 .\" ."pdfinfo" provides a general purpose form of metadata entry ...
535 .\" it allows arbitrary text to be associated with any specified
536 .\" metadata field name.
538 .de pdfinfo
539 .\" -------------------------------------------------------------------
540 .\" Usage:
541 .\"   .pdfinfo /FieldName field content ...
542 .\" Examples:
543 .\"   .pdfinfo /Title   A PDF Document
544 .\"   .pdfinfo /Author  Keith Marshall
545 .\" -------------------------------------------------------------------
547 .ds pdf:meta.field \\$1
548 .shift
549 .da pdf:metadata
550 \!.pdfmark \\*[pdf:meta.field] (\\$*) /DOCINFO
552 .rm pdf:meta.field
555 .\" Macro "pdfview" defines a special form of metadata entry ...
556 .\" it uses the /DOCVIEW pdfmark, to specify the initial (default) view,
557 .\" when the document is opened.
559 .de pdfview
560 .\" -------------------------------------------------------------------
561 .\" Usage:
562 .\"   .pdfview view parameters ...
563 .\" Examples:
564 .\"   .pdfview /PageMode /UseOutlines
565 .\"   .pdfview /Page 2 /View [/FitH \n(.p u]
566 .\" -------------------------------------------------------------------
568 .da pdf:metadata
569 \!.pdfmark \\$* /DOCVIEW
574 .\" =====================================================================
575 .\" Module PDFNOTE: Insert "Sticky Note" Style Comments in a PDF Document
576 .\" =====================================================================
578 .\" "PDFNOTE.WIDTH" and "PDFNOTE.HEIGHT" set the preferred size for
579 .\" display of the "sticky note" pane, when opened.  Acrobat Reader
580 .\" seems not to honour these -- perhaps GhostScript doesn't encode
581 .\" them correctly!  Anyway, let's set some suitable default values,
582 .\" in case the user has a set up which does work as advertised.
584 .nr PDFNOTE.WIDTH  3.5i
585 .nr PDFNOTE.HEIGHT 2.0i
587 .\" "pdf:bbox" defines the expression used to set the size and location
588 .\" of the bounding rectangle for display of notes and link "hot-spots".
589 .\" This is defined, such that a note is placed at troff's current text
590 .\" position on the current page, with its displayed image size defined
591 .\" by the "PDFNOTE.WIDTH" and "PDFNOTE.HEIGHT" registers, while the
592 .\" bounds for a link "hot-spot" are matched to the text region which
593 .\" defines the "hot-spot".
595 .ds pdf:bbox \\n[pdf:llx] u \\n[pdf:lly] u \\n[pdf:urx] u \\n[pdf:ury] u
597 .\" Getting line breaks into the text of a PDFNOTE is tricky -- we need
598 .\" to get a "\n" into the Postscript stream, but three levels of "\" are
599 .\" swallowed, when we invoke "pdfnote".  The following definition of "PDFLB",
600 .\" (for LineBreak), is rather ugly, but does allow us to use
602 .\"    .pdfnote  Some text.\*[PDFLB]Some more text, on a new line.
604 .ds PDFLB \\\\\\\\\\\\\\\\n
606 .de pdfnote
607 .\" ----------------------------------------------------------------------
608 .\" Usage:
609 .\"   .pdfnote [-T "Text for Title"] Text of note ...
610 .\" ----------------------------------------------------------------------
612 .if \\n[PDFOPMODE] \{\
614 .\" First, compute the bounding rectangle,
615 .\" for this PDFNOTE instance
617 .   mk pdf:ury
618 .   nr pdf:llx \\n(.k+\\n(.o+\\n[.in]
619 .   nr pdf:lly \\n[pdf:ury]-\\n[PDFNOTE.HEIGHT]
620 .   nr pdf:urx \\n[pdf:llx]+\\n[PDFNOTE.WIDTH]
621 .   ds pdf:note.instance /Rect [\\*[pdf:bbox]]
623 .\" Parse any specified (recognisable) PDFNOTE options
625 .   while dpdf:note\\$1 \{\
626 .      pdf:note\\$1 \\$@
627 .      shift \\n[pdf:note.argc]
628 .      \}
630 .\" Emit the note, and clean up
632 .   pdfmark \\*[pdf:note.instance] /Contents (\\$*) /ANN
633 .   rm pdf:note.instance
634 .   rr pdf:note.argc
635 .   \}
637 .de pdf:note-T
638 .nr pdf:note.argc 2
639 .as pdf:note.instance " /Title (\\$2)
643 .\" =====================================================================
644 .\" Module PDFBOOKMARK: Add an Outline Reference in the PDF Bookmark Pane
645 .\" =====================================================================
647 .\" "PDFBOOKMARK.VIEW" controls how the document will be displayed,
648 .\" when the user selects a bookmark.  This default setting will fit
649 .\" the page width to the viewing window, with the bookmarked entry
650 .\" located at the top of the viewable area.
652 .ds PDFBOOKMARK.VIEW /FitH \\n[PDFPAGE.Y] u
654 .\" "PDFOUTLINE.FOLDLEVEL" controls how the document outline will be
655 .\" displayed.  It is a number, defining the maximum heading level
656 .\" which will be visible, without outline expansion by the user, in
657 .\" the initial view of the document outline.  Assuming that no sane
658 .\" document will ever extend to 10,000 levels of nested headings,
659 .\" this initial default value causes outlines to be fully expanded.
661 .nr PDFOUTLINE.FOLDLEVEL 10000
663 .\" The actual job of creating an outline reference
664 .\" is performed by the "pdfbookmark" macro.
666 .de pdfbookmark
667 .\" ------------------------------------------------------------------
668 .\" Usage:
669 .\"   .pdfbookmark [-T tag] level "Text of Outline Entry"
671 .\"   $1 = nesting level for bookmark (1 is top level)
672 .\"   $2 = text for bookmark, (in PDF viewer bookmarks list)
673 .\"   $3 = suffix for PDF internal bookmark name (optional)
674 .\" ------------------------------------------------------------------
676 .ie '\\n(.z'' \{\
678 .\" When we are at the top diversion level, i.e. actually emitting text
679 .\" to the output device stream, then we compute the location of, and
680 .\" plant this bookmark immediately.
682 .   if \\n[PDFOPMODE] \{\
683 .   \"
684 .   \" Make the bookmark name "untagged" by default,
685 .   \" then parse any specified options, to set a "tag", if required
686 .   \"
687 .      ds pdf:href-T
688 .      while dpdf:href.opt\\$1 \{\
689 .         pdf:href.opt\\$1 \\$@
690 .         shift \\n[pdf:href.argc]
691 .         \}
692 .      rr pdf:href.argc
693 .   \"
694 .   \" If we found "--" to mark the end of the options, discard it
695 .   \"
696 .      if '\\$1'--' .shift
697 .   \"
698 .   \" Synchronise the bookmark cache
699 .   \" to the requested bookmark nesting level
700 .   \"
701 .      pdf:bm.sync \\$1
702 .      shift
703 .   \"
704 .   \" Increment the bookmark serialisation index
705 .   \" in order to generate a uniquely serialised bookmark name,
706 .   \" ( which we return in the string "PDFBOOKMARK.NAME" ),
707 .   \" and insert this bookmark into the cache
708 .   \"
709 .      pdf:href.sety
710 .      nr pdf:bm.nr +1
711 .      ds PDFBOOKMARK.NAME pdf:bm\\n[pdf:bm.nr]\\*[pdf:href-T]
712 .      ds pdf:bm\\n[pdf:bm.nr] /Dest /\\*[PDFBOOKMARK.NAME]
713 .      pdfmark \\*[pdf:bm\\n[pdf:bm.nr]] /View [\\*[PDFBOOKMARK.VIEW]] /DEST
714 .      as pdf:bm\\n[pdf:bm.nr] " /Title (\\$*)
715 .      pdf:href.options.clear
716 .      rr PDFPAGE.Y
717 .      \}
718 .   \}
719 .el \{\
721 .\" But when we are collecting a diversion which will be written out later,
722 .\" then we must defer bookmark placement, until we emit the diversion.
723 .\" (don't rely on $0 == pdfbookmark here; it may be a volatile alias).
725 .   nop \!.pdfbookmark \\$@
726 .   \}
729 .\" Macro "pdf:bm.sync" is called for each bookmark created,
730 .\" to establish a cache entry at the appropriate nesting level.
731 .\" It will flush ALL previous cache content, when called to
732 .\" add a new bookmark at level 1, or if simply called at
733 .\" level 1, without adding any bookmark.
735 .de pdf:bm.sync
736 .\" ------------------------------------------------------------------
737 .\" Usage:
738 .\"   .pdf:bm.sync  level
739 .\"   $1 = nesting level of current bookmark, or 1 to flush cache
740 .\" ------------------------------------------------------------------
742 .\" First validate the bookmark nesting level
743 .\" adjusting it if required
745 .if \\$1>\\n[pdf:bm.nl] .nr pdf:bm.nl +1
746 .ie \\$1>\\n[pdf:bm.nl] \{\
747 .   pdf:warn adjusted level \\$1 bookmark; should be <= \\n[pdf:bm.nl]
748 .   \}
749 .el .nr pdf:bm.nl \\$1
750 .if \\n[pdf:bm.nl]<1 \{\
751 .   pdf:warn bad arg (\\$1) in \\$0 \\$1; \\$0 1 forced
752 .   nr pdf:bm.nl 1
753 .   \}
755 .\" If reverting from a higher to a lower nesting level,
756 .\" cyclicly adjust cache counts for each pending higher level
758 .if \\n[pdf:bm.lc]>=\\n[pdf:bm.nl] \{\
759 .   nr pdf:bm.lc +1
760 .   if !rpdf:bm.c\\n[pdf:bm.lc].c .nr pdf:bm.c\\n[pdf:bm.lc].c 0
761 .   while \\n[pdf:bm.lc]>\\n[pdf:bm.nl] \{\
762 .      as pdf:bm.c\\n[pdf:bm.lc] " \\n[pdf:bm.c\\n[pdf:bm.lc].c]
763 .      rr pdf:bm.c\\n[pdf:bm.lc].c
764 .      nr pdf:bm.lc -1
765 .      \}
766 .   \}
768 .\" Update the cache level,
769 .\" flushing when we are at level 1
771 .nr pdf:bm.lc \\n[pdf:bm.nl]
772 .ie \\n[pdf:bm.nl]=1 \{\
773 .   while \\n[pdf:bm.ic]<\\n[pdf:bm.nr] .pdf:bm.emit 0
774 .   rr pdf:bm.rc
775 .   \}
776 .el .nr pdf:bm.c\\n[pdf:bm.nl].c +1
778 .\" Macro "pdf:bm.emit" is called, when the cache is at level 1.
779 .\" This flushes ALL pending bookmarks from the cache, i.e. the
780 .\" preceding level 1 bookmark, and any nested dependents,
781 .\" which it may have.
783 .de pdf:bm.emit
784 .\" ------------------------------------------------------------------
785 .\" Usage:
786 .\"   .pdf:bm.emit  flag
787 .\"   $1 = reference counting flag, used to control recursion
788 .\" ------------------------------------------------------------------
790 .\" First check for nested dependents,
791 .\" and append the "dependent count" to the bookmark, as required.
793 .nr pdf:bm.ic +1
794 .nr pdf:bm.lc +1
795 .pdf:pop nr pdf:bm.rc pdf:bm.c\\n[pdf:bm.lc]
796 .if \\n[pdf:bm.rc] \{\
797 .   ds pdf:bm.fold
798 .   if \\n[pdf:bm.lc]>\\n[PDFOUTLINE.FOLDLEVEL] .ds pdf:bm.fold -
799 .   as pdf:bm\\n[pdf:bm.ic] " /Count \\*[pdf:bm.fold]\\n[pdf:bm.rc]
800 .   rm pdf:bm.fold
801 .   \}
802 .pdfmark \\*[pdf:bm\\n[pdf:bm.ic]] /OUT
803 .rm pdf:bm\\n[pdf:bm.ic]
805 .\" For ALL dependents, if any,
806 .\" recursively flush out any higher level dependents,
807 .\" which they themselves may have
809 .while \\n[pdf:bm.rc] \{\
810 .   nr pdf:bm.rc -1
811 .   pdf:bm.emit \\n[pdf:bm.rc]
812 .   \}
814 .\" Finally,
815 .\" unwind the recursive call stack, until we return to the top level.
817 .nr pdf:bm.rc \\$1
818 .nr pdf:bm.lc -1
820 .nr pdf:bm.nr 0
821 .nr pdf:bm.nl 1
822 .nr pdf:bm.lc 0
823 .nr pdf:bm.ic 0
826 .\" =============================================================
827 .\" Module PDFHREF: Create Hypertext References in a PDF Document
828 .\" =============================================================
830 .\" "PDFHREF.VIEW" controls how the document will be displayed,
831 .\" when the user follows a link to a named reference.
833 .ds PDFHREF.VIEW     /FitH \\n[PDFPAGE.Y] u
835 .\" This default setting will fit the page width to the viewing
836 .\" window, with the bookmarked entry located close to the top
837 .\" of the viewable area.  "PDFHREF.VIEW.LEADING" controls the
838 .\" actual distance below the top of the viewing window, where
839 .\" the reference will be positioned; 5 points is a reasonable
840 .\" default offset.
842 .nr PDFHREF.VIEW.LEADING  5.0p
844 .\" Yuk!!!
845 .\" PDF view co-ordinates are mapped from the bottom left corner,
846 .\" of the page, whereas page printing co-ordinates are mapped
847 .\" conventionally, from top left.
849 .\" Macro "pdf:href.sety" transforms the vertical position of the
850 .\" last printed baseline, from the printing co-ordinate domain to
851 .\" the PDF view domain.
853 .de pdf:href.sety
854 .\" ----------------------------------------------------------------
855 .\" Usage:
856 .\"   .pdf:href.sety
857 .\" ----------------------------------------------------------------
859 .\" This computation yields the vertical view co-ordinate
860 .\" in groff's basic units; don't forget to append grops' "u"
861 .\" conversion operator, when writing the pdfmark!
863 .nr PDFPAGE.Y \\n(.p-\\n(nl+\\n[PDFHREF.VIEW.LEADING]
865 .\" When we create a link "hot-spot" ...
866 .\" "PDFHREF.LEADING" sets the distance above the top of the glyph
867 .\" bounding boxes, in each line of link text, over which the link
868 .\" hot-spot will extend, while "PDFHREF.HEIGHT" sets the hot-spot
869 .\" height, PER LINE of text occupied by the reference.
871 .\" Since most fonts specify some leading space within the bounding
872 .\" boxes of their glyphs, a better appearance may be achieved when
873 .\" NEGATIVE leading is specified for link hot-spots;  indeed, when
874 .\" the default 10pt Times font is used, -1.0 point seems to be a
875 .\" reasonable default value for "PDFHREF.LEADING" -- it may be
876 .\" changed, if desired.
878 .\" "PDFHREF.HEIGHT" is initially set as one vertical spacing unit;
879 .\" note that it is defined as a string, so it will adapt to changes
880 .\" in the vertical spacing.  Changing it is NOT RECOMMENDED.
882 .nr PDFHREF.LEADING -1.0p
883 .ds PDFHREF.HEIGHT   1.0v
885 .\" PDF readers generally place a rectangular border around link
886 .\" "hot-spots".  Within text, this looks rather ugly, so we set
887 .\" "PDFHREF.BORDER" to suppress it -- the three zeroes represent
888 .\" the border parameters in the "/Border [0 0 0]" PDFMARK string,
889 .\" and may be changed to any valid form, as defined in Adobe's
890 .\" PDFMARK Reference Manual.
892 .ds PDFHREF.BORDER   0 0 0
894 .\" "PDFHREF.COLOUR" (note British spelling) defines the colour to
895 .\" be used for display of link "hot-spots".  This will apply both
896 .\" to borders, if used, and, by default to text; however, actual
897 .\" text colour is set by "PDFHREF.TEXT.COLOUR", which may be reset
898 .\" independently of "PDFHREF.COLOUR", to achieve contrasting text
899 .\" and border colours.
901 .\" "PDFHREF.COLOUR" must be set to a sequence of three values,
902 .\" each in the range 0.0 .. 1.0, representing the red, green, and
903 .\" blue components of the colour specification in the RGB colour
904 .\" domain, which is shared by "groff" and the PDF readers.
906 .ds PDFHREF.COLOUR   0.35 0.00 0.60
907 .defcolor pdf:href.colour rgb \*[PDFHREF.COLOUR]
909 .\" "PDFHREF.TEXT.COLOUR", on the other hand, is simply defined
910 .\" using any "groff" colour name -- this default maps it to the
911 .\" same colour value as "PDFHREF.COLOUR".
913 .ds PDFHREF.TEXT.COLOUR  pdf:href.colour
915 .\" Accommodate users who prefer the American spelling, COLOR, to
916 .\" the British spelling, COLOUR.
918 .als PDFHREF.COLOR       PDFHREF.COLOUR
919 .als PDFHREF.TEXT.COLOR  PDFHREF.TEXT.COLOUR
921 .\" All PDF "Hypertext" reference capabilities are accessed
922 .\" through the "pdfhref" macro
924 .de pdfhref
925 .\" -----------------------------------------------------------------
926 .\" Usage:
927 .\"   .pdfhref <subcommand [options ...] [parameters ...]> ...
928 .\" -----------------------------------------------------------------
930 .if \\n[PDFOPMODE] \{\
932 .\" Loop over all subcommands specified in the argument list
934 .   while \\n(.$ \{\
935 .   \"
936 .   \" Initially, assume each subcommand will complete successfully
937 .   \"
938 .      nr pdf:href.ok 1
939 .   \"
940 .   \" Initialise -E and -X flags in the OFF state
941 .   \"
942 .      nr pdf:href-E 0
943 .      nr pdf:href-X 0
944 .   \"
945 .   \" Handle the case where subcommand is specified as "-class",
946 .   \" setting up appropriate macro aliases for subcommand handlers.
947 .   \"
948 .      if dpdf*href\\$1       .als pdf*href      pdf*href\\$1
949 .      if dpdf*href\\$1.link  .als pdf*href.link pdf*href\\$1.link
950 .      if dpdf*href\\$1.file  .als pdf*href.file pdf*href\\$1.file
951 .   \"
952 .   \" Repeat macro alias setup
953 .   \" for the case where the subcommand is specified as "class",
954 .   \" (without a leading hyphen)
955 .   \"
956 .      if dpdf*href-\\$1      .als pdf*href      pdf*href-\\$1
957 .      if dpdf*href-\\$1.link .als pdf*href.link pdf*href-\\$1.link
958 .      if dpdf*href-\\$1.file .als pdf*href.file pdf*href-\\$1.file
959 .   \"
960 .   \" Process one subcommand ...
961 .   \"
962 .      ie dpdf*href \{\
963 .      \"
964 .      \" Subcommand "class" is recognised ...
965 .      \" discard the "class" code from the argument list,
966 .      \" set the initial argument count to swallow all arguments,
967 .      \" and invoke the selected subcommand handler.
968 .      \"
969 .         shift
970 .         nr pdf:argc \\n(.$
971 .         pdf*href \\$@
972 .      \"
973 .      \" When done,
974 .      \" discard all arguments actually consumed by the handler,
975 .      \" before proceeding to the next subcommand (if any).
976 .      \"
977 .         shift \\n[pdf:argc]
978 .      \}
979 .      el \{\
980 .      \"
981 .      \" Subcommand "class" is not recognised ...
982 .      \" issue a warning, and discard the entire argument list,
983 .      \" so aborting this "pdfhref" invocation
984 .      \"
985 .         pdf:warn \\$0: undefined reference class '\\$1' ignored
986 .         shift \\n(.$
987 .         \}
988 .   \"
989 .   \" Clean up temporary reference data,
990 .   \" to ensure it doesn't propagate to any future reference
991 .   \"
992 .      rm pdf*href pdf:href.link pdf:href.files
993 .      rr pdf:href-E pdf:href-X
994 .      pdf:href.options.clear
995 .      \}
996 .   rr pdf:href.ok
997 .   \}
1000 .\" Macros "pdf:href.flag" and "pdf:href.option"
1001 .\" provide a generic mechanism for switching on flag type options,
1002 .\" and for decoding options with arguments, respectively
1004 .de pdf:href.flag
1005 .\" ----------------------------------------------------------------------
1006 .\" ----------------------------------------------------------------------
1007 .nr pdf:href\\$1 1
1008 .nr pdf:href.argc 1
1010 .de pdf:href.option
1011 .\" ----------------------------------------------------------------------
1012 .\" ----------------------------------------------------------------------
1013 .ds pdf:href\\$1 \\$2
1014 .nr pdf:href.argc 2
1017 .\" Valid PDFHREF options are simply declared
1018 .\" by aliasing option handlers to "pdf:href.option",
1019 .\" or to "pdf:href.flag", as appropriate
1021 .als pdf:href.opt-A pdf:href.option   \" affixed text
1022 .als pdf:href.opt-D pdf:href.option   \" destination name
1023 .als pdf:href.opt-E pdf:href.flag     \" echo link descriptor
1024 .als pdf:href.opt-F pdf:href.option   \" remote file specifier
1025 .als pdf:href.opt-N pdf:href.option   \" reference name
1026 .als pdf:href.opt-P pdf:href.option   \" prefixed text
1027 .als pdf:href.opt-T pdf:href.option   \" bookmark "tag"
1028 .als pdf:href.opt-X pdf:href.flag     \" cross reference
1030 .\" For references to another document file
1031 .\" we also need to support OS dependent file name specifiers
1033 .als pdf:href.opt-DF pdf:href.option  \" /DOSFile specifier
1034 .als pdf:href.opt-MF pdf:href.option  \" /MacFile specifier
1035 .als pdf:href.opt-UF pdf:href.option  \" /UnixFile specifier
1036 .als pdf:href.opt-WF pdf:href.option  \" /WinFile specifier
1038 .\" Macro "pdf:href.options.clear" ensures that ALL option
1039 .\" argument strings are deleted, after "pdfhref" has completed
1040 .\" all processing which depends on them
1042 .de pdf:href.options.clear
1043 .\" -----------------------------------------------------------------
1044 .\" Usage:
1045 .\"   .pdf:href.options.clear [option ...]
1046 .\" -----------------------------------------------------------------
1048 .\" When an option list is specified ...
1050 .ie \\n(.$ \{\
1051 .   \"
1052 .   \" then loop through the list,
1053 .   \" deleting each specified option argument string in turn
1054 .   \"
1055 .   while \\n(.$ \{\
1056 .      if dpdf:href-\\$1 .rm pdf:href-\\$1
1057 .      shift
1058 .      \}
1059 .   \}
1061 .\" ... but when no list is specified,
1062 .\" then recurse, to clear all known option argument strings
1064 .el .pdf:href.options.clear A D F N P T DF MF UF WF
1067 .\" "PDFHREF.INFO" establishes the content of the cross reference
1068 .\" data record, which is exported via the "stderr" stream, when a
1069 .\" cross reference anchor is created using a "pdfhref" macro request
1070 .\" of the form
1072 .\"    .pdfhref M -N name -X text ...
1074 .\"    .ds PDFHREF.INFO \\*[PDFHREF.NAME] reference data ...
1076 .ds PDFHREF.INFO page \\n% \\$*
1078 .\" Macro "pdf*href-M" is the handler invoked by "pdfhref", when
1079 .\" called with the "M" reference class specifier, to create a
1080 .\" named cross reference mark, and to emit a cross reference
1081 .\" data record, as specified by "PDFHREF.INFO".
1083 .de pdf*href-M
1084 .\" -----------------------------------------------------------------
1085 .\" Usage:
1086 .\"   .pdfhref M [-X] [-N name | -D name] [-E] descriptive text ...
1087 .\" -----------------------------------------------------------------
1089 .\" Initially, declare the -D and -N string options as empty,
1090 .\" so we avoid warning messages when we try to use them, and find
1091 .\" that they are undefined.
1093 .ds pdf:href-D
1094 .ds pdf:href-N
1096 .\" Parse, interpret, and strip any specified options from the
1097 .\" argument list.  (Note that only options with a declared handler
1098 .\" will be processed; there is no provision for detecting invalid
1099 .\" options -- anything which is not recognised is assumed to start
1100 .\" the "descriptive text" component of the argument list).
1102 .while dpdf:href.opt\\$1 \{\
1103 .   pdf:href.opt\\$1 \\$@
1104 .   shift \\n[pdf:href.argc]
1105 .   \}
1107 .\" If we found "--", to mark the end of the options,
1108 .\" then we should discard it.
1110 .if '\\$1'--' .shift
1112 .\" All PDF reference markers MUST be named. The name may have been
1113 .\" supplied using the "-N Name" option, (or the "-D Name" option);
1114 .\" if not, deduce it from the first "word" in the "descriptive text",
1115 .\" if any, and set the marker -- if we still can't identify the name
1116 .\" for the destination, then this marker will not be created.
1118 .pdf*href.set \\*[pdf:href-N] \\*[pdf:href-D] \\$1
1120 .\" If we specified a cross reference, with the "-X" option, and the
1121 .\" reference mark has been sucessfully created, then we now need to
1122 .\" write the cross reference info to the STDERR stream
1124 .if \\n[pdf:href-X] .pdf*href.export \\*[PDFHREF.INFO]
1126 .\" Irrespective of whether this marker is created, or not,
1127 .\" the descriptive text will be copied to the groff output stream,
1128 .\" provided the "-E" option was specified
1130 .if \\n[pdf:href-E] \&\\$*
1133 .de pdf*href.set
1134 .\" ----------------------------------------------------------------------
1135 .\" ----------------------------------------------------------------------
1136 .pdf*href.map.init
1137 .ie \\n(.$ \{\
1138 .   \"
1139 .   \" a marker name has been supplied ...
1140 .   \" if we are formatting for immediate output,
1141 .   \" emit PDFMARK code to establish the associated view
1142 .   \"
1143 .   ie '\\n(.z'' \{\
1144 .      pdf:href.sety
1145 .      pdfmark /Dest /\\$1 /View [\\*[PDFHREF.VIEW]] /DEST
1146 .      ds PDFHREF.NAME \\$1
1147 .      rr PDFPAGE.Y
1148 .      \}
1149 .   \"
1150 .   \" but, when formatting a diversion ...
1151 .   \" delay output of the PDFMARK code, until the diversion
1152 .   \" is eventually written out
1153 .   \"
1154 .   el \!.\\$0 \\$@
1155 .   \"
1156 .   \" check if we also need to emit cross reference data
1157 .   \" (caller will do this if "pdf:href-X" is set, but it is
1158 .   \"  not necessary, when "pdf:href.map" already exists)
1159 .   \"
1160 .   if dpdf:href.map .nr pdf:href-X 0
1161 .   \}
1162 .el \{\
1163 .   \" marker is unnamed ...
1164 .   \" issue error message; do not emit reference data
1165 .   \"
1166 .   pdf:warn pdfhref destination marker must be named
1167 .   nr pdf:href-X 0
1168 .   \}
1170 .de pdf*href.export
1172 .\" Called ONLY by "pdf*href-M",
1173 .\" this macro ensures that the emission of exported reference data
1174 .\" is synchronised with the placement of the reference mark,
1175 .\" especially when the mark is defined within a diversion.
1177 .ie '\\n(.z'' .tm pdfmark-info:href \\*[PDFHREF.NAME] \\$*
1178 .el \!.\\$0 \\$@
1181 .\" Macro "pdf*href-D" is invoked when "pdfhref" is called
1182 .\" with the "D" reference class specifier; it provides a
1183 .\" standardised mechanism for interpreting reference data
1184 .\" exported by the "M" reference class, and may be used
1185 .\" to directly define external reference data, without the
1186 .\" use of "M" reference class designators in the source
1187 .\" document.
1189 .de pdf*href-D
1190 .ds pdf:href-N
1192 .\" Parse, interpret, and strip any specified options from the
1193 .\" argument list.  (Note that only options with a declared handler
1194 .\" will be processed; there is no provision for detecting invalid
1195 .\" options -- anything which is not recognised is assumed to start
1196 .\" the "descriptive text" component of the argument list).
1198 .while dpdf:href.opt\\$1 \{\
1199 .   pdf:href.opt\\$1 \\$@
1200 .   shift \\n[pdf:href.argc]
1201 .   \}
1203 .\" If we found "--", to mark the end of the options,
1204 .\" then we should discard it.
1206 .if '\\$1'--' .shift
1208 .ie '\\*[pdf:href-N]'' \{\
1209 .   pdf:warn pdfhref defined reference requires a name
1210 .   \}
1211 .el \{\
1212 .   ds pdf:href(\\*[pdf:href-N]).info \\$*
1213 .   \}
1216 .\" Macro "pdf*href-F" is invoked when "pdfhref" is called
1217 .\" with the "F" reference class specifier; it allows the user
1218 .\" to provide an alternative interpreter macro, which will be
1219 .\" called when a "PDFHREF.INFO" record is retrieved to define
1220 .\" the text of a cross reference link "hot spot".
1222 .de pdf*href-F
1223 .\" ----------------------------------------------------------------
1224 .\" Usage:
1225 .\"   .pdfhref F [macro-name]
1226 .\" ----------------------------------------------------------------
1228 .\" Set macro specified by "macro-name" as the format interpreter
1229 .\" for parsing "PDFHREF.INFO" records; if "macro-name" is omitted,
1230 .\" or is specified as the reserved name "default", then use the
1231 .\" default format parser, "pdf*href.format", defined below.
1233 .if '\\$1'default' .shift \\n(.$
1234 .ie \\n(.$ .als pdf*href.format \\$1
1235 .el .als pdf*href.format pdf*href.default
1236 .nr pdf:argc 1
1238 .\" The default reference formatting macro is defined below.
1239 .\" It parses the "PDFHREF.INFO" record specific to each reference,
1240 .\" recognising the keywords "file", "page" and "section", when they
1241 .\" appear in initial key/value pairs, replacing the key/value pair
1242 .\" with "PDFHREF.FILEREF", "PDFHREF.PAGEREF" or "PDFHREF.SECTREF"
1243 .\" respectively; any additional data in the "PDFHREF.INFO" record
1244 .\" is enclosed in typographic double quotes, and the parsed record
1245 .\" is appended to "PDFHREF.PREFIX", to be returned as the formatted
1246 .\" reference text.
1248 .\" Default definitions for the reference strings "PDFHREF.PREFIX",
1249 .\" "PDFHREF.FILEREF", "PDFHREF.PAGEREF" and "PDFHREF.SECTREF" are
1250 .\" provided, in the English language.  Users may substitute any
1251 .\" desired alternative definitions, for example, when formatting
1252 .\" documents in other languages.  In each case, "\\$1" may be used
1253 .\" in the substitution, to represent the "value" component of the
1254 .\" respective key/value pair specified in the "PDFHREF.INFO" record.
1256 .ds PDFHREF.PREFIX   see
1257 .ds PDFHREF.PAGEREF  page \\$1,
1258 .ds PDFHREF.SECTREF  section \\$1,
1259 .ds PDFHREF.FILEREF  \\$1
1261 .de pdf*href.format
1262 .\" -----------------------------------------------------------------
1263 .\" Usage: (to be called ONLY by "pdfhref")
1264 .\"   .pdf*href.format cross reference data ...
1265 .\" -----------------------------------------------------------------
1267 .\" This macro is responsible for defining the strings "PDFHREF.TEXT"
1268 .\" and "PDFHREF.DESC", which are used by the "pdfhref" macro, as the
1269 .\" basis for generating the text content of a link "hot spot"; (any
1270 .\" user specified alternate formatter MUST do likewise).
1272 .\" Note that "PDFHREF.TEXT" defines the overall format for the "link
1273 .\" text", while "PDFHREF.DESC" is the descriptive component thereof.
1275 .\" This default implementation, subject to user customisation of the
1276 .\" "internationalisation" strings defined above, formats "hot spots"
1277 .\" of the style
1279 .\"    see page N, section S, "descriptive text ..."
1281 .ds PDFHREF.TEXT \\*[PDFHREF.PREFIX]
1282 .while d\\$0.\\$1 \{\
1283 .   \\$0.\\$1 "\\$2"
1284 .   shift 2
1285 .   \}
1287 .\" Retrieve the descriptive text from the cross reference data,
1288 .\" ONLY IF no overriding description has been set by the calling
1289 .\" "pdfhref" macro invocation.
1291 .if \\n(.$ .if !dPDFHREF.DESC .ds PDFHREF.DESC \\$*
1293 .\" Augment "PDFHREF.TEXT" so the descriptive text will be included
1294 .\" in the text of the formatted reference
1296 .if dPDFHREF.DESC .as PDFHREF.TEXT " \(lq\\\\*[PDFHREF.DESC]\(rq
1298 .\" Finally, suppress any leading spaces,
1299 .\" which may have been included in the PDFHREF.TEXT definition.
1301 .ds PDFHREF.TEXT \\*[PDFHREF.TEXT]
1303 .de pdf*href.format.file
1304 .\" ----------------------------------------------------------------------
1305 .\" Include a file identifier in a formatted reference.
1306 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1307 .\" reference data includes an initial file identifier tuple.
1308 .\" ----------------------------------------------------------------------
1310 .as PDFHREF.TEXT " \\*[PDFHREF.FILEREF]
1312 .de pdf*href.format.page
1313 .\" ----------------------------------------------------------------------
1314 .\" Include a page number in a formatted reference.
1315 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1316 .\" reference data includes an initial page number tuple.
1317 .\" ----------------------------------------------------------------------
1319 .as PDFHREF.TEXT " \\*[PDFHREF.PAGEREF]
1321 .de pdf*href.format.section
1322 .\" ----------------------------------------------------------------------
1323 .\" Include a section number in a formatted reference.
1324 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1325 .\" reference data includes an initial section number tuple.
1326 .\" ----------------------------------------------------------------------
1328 .as PDFHREF.TEXT " \\*[PDFHREF.SECTREF]
1331 .\" Make "pdf*href.format" the default cross reference formatter
1333 .als pdf*href.default pdf*href.format
1336 .\" Macro "pdf*href" provides a generic mechanism for placing link
1337 .\" "hot-spots" in a PDF document.  ALL "pdfhref" class macros which
1338 .\" create "hot-spots" are aliased to this macro; each must also have
1339 .\" an appropriately aliased definition for "pdf*href.template".
1341 .de pdf*href
1342 .\" ------------------------------------------------------------------
1343 .\" Usage:
1344 .\"   .pdf*href class [options ...] [link text ...]
1345 .\" ------------------------------------------------------------------
1347 .\" First, we initialise an empty string, which will be affixed to
1348 .\" the end of the "link text".  (This is needed to cancel the effect
1349 .\" of a "\c" escape, which is placed at the end of the "link text"
1350 .\" to support the "-A" option -- any text supplied by the user, when
1351 .\" the "-A" option is specified, will replace this empty string).
1353 .ds pdf:href-A
1355 .\" Now we interpret, and remove any specified options from the
1356 .\" argument list.  (Note that only options with a declared handler
1357 .\" will be processed;  there is no provision for detecting invalid
1358 .\" options -- anything which is not recognised is assumed to start
1359 .\" the "link text" component of the argument list).
1361 .while dpdf:href.opt\\$1 \{\
1362 .   pdf:href.opt\\$1 \\$@
1363 .   shift \\n[pdf:href.argc]
1364 .   \}
1366 .\" If we found "--", to mark the end of the options, then we should
1367 .\" discard it.
1369 .if '\\$1'--' .shift
1371 .\" All PDF link classes REQUIRE a named destination.  This may have
1372 .\" been supplied using the "-D Name" option, but, if not, deduce it
1373 .\" from the first "word" in the "link text", if any -- if we still
1374 .\" can't identify the destination, then set "pdf:href.ok" to zero,
1375 .\" so this link will not be created.
1377 .if !dpdf:href-D .pdf:href.option -D \\$1
1378 .if '\\*[pdf:href-D]'' \{\
1379 .   pdf:error pdfhref has no destination
1380 .   nr pdf:href.ok 0
1381 .   \}
1383 .\" Some PDF link classes support a "/File (FilePathName)" argument.
1385 .if dpdf*href.file \{\
1386 .   \"
1387 .   \" When this is supported, it may be specified by supplying
1388 .   \" the "-F FileName" option, which is captured in "pdf:href-F".
1389 .   \"
1390 .   if dpdf:href-F \{\
1391 .      \"
1392 .      \" the /File key is present, so set up the link specification
1393 .      \" to establish the reference to the specified file
1394 .      \"
1395 .      als pdf*href.link pdf*href.file
1396 .      ds pdf:href.files /File (\\*[pdf:href-F])
1397 .      \"
1398 .      \" in addition to the /File key,
1399 .      \" there may also be platform dependent alternate file names
1400 .      \"
1401 .      if dpdf:href-DF .as pdf:href.files " /DOSFile (\\*[pdf:href-DF])
1402 .      if dpdf:href-MF .as pdf:href.files " /MacFile (\\*[pdf:href-MF])
1403 .      if dpdf:href-UF .as pdf:href.files " /UnixFile (\\*[pdf:href-UF])
1404 .      if dpdf:href-WF .as pdf:href.files " /WinFile (\\*[pdf:href-WF])
1405 .      \}
1406 .   \" In some cases, the "/File" key is REQUIRED.
1407 .   \" We will know it is missing, if "pdf*href.link" is not defined.
1408 .   \"
1409 .   if !dpdf*href.link \{\
1410 .   \"
1411 .   \" When a REQUIRED "/File" key specification is not supplied,
1412 .   \" then complain, and set "pdf:href.ok" to abort the creation
1413 .   \" of the current reference.
1414 .   \"
1415 .      pdf:error pdfhref: required -F specification omitted
1416 .      nr pdf:href.ok 0
1417 .      \}
1418 .   \" Now, we have no further use for "pdf*href.file".
1419 .   \"
1420 .   rm pdf*href.file
1421 .   \}
1423 .\" Now, initialise a string, defining the PDFMARK code sequence
1424 .\" to create the reference, using the appropriate type indicators.
1426 .ds pdf:href.link /Subtype /Link \\*[pdf*href.link]
1428 .\" And now, we have no further use for "pdf*href.link".
1430 .rm pdf*href.link
1432 .\" If the user specified any "link prefix" text, (using the "-P text"
1433 .\" option), then emit it BEFORE processing the "link text" itself.
1435 .if dpdf:href-P \&\\*[pdf:href-P]\c
1436 .ie \\n[pdf:href.ok] \{\
1437 .   \"
1438 .   \" This link is VALID (so far as we can determine) ...
1439 .   \" Modify the "link text" argument specification, as required,
1440 .   \" to include any pre-formatted cross reference information
1441 .   \"
1442 .   ie \\n(.$ \{\
1443 .      \"
1444 .      \" One or more "link text" argument(s) are present,
1445 .      \" so, set the link description from the argument(s) ...
1446 .      \"
1447 .      ds PDFHREF.DESC \\\\$*
1448 .      ie \\n[pdf:href-X] \{\
1449 .         \"
1450 .         \" ... and, when the "-X" flag is set,
1451 .         \" also include formatted location information,
1452 .         \" derived from the cross reference record.
1453 .         \"
1454 .         pdf*href.format \\*[pdf:href(\\*[pdf:href-D]).info]
1455 .         \}
1456 .      el \{\
1457 .         \" ... but, when the "-X" flag is NOT set,
1458 .         \" use only the argument(s) as the entire content
1459 .         \" of the "link text"
1460 .         \"
1461 .         rn PDFHREF.DESC PDFHREF.TEXT
1462 .         \}
1463 .      \}
1464 .   el \{\
1465 .      \" No "link text" arguments are present,
1466 .      \" so, format the cross reference record to define
1467 .      \" the content of the "link text".
1468 .      \"
1469 .      pdf*href.format \\*[pdf:href(\\*[pdf:href-D]).info]
1470 .      \}
1471 .   \" Apply border and colour specifications to the PDFMARK string
1472 .   \" definition, as required.
1473 .   \"
1474 .   if dPDFHREF.BORDER .as pdf:href.link " /Border [\\*[PDFHREF.BORDER]]
1475 .   if dPDFHREF.COLOUR .as pdf:href.link " /Color  [\\*[PDFHREF.COLOUR]]
1476 .   \"
1477 .   \" Emit the "link text", in its appropriate colour, marking the
1478 .   \" limits of its bounding box(es), as the before and after output
1479 .   \" text positions.
1480 .   \"
1481 .   pdf*href.mark.begin "\\*[pdf:href.link]"
1482 .   if dPDFHREF.COLOUR .defcolor pdf:href.colour rgb \\*[PDFHREF.COLOUR]
1483 .   nop \&\m[\\*[PDFHREF.TEXT.COLOUR]]\\*[PDFHREF.TEXT]\m[]\c
1484 .   pdf*href.mark.end
1485 .   \"
1486 .   \" Clean up the temporary registers and strings, used to
1487 .   \" compute the "hot-spot" bounds, and format the reference,
1488 .   \"
1489 .   rm PDFHREF.DESC PDFHREF.TEXT
1490 .   \}
1492 .\" But when we identify an INVALID link ...
1493 .\" We simply emit the "link text", with no colour change, no border,
1494 .\" and no associated "hot-spot".
1496 .el \&\\$*\c
1498 .\" And then, if the user specified any affixed text, (using the
1499 .\" "-A text" option), we tack it on at the end.
1501 .nop \&\\*[pdf:href-A]
1503 .de pdf*href.map.init
1504 .\" ----------------------------------------------------------------------
1505 .\" ----------------------------------------------------------------------
1507 .if dpdf:href.map-1 \{\
1508 .   \"
1509 .   \" We have a reference map, but we haven't started to parse it yet.
1510 .   \" This must be the first map reference in pass 2, so we need to
1511 .   \" "kick-start" the parsing process, by loading the first indexed
1512 .   \" sub-map into the global map.
1513 .   \"
1514 .   rn pdf:href.map-1 pdf:href.map
1515 .   als pdf:href.map.internal pdf:href.map
1516 .   nr pdf:href.map.index 1 1
1517 .   \}
1518 .als pdf*href.map.init pdf*href.mark.idle
1521 .\" "pdf*href-Z" is used to add link co-ordinate entries to the
1522 .\" "pdf:href.map".  Primarily, it is used by the "pdfroff" formatter,
1523 .\" to pass link co-ordinate data from one "groff" formatting pass to
1524 .\" the next, and is not generally useful to the end user.
1526 .de pdf*href-Z
1527 .\" ----------------------------------------------------------------------
1528 .\" Usage:
1529 .\"   .pdfhref Z page-index x-displacement y-displacement
1530 .\" Where:
1531 .\"   page-index      is the reference mark's page number
1532 .\"   x-displacement  is its offset from the left edge of the page
1533 .\"   y-displacement  is its offset from the top edge of the page
1534 .\" ( both displacement values are expressed in basic groff units, )
1535 .\" ( and measured perpendicular to their respective page edges.   )
1536 .\" ----------------------------------------------------------------------
1538 .ie \\n(.$=3 .ds pdf:href.map-\\n+[pdf*href-Z.index] \\$*
1539 .el .pdf:error pdfhref Z operator expects exactly three arguments
1541 .\" Initialise the auto-incrementing "pdf*href-Z.index" register,
1542 .\" to ensure that sub-map numbering starts at 1.
1544 .nr pdf*href-Z.index 0 1
1546 .de pdf*href.map.read
1547 .\" ----------------------------------------------------------------------
1548 .\" Usage: (internal use only):
1549 .\"   .pdf*href.map.read co-ordinate name list ...
1550 .\" ----------------------------------------------------------------------
1552 .\" Reads values from "pdf:href.map" to each named register, in turn
1553 .\" Reading to "null" discards the corresponding value in "pdf:href.map"
1555 .while \\n(.$ \{\
1556 .   \"
1557 .   \" Loop over all registers named in the argument list,
1558 .   \" assigning values from "pdf:href.map" to each in turn.
1559 .   \"
1560 .   pdf:pop nr pdf:\\$1 pdf:href.map.internal
1561 .   if !dpdf:href.map.internal \{\
1562 .      \"
1563 .      \" We ran out of map references in the current sub-map,
1564 .      \" so move on to the next indexed sub-map, if any.
1565 .      \"
1566 .      if dpdf:href.map-\\n+[pdf:href.map.index] \{\
1567 .         rn pdf:href.map-\\n[pdf:href.map.index] pdf:href.map
1568 .         als pdf:href.map.internal pdf:href.map
1569 .         \}
1570 .      \}
1571 .   \"
1572 .   \" Proceed to the next named co-ordinate, (if any), specified
1573 .   \" in the argument list.
1574 .   \"
1575 .   shift
1576 .   \}
1578 .\" Discard any assignments to a register named "null"
1580 .rr pdf:null
1582 .de pdf*href.mark.begin
1583 .\" ----------------------------------------------------------------------
1584 .\" ----------------------------------------------------------------------
1585 .pdf*href.map.init
1586 .ie dpdf:href.map \{\
1587 .   \"
1588 .   \" Once we have established a document reference map,
1589 .   \" then this, and all subsequent calls to "pdf*href.mark.begin",
1590 .   \" may be redirected to the reference mark resolver, and the
1591 .   \" "pdf*href.mark.end" macro has nothing further to do.
1592 .   \"
1593 .   pdf*href.mark.resolve \\$@
1594 .   rn pdf*href.mark.resolve pdf*href.mark.begin
1595 .   als pdf*href.mark.end pdf*href.mark.idle
1596 .   \}
1597 .el \{\
1598 .   \" Since we don't yet have a document reference map, the
1599 .   \" reference mark resolver will not work, in this pass of the
1600 .   \" formatter;  this, and all subsequent calls to "pdf*href.mark.begin",
1601 .   \" may be redirected to "pdf*href.mark.end", which is responsible
1602 .   \" for emitting the reference mark data to be incorporated into
1603 .   \" the reference map in a subsequent formatting pass.
1604 .   \"
1605 .   pdf*href.mark.end
1606 .   als pdf*href.mark.begin pdf*href.mark.end
1607 .   \}
1609 .de pdf*href.mark.resolve
1610 .\" ----------------------------------------------------------------------
1611 .\" ----------------------------------------------------------------------
1612 .ie '\\n(.z'' \{\
1613 .   ds pdf:href.link \\$1
1614 .   nr pdf:urx \\n(.o+\\n(.l
1615 .   pdf*href.map.read spg llx ury epg urx.end lly.end
1616 .   ie \\n[pdf:spg]=\\n[pdf:epg] \{\
1617 .      \"
1618 .      \" This link is entirely contained on a single page ...
1619 .      \" emit the text, which defines the content of the link region,
1620 .      \" then make it active.
1621 .      \"
1622 .      pdf*href.mark.emit 1 \\n[pdf:urx.end]
1623 .      if \\n[pdf:lly]<\\n[pdf:lly.end] \{\
1624 .         \"
1625 .         \" This link spans multiple output lines; we must save its
1626 .         \" original end co-ordinates, then define a new intermediate
1627 .         \" end point, to create a PDFMARK "hot-spot" extending from
1628 .         \" the start of the link to the end if its first line.
1629 .         \"
1630 .         nr pdf:ury +1v
1631 .         nr pdf:llx \\n(.o+\\n[.in]
1632 .         nr pdf:lly \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1633 .         if \\n[pdf:ury]<\\n[pdf:lly] \{\
1634 .            nr pdf:lly +\\*[PDFHREF.HEIGHT]-1v
1635 .            pdf*href.mark.emit 2
1636 .            nr pdf:ury \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1637 .            \}
1638 .         pdf*href.mark.emit 0 \\n[pdf:urx.end]
1639 .         \}
1640 .      pdf*href.mark.flush
1641 .      \}
1642 .   el \{\
1643 .      \" This link is split across a page break, so ...
1644 .      \" We must mark the "hot-spot" region on the current page,
1645 .      \" BEFORE we emit the link text, as we will have moved off
1646 .      \" this page, by the time the text has been output.
1647 .      \"
1648 .      \" First step: define the region from the start of the link,
1649 .      \" to the end of its first line.
1650 .      \"
1651 .      pdf*href.mark.emit 1 \\n[pdf:urx]
1652 .      \"
1653 .      \" All additional regions MUST align with the left margin.
1654 .      \"
1655 .      nr pdf:llx \\n(.o+\\n[.in]
1656 .      \"
1657 .      \" If the current page can accomodate more than the current line,
1658 .      \" then it will include a second active region for this link; this
1659 .      \" will extend from just below the current line to the end of page
1660 .      \" trap, if any, or the bottom of the page otherwise, and occupy
1661 .      \" the full width of the page, between the margins.
1662 .      \"
1663 .      nr pdf:ury +1v
1664 .      pdf*href.mark.emit 3
1665 .      \"
1666 .      \" We now need a page transition trap, to map the active link
1667 .      \" region(s), which overflow on to the following page(s); (the
1668 .      \" handler for this trap MUST have been previously installed).
1669 .      \"
1670 .      ie dpdf*href.mark.hook \{\
1671 .         \"
1672 .         \" The page transition trap handler has been installed,
1673 .         \" so we may activate both it, and also the appropriate
1674 .         \" termination handler, to deactivate it when done.
1675 .         \"
1676 .         als pdf*href.mark.hook pdf*href.mark.trap
1677 .         \"
1678 .         \" Now we set up "pdf:epg" to count the number of page breaks
1679 .         \" which this link will span, and emit the link text, leaving
1680 .         \" the page trap macro to map active regions on intervening
1681 .         \" pages, which are included in the link.
1682 .         \"
1683 .         nr pdf:epg -\\n[pdf:spg] 1
1684 .         \}
1685 .      el \{\
1686 .         \" There was no handler initialised for the page trap,
1687 .         \" so we are unable to map the active regions for this link;
1688 .         \" we may discard the remaining map data for this link,
1689 .         \" and issue a diagnostic.
1690 .         \"
1691 .         pdf:error pdfhref: link dissociated at page break (trap not initialised)
1692 .         if dPDFHREF.BROKEN.COLOR \{\
1693 .            \"
1694 .            \" The user may opt to have such broken links highlighted.
1695 .            \" We use "PDFHREF.BROKEN.COLOUR" to specify this requirement,
1696 .            \" but the user may prefer the American spelling, so we will
1697 .            \" handle both as equivalent.
1698 .            \"
1699 .            als PDFHREF.BROKEN.COLOUR PDFHREF.BROKEN.COLOR
1700 .            \}
1701 .         if dPDFHREF.BROKEN.COLOUR \{\
1702 .            if dPDFHREF.COLOUR .als PDFHREF.COLOUR PDFHREF.BROKEN.COLOUR
1703 .            \}
1704 .         \}
1705 .      \}
1706 .   \}
1707 .el \!.\\$0 \\$@
1710 .\" Macro "pdf*href.mark.emit" is called only by "pdf*href".  It is
1711 .\" responsible for emitting the PDFMARK code, to establish the
1712 .\" "hot-spot" region associated with a document or resource link.
1714 .de pdf*href.mark.emit
1715 .\" ----------------------------------------------------------------------
1716 .\" Usage:
1717 .\"   .pdf*href.mark.emit <action> [<end-urx>]
1718 .\"     <action> == 0 --> normal operation -- link height = 1 line
1719 .\"     <action> == 1 --> start of link -- add leading above text
1720 .\"     <action> == 2 --> overtall link -- set intermediate baseline
1721 .\"     <action> == 3 --> split link -- break at bottom of page
1722 .\" ----------------------------------------------------------------------
1724 .if \\$1=1 \{\
1725 .   \"
1726 .   \" Initialising a new link region ...
1727 .   \" Some different versions of "groff" disagree about the vertical
1728 .   \" displacement of "opminy", as emitted by "\O1|\h'-\w"|"u'\O2\c",
1729 .   \" relative to the current text baseline.  Therefore, recompute
1730 .   \" the link displacement, independently of "opminy".
1731 .   \"
1732 .   mk pdf:ury.base
1733 .   while \\n[pdf:ury.base]<\\n[pdf:ury] .nr pdf:ury.base +1v
1734 .   nr pdf:ury.base -1m+\\n[PDFHREF.LEADING]
1735 .   \"
1736 .   \" adjust the end-point vertical displacement by the same offset,
1737 .   \" and then relocate the link starting point to its new displacement,
1738 .   \" as established by this base line relative computation.
1739 .   \"
1740 .   nr pdf:lly.end +\\n[pdf:ury.base]-\\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1741 .   rnn pdf:ury.base pdf:ury
1742 .   \}
1743 .if \\$1<2 \{\
1744 .   \"
1745 .   \" Link segment fits on a single line ...
1746 .   \" Set its height and end-point horizontal displacement accordingly.
1747 .   \"
1748 .   nr pdf:lly \\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1749 .   if \\n[pdf:lly]>=\\n[pdf:lly.end] .nr pdf:urx \\$2
1750 .   \}
1751 .ie \\$1=3 \{\
1752 .   \"
1753 .   \" Link segment extends beyond the next page break ...
1754 .   \" Recompute truncated height, to just fit portion on current page,
1755 .   \" recursing to emit it, and leaving page trap mechanism to place
1756 .   \" continuation region(s) on following page(s).
1757 .   \"
1758 .   nr pdf:lly (\\n[.t]u-\\n[.V]u)/1v
1759 .   if \\n[pdf:lly]>0 \{\
1760 .      nr pdf:lly \\n[pdf:ury]+\\n[pdf:lly]v-1v+\\*[PDFHREF.HEIGHT]
1761 .      pdf*href.mark.emit 2
1762 .      \}
1763 .   \}
1764 .el \{\
1765 .   \" Link region size and placement has been fully specified ...
1766 .   \" Emit it.
1767 .   \"
1768 .   pdfmark \\*[pdf:href.link] /Rect [\\*[pdf:bbox]] /ANN
1769 .   \}
1772 .\" When "pdf*href" emits a link for which the "hot-spot" spans a
1773 .\" page break, then we need to provide a "hook" in to the page break
1774 .\" trap, so we can map the "hot-spot" regions which are to be placed
1775 .\" on either side of the page break.
1777 .\" Macro "pdf*href.mark.idle" is a dummy macro, which provide this
1778 .\" "hook" for normal page breaks, where there is no link "hot-spot"
1779 .\" crossing the break.
1781 .de pdf*href.mark.idle
1782 .\" ----------------------------------------------------------------------
1783 .\" Usage:
1784 .\"   Called only as an internal hook, by a page trap macro.
1785 .\"   Expects no arguments, and does nothing.
1786 .\" ----------------------------------------------------------------------
1789 .\" Macro "pdf*href.mark.trap" is the active "hook", which is substituted
1790 .\" for "pdf*href,mark.idle" at those page breaks which are crossed by
1791 .\" a link "hot-spot".
1793 .de pdf*href.mark.trap
1794 .\" ----------------------------------------------------------------------
1795 .\" Usage:
1796 .\"   Called only as an internal hook, by a page trap macro.
1797 .\"   Expects no arguments.  Maps residual link "hot-spot" regions,
1798 .\"   which spill beyond any page break.  Not to be invoked directly
1799 .\"   by the user, nor by any user supplied macro.
1800 .\" ----------------------------------------------------------------------
1802 .mk pdf:ury
1803 .nr pdf:ury +1v-1m-\\n[PDFHREF.LEADING]
1804 .ie \\n-[pdf:epg] \{\
1805 .   \"
1806 .   \" The link "hot-spot" extends across more than one page break,
1807 .   \" so, for each page which is completely contained within the
1808 .   \" extent of the link, simply mark the entire text area on the
1809 .   \" page as a "hot-spot".
1810 .   \"
1811 .   pdf*href.mark.emit 3
1812 .   \}
1813 .el \{\
1814 .   \" The link "hot-spot" ends on the page which immediately follows
1815 .   \" the current page transition, so we may now finalise this link.
1816 .   \"
1817 .   nr pdf:lly \\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1818 .   if \\n[pdf:lly.end]>\\n[pdf:lly] \{\
1819 .      \"
1820 .      \" The "hot-spot" extends beyond the first line of text,
1821 .      \" on its final page; compute and emit "hot-spot" region to cover
1822 .      \" the full with of the text area, including all but the last
1823 .      \" line of the link text.
1824 .      \"
1825 .      while \\n[pdf:lly.end]>\\n[pdf:lly] .nr pdf:lly +1v
1826 .      nr pdf:lly -1v
1827 .      pdf*href.mark.emit 2
1828 .      \"
1829 .      \" Now, adjust the vertical "hot-spot" mapping reference,
1830 .      \" to identify the correct position for the the last line of
1831 .      \" text, over which the "hot-spot" extends.
1832 .      \"
1833 .      nr pdf:ury \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1834 .      \}
1835 .   \"
1836 .   \" We now have exactly one final line of text, over which we must
1837 .   \" emit a "hot-spot" region;  map it, terminate page trap processing
1838 .   \" for this "hot-spot", and clean up the "hot-spot" mapping context.
1839 .   \"
1840 .   pdf*href.mark.emit 0 \\n[pdf:urx.end]
1841 .   als pdf*href.mark.hook pdf*href.mark.idle
1842 .   pdf*href.mark.flush
1843 .   \}
1845 .de pdf*href.mark.flush
1846 .\" ----------------------------------------------------------------------
1847 .\" ----------------------------------------------------------------------
1848 .rr pdf:spg pdf:epg
1849 .rr pdf:llx pdf:lly pdf:urx pdf:ury
1850 .if dPDFHREF.COLOR .als PDFHREF.COLOUR PDFHREF.COLOR
1851 .rr pdf:urx.end pdf:lly.end
1853 .de pdf*href.mark.end
1854 .\" ----------------------------------------------------------------------
1855 .\" ----------------------------------------------------------------------
1856 \O1\Z'|'\O2\c
1858 .\" Macro "pdf*href-I" is used for one time initialisation of special
1859 .\" "pdfhref" features; (currently, only the above page trap hook is
1860 .\" supported, but it is implemented with one level of indirection, to
1861 .\" accommodate possible future expansion).
1863 .de pdf*href-I
1864 .\" ----------------------------------------------------------------------
1865 .\" Usage:
1866 .\"   .pdfhref I -<option> <optarg> [-<option> <optarg>] ...
1867 .\" ----------------------------------------------------------------------
1869 .\" Loop over all arguments, in pairs ...
1871 .while \\n(.$ \{\
1872 .   \"
1873 .   \" handing them off to their respective initialisers,
1874 .   \" when suitable initialisers exist, or complaining otherwise.
1875 .   \"
1876 .   ie dpdf*href\\$1.init .pdf*href\\$1.init \\$2
1877 .   el .pdf*error pdfhref:init: unknown feature '\\$1'
1878 .   shift 2
1879 .   \}
1881 .\" Before we can use the page break "hook", we need to initialise it
1882 .\" as an addendum to a regular page break trap. To ensure that we don't
1883 .\" compromise the user's page trap setup, we leave the onus for this
1884 .\" initialisation with the user, but we provide the "pdf*href-PT.init"
1885 .\" macro, (invoked by ".pdfhref I -PT <macro-name>"), to implement a
1886 .\" suitable initialisation action.
1888 .de pdf*href-PT.init
1889 .\" ----------------------------------------------------------------------
1890 .\" Usage:
1891 .\"   .pdfhref I -PT <macro-name>
1892 .\"     <macro-name> == name of user's page break trap macro
1893 .\" ----------------------------------------------------------------------
1895 .\" Initially, map the page break hook to its default, do nothing helper.
1897 .als pdf*href.mark.hook pdf*href.mark.idle
1898 .ie !\\n(.$ \{\
1899 .   \"
1900 .   \" Don't have enough arguments to specify a page trap macro name,
1901 .   \" so simply plant "pdf*href.mark.hook" as a top of page trap.
1902 .   \"
1903 .   wh 0 pdf*href.mark.hook
1904 .   \}
1905 .el \{\
1906 .   \" Page trap macro name is specified in "\\$1" ...
1907 .   \"
1908 .   ie d\\$1 \{\
1909 .      \"
1910 .      \" When this page trap macro already exists, then we simply
1911 .      \" append a call to "pdf*href.mark.hook" to it.
1912 .      \"
1913 .      am \\$1 pdf*href.mark.idle
1914 .         pdf*href.mark.hook
1915 .         pdf*href.mark.idle
1916 .      \}
1917 .   el \{\
1918 .      \" However, when the specified page trap macro does not yet
1919 .      \" exist, then we create it, and plant it as a top of page
1920 .      \" trap.
1921 .      \"
1922 .      de \\$1 pdf*href.mark.idle
1923 .         pdf*href.mark.hook
1924 .         pdf*href.mark.idle
1925 .      wh 0 \\$1
1926 .      \}
1927 .   \}
1930 .\" "pdf*href-L" is the generic handler for creating references to
1931 .\" named destinations in PDF documents.  It supports both local
1932 .\" references, to locations within the same document, through its
1933 .\" "pdf*href-L.link" attribute, and also references to locations
1934 .\" in any other PDF document, through "pdf*href-L.file".
1936 .als pdf*href-L      pdf*href
1937 .ds  pdf*href-L.link /Dest /\\\\*[pdf:href-D]
1938 .ds  pdf*href-L.file /Action /GoToR \\\\*[pdf:href.files] \\*[pdf*href-L.link]
1940 .\" "pdf*href-O" is the "official" handler for creating PDF
1941 .\" document outlines.  It is simply an alias to "pdfbookmark",
1942 .\" which may also be invoked directly, if preferred.  Neither
1943 .\" a "pdf*href-O.link" nor a "pdf*href-O.file" attribute is
1944 .\" required.
1946 .als pdf*href-O      pdfbookmark
1948 .\" "pdf*href-W" is the generic handler for creating references to
1949 .\" web resources, (or any resource specified by a uniform resource
1950 .\" identifier).  Such resource links are fully specified by the
1951 .\" "pdf*href-W.link" attribute.
1953 .als pdf*href-W      pdf*href
1954 .ds  pdf*href-W.link /Action << /Subtype /URI /URI (\\\\*[pdf:href-D]) >>
1956 .\" s-tr-mode