[cl-typesetting-devel] Anyway to measure the size of some text

Peter Seibel peter at javamonkey.com
Tue Oct 5 20:40:50 UTC 2004


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

> Peter Seibel wrote:
>
>
>> Is there any way to determine the "natural" size of some generated
>> text? 

> META-WEB 20 > (typeset::compute-boxes-natural-size (typeset::boxes
> *content*) 'typeset::dx)
> 54.83
>
> META-WEB 21 > (typeset::compute-parallel-size (typeset::boxes *content*)
> 'typeset::dy)
> 12.0
> 10

Ah. That's just what I was looking for. So here's how I handled it:

  (defmacro compute-natural-width (&body body)
    `(typeset::compute-boxes-natural-size
      (typeset::boxes 
       (typeset:compile-text ()
         , at body))
      'typeset::dx))

  (defun compile-header (content-width header-height)
    (declare (ignore header-height))
    (let* ((second-col-width (compute-natural-width (page-number-contents 999 999)))
           (first-col-width (- content-width second-col-width)))
      (typeset:table 
        (:col-widths (list first-col-width second-col-width)
                     :border 0
                     :padding 0
                     :cell-padding 0)
        (typeset::row ()
          (typeset:cell () 
            (typeset::paragraph
                (:h-align :left :font "Times-Italic" :font-size 10)
              (typeset::put-string 
               (typeset::get-contextual-variable 'chapter-name))))
          (typeset:cell ()
            (page-number-contents 
             pdf:*page-number*
             (typeset:find-ref-point-page-number :the-end)))))))

  (defun page-number-contents (page max)
    (typeset::paragraph
        (:h-align :right :font "Times-Italic" :font-size 10)
      (typeset::put-string (format nil "Page ~d of ~d" page max))))

As you can see I didn't need the code to add the text contents to the
cell since I "measured" an example, not the actual text I used.

-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