[cl-typesetting-devel] Reusing bits of code
Marc Battyani
marc.battyani at fractalconcept.com
Fri Jul 8 08:31:56 UTC 2005
"Peter Seibel" <peter at gigamonkeys.com> wrote:
[sorry for the late reply. I hope it's not to late...]
> I have some code that generates a logo using cl-typesetting. Now I'd
> like to generate documents that use that same logo in different
> places (and possibly even scaled). What's the best way to separate
> the code that sets the logo so I can reuse it in different contexts.
> FWIW, here's the function I used to genarate the logo:
>
> (defun logo (&optional (file "/tmp/logo.pdf"))
> (let ((big-font 48)
> (small-font 16)
> (extra-spacing 7))
>
> (pdf:with-document ()
> (pdf:with-page (:bounds (vector 0 0 612 792))
> (let ((content
> (compile-text ()
> (with-style (:font "Didot-Bold" :font-size big-font)
> (put-string "gigamonkeys")) :eol
> (vspace -12)
> (hspace 69)
> (with-style (:font "Optima-Regular" :font-size small-font)
> (loop for char across "CONSULTING" do
> (put-string (string char))
> (typeset::add-box
> (make-instance 'typeset::h-spacing
> :dx extra-spacing
> :max-expansion extra-spacing
> :max-compression extra-spacing
> :expansibility 1.0
> :compressibility 1.0)))))))
> (typeset::draw-block content 100 (- 792 100) (- 612 (* 2 100))
> 100 :v-align :fill :border nil)))
> (pdf:write-document file))))
Here is how I would do it:
(defun draw-logo (x y scale rotation)
(let* ((big-font 48)
(small-font 16)
(extra-spacing 7)
(content
(compile-text ()
(with-style (:font "helvetica-bold" :font-size big-font)
(put-string "gigamonkeys")) :eol
(vspace -12)
(hspace 69)
(with-style (:font "helvetica" :font-size small-font)
(loop for char across "CONSULTING" do
(put-string (string char))
(typeset::add-box
(make-instance 'typeset::h-spacing
:dx extra-spacing
:max-expansion extra-spacing
:max-compression extra-spacing
:expansibility 1.0
:compressibility 1.0)))))))
(pdf:with-saved-state
(pdf:translate x y)
(pdf:scale scale scale)
(pdf:rotate rotation)
(typeset::draw-block content 0 0 412 100 :v-align :fill :border
nil))))
Test:
(defun logo (&optional (file #P"/tmp/logo.pdf"))
(pdf:with-document ()
(pdf:with-page ()
(loop repeat 5
for scale = 1.0 then (* scale 0.7)
for rotation from 0.0 by 20
for x from 100 by 60
for y from 692 by -120
do (draw-logo x y scale rotation)))
(pdf:write-document file)))
Marc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo.pdf
Type: application/pdf
Size: 1388 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cl-typesetting-devel/attachments/20050708/aff9dba7/attachment.pdf>
More information about the cl-typesetting-devel
mailing list