[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] pdfmark, URI and coordinates of output text
From: |
Werner LEMBERG |
Subject: |
Re: [Groff] pdfmark, URI and coordinates of output text |
Date: |
Wed, 19 Nov 2003 21:14:33 +0100 (CET) |
> But is has essentially one major failure-- I need to get the x,y
> position where my URL is displayed and where is ends, and I simply
> can't do that correctly. I've tried lots of different setups, using
> \n[hp] \k[reg] |0 and others, but that doesn't appear to work.
>
> Currenly I'm using .mk to get vertical position and
> \n[.k]+\n[.o]+\n[.in] to get horizontal position.
This is the correct way.
> This only works if the URL is kept on a single line. We can force
> this to happen if we disable hyphenation temporarly, but there is a
> problem I can't fix: when the complete URL wraps into the other
> line. I can not detect (but have tried!) when this happens.
What you want to do is not possible with groff in a single pass. The
same problem occurs while defining a macro for continuous underlining.
Line breaks are computed after all groff input tokens have been
processed. Note that TeX has exactly the same problem, and there is a
special code in pdftex to handle URLs which contain a line break.
For the moment I suggest to use Gaius's solution, in combination with
a yet-to-be-written script `makepdfmark' which processes the lines
written by \O2 to stderr:
groff -Z foo > /dev/null 2> foo.log
makepdfmark < foo.log > foo.aux
groff foo.aux foo > foo.ps
In the first run, a PSHREF call does something like this to mark the
start and end of an HREF:
.nr pshref-count 0
.
.de PSHREF
. tmc pshref: \\n[pshref-count]-start: \"
. nop \&\O1\m[white]|\m[]\h'-\w'|'u'\O2\c
. tmc pshref: \\n[pshref-count]-end: \"
. ie !'\\$3'' \
. nop \\$3\O1\m[white]|\m[]\h'-\w'|'u'\O2\c
. el \
. nop \\$1\O1\m[white]|\m[]\h'-\w'|'u'\O2\c
. nr pshref-count +1
..
[The trick with the white colour to print an invisible `|' with no
width is a workaround to make \O output something useful.]
This produces lines like this (broken for better readability):
pshref: 1-start: grohtml-info:page 1 145610 89240 147610 96140 \
504000 1 1 pshref.me
pshref: 1-end: grohtml-info:page 1 313860 89240 315860 96140 \
504000 1 1 pshref.me
pshref: 2-start: grohtml-info:page 1 436040 101240 438040 108140 \
504000 1 1 pshref.me
pshref: 2-end: grohtml-info:page 1 175620 113240 177620 120140 \
504000 1 1 pshref.me
...
makepdfmark should convert the data to something like this:
.ds pdfref-1 ps: exec [ /Rect [145610 u 89240 u 313860 u 96140 u] \
/Border [0 0 \\n[wid]] \
/Action << /Subtype /URI /URI (\\$1) >> \
/Subtype /Link \
/ANN pdfmark'\c
...
[The `u' command (defined by grops) converts groff units to PS units.]
At the second run, groff reads in the file foo.aux which contains
those number definitions which can subsequently be used by a second
version of PSHREF (using \Y to read the defined pdfref-XXX strings).
The whole process is quite similar to the `makeindex' stuff of TeX.
To simplify the process, making an external script obsolete, I'll
probably add a variation of the \O escape to groff which will write
just the current position *after* formatting to a file instead of
stderr. Suggestions are highly welcome.
Werner