[cl-typesetting-devel] Page n of m?

Peter Seibel peter at javamonkey.com
Fri Oct 1 20:55:48 UTC 2004


"Marc Battyani" <marc.battyani at fractalconcept.com> writes:

> Peter Seibel <peter at javamonkey.com> writes:
>>
>> Cool. BTW, my code also genenerated headers out of order. At least I
>> think so--I compile-text the main body of my document which includes
>> the mark-ref-point call and then I loop using compile-text to build a
>> header and drawing the individual pages. And that worked with just my
>> patch. (You can see my code in earlier messages.)
>>
>> > Checking if the x and y coordonates have changed is probably too
>> > strict and will give many redefined refs IMO.
>>
>> Yes. I did have to bump up *max-number-of-passes* to get it to
>> actually settle down. (Took three passes instead of two.)
>
> It can potentially never completely settle with the floats computations.
>
> I finished the rewriting of the references processing with only one ref
> table. I discarded all the "previous" stuff.
>
> Can you please tests if it still work for you.

Yup, looks good. Thanks.

In the meantime I gave contextual variables a whirl, trying to add the
name of the current chapter to my headers. And it works great except
the very first time I call get-contextual-variable it returns NIL.
Basically I modified this function that emits the chapter headers.

  (defmethod emit-pdf-by-type ((type (eql 'text-parser::chapter)) children)
    (typeset::fresh-page)
    (typeset::set-contextual-variable 'chapter-name (first children)) ;; <--- new
    (typeset::paragraph
     (:h-align :left :font "Helvetica" :font-size 24)
     (typeset::vspace 24)
     (dolist (c children) (emit-pdf c))))

and then changed my sexp->pdf function to use get-contextual-variable
to get at the chapter when compiling the header:

  (defun sexp->pdf (paragraphs &optional (file #P"/tmp/hello.pdf"))
    (let ((*note-counter* 0)
          (*notes* nil))
      (typeset:with-document ()
        (let ((content
               (typeset::compile-text ()
                 (let ((*my-leading-ratio* 2.0))
                   (dolist (p paragraphs) (emit-pdf p)))
                 (typeset::vspace 24)
                 (typeset::hrule :dy .1)
                 (typeset::vspace 6)
                 (let ((*default-font-size* 10))
                   (loop for n in (nreverse *notes*)
                         for counter from 1
                         do (emit-note counter n)))
                 (typeset:mark-ref-point :the-end))))
          (loop
             for header = (typeset::compile-text ()
                            (typeset::paragraph
                                (:h-align :right :font "Times-Italic" :font-size 10)
                              (typeset::put-string 
                               (format nil "~a~c~d of ~d"
                                       (typeset::get-contextual-variable 'chapter-name)
                                       +mdash+
                                       (1+ pdf:*page-number*)
                                       (typeset:find-ref-point-page-number :the-end)))
                              :eol
                              (typeset::put-string
                               (format nil "Copyright ~c 2003-2004, Peter Seibel." +copyright+))
                              :eol
                              (typeset::put-string (date-string))
                              :eol))
             while (typeset::boxes content)
             do (draw-page
                 content
                 header
                 :width 612
                 :height 792
                 :margins '(72 36 72 72)
                 :header-height (- 108 36))))
        (pdf:write-document file)))
    (truename file))

It works fine for all but the first page. Even when the chapter
changes--the header on the first page of all the chapters after the
first gets the right title. Any suggestions.

-Peter

-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the cl-typesetting-devel mailing list