6 Copyright (C) 2004, 2005, 2006, 2007
7 Free Software Foundation, Inc.
8 Written by Keith Marshall (keith.d.marshall@ntlworld.com)
10 This file is part of groff.
12 groff is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 2, or (at your option) any later
17 groff is distributed in the hope that it will be useful, but WITHOUT ANY
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 You should have received a copy of the GNU General Public License along
23 with groff; see the file COPYING. If not, write to the Free Software
24 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
29 While I have written this macro package from scratch, much of my
30 inspiration has come from discussion on the groff mailing list
31 (mailto:groff@gnu.org). I am particularly indebted to:
33 Kees Zeelenberg, for an earlier macro package he posted,
34 a study of which helped me to get started.
36 Carlos J. G. Duarte and Werner Lemberg, whose discussion
37 on computation of the bounding boxes for link "hot-spots"
38 forms the basis of such computations in this package.
40 .if !\n(.g .ab These pdfmark macros require groff.
42 .\" Check if we have already been loaded -- do not reload
45 .\" ======================================================================
46 .\" Module PDFMARK: Insert Arbitrary PDFMARK Code in the Postscript Stream
47 .\" ======================================================================
49 .\" PDFMARK output may be disabled, by zeroing the PDFOPMODE register,
50 .\" ( which mimics a more generic OPMODE, if it is defined ).
52 .if rOPMODE .aln PDFOPMODE OPMODE
54 .\" but if OPMODE wasn't defined,
55 .\" then make the default PDFMARK mode ENABLED.
57 .if !rPDFOPMODE .nr PDFOPMODE 1
59 .\" PDFMARK output must be constrained to a maximum line length limit,
60 .\" for strict compliance with the Postscript DSC. This limit is defined
61 .\" in register "PDFMARK.FOLDWIDTH.MAX". This is user definable, up to a
62 .\" ceiling value of 255, which is also its default value; this limit
63 .\" is enforced for each PDFMARK, by macro "pdf*pdfmark.limit".
66 .\" ----------------------------------------------------------------
68 .\" .pdf*pdfmark.limit REGISTER-NAME DEFAULT-MAXIMUM-VALUE
69 .\" ----------------------------------------------------------------
71 .\" If a register named REGISTER-NAME has not been defined, then
72 .\" define it now, with default value = DEFAULT-MAXIMUM-VALUE.
74 .if !r\\$1 .nr \\$1 \\$2
76 .\" But when it has already been defined, ensure that its value does
77 .\" not exceed DEFAULT-MAXIMUM-VALUE; if value does exceed this ceiling,
78 .\" then redefine it, to enforce the limit.
80 .if (\\n[\\$1] > \\$2) .nr \\$1 \\$2
82 .\" The "pdfmark" macro is responsible for emitting the appropriate
86 .\" ----------------------------------------------------------------
88 .\" .pdfmark text of pdfmark instruction
89 .\" Macro supplies the required opening "[" and closing "pdfmark"
90 .\" operator; DO NOT include them in the instruction text!
91 .\" ----------------------------------------------------------------
93 .if \\n[PDFOPMODE] \{\
95 .\" Strict DSC compliance forbids emission of ps:exec lines which
96 .\" exceed 255 characters in length. We will allow the user to specify
97 .\" an alternative lesser limit ...
99 . pdf*pdfmark.limit PDFMARK.FOLDWIDTH.MAX 255
101 .\" ... and we will also support a second lesser limit, which will be
102 .\" applied to literal text parenthetically embedded within the PDFMARK.
104 . pdf*pdfmark.limit PDFMARK.FOLDWIDTH \\n[PDFMARK.FOLDWIDTH.MAX]
106 .\" We will push out the entire PDFMARK in one chunk, provided it fits
107 .\" within this limit.
109 . length pdf:length "[\\$* pdfmark\"
110 . ie !(\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH]) \{\
112 . \" This PDFMARK is suitable for single chunk output ...
114 . nop \X'ps:exec [\\$* pdfmark'\c
117 . \" ... but, when the limit would be violated, then we must
118 . \" recompose the specified PDFMARK, spreading it over as many
119 . \" continuation lines as are necessary.
121 . als pdf*compose pdf*compose.first
127 . \" Complete the PDFMARK recomposition, by appending a
128 . \" "pdfmark" operator, and push it out to the intermediate
129 . \" output stream, (excluding its final line break).
131 . pdf*compose pdfmark
132 . pdf*pdfmark.dispatch
134 . nop \Y[pdf:composed]\c
136 . \" And clean up when done.
138 . rm pdf*compose pdf*pdfmark.post
139 . rm pdf:compose.test pdf:composed pdf:composed.literal
144 .\" When a PDFMARK exceeds the specified output record length limit,
145 .\" then we decompose it, subsequently using the dynamically overloaded
146 .\" macro, "pdf*compose", to reassemble it into as many continuation
147 .\" records as it may require.
149 .\" Each call to "pdf*compose" uses macro "pdf*length.increment" to
150 .\" keep track of the current output record length, so ensuring that
151 .\" the active maximum length limit is not violated.
153 .de pdf*length.increment
154 .\" ----------------------------------------------------------------
156 .\" .pdf*length.increment NEXT-ADDITION
157 .\" ----------------------------------------------------------------
159 .ie d pdf:composed.line \
160 . length pdf:length "\\*[pdf:composed.line] \\$*\"
161 .el .length pdf:length "\\$*\"
163 .\" The first call to "pdf*compose" for each PDFMARK is directed
164 .\" to "pdf*compose.first"; this initialises the local strings
165 .\" and macros used to compose the eventual PDFMARK output.
167 .de pdf*compose.first
168 .\" ----------------------------------------------------------------
170 .\" .als pdf*compose pdf*compose.first
171 .\" . pdf*compose TOKEN
172 .\" ----------------------------------------------------------------
174 .\" Ensure that the output record accumulator will be initialised
175 .\" on posting of the first composed PDFMARK record.
177 .als pdf*pdfmark.post pdf*pdfmark.post.first
179 .\" The first token passed to "pdf*compose" should not be a
180 .\" literal, but be prepared to handle one, just in case.
182 .ds pdf:compose.test \\$1
183 .substring pdf:compose.test 0 0
184 .ie '('\\*[pdf:compose.test]' \{\
186 .\" We found a literal, even though we didn't expect it;
187 .\" if it's a single element literal, we can just handle it
188 .\" as if it is a regular token anyway.
190 . ds pdf:compose.test "\\$\\n(.$\"
191 . substring pdf:compose.test -1
192 . if !')'\\*[pdf:compose.test]' \{\
194 . \" But when it is the first of a literal sequence,
195 . \" then we need to set up "pdf*compose" to handle it.
197 . ds pdf:composed.literal "[\\$*\"
198 . als pdf*compose pdf*compose.literal
201 .el .ds pdf:compose.test )
202 .if ')'\\*[pdf:compose.test]' \{\
204 .\" In the normal case, we start each new PDFMARK with a
205 .\" regular token; save it as the first in the composed output
206 .\" line sequence, and set up "pdf*compose" to collect
207 .\" the rest of the sequence.
209 . ds pdf:composed.line "[\\$*\"
210 . als pdf*compose pdf*compose.next
213 .\" Subsequent calls to "pdf*compose", while collecting
214 .\" regular tokens, are then directed to "pdf*compose.next".
217 .\" ----------------------------------------------------------------
219 .\" .als pdf*compose pdf*compose.next
220 .\" . pdf*compose TOKEN
221 .\" ----------------------------------------------------------------
223 .\" This first checks to ensure that the supplied token really is
224 .\" a regular token, and not the first element in a literal.
226 .ds pdf:compose.test \\$1
227 .substring pdf:compose.test 0 0
228 .ie '('\\*[pdf:compose.test]' \{\
230 .\" The supplied token represents the first element of a literal,
231 .\" but it may be a single element literal, which we simply handle
232 .\" as a regular token anyway.
234 . ds pdf:compose.test "\\$\\n(.$\"
235 . substring pdf:compose.test -1
236 . if !')'\\*[pdf:compose.test]' \{\
238 . \" The supplied token is the first of a sequence of elements
239 . \" which collectively define a literal, so start collecting a
240 . \" composite literal token, and change the "pdf*compose"
241 . \" state, to collect and append the remaining elements.
243 . ds pdf:composed.literal "\\$*\"
244 . als pdf*compose pdf*compose.literal
247 .el .ds pdf:compose.test )
248 .if ')'\\*[pdf:compose.test]' \{\
250 .\" The supplied token IS a regular token; add it, but ensure that
251 .\" the active maximum record length limit is honoured.
253 . pdf*length.increment "\\$*\"
254 . ie (\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH.MAX]) \{\
256 . \" Adding this token would cause the current PDFMARK record, in
257 . \" groff's intermediate output file, to overflow the active record
258 . \" length limit, so post the current record and start another.
260 . pdf*pdfmark.dispatch
261 . ds pdf:composed.line "\\$*\"
265 . \" This token will fit in the current PDFMARK record, without
266 . \" violating the active length limit, so simply add it.
268 . ie d pdf:composed.line .as pdf:composed.line " \\$*\"
269 . el .ds pdf:composed.line "\\$*\"
273 .\" While assembling a multiple token literal sequence into a single
274 .\" literal token, successive calls to "pdf*compose" are directed
275 .\" to "pdf*compose.literal".
277 .de pdf*compose.literal
278 .\" ----------------------------------------------------------------
280 .\" .als pdf*compose pdf*compose.literal
281 .\" . pdf*compose TOKEN
282 .\" ----------------------------------------------------------------
284 .\" First, check to ensure that the current token can be appended to
285 .\" the accumulated literal, without extending it beyond the maximum
286 .\" allowed literal token length.
288 .length pdf:length "\\*[pdf:composed.literal] \\$*\"
289 .ie (\\n[pdf:length] > (\\n[PDFMARK.FOLDWIDTH] - 2)) \{\
291 .\" If it has grown too long, then it must be folded across two
292 .\" physical PDFMARK output records, so check if we can accommodate
293 .\" the portion collected so far within the current output record.
295 . pdf*length.increment "\\*[pdf:composed.literal]\"
296 . if (\\n[pdf:length] > (\\n[PDFMARK.FOLDWIDTH.MAX] - 2)) \{\
298 . \" The current output record CAN'T accommodate the currently
299 . \" composed portion of the literal, so flush out the current
300 . \" record, to make way for the accumulated literal, and mark
301 . \" the dispatch mode as "wrapped", for the fragments of the
302 . \" folded literal string, which are to follow.
304 . pdf*pdfmark.dispatch
305 . ds pdf*pdfmark.dispatch.wrapped
307 . ie d pdf:composed.line \{\
309 . \" If we DIDN'T need to flush the current output record,
310 . \" then we can simply append the accumulated literal to it...
312 . as pdf:composed.line " \\*[pdf:composed.literal]\"
316 . \" otherwise, when the current record has been flushed, or is
317 . \" empty, then we promote the accumulated literal, to make it
318 . \" the next output record...
320 . rn pdf:composed.literal pdf:composed.line
323 .\" Now, to complete the fold, flush out any accumulated partial
324 .\" output record, and continue accumulating the literal, starting
325 .\" with the current token.
327 . pdf*pdfmark.dispatch
328 . ds pdf:composed.literal "\\$*\"
332 .\" Alternatively, when we HAVEN'T identified a need to fold the
333 .\" current output record, then we simply append the current token
334 .\" to the accumulated literal token buffer string.
336 . as pdf:composed.literal " \\$*\"
339 .\" Having ensured that we have sufficient space, in which to
340 .\" append the current token to the currently accumulated literal,
341 .\" we check its rightmost character, to see if is the closing
342 .\" parenthesis, which completes the literal.
344 .ds pdf:compose.test \\$\\n(.$
345 .substring pdf:compose.test -1
346 .if ')'\\*[pdf:compose.test]' \{\
348 .\" The literal has been completely collected, so we may now append
349 .\" it to the current output record, as a single literal token, but
350 .\" subject to the constraint that it must not extend the output
351 .\" record beyond the maximum permitted length.
353 . pdf*length.increment "\\*[pdf:composed.literal]\"
354 . ie (\\n[pdf:length] > \\n[PDFMARK.FOLDWIDTH.MAX]) \{\
356 . \" So, when the literal cannot be accommodated within the maximum
357 . \" length constraint, then we flush the current record, and start
358 . \" a new one, with the literal token as its first entry.
360 . pdf*pdfmark.dispatch
361 . rn pdf:composed.literal pdf:composed.line
365 . \" When the literal CAN be accommodated within the maximum length
366 . \" constraint, then ...
368 . ie d pdf:composed.line \{\
370 . \" When an output record has already been instantiated, we
371 . \" append the literal token to it, and discard the accumulator
372 . \" string, which is no longer required.
374 . as pdf:composed.line " \\*[pdf:composed.literal]\"
375 . rm pdf:composed.literal
379 . \" But when no output record yet exists, then we simply
380 . \" reassign the accumulated literal token, to instantiate a
381 . \" new output record.
383 . rn pdf:composed.literal pdf:composed.line
387 .\" Finally, since we have completed the accumulation of the literal, we
388 .\" revert to the "unwrapped" mode of operation for "pdf*pdfmark.dispatch",
389 .\" and restore the normal "pdf*compose" action, for collection of the next
392 . rm pdf*pdfmark.dispatch.wrapped
393 . als pdf*compose pdf*compose.next
396 .\" While composing a multiple record PDFMARK, each composed record
397 .\" must be added to the collection, whenever the partially composed
398 .\" output record has been filled; this is handled when necessary,
399 .\" by calling the "pdf*pdfmark.dispatch" macro.
401 .de pdf*pdfmark.dispatch
402 .\" ----------------------------------------------------------------
404 .\" .pdf*pdfmark.dispatch
405 .\" ----------------------------------------------------------------
407 .if d pdf:composed.line \{\
409 .\" This is simply a wrapper around the overloaded "pdf*pdfmark.post"
410 .\" macro, ensuring that an output record has actually been collected
411 .\" before attempting to post it; it then cleans up after posting, to
412 .\" ensure that each collected record is posted only once.
414 . if d pdf*pdfmark.dispatch.wrapped \{\
416 . \" When dispatching an excessively long literal string, which
417 . \" must be wrapped over multiple records, this mode is active
418 . \" for all but the closing record; we must escape the newline
419 . \" at the end of each such unclosed literal record.
421 . as pdf:composed.line " \\\\\\\\\"
424 . rm pdf:composed.line
427 .\" For each PDFMARK, the first call of "pdf*pdfmark.post" is directed
428 .\" to the "pdf*pdfmark.post.first" macro; this initialises the state
429 .\" of the "pdf:composed" macro, for assembly of a new PDFMARK.
431 .de pdf*pdfmark.post.first
432 .de pdf:composed pdf*end
433 ps:exec \\*[pdf:composed.line]
436 .\" Subsequent calls to "pdf*pdfmark.post" are redirected to the
437 .\" alternative "pdf*pdfmark.post.next" macro, which simply appends
438 .\" additional PDFMARK records to the "pdf:composed" macro.
440 .als pdf*pdfmark.post pdf*pdfmark.post.next
442 .de pdf*pdfmark.post.next
443 .am pdf:composed pdf*end
444 \\*[pdf:composed.line]
447 .\" "pdf*end" is a dummy macro. It is required to mark the end
448 .\" of each individual fragment which is added to "pdf:composed";
449 .\" other than this, it does nothing.
454 .\" Some supporting macros defer actual pdfmark output until an
455 .\" appropriate time for it to be written; the "pdfsync" macro
456 .\" provides a mechanism for flushing such deferred output;
457 .\" it should be called from an end macro, and at any other time
458 .\" when it may be deemed necessary to flush pdfmark context.
461 .\" ----------------------------------------------------------------
463 .\" .pdfsync buffer ...
464 .\" Arguments indicate which "buffer(s)" to flush:
465 .\" O -> bookmark (outline) cache
466 .\" M -> document metadata diversion
467 .\" If no argument, flush ALL buffers
468 .\" ----------------------------------------------------------------
472 . if '\\$1'O' .pdf:bm.sync 1
474 . if dpdf:metadata .pdf:metadata
483 .\" some helper functions ...
485 .\" "pdf:warn" and "pdf:error" write diagnostic messages to stderr
488 .\" ----------------------------------------------------------
490 .\" .pdf:warn text of message
491 .\" ----------------------------------------------------------
493 .tm \\n(.F:\\n(.c: macro warning: \\$*
496 .\" ----------------------------------------------------------
498 .\" .pdf:error text of message
499 .\" ----------------------------------------------------------
501 .tm \\n(.F:\\n(.c: macro error: \\$*
503 .\" "pdf:pop", assisted by "pdf*pop", allows us to retrieve register,
504 .\" or string values, from a string masquerading as a data queue,
508 .\" ----------------------------------------------------------------
510 .\" .pdf:pop <type> <to-name> <from-name>
511 .\" $1 = nr for numeric register, ds for string
512 .\" $2 = name of register or string to be assigned
513 .\" $3 = name of string, from which data is to be retrieved
514 .\" ----------------------------------------------------------------
516 .pdf*pop \\$* \\*[\\$3]
522 .ie \\n(.$ .ds \\*[pdf:stack] \\$*
523 .el .rm \\*[pdf:stack]
528 .\" ===========================================================
529 .\" Module PDFINFO: Insert MetaData Entries into a PDF Document
530 .\" ===========================================================
533 .\" Output from the macros in this module is deferred, until
534 .\" subsequent invocation of .pdfsync, or .pdfexit
536 .\" ."pdfinfo" provides a general purpose form of metadata entry ...
537 .\" it allows arbitrary text to be associated with any specified
538 .\" metadata field name.
541 .\" -------------------------------------------------------------------
543 .\" .pdfinfo /FieldName field content ...
545 .\" .pdfinfo /Title A PDF Document
546 .\" .pdfinfo /Author Keith Marshall
547 .\" -------------------------------------------------------------------
549 .ds pdf:meta.field \\$1
552 \!.pdfmark \\*[pdf:meta.field] (\\$*) /DOCINFO
557 .\" Macro "pdfview" defines a special form of metadata entry ...
558 .\" it uses the /DOCVIEW pdfmark, to specify the initial (default) view,
559 .\" when the document is opened.
562 .\" -------------------------------------------------------------------
564 .\" .pdfview view parameters ...
566 .\" .pdfview /PageMode /UseOutlines
567 .\" .pdfview /Page 2 /View [/FitH \n(.p u]
568 .\" -------------------------------------------------------------------
571 \!.pdfmark \\$* /DOCVIEW
576 .\" =====================================================================
577 .\" Module PDFNOTE: Insert "Sticky Note" Style Comments in a PDF Document
578 .\" =====================================================================
580 .\" "PDFNOTE.WIDTH" and "PDFNOTE.HEIGHT" set the preferred size for
581 .\" display of the "sticky note" pane, when opened. Acrobat Reader
582 .\" seems not to honour these -- perhaps GhostScript doesn't encode
583 .\" them correctly! Anyway, let's set some suitable default values,
584 .\" in case the user has a set up which does work as advertised.
586 .nr PDFNOTE.WIDTH 3.5i
587 .nr PDFNOTE.HEIGHT 2.0i
589 .\" "pdf:bbox" defines the expression used to set the size and location
590 .\" of the bounding rectangle for display of notes and link "hot-spots".
591 .\" This is defined, such that a note is placed at troff's current text
592 .\" position on the current page, with its displayed image size defined
593 .\" by the "PDFNOTE.WIDTH" and "PDFNOTE.HEIGHT" registers, while the
594 .\" bounds for a link "hot-spot" are matched to the text region which
595 .\" defines the "hot-spot".
597 .ds pdf:bbox \\n[pdf:llx] u \\n[pdf:lly] u \\n[pdf:urx] u \\n[pdf:ury] u
599 .\" Getting line breaks into the text of a PDFNOTE is tricky -- we need
600 .\" to get a "\n" into the Postscript stream, but three levels of "\" are
601 .\" swallowed, when we invoke "pdfnote". The following definition of "PDFLB",
602 .\" (for LineBreak), is rather ugly, but does allow us to use
604 .\" .pdfnote Some text.\*[PDFLB]Some more text, on a new line.
606 .ds PDFLB \\\\\\\\\\\\\\\\n
609 .\" ----------------------------------------------------------------------
611 .\" .pdfnote [-T "Text for Title"] Text of note ...
612 .\" ----------------------------------------------------------------------
614 .if \\n[PDFOPMODE] \{\
616 .\" First, compute the bounding rectangle,
617 .\" for this PDFNOTE instance
620 . nr pdf:llx \\n(.k+\\n(.o+\\n[.in]
621 . nr pdf:lly \\n[pdf:ury]-\\n[PDFNOTE.HEIGHT]
622 . nr pdf:urx \\n[pdf:llx]+\\n[PDFNOTE.WIDTH]
623 . ds pdf:note.instance /Rect [\\*[pdf:bbox]]
625 .\" Parse any specified (recognisable) PDFNOTE options
627 . while dpdf:note\\$1 \{\
629 . shift \\n[pdf:note.argc]
632 .\" Emit the note, and clean up
634 . pdfmark \\*[pdf:note.instance] /Contents (\\$*) /ANN
635 . rm pdf:note.instance
641 .as pdf:note.instance " /Title (\\$2)
645 .\" =====================================================================
646 .\" Module PDFBOOKMARK: Add an Outline Reference in the PDF Bookmark Pane
647 .\" =====================================================================
649 .\" "PDFBOOKMARK.VIEW" controls how the document will be displayed,
650 .\" when the user selects a bookmark. This default setting will fit
651 .\" the page width to the viewing window, with the bookmarked entry
652 .\" located at the top of the viewable area.
654 .ds PDFBOOKMARK.VIEW /FitH \\n[PDFPAGE.Y] u
656 .\" "PDFOUTLINE.FOLDLEVEL" controls how the document outline will be
657 .\" displayed. It is a number, defining the maximum heading level
658 .\" which will be visible, without outline expansion by the user, in
659 .\" the initial view of the document outline. Assuming that no sane
660 .\" document will ever extend to 10,000 levels of nested headings,
661 .\" this initial default value causes outlines to be fully expanded.
663 .nr PDFOUTLINE.FOLDLEVEL 10000
665 .\" The actual job of creating an outline reference
666 .\" is performed by the "pdfbookmark" macro.
669 .\" ------------------------------------------------------------------
671 .\" .pdfbookmark [-T tag] level "Text of Outline Entry"
673 .\" $1 = nesting level for bookmark (1 is top level)
674 .\" $2 = text for bookmark, (in PDF viewer bookmarks list)
675 .\" $3 = suffix for PDF internal bookmark name (optional)
676 .\" ------------------------------------------------------------------
680 .\" When we are at the top diversion level, i.e. actually emitting text
681 .\" to the output device stream, then we compute the location of, and
682 .\" plant this bookmark immediately.
684 . if \\n[PDFOPMODE] \{\
686 . \" Make the bookmark name "untagged" by default,
687 . \" then parse any specified options, to set a "tag", if required
690 . while dpdf:href.opt\\$1 \{\
691 . pdf:href.opt\\$1 \\$@
692 . shift \\n[pdf:href.argc]
696 . \" If we found "--" to mark the end of the options, discard it
698 . if '\\$1'--' .shift
700 . \" Synchronise the bookmark cache
701 . \" to the requested bookmark nesting level
706 . \" Increment the bookmark serialisation index
707 . \" in order to generate a uniquely serialised bookmark name,
708 . \" ( which we return in the string "PDFBOOKMARK.NAME" ),
709 . \" and insert this bookmark into the cache
713 . ds PDFBOOKMARK.NAME pdf:bm\\n[pdf:bm.nr]\\*[pdf:href-T]
714 . ds pdf:bm\\n[pdf:bm.nr] /Dest /\\*[PDFBOOKMARK.NAME]
715 . pdfmark \\*[pdf:bm\\n[pdf:bm.nr]] /View [\\*[PDFBOOKMARK.VIEW]] /DEST
716 . as pdf:bm\\n[pdf:bm.nr] " /Title (\\$*)
717 . pdf:href.options.clear
723 .\" But when we are collecting a diversion which will be written out later,
724 .\" then we must defer bookmark placement, until we emit the diversion.
725 .\" (don't rely on $0 == pdfbookmark here; it may be a volatile alias).
727 . nop \!.pdfbookmark \\$@
731 .\" Macro "pdf:bm.sync" is called for each bookmark created,
732 .\" to establish a cache entry at the appropriate nesting level.
733 .\" It will flush ALL previous cache content, when called to
734 .\" add a new bookmark at level 1, or if simply called at
735 .\" level 1, without adding any bookmark.
738 .\" ------------------------------------------------------------------
740 .\" .pdf:bm.sync level
741 .\" $1 = nesting level of current bookmark, or 1 to flush cache
742 .\" ------------------------------------------------------------------
744 .\" First validate the bookmark nesting level
745 .\" adjusting it if required
747 .if \\$1>\\n[pdf:bm.nl] .nr pdf:bm.nl +1
748 .ie \\$1>\\n[pdf:bm.nl] \{\
749 . pdf:warn adjusted level \\$1 bookmark; should be <= \\n[pdf:bm.nl]
751 .el .nr pdf:bm.nl \\$1
752 .if \\n[pdf:bm.nl]<1 \{\
753 . pdf:warn bad arg (\\$1) in \\$0 \\$1; \\$0 1 forced
757 .\" If reverting from a higher to a lower nesting level,
758 .\" cyclicly adjust cache counts for each pending higher level
760 .if \\n[pdf:bm.lc]>=\\n[pdf:bm.nl] \{\
762 . if !rpdf:bm.c\\n[pdf:bm.lc].c .nr pdf:bm.c\\n[pdf:bm.lc].c 0
763 . while \\n[pdf:bm.lc]>\\n[pdf:bm.nl] \{\
764 . as pdf:bm.c\\n[pdf:bm.lc] " \\n[pdf:bm.c\\n[pdf:bm.lc].c]
765 . rr pdf:bm.c\\n[pdf:bm.lc].c
770 .\" Update the cache level,
771 .\" flushing when we are at level 1
773 .nr pdf:bm.lc \\n[pdf:bm.nl]
774 .ie \\n[pdf:bm.nl]=1 \{\
775 . while \\n[pdf:bm.ic]<\\n[pdf:bm.nr] .pdf:bm.emit 0
778 .el .nr pdf:bm.c\\n[pdf:bm.nl].c +1
780 .\" Macro "pdf:bm.emit" is called, when the cache is at level 1.
781 .\" This flushes ALL pending bookmarks from the cache, i.e. the
782 .\" preceding level 1 bookmark, and any nested dependents,
783 .\" which it may have.
786 .\" ------------------------------------------------------------------
788 .\" .pdf:bm.emit flag
789 .\" $1 = reference counting flag, used to control recursion
790 .\" ------------------------------------------------------------------
792 .\" First check for nested dependents,
793 .\" and append the "dependent count" to the bookmark, as required.
797 .pdf:pop nr pdf:bm.rc pdf:bm.c\\n[pdf:bm.lc]
798 .if \\n[pdf:bm.rc] \{\
800 . if \\n[pdf:bm.lc]>\\n[PDFOUTLINE.FOLDLEVEL] .ds pdf:bm.fold -
801 . as pdf:bm\\n[pdf:bm.ic] " /Count \\*[pdf:bm.fold]\\n[pdf:bm.rc]
804 .pdfmark \\*[pdf:bm\\n[pdf:bm.ic]] /OUT
805 .rm pdf:bm\\n[pdf:bm.ic]
807 .\" For ALL dependents, if any,
808 .\" recursively flush out any higher level dependents,
809 .\" which they themselves may have
811 .while \\n[pdf:bm.rc] \{\
813 . pdf:bm.emit \\n[pdf:bm.rc]
817 .\" unwind the recursive call stack, until we return to the top level.
828 .\" =============================================================
829 .\" Module PDFHREF: Create Hypertext References in a PDF Document
830 .\" =============================================================
832 .\" "PDFHREF.VIEW" controls how the document will be displayed,
833 .\" when the user follows a link to a named reference.
835 .ds PDFHREF.VIEW /FitH \\n[PDFPAGE.Y] u
837 .\" This default setting will fit the page width to the viewing
838 .\" window, with the bookmarked entry located close to the top
839 .\" of the viewable area. "PDFHREF.VIEW.LEADING" controls the
840 .\" actual distance below the top of the viewing window, where
841 .\" the reference will be positioned; 5 points is a reasonable
844 .nr PDFHREF.VIEW.LEADING 5.0p
847 .\" PDF view co-ordinates are mapped from the bottom left corner,
848 .\" of the page, whereas page printing co-ordinates are mapped
849 .\" conventionally, from top left.
851 .\" Macro "pdf:href.sety" transforms the vertical position of the
852 .\" last printed baseline, from the printing co-ordinate domain to
853 .\" the PDF view domain.
856 .\" ----------------------------------------------------------------
859 .\" ----------------------------------------------------------------
861 .\" This computation yields the vertical view co-ordinate
862 .\" in groff's basic units; don't forget to append grops' "u"
863 .\" conversion operator, when writing the pdfmark!
865 .nr PDFPAGE.Y \\n(.p-\\n(nl+\\n[PDFHREF.VIEW.LEADING]
867 .\" When we create a link "hot-spot" ...
868 .\" "PDFHREF.LEADING" sets the distance above the top of the glyph
869 .\" bounding boxes, in each line of link text, over which the link
870 .\" hot-spot will extend, while "PDFHREF.HEIGHT" sets the hot-spot
871 .\" height, PER LINE of text occupied by the reference.
873 .\" Since most fonts specify some leading space within the bounding
874 .\" boxes of their glyphs, a better appearance may be achieved when
875 .\" NEGATIVE leading is specified for link hot-spots; indeed, when
876 .\" the default 10pt Times font is used, -1.0 point seems to be a
877 .\" reasonable default value for "PDFHREF.LEADING" -- it may be
878 .\" changed, if desired.
880 .\" "PDFHREF.HEIGHT" is initially set as one vertical spacing unit;
881 .\" note that it is defined as a string, so it will adapt to changes
882 .\" in the vertical spacing. Changing it is NOT RECOMMENDED.
884 .nr PDFHREF.LEADING -1.0p
885 .ds PDFHREF.HEIGHT 1.0v
887 .\" PDF readers generally place a rectangular border around link
888 .\" "hot-spots". Within text, this looks rather ugly, so we set
889 .\" "PDFHREF.BORDER" to suppress it -- the three zeroes represent
890 .\" the border parameters in the "/Border [0 0 0]" PDFMARK string,
891 .\" and may be changed to any valid form, as defined in Adobe's
892 .\" PDFMARK Reference Manual.
894 .ds PDFHREF.BORDER 0 0 0
896 .\" "PDFHREF.COLOUR" (note British spelling) defines the colour to
897 .\" be used for display of link "hot-spots". This will apply both
898 .\" to borders, if used, and, by default to text; however, actual
899 .\" text colour is set by "PDFHREF.TEXT.COLOUR", which may be reset
900 .\" independently of "PDFHREF.COLOUR", to achieve contrasting text
901 .\" and border colours.
903 .\" "PDFHREF.COLOUR" must be set to a sequence of three values,
904 .\" each in the range 0.0 .. 1.0, representing the red, green, and
905 .\" blue components of the colour specification in the RGB colour
906 .\" domain, which is shared by "groff" and the PDF readers.
908 .ds PDFHREF.COLOUR 0.35 0.00 0.60
909 .defcolor pdf:href.colour rgb \*[PDFHREF.COLOUR]
911 .\" "PDFHREF.TEXT.COLOUR", on the other hand, is simply defined
912 .\" using any "groff" colour name -- this default maps it to the
913 .\" same colour value as "PDFHREF.COLOUR".
915 .ds PDFHREF.TEXT.COLOUR pdf:href.colour
917 .\" Accommodate users who prefer the American spelling, COLOR, to
918 .\" the British spelling, COLOUR.
920 .als PDFHREF.COLOR PDFHREF.COLOUR
921 .als PDFHREF.TEXT.COLOR PDFHREF.TEXT.COLOUR
923 .\" All PDF "Hypertext" reference capabilities are accessed
924 .\" through the "pdfhref" macro
927 .\" -----------------------------------------------------------------
929 .\" .pdfhref <subcommand [options ...] [parameters ...]> ...
930 .\" -----------------------------------------------------------------
932 .if \\n[PDFOPMODE] \{\
934 .\" Loop over all subcommands specified in the argument list
938 . \" Initially, assume each subcommand will complete successfully
942 . \" Initialise -E and -X flags in the OFF state
947 . \" Handle the case where subcommand is specified as "-class",
948 . \" setting up appropriate macro aliases for subcommand handlers.
950 . if dpdf*href\\$1 .als pdf*href pdf*href\\$1
951 . if dpdf*href\\$1.link .als pdf*href.link pdf*href\\$1.link
952 . if dpdf*href\\$1.file .als pdf*href.file pdf*href\\$1.file
954 . \" Repeat macro alias setup
955 . \" for the case where the subcommand is specified as "class",
956 . \" (without a leading hyphen)
958 . if dpdf*href-\\$1 .als pdf*href pdf*href-\\$1
959 . if dpdf*href-\\$1.link .als pdf*href.link pdf*href-\\$1.link
960 . if dpdf*href-\\$1.file .als pdf*href.file pdf*href-\\$1.file
962 . \" Process one subcommand ...
966 . \" Subcommand "class" is recognised ...
967 . \" discard the "class" code from the argument list,
968 . \" set the initial argument count to swallow all arguments,
969 . \" and invoke the selected subcommand handler.
976 . \" discard all arguments actually consumed by the handler,
977 . \" before proceeding to the next subcommand (if any).
979 . shift \\n[pdf:argc]
983 . \" Subcommand "class" is not recognised ...
984 . \" issue a warning, and discard the entire argument list,
985 . \" so aborting this "pdfhref" invocation
987 . pdf:warn \\$0: undefined reference class '\\$1' ignored
991 . \" Clean up temporary reference data,
992 . \" to ensure it doesn't propagate to any future reference
994 . rm pdf*href pdf:href.link pdf:href.files
995 . rr pdf:href-E pdf:href-X
996 . pdf:href.options.clear
1002 .\" Macros "pdf:href.flag" and "pdf:href.option"
1003 .\" provide a generic mechanism for switching on flag type options,
1004 .\" and for decoding options with arguments, respectively
1007 .\" ----------------------------------------------------------------------
1008 .\" ----------------------------------------------------------------------
1013 .\" ----------------------------------------------------------------------
1014 .\" ----------------------------------------------------------------------
1015 .ds pdf:href\\$1 \\$2
1019 .\" Valid PDFHREF options are simply declared
1020 .\" by aliasing option handlers to "pdf:href.option",
1021 .\" or to "pdf:href.flag", as appropriate
1023 .als pdf:href.opt-A pdf:href.option \" affixed text
1024 .als pdf:href.opt-D pdf:href.option \" destination name
1025 .als pdf:href.opt-E pdf:href.flag \" echo link descriptor
1026 .als pdf:href.opt-F pdf:href.option \" remote file specifier
1027 .als pdf:href.opt-N pdf:href.option \" reference name
1028 .als pdf:href.opt-P pdf:href.option \" prefixed text
1029 .als pdf:href.opt-T pdf:href.option \" bookmark "tag"
1030 .als pdf:href.opt-X pdf:href.flag \" cross reference
1032 .\" For references to another document file
1033 .\" we also need to support OS dependent file name specifiers
1035 .als pdf:href.opt-DF pdf:href.option \" /DOSFile specifier
1036 .als pdf:href.opt-MF pdf:href.option \" /MacFile specifier
1037 .als pdf:href.opt-UF pdf:href.option \" /UnixFile specifier
1038 .als pdf:href.opt-WF pdf:href.option \" /WinFile specifier
1040 .\" Macro "pdf:href.options.clear" ensures that ALL option
1041 .\" argument strings are deleted, after "pdfhref" has completed
1042 .\" all processing which depends on them
1044 .de pdf:href.options.clear
1045 .\" -----------------------------------------------------------------
1047 .\" .pdf:href.options.clear [option ...]
1048 .\" -----------------------------------------------------------------
1050 .\" When an option list is specified ...
1054 . \" then loop through the list,
1055 . \" deleting each specified option argument string in turn
1058 . if dpdf:href-\\$1 .rm pdf:href-\\$1
1063 .\" ... but when no list is specified,
1064 .\" then recurse, to clear all known option argument strings
1066 .el .pdf:href.options.clear A D F N P T DF MF UF WF
1069 .\" "PDFHREF.INFO" establishes the content of the cross reference
1070 .\" data record, which is exported via the "stderr" stream, when a
1071 .\" cross reference anchor is created using a "pdfhref" macro request
1074 .\" .pdfhref M -N name -X text ...
1076 .\" .ds PDFHREF.INFO \\*[PDFHREF.NAME] reference data ...
1078 .ds PDFHREF.INFO page \\n% \\$*
1080 .\" Macro "pdf*href-M" is the handler invoked by "pdfhref", when
1081 .\" called with the "M" reference class specifier, to create a
1082 .\" named cross reference mark, and to emit a cross reference
1083 .\" data record, as specified by "PDFHREF.INFO".
1086 .\" -----------------------------------------------------------------
1088 .\" .pdfhref M [-X] [-N name | -D name] [-E] descriptive text ...
1089 .\" -----------------------------------------------------------------
1091 .\" Initially, declare the -D and -N string options as empty,
1092 .\" so we avoid warning messages when we try to use them, and find
1093 .\" that they are undefined.
1098 .\" Parse, interpret, and strip any specified options from the
1099 .\" argument list. (Note that only options with a declared handler
1100 .\" will be processed; there is no provision for detecting invalid
1101 .\" options -- anything which is not recognised is assumed to start
1102 .\" the "descriptive text" component of the argument list).
1104 .while dpdf:href.opt\\$1 \{\
1105 . pdf:href.opt\\$1 \\$@
1106 . shift \\n[pdf:href.argc]
1109 .\" If we found "--", to mark the end of the options,
1110 .\" then we should discard it.
1112 .if '\\$1'--' .shift
1114 .\" All PDF reference markers MUST be named. The name may have been
1115 .\" supplied using the "-N Name" option, (or the "-D Name" option);
1116 .\" if not, deduce it from the first "word" in the "descriptive text",
1117 .\" if any, and set the marker -- if we still can't identify the name
1118 .\" for the destination, then this marker will not be created.
1120 .pdf*href.set \\*[pdf:href-N] \\*[pdf:href-D] \\$1
1122 .\" If we specified a cross reference, with the "-X" option, and the
1123 .\" reference mark has been sucessfully created, then we now need to
1124 .\" write the cross reference info to the STDERR stream
1126 .if \\n[pdf:href-X] .pdf*href.export \\*[PDFHREF.INFO]
1128 .\" Irrespective of whether this marker is created, or not,
1129 .\" the descriptive text will be copied to the groff output stream,
1130 .\" provided the "-E" option was specified
1132 .if \\n[pdf:href-E] \&\\$*
1136 .\" ----------------------------------------------------------------------
1137 .\" ----------------------------------------------------------------------
1141 . \" a marker name has been supplied ...
1142 . \" if we are formatting for immediate output,
1143 . \" emit PDFMARK code to establish the associated view
1147 . pdfmark /Dest /\\$1 /View [\\*[PDFHREF.VIEW]] /DEST
1148 . ds PDFHREF.NAME \\$1
1152 . \" but, when formatting a diversion ...
1153 . \" delay output of the PDFMARK code, until the diversion
1154 . \" is eventually written out
1158 . \" check if we also need to emit cross reference data
1159 . \" (caller will do this if "pdf:href-X" is set, but it is
1160 . \" not necessary, when "pdf:href.map" already exists)
1162 . if dpdf:href.map .nr pdf:href-X 0
1165 . \" marker is unnamed ...
1166 . \" issue error message; do not emit reference data
1168 . pdf:warn pdfhref destination marker must be named
1174 .\" Called ONLY by "pdf*href-M",
1175 .\" this macro ensures that the emission of exported reference data
1176 .\" is synchronised with the placement of the reference mark,
1177 .\" especially when the mark is defined within a diversion.
1179 .ie '\\n(.z'' .tm gropdf-info:href \\*[PDFHREF.NAME] \\$*
1183 .\" Macro "pdf*href-D" is invoked when "pdfhref" is called
1184 .\" with the "D" reference class specifier; it provides a
1185 .\" standardised mechanism for interpreting reference data
1186 .\" exported by the "M" reference class, and may be used
1187 .\" to directly define external reference data, without the
1188 .\" use of "M" reference class designators in the source
1194 .\" Parse, interpret, and strip any specified options from the
1195 .\" argument list. (Note that only options with a declared handler
1196 .\" will be processed; there is no provision for detecting invalid
1197 .\" options -- anything which is not recognised is assumed to start
1198 .\" the "descriptive text" component of the argument list).
1200 .while dpdf:href.opt\\$1 \{\
1201 . pdf:href.opt\\$1 \\$@
1202 . shift \\n[pdf:href.argc]
1205 .\" If we found "--", to mark the end of the options,
1206 .\" then we should discard it.
1208 .if '\\$1'--' .shift
1210 .ie '\\*[pdf:href-N]'' \{\
1211 . pdf:warn pdfhref defined reference requires a name
1214 . ds pdf:href(\\*[pdf:href-N]).info \\$*
1218 .\" Macro "pdf*href-F" is invoked when "pdfhref" is called
1219 .\" with the "F" reference class specifier; it allows the user
1220 .\" to provide an alternative interpreter macro, which will be
1221 .\" called when a "PDFHREF.INFO" record is retrieved to define
1222 .\" the text of a cross reference link "hot spot".
1225 .\" ----------------------------------------------------------------
1227 .\" .pdfhref F [macro-name]
1228 .\" ----------------------------------------------------------------
1230 .\" Set macro specified by "macro-name" as the format interpreter
1231 .\" for parsing "PDFHREF.INFO" records; if "macro-name" is omitted,
1232 .\" or is specified as the reserved name "default", then use the
1233 .\" default format parser, "pdf*href.format", defined below.
1235 .if '\\$1'default' .shift \\n(.$
1236 .ie \\n(.$ .als pdf*href.format \\$1
1237 .el .als pdf*href.format pdf*href.default
1240 .\" The default reference formatting macro is defined below.
1241 .\" It parses the "PDFHREF.INFO" record specific to each reference,
1242 .\" recognising the keywords "file", "page" and "section", when they
1243 .\" appear in initial key/value pairs, replacing the key/value pair
1244 .\" with "PDFHREF.FILEREF", "PDFHREF.PAGEREF" or "PDFHREF.SECTREF"
1245 .\" respectively; any additional data in the "PDFHREF.INFO" record
1246 .\" is enclosed in typographic double quotes, and the parsed record
1247 .\" is appended to "PDFHREF.PREFIX", to be returned as the formatted
1250 .\" Default definitions for the reference strings "PDFHREF.PREFIX",
1251 .\" "PDFHREF.FILEREF", "PDFHREF.PAGEREF" and "PDFHREF.SECTREF" are
1252 .\" provided, in the English language. Users may substitute any
1253 .\" desired alternative definitions, for example, when formatting
1254 .\" documents in other languages. In each case, "\\$1" may be used
1255 .\" in the substitution, to represent the "value" component of the
1256 .\" respective key/value pair specified in the "PDFHREF.INFO" record.
1258 .ds PDFHREF.PREFIX see
1259 .ds PDFHREF.PAGEREF page \\$1,
1260 .ds PDFHREF.SECTREF section \\$1,
1261 .ds PDFHREF.FILEREF \\$1
1264 .\" -----------------------------------------------------------------
1265 .\" Usage: (to be called ONLY by "pdfhref")
1266 .\" .pdf*href.format cross reference data ...
1267 .\" -----------------------------------------------------------------
1269 .\" This macro is responsible for defining the strings "PDFHREF.TEXT"
1270 .\" and "PDFHREF.DESC", which are used by the "pdfhref" macro, as the
1271 .\" basis for generating the text content of a link "hot spot"; (any
1272 .\" user specified alternate formatter MUST do likewise).
1274 .\" Note that "PDFHREF.TEXT" defines the overall format for the "link
1275 .\" text", while "PDFHREF.DESC" is the descriptive component thereof.
1277 .\" This default implementation, subject to user customisation of the
1278 .\" "internationalisation" strings defined above, formats "hot spots"
1281 .\" see page N, section S, "descriptive text ..."
1283 .ds PDFHREF.TEXT \\*[PDFHREF.PREFIX]
1284 .while d\\$0.\\$1 \{\
1289 .\" Retrieve the descriptive text from the cross reference data,
1290 .\" ONLY IF no overriding description has been set by the calling
1291 .\" "pdfhref" macro invocation.
1293 .if \\n(.$ .if !dPDFHREF.DESC .ds PDFHREF.DESC \\$*
1295 .\" Augment "PDFHREF.TEXT" so the descriptive text will be included
1296 .\" in the text of the formatted reference
1298 .if dPDFHREF.DESC .as PDFHREF.TEXT " \(lq\\\\*[PDFHREF.DESC]\(rq
1300 .\" Finally, suppress any leading spaces,
1301 .\" which may have been included in the PDFHREF.TEXT definition.
1303 .ds PDFHREF.TEXT \\*[PDFHREF.TEXT]
1305 .de pdf*href.format.file
1306 .\" ----------------------------------------------------------------------
1307 .\" Include a file identifier in a formatted reference.
1308 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1309 .\" reference data includes an initial file identifier tuple.
1310 .\" ----------------------------------------------------------------------
1312 .as PDFHREF.TEXT " \\*[PDFHREF.FILEREF]
1314 .de pdf*href.format.page
1315 .\" ----------------------------------------------------------------------
1316 .\" Include a page number in a formatted reference.
1317 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1318 .\" reference data includes an initial page number tuple.
1319 .\" ----------------------------------------------------------------------
1321 .as PDFHREF.TEXT " \\*[PDFHREF.PAGEREF]
1323 .de pdf*href.format.section
1324 .\" ----------------------------------------------------------------------
1325 .\" Include a section number in a formatted reference.
1326 .\" This is invoked ONLY by "pdf*href.format", and ONLY IF the
1327 .\" reference data includes an initial section number tuple.
1328 .\" ----------------------------------------------------------------------
1330 .as PDFHREF.TEXT " \\*[PDFHREF.SECTREF]
1333 .\" Make "pdf*href.format" the default cross reference formatter
1335 .als pdf*href.default pdf*href.format
1338 .\" Macro "pdf*href" provides a generic mechanism for placing link
1339 .\" "hot-spots" in a PDF document. ALL "pdfhref" class macros which
1340 .\" create "hot-spots" are aliased to this macro; each must also have
1341 .\" an appropriately aliased definition for "pdf*href.template".
1344 .\" ------------------------------------------------------------------
1346 .\" .pdf*href class [options ...] [link text ...]
1347 .\" ------------------------------------------------------------------
1349 .\" First, we initialise an empty string, which will be affixed to
1350 .\" the end of the "link text". (This is needed to cancel the effect
1351 .\" of a "\c" escape, which is placed at the end of the "link text"
1352 .\" to support the "-A" option -- any text supplied by the user, when
1353 .\" the "-A" option is specified, will replace this empty string).
1357 .\" Now we interpret, and remove any specified options from the
1358 .\" argument list. (Note that only options with a declared handler
1359 .\" will be processed; there is no provision for detecting invalid
1360 .\" options -- anything which is not recognised is assumed to start
1361 .\" the "link text" component of the argument list).
1363 .while dpdf:href.opt\\$1 \{\
1364 . pdf:href.opt\\$1 \\$@
1365 . shift \\n[pdf:href.argc]
1368 .\" If we found "--", to mark the end of the options, then we should
1371 .if '\\$1'--' .shift
1373 .\" All PDF link classes REQUIRE a named destination. This may have
1374 .\" been supplied using the "-D Name" option, but, if not, deduce it
1375 .\" from the first "word" in the "link text", if any -- if we still
1376 .\" can't identify the destination, then set "pdf:href.ok" to zero,
1377 .\" so this link will not be created.
1379 .if !dpdf:href-D .pdf:href.option -D \\$1
1380 .if '\\*[pdf:href-D]'' \{\
1381 . pdf:error pdfhref has no destination
1385 .\" Some PDF link classes support a "/File (FilePathName)" argument.
1387 .if dpdf*href.file \{\
1389 . \" When this is supported, it may be specified by supplying
1390 . \" the "-F FileName" option, which is captured in "pdf:href-F".
1392 . if dpdf:href-F \{\
1394 . \" the /File key is present, so set up the link specification
1395 . \" to establish the reference to the specified file
1397 . als pdf*href.link pdf*href.file
1398 . ds pdf:href.files /File (\\*[pdf:href-F])
1400 . \" in addition to the /File key,
1401 . \" there may also be platform dependent alternate file names
1403 . if dpdf:href-DF .as pdf:href.files " /DOSFile (\\*[pdf:href-DF])
1404 . if dpdf:href-MF .as pdf:href.files " /MacFile (\\*[pdf:href-MF])
1405 . if dpdf:href-UF .as pdf:href.files " /UnixFile (\\*[pdf:href-UF])
1406 . if dpdf:href-WF .as pdf:href.files " /WinFile (\\*[pdf:href-WF])
1408 . \" In some cases, the "/File" key is REQUIRED.
1409 . \" We will know it is missing, if "pdf*href.link" is not defined.
1411 . if !dpdf*href.link \{\
1413 . \" When a REQUIRED "/File" key specification is not supplied,
1414 . \" then complain, and set "pdf:href.ok" to abort the creation
1415 . \" of the current reference.
1417 . pdf:error pdfhref: required -F specification omitted
1420 . \" Now, we have no further use for "pdf*href.file".
1425 .\" Now, initialise a string, defining the PDFMARK code sequence
1426 .\" to create the reference, using the appropriate type indicators.
1428 .ds pdf:href.link /Subtype /Link \\*[pdf*href.link]
1430 .\" And now, we have no further use for "pdf*href.link".
1434 .\" If the user specified any "link prefix" text, (using the "-P text"
1435 .\" option), then emit it BEFORE processing the "link text" itself.
1437 .if dpdf:href-P \&\\*[pdf:href-P]\c
1438 .ie \\n[pdf:href.ok] \{\
1440 . \" This link is VALID (so far as we can determine) ...
1441 . \" Modify the "link text" argument specification, as required,
1442 . \" to include any pre-formatted cross reference information
1446 . \" One or more "link text" argument(s) are present,
1447 . \" so, set the link description from the argument(s) ...
1449 . ds PDFHREF.DESC \\\\$*
1450 . ie \\n[pdf:href-X] \{\
1452 . \" ... and, when the "-X" flag is set,
1453 . \" also include formatted location information,
1454 . \" derived from the cross reference record.
1456 . pdf*href.format \\*[pdf:href(\\*[pdf:href-D]).info]
1459 . \" ... but, when the "-X" flag is NOT set,
1460 . \" use only the argument(s) as the entire content
1461 . \" of the "link text"
1463 . rn PDFHREF.DESC PDFHREF.TEXT
1467 . \" No "link text" arguments are present,
1468 . \" so, format the cross reference record to define
1469 . \" the content of the "link text".
1471 . pdf*href.format \\*[pdf:href(\\*[pdf:href-D]).info]
1473 . \" Apply border and colour specifications to the PDFMARK string
1474 . \" definition, as required.
1476 . if dPDFHREF.BORDER .as pdf:href.link " /Border [\\*[PDFHREF.BORDER]]
1477 . if dPDFHREF.COLOUR .as pdf:href.link " /Color [\\*[PDFHREF.COLOUR]]
1479 . \" Emit the "link text", in its appropriate colour, marking the
1480 . \" limits of its bounding box(es), as the before and after output
1481 . \" text positions.
1483 . pdf*href.mark.begin "\\*[pdf:href.link]"
1484 . if dPDFHREF.COLOUR .defcolor pdf:href.colour rgb \\*[PDFHREF.COLOUR]
1485 . nop \&\m[\\*[PDFHREF.TEXT.COLOUR]]\\*[PDFHREF.TEXT]\m[]\c
1488 . \" Clean up the temporary registers and strings, used to
1489 . \" compute the "hot-spot" bounds, and format the reference,
1491 . rm PDFHREF.DESC PDFHREF.TEXT
1494 .\" But when we identify an INVALID link ...
1495 .\" We simply emit the "link text", with no colour change, no border,
1496 .\" and no associated "hot-spot".
1500 .\" And then, if the user specified any affixed text, (using the
1501 .\" "-A text" option), we tack it on at the end.
1503 .nop \&\\*[pdf:href-A]
1505 .de pdf*href.map.init
1506 .\" ----------------------------------------------------------------------
1507 .\" ----------------------------------------------------------------------
1509 .if dpdf:href.map-1 \{\
1511 . \" We have a reference map, but we haven't started to parse it yet.
1512 . \" This must be the first map reference in pass 2, so we need to
1513 . \" "kick-start" the parsing process, by loading the first indexed
1514 . \" sub-map into the global map.
1516 . rn pdf:href.map-1 pdf:href.map
1517 . als pdf:href.map.internal pdf:href.map
1518 . nr pdf:href.map.index 1 1
1520 .als pdf*href.map.init pdf*href.mark.idle
1523 .\" "pdf*href-Z" is used to add link co-ordinate entries to the
1524 .\" "pdf:href.map". Primarily, it is used by the "pdfroff" formatter,
1525 .\" to pass link co-ordinate data from one "groff" formatting pass to
1526 .\" the next, and is not generally useful to the end user.
1529 .\" ----------------------------------------------------------------------
1531 .\" .pdfhref Z page-index x-displacement y-displacement
1533 .\" page-index is the reference mark's page number
1534 .\" x-displacement is its offset from the left edge of the page
1535 .\" y-displacement is its offset from the top edge of the page
1536 .\" ( both displacement values are expressed in basic groff units, )
1537 .\" ( and measured perpendicular to their respective page edges. )
1538 .\" ----------------------------------------------------------------------
1540 .ie \\n(.$=3 .ds pdf:href.map-\\n+[pdf*href-Z.index] \\$*
1541 .el .pdf:error pdfhref Z operator expects exactly three arguments
1543 .\" Initialise the auto-incrementing "pdf*href-Z.index" register,
1544 .\" to ensure that sub-map numbering starts at 1.
1546 .nr pdf*href-Z.index 0 1
1548 .de pdf*href.map.read
1549 .\" ----------------------------------------------------------------------
1550 .\" Usage: (internal use only):
1551 .\" .pdf*href.map.read co-ordinate name list ...
1552 .\" ----------------------------------------------------------------------
1554 .\" Reads values from "pdf:href.map" to each named register, in turn
1555 .\" Reading to "null" discards the corresponding value in "pdf:href.map"
1559 . \" Loop over all registers named in the argument list,
1560 . \" assigning values from "pdf:href.map" to each in turn.
1562 . pdf:pop nr pdf:\\$1 pdf:href.map.internal
1563 . if !dpdf:href.map.internal \{\
1565 . \" We ran out of map references in the current sub-map,
1566 . \" so move on to the next indexed sub-map, if any.
1568 . if dpdf:href.map-\\n+[pdf:href.map.index] \{\
1569 . rn pdf:href.map-\\n[pdf:href.map.index] pdf:href.map
1570 . als pdf:href.map.internal pdf:href.map
1574 . \" Proceed to the next named co-ordinate, (if any), specified
1575 . \" in the argument list.
1580 .\" Discard any assignments to a register named "null"
1584 .de pdf*href.mark.begin
1585 .\" ----------------------------------------------------------------------
1586 .\" ----------------------------------------------------------------------
1588 .ie dpdf:href.map \{\
1590 . \" Once we have established a document reference map,
1591 . \" then this, and all subsequent calls to "pdf*href.mark.begin",
1592 . \" may be redirected to the reference mark resolver, and the
1593 . \" "pdf*href.mark.end" macro has nothing further to do.
1595 . pdf*href.mark.resolve \\$@
1596 . rn pdf*href.mark.resolve pdf*href.mark.begin
1597 . als pdf*href.mark.end pdf*href.mark.idle
1600 . \" Since we don't yet have a document reference map, the
1601 . \" reference mark resolver will not work, in this pass of the
1602 . \" formatter; this, and all subsequent calls to "pdf*href.mark.begin",
1603 . \" may be redirected to "pdf*href.mark.end", which is responsible
1604 . \" for emitting the reference mark data to be incorporated into
1605 . \" the reference map in a subsequent formatting pass.
1608 . als pdf*href.mark.begin pdf*href.mark.end
1611 .de pdf*href.mark.resolve
1612 .\" ----------------------------------------------------------------------
1613 .\" ----------------------------------------------------------------------
1615 . ds pdf:href.link \\$1
1616 . nr pdf:urx \\n(.o+\\n(.l
1617 . pdf*href.map.read spg llx ury epg urx.end lly.end
1618 . ie \\n[pdf:spg]=\\n[pdf:epg] \{\
1620 . \" This link is entirely contained on a single page ...
1621 . \" emit the text, which defines the content of the link region,
1622 . \" then make it active.
1624 . pdf*href.mark.emit 1 \\n[pdf:urx.end]
1625 . if \\n[pdf:lly]<\\n[pdf:lly.end] \{\
1627 . \" This link spans multiple output lines; we must save its
1628 . \" original end co-ordinates, then define a new intermediate
1629 . \" end point, to create a PDFMARK "hot-spot" extending from
1630 . \" the start of the link to the end if its first line.
1633 . nr pdf:llx \\n(.o+\\n[.in]
1634 . nr pdf:lly \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1635 . if \\n[pdf:ury]<\\n[pdf:lly] \{\
1636 . nr pdf:lly +\\*[PDFHREF.HEIGHT]-1v
1637 . pdf*href.mark.emit 2
1638 . nr pdf:ury \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1640 . pdf*href.mark.emit 0 \\n[pdf:urx.end]
1642 . pdf*href.mark.flush
1645 . \" This link is split across a page break, so ...
1646 . \" We must mark the "hot-spot" region on the current page,
1647 . \" BEFORE we emit the link text, as we will have moved off
1648 . \" this page, by the time the text has been output.
1650 . \" First step: define the region from the start of the link,
1651 . \" to the end of its first line.
1653 . pdf*href.mark.emit 1 \\n[pdf:urx]
1655 . \" All additional regions MUST align with the left margin.
1657 . nr pdf:llx \\n(.o+\\n[.in]
1659 . \" If the current page can accomodate more than the current line,
1660 . \" then it will include a second active region for this link; this
1661 . \" will extend from just below the current line to the end of page
1662 . \" trap, if any, or the bottom of the page otherwise, and occupy
1663 . \" the full width of the page, between the margins.
1666 . pdf*href.mark.emit 3
1668 . \" We now need a page transition trap, to map the active link
1669 . \" region(s), which overflow on to the following page(s); (the
1670 . \" handler for this trap MUST have been previously installed).
1672 . ie dpdf*href.mark.hook \{\
1674 . \" The page transition trap handler has been installed,
1675 . \" so we may activate both it, and also the appropriate
1676 . \" termination handler, to deactivate it when done.
1678 . als pdf*href.mark.hook pdf*href.mark.trap
1680 . \" Now we set up "pdf:epg" to count the number of page breaks
1681 . \" which this link will span, and emit the link text, leaving
1682 . \" the page trap macro to map active regions on intervening
1683 . \" pages, which are included in the link.
1685 . nr pdf:epg -\\n[pdf:spg] 1
1688 . \" There was no handler initialised for the page trap,
1689 . \" so we are unable to map the active regions for this link;
1690 . \" we may discard the remaining map data for this link,
1691 . \" and issue a diagnostic.
1693 . pdf:error pdfhref: link dissociated at page break (trap not initialised)
1694 . if dPDFHREF.BROKEN.COLOR \{\
1696 . \" The user may opt to have such broken links highlighted.
1697 . \" We use "PDFHREF.BROKEN.COLOUR" to specify this requirement,
1698 . \" but the user may prefer the American spelling, so we will
1699 . \" handle both as equivalent.
1701 . als PDFHREF.BROKEN.COLOUR PDFHREF.BROKEN.COLOR
1703 . if dPDFHREF.BROKEN.COLOUR \{\
1704 . if dPDFHREF.COLOUR .als PDFHREF.COLOUR PDFHREF.BROKEN.COLOUR
1712 .\" Macro "pdf*href.mark.emit" is called only by "pdf*href". It is
1713 .\" responsible for emitting the PDFMARK code, to establish the
1714 .\" "hot-spot" region associated with a document or resource link.
1716 .de pdf*href.mark.emit
1717 .\" ----------------------------------------------------------------------
1719 .\" .pdf*href.mark.emit <action> [<end-urx>]
1720 .\" <action> == 0 --> normal operation -- link height = 1 line
1721 .\" <action> == 1 --> start of link -- add leading above text
1722 .\" <action> == 2 --> overtall link -- set intermediate baseline
1723 .\" <action> == 3 --> split link -- break at bottom of page
1724 .\" ----------------------------------------------------------------------
1728 . \" Initialising a new link region ...
1729 . \" Some different versions of "groff" disagree about the vertical
1730 . \" displacement of "opminy", as emitted by "\O1|\h'-\w"|"u'\O2\c",
1731 . \" relative to the current text baseline. Therefore, recompute
1732 . \" the link displacement, independently of "opminy".
1735 . while \\n[pdf:ury.base]<\\n[pdf:ury] .nr pdf:ury.base +1v
1736 . nr pdf:ury.base -1m+\\n[PDFHREF.LEADING]
1738 . \" adjust the end-point vertical displacement by the same offset,
1739 . \" and then relocate the link starting point to its new displacement,
1740 . \" as established by this base line relative computation.
1742 . nr pdf:lly.end +\\n[pdf:ury.base]-\\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1743 . rnn pdf:ury.base pdf:ury
1747 . \" Link segment fits on a single line ...
1748 . \" Set its height and end-point horizontal displacement accordingly.
1750 . nr pdf:lly \\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1751 . if \\n[pdf:lly]>=\\n[pdf:lly.end] .nr pdf:urx \\$2
1755 . \" Link segment extends beyond the next page break ...
1756 . \" Recompute truncated height, to just fit portion on current page,
1757 . \" recursing to emit it, and leaving page trap mechanism to place
1758 . \" continuation region(s) on following page(s).
1760 . nr pdf:lly (\\n[.t]u-\\n[.V]u)/1v
1761 . if \\n[pdf:lly]>0 \{\
1762 . nr pdf:lly \\n[pdf:ury]+\\n[pdf:lly]v-1v+\\*[PDFHREF.HEIGHT]
1763 . pdf*href.mark.emit 2
1767 . \" Link region size and placement has been fully specified ...
1770 . pdfmark \\*[pdf:href.link] /Rect [\\*[pdf:bbox]] /ANN
1774 .\" When "pdf*href" emits a link for which the "hot-spot" spans a
1775 .\" page break, then we need to provide a "hook" in to the page break
1776 .\" trap, so we can map the "hot-spot" regions which are to be placed
1777 .\" on either side of the page break.
1779 .\" Macro "pdf*href.mark.idle" is a dummy macro, which provide this
1780 .\" "hook" for normal page breaks, where there is no link "hot-spot"
1781 .\" crossing the break.
1783 .de pdf*href.mark.idle
1784 .\" ----------------------------------------------------------------------
1786 .\" Called only as an internal hook, by a page trap macro.
1787 .\" Expects no arguments, and does nothing.
1788 .\" ----------------------------------------------------------------------
1791 .\" Macro "pdf*href.mark.trap" is the active "hook", which is substituted
1792 .\" for "pdf*href,mark.idle" at those page breaks which are crossed by
1793 .\" a link "hot-spot".
1795 .de pdf*href.mark.trap
1796 .\" ----------------------------------------------------------------------
1798 .\" Called only as an internal hook, by a page trap macro.
1799 .\" Expects no arguments. Maps residual link "hot-spot" regions,
1800 .\" which spill beyond any page break. Not to be invoked directly
1801 .\" by the user, nor by any user supplied macro.
1802 .\" ----------------------------------------------------------------------
1805 .nr pdf:ury +1v-1m-\\n[PDFHREF.LEADING]
1806 .ie \\n-[pdf:epg] \{\
1808 . \" The link "hot-spot" extends across more than one page break,
1809 . \" so, for each page which is completely contained within the
1810 . \" extent of the link, simply mark the entire text area on the
1811 . \" page as a "hot-spot".
1813 . pdf*href.mark.emit 3
1816 . \" The link "hot-spot" ends on the page which immediately follows
1817 . \" the current page transition, so we may now finalise this link.
1819 . nr pdf:lly \\n[pdf:ury]+\\*[PDFHREF.HEIGHT]
1820 . if \\n[pdf:lly.end]>\\n[pdf:lly] \{\
1822 . \" The "hot-spot" extends beyond the first line of text,
1823 . \" on its final page; compute and emit "hot-spot" region to cover
1824 . \" the full with of the text area, including all but the last
1825 . \" line of the link text.
1827 . while \\n[pdf:lly.end]>\\n[pdf:lly] .nr pdf:lly +1v
1829 . pdf*href.mark.emit 2
1831 . \" Now, adjust the vertical "hot-spot" mapping reference,
1832 . \" to identify the correct position for the the last line of
1833 . \" text, over which the "hot-spot" extends.
1835 . nr pdf:ury \\n[pdf:lly.end]-\\*[PDFHREF.HEIGHT]
1838 . \" We now have exactly one final line of text, over which we must
1839 . \" emit a "hot-spot" region; map it, terminate page trap processing
1840 . \" for this "hot-spot", and clean up the "hot-spot" mapping context.
1842 . pdf*href.mark.emit 0 \\n[pdf:urx.end]
1843 . als pdf*href.mark.hook pdf*href.mark.idle
1844 . pdf*href.mark.flush
1847 .de pdf*href.mark.flush
1848 .\" ----------------------------------------------------------------------
1849 .\" ----------------------------------------------------------------------
1851 .rr pdf:llx pdf:lly pdf:urx pdf:ury
1852 .if dPDFHREF.COLOR .als PDFHREF.COLOUR PDFHREF.COLOR
1853 .rr pdf:urx.end pdf:lly.end
1855 .de pdf*href.mark.end
1856 .\" ----------------------------------------------------------------------
1857 .\" ----------------------------------------------------------------------
1858 \O1|\h'-\w"|"u'\O2\c
1860 .\" Macro "pdf*href-I" is used for one time initialisation of special
1861 .\" "pdfhref" features; (currently, only the above page trap hook is
1862 .\" supported, but it is implemented with one level of indirection, to
1863 .\" accommodate possible future expansion).
1866 .\" ----------------------------------------------------------------------
1868 .\" .pdfhref I -<option> <optarg> [-<option> <optarg>] ...
1869 .\" ----------------------------------------------------------------------
1871 .\" Loop over all arguments, in pairs ...
1875 . \" handing them off to their respective initialisers,
1876 . \" when suitable initialisers exist, or complaining otherwise.
1878 . ie dpdf*href\\$1.init .pdf*href\\$1.init \\$2
1879 . el .pdf*error pdfhref:init: unknown feature '\\$1'
1883 .\" Before we can use the page break "hook", we need to initialise it
1884 .\" as an addendum to a regular page break trap. To ensure that we don't
1885 .\" compromise the user's page trap setup, we leave the onus for this
1886 .\" initialisation with the user, but we provide the "pdf*href-PT.init"
1887 .\" macro, (invoked by ".pdfhref I -PT <macro-name>"), to implement a
1888 .\" suitable initialisation action.
1890 .de pdf*href-PT.init
1891 .\" ----------------------------------------------------------------------
1893 .\" .pdfhref I -PT <macro-name>
1894 .\" <macro-name> == name of user's page break trap macro
1895 .\" ----------------------------------------------------------------------
1897 .\" Initially, map the page break hook to its default, do nothing helper.
1899 .als pdf*href.mark.hook pdf*href.mark.idle
1902 . \" Don't have enough arguments to specify a page trap macro name,
1903 . \" so simply plant "pdf*href.mark.hook" as a top of page trap.
1905 . wh 0 pdf*href.mark.hook
1908 . \" Page trap macro name is specified in "\\$1" ...
1912 . \" When this page trap macro already exists, then we simply
1913 . \" append a call to "pdf*href.mark.hook" to it.
1915 . am \\$1 pdf*href.mark.idle
1916 . pdf*href.mark.hook
1917 . pdf*href.mark.idle
1920 . \" However, when the specified page trap macro does not yet
1921 . \" exist, then we create it, and plant it as a top of page
1924 . de \\$1 pdf*href.mark.idle
1925 . pdf*href.mark.hook
1926 . pdf*href.mark.idle
1932 .\" "pdf*href-L" is the generic handler for creating references to
1933 .\" named destinations in PDF documents. It supports both local
1934 .\" references, to locations within the same document, through its
1935 .\" "pdf*href-L.link" attribute, and also references to locations
1936 .\" in any other PDF document, through "pdf*href-L.file".
1938 .als pdf*href-L pdf*href
1939 .ds pdf*href-L.link /Dest /\\\\*[pdf:href-D]
1940 .ds pdf*href-L.file /Action /GoToR \\\\*[pdf:href.files] \\*[pdf*href-L.link]
1942 .\" "pdf*href-O" is the "official" handler for creating PDF
1943 .\" document outlines. It is simply an alias to "pdfbookmark",
1944 .\" which may also be invoked directly, if preferred. Neither
1945 .\" a "pdf*href-O.link" nor a "pdf*href-O.file" attribute is
1948 .als pdf*href-O pdfbookmark
1950 .\" "pdf*href-W" is the generic handler for creating references to
1951 .\" web resources, (or any resource specified by a uniform resource
1952 .\" identifier). Such resource links are fully specified by the
1953 .\" "pdf*href-W.link" attribute.
1955 .als pdf*href-W pdf*href
1956 .ds pdf*href-W.link /Action << /Subtype /URI /URI (\\\\*[pdf:href-D]) >>
1958 .\" pdfmark.tmac: end of file / vim: ft=groff