[cl-typesetting-devel] Page n of m?
Bob Hutchison
hutch at recursive.ca
Fri Oct 1 12:52:19 UTC 2004
On Oct 1, 2004, at 4:31 AM, Marc Battyani wrote:
> Marc Battyani wrote:
>> Peter Seibel <peter at javamonkey.com> writes:
>>>
>>> Okay, that makes sense. So is my workaround the Right Way or a nasty
>>> kludge?
>>
>> You really want to know ? ;-)
>>
>> I will have a deeper look at all this tomorow.
>
> I've looked at it. the reason why it worked well for me and not for
> you was
> because I used the reference in the text while you were using it only
> in the
> footer. It turn out that the footer can be called in a rather out of
> order
> way relative to the normal flow of the text (at stroking time). So the
> right
> way is to add a located-p to the ref class as a ref can be defined but
> not
> yet located when it is seen from a footer.
> I hope I'm clear enough. Anyway now Bob' example works.
>
> The new version is on the repositories.(get cl-pdf also)
> Please tell me if this works in your case now.
I've checked this out, and it works for all of my other examples as
well. Thanks.
>
> Another nice stuff related to references is the contextual variables.
> Have
> you looked at it ?
I just had a look. I added a contextual variable to keep track of the
paragraph count and I can show it in the header (yes, I know it isn't a
great example). Interesting effect going on, not sure why either, but
it seems that the paragraph count is not updated until after the whole
paragraph is completed (i.e. the counter will contain the number of the
last completed paragraph on the page). Actually, when I think about
it... when is the header 'computed' for the page? How is this working
at all? I've added the modified example at the end of this post.
It looks as though we can have a stack of values with contextual
variables, so I guess this means that I could keep track of the current
section title, pushing and popping as the sections nest. What did you
have in mind for these?
I also see that there are contextual actions. What did you have in mind
for these? What kind of thing can you do here? When are these called?
They are triggered by the stroke method, so these are executed at
drawing time?
Cheers,
Bob
(defun page-n-of-m (&optional (file #P"/tmp/page-n-of-m.pdf")
&aux (content nil) (margins '(72 72 72 50)))
(with-document ()
(let* ((print-stamp (multiple-value-bind (second minute hour date
month year)
(get-decoded-time)
(declare (ignore second))
(format nil "Printed on ~4D-~2,'0D-~2,'0D
~2,'0D:~2,'0D"
year month date hour minute)))
(sentence1 "The quick brown fox jumps over the lazy dog. ")
(sentence2 " associate associates declination obligatory
philanthropic.")
(header (lambda (pdf:*page*)
(compile-text ()
(hbox (:align :center :adjustable-p t)
:hfill
(verbatim
(format nil "Multi-page example document
(paragraph ~A)"
(tt::get-contextual-variable
:current-paragraph-number -1))))
(hrule :dy 1/2))))
(footer (lambda (pdf:*page*)
(compile-text (:font "Helvetica" :font-size 10)
(hrule :dy 1/2)
(hbox (:align :center :adjustable-p t)
(verbatim print-stamp)
:hfill
(verbatim
(format nil "Page ~d of ~d" pdf:*page-number*
(tt::find-ref-point-page-number
:end-of-doc))))))))
(format t "about to compile...~%")
(setq content
(compile-text ()
(paragraph (:font "Times-Bold" :font-size 16 :top-margin
20)
"2. Second paragraph group"
(hrule :dy 2))
(dotimes (i 400)
(tt::set-contextual-variable :current-paragraph-number
i)
(paragraph (:font "Times-Roman" :font-size (+ 6 (random
10)) :h-align :justified)
(verbatim (format nil "2.~d. " (1+ i)))
(dotimes (j (1+ (random 5)))
(put-string sentence2))))
(unless (typeset::find-ref-point :end-of-doc)
(tt::mark-ref-point :end-of-doc))))
(format t "about to draw...~%")
(draw-pages content :margins margins :header header :footer
footer))
(when pdf:*page* (finalize-page pdf:*page*))
(format t "current pass: ~A ~A, undefined references: ~A,
changed-references: ~A~%" tt::*current-pass* (if (tt::final-pass-p)
"FINAL" "") tt::*undefined-references* tt::*changed-references*)
(when (tt::final-pass-p)
(format t "WRITE THE DOCUMENT NOW~%")
(pdf:write-document file))))
More information about the cl-typesetting-devel
mailing list