From: Marc Battyani
Subject: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <07414CA78EAD9397.3DE2942F03E73D29.F576D0D448E8BB87@lp.airnews.net>
02 February 2002: Release 0.3
   removed the use of keywords as PDF names
   cleaned up the code, put back write-line, removed gensym, etc.
   added a maze generation example

Here is what you get with the maze generation example:
(make-maze 53 80) gives the following pdf file
http://www.fractalconcept.com/fcweb/download/ex5.pdf

Marc

*****************************************
CL-PDF is a Common Lisp PDF Library for generating PDF files.

You will find it here:
www.fractalconcept.com/asp/html/cl-pdf.html

It is released with a BSD style license so it's usable for commercial work.

It it how it looks:

(pdf:with-document ()
    (pdf:with-page ()
      (let ((helvetica (make-instance 'pdf:font)))
 (pdf:add-fonts-to-page helvetica)
 (pdf:in-text-mode
  (pdf:set-font helvetica 36.0)
  (pdf:move-text 100 800)
  (pdf:draw-text "cl-pdf: Example 1"))
 (pdf:translate 230 500)
 (loop repeat 101
       for i = 0.67 then (* i 1.045)
       do (pdf:in-text-mode
    (pdf:set-font helvetica i)
    (pdf:move-text (* i 3) 0)
    (pdf:draw-text "rotation"))
       (pdf:rotate 18))))
    (pdf:write-document file))

=> gives this > http://www.fractalconcept.com/fcweb/download/ex1.pdf

Before writing it, I was rather impressed by the size of the PDF
documentation. After writing it I'm really impressed by Common Lisp. As you
will see, the library is quite small, yet really powerful.

So enjoy it and send me some great looking PDF files to put in a gallery on
the web site.

I also think that it's an opportunity to open several sub projects.

1) Finishing CL-PDF:

1.1- In CL-PDF I open the file for writing with a LW specific option to open
it with no CR/LF translation.
I would need the different versions of doing this on other implementation
running on Windows.

1.2-Compression : If someone would like to FLI the zlib compression, I could
integrate it to generate compressed PDF files. I can't do it alone as it has
to be done for several implementations to be useful.

2) Building utility layers on top of CL-PDF to turn it as a really powerful
drawing publication platform. I'm willing to coordinate and drive this
effort but I haven't the time to do it alone.

2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round rect,
etc.

2.2- Higher level Graphic functions. ie Functions to draw : axis, lin/log
scales, barcodes etc.
(OK all this exists but it's not always very good and does not always do
what you want.)

2.3-Text layout functions (well not a full Tex but at least writing text in
a box for instance)

2.4-CL-TeX: Well here I'm kidding but not completely ;-)

3) CL-PDF Logo like layer for kids. I have teach Logo at a local school
where my sons go but I've found that Logo was great to start but a deceptive
one after a while. A CL-PDF Logo could lead to extremely good quality
drawings. I definitively think that's a way to explore.

Feedback welcomed.

Marc

From: Eduardo Muñoz
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <u8zaa937n.fsf@jet.es>
"Marc Battyani" <·············@fractalconcept.com> writes:

> 1.1- In CL-PDF I open the file for writing with a LW specific option to open
> it with no CR/LF translation.
> I would need the different versions of doing this on other implementation
> running on Windows.

You want to write the file with Unix style. Isn't
it?

In Clisp you could use:

(with-open-file (s filename :direction :output :if-exists :supersede :external-format :unix)
        ....

BTW, the generated file looks OK using
:external-format :default (with CR/LF) when viewed
using adobe acrobat reader. Is this convention
required by the PDF spec.?
  
> 2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round rect,
> etc.

I'm a CL newbie and short of free time, but I have
a good background in geometry. Perhaps you could
crate a general design and I (or someone else)
could fill the implementation.

PD. Maybe we should move to private email?

-- 

Eduardo Mu�oz
From: Marc Battyani
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <95D6FE9D6BD64962.E75F8F9C00948C45.3E8349248D76EEA9@lp.airnews.net>
"Eduardo Mu�oz" <···@jet.es> wrote
> "Marc Battyani" <·············@fractalconcept.com> writes:
>
> > 1.1- In CL-PDF I open the file for writing with a LW specific option to
open
> > it with no CR/LF translation.
> > I would need the different versions of doing this on other
implementation
> > running on Windows.
>
> You want to write the file with Unix style. Isn't
> it?
>
> In Clisp you could use:
>
> (with-open-file (s filename :direction :output :if-exists :supersede
:external-format :unix)

OK. :external-format is starndard but its values are implementation
dependent.

> BTW, the generated file looks OK using
> :external-format :default (with CR/LF) when viewed
> using adobe acrobat reader. Is this convention
> required by the PDF spec.?

No you can use LF or CR/LF in PDF files but as the positions in the file are
absolute you have to be sure that the Lisp implementation does not convert
them when reading or writing the file to disk.

> > 2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round
rect,
> > etc.
>
> I'm a CL newbie and short of free time, but I have
> a good background in geometry. Perhaps you could
> crate a general design and I (or someone else)
> could fill the implementation.

For example PDF has only B�zier curves no arc nor circle. it would be useful
to have arcs functions that translate to B�zier curves. Same pb with
ellipical arc, ellipses etc.

For instance :
    circle center-x center-y radius
    ellipse center-x center-y radius-a radius-b rotation
    angle-arc center-x center-y radius start-angle sweep-angle
    angle-pie center-x center-y radius start-angle sweep-angle
    round-rect left-x bottom-y right-x top-y radius-x radius-y
    etc.


 > PD. Maybe we should move to private email?

As you want. I'm open to both email or c.l.l.

Marc
From: Thomas F. Burdick
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <xcvwuxutn8u.fsf@famine.OCF.Berkeley.EDU>
"Marc Battyani" <·············@fractalconcept.com> writes:

> "Eduardo Mu�oz" <···@jet.es> wrote
> > "Marc Battyani" <·············@fractalconcept.com> writes:
> >
> > > 1.1- In CL-PDF I open the file for writing with a LW specific option to
> open
> > > it with no CR/LF translation.
> > > I would need the different versions of doing this on other
> implementation
> > > running on Windows.
> >
> > You want to write the file with Unix style. Isn't
> > it?
> >
> > In Clisp you could use:
> >
> > (with-open-file (s filename :direction :output :if-exists :supersede
> :external-format :unix)
> 
> OK. :external-format is starndard but its values are implementation
> dependent.
> 

> > BTW, the generated file looks OK using
> > :external-format :default (with CR/LF) when viewed
> > using adobe acrobat reader. Is this convention
> > required by the PDF spec.?
> 
> No you can use LF or CR/LF in PDF files but as the positions in the file are
> absolute you have to be sure that the Lisp implementation does not convert
> them when reading or writing the file to disk.

But why did it work in Acrobat Reader anyway, you ask?  Acrobat
quitely fixes up the xref table.  xpdf complains, and fixes it.
Ghostscript can't deal with it.

>  > PD. Maybe we should move to private email?
> 
> As you want. I'm open to both email or c.l.l.

I, for one, appreciate this discussion being on c.l.l.  I don't have
time to play with it right now, but when a need comes up (or I can
come up with a need for it) I plan on playing with it and maybe
contributing.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Marc Battyani
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <0310CAF0D1C2BB2C.0EFF222A6F84575B.40DA0E71BD0CF4AD@lp.airnews.net>
"Thomas F. Burdick" <···@famine.OCF.Berkeley.EDU> wrote
> "Marc Battyani" <·············@fractalconcept.com> writes:
>
> > No you can use LF or CR/LF in PDF files but as the positions in the file
are
> > absolute you have to be sure that the Lisp implementation does not
convert
> > them when reading or writing the file to disk.
>
> But why did it work in Acrobat Reader anyway, you ask?  Acrobat
> quitely fixes up the xref table.  xpdf complains, and fixes it.
> Ghostscript can't deal with it.

This is why I need the :external-format value that will not translate CR/LF
to LF (and vice versa)  for every Common Lisp implementation working on
WinXXXX. I would then happily add the corresponding #+ to open the file.

So far I only have (:default :eol-style :lf) for LWW and :unix for CLISP

> >  > PD. Maybe we should move to private email?
> >
> > As you want. I'm open to both email or c.l.l.
>
> I, for one, appreciate this discussion being on c.l.l.  I don't have
> time to play with it right now, but when a need comes up (or I can
> come up with a need for it) I plan on playing with it and maybe
> contributing.

OK let's talk here....

Marc
From: Eduardo Muñoz
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <ulmeatbza.fsf@jet.es>
"Marc Battyani" <·············@fractalconcept.com> writes:

> So far I only have (:default :eol-style :lf) for LWW and :unix for CLISP

I checked Corman Lisp. It will accept any value
and write the file in windows format anyway.
 
> OK let's talk here....

Here we go  :)

The following code adds support for circles and
rounded rectangles. I welcome any suggestion since
I'm a newbie with CL. Any corrections to my
english are welcome too :)

Some comments. The quadrants stuff could be made
using pure geometry instead of these four
functions but IMHO it's too complicated (rotation
matrices) for the gain we would get.
I haven't added support for rotated elements by
now because you can handle rotation at a higer
level (pdf:rotate) and the things get messy very
quickly. Any curve has to be stroked and/or filled
with the page still rotated, so the function used
should be passed as a parameter.


(in-package pdf)

(defconstant +kappa+ (* 4 (/ (1- (sqrt 2.0)) 3)))

(defun first-quadrant (center-x center-y radius l-distance)
  (bezier-to (+ center-x radius) (+ center-y l-distance)
             (+ center-x l-distance) (+ center-y radius)
             center-x (+ center-y radius)))

(defun second-quadrant (center-x center-y radius l-distance)
  (bezier-to (- center-x l-distance) (+ center-y radius)
             (- center-x radius) (+ center-y l-distance)
             (- center-x radius) center-y))

(defun third-quadrant (center-x center-y radius l-distance)
  (bezier-to (- center-x radius) (- center-y l-distance)
             (- center-x l-distance) (- center-y radius)
             center-x (- center-y radius)))

(defun fourth-quadrant (center-x center-y radius l-distance)
  (bezier-to (+ center-x l-distance) (- center-y radius)
             (+ center-x radius) (- center-y l-distance)
             (+ center-x radius) center-y))


(defun circle (center-x center-y radius)
  ;; See http://www.whizkidtech.net/bezier/circle/
  ;; to know what are +kappa+ and l-distance
  (let ((l-distance (* radius +kappa+)))
    (move-to (+ center-x radius) center-y)
    (first-quadrant center-x center-y radius l-distance)
    (second-quadrant center-x center-y radius l-distance)
    (third-quadrant center-x center-y radius l-distance)
    (fourth-quadrant center-x center-y radius l-distance)))


(defun rectangle (x y dx dy &optional (radius 0))
  (cond ((eql radius 0)
         (format *page-stream* "~,3f ~,3f ~,3f ~,3f re~%" x y dx dy))
        (t
         (let ((l-distance (* radius +kappa+)))
           (move-to (+ x dx) (- (+ y dy) radius))
           (first-quadrant (- (+ x dx) radius) (- (+ y dy) radius)
                           radius l-distance)
           ;; Top line
           (line-to (+ x radius) (+ y dy))
           (second-quadrant (+ x radius) (- (+ y dy) radius)
                            radius l-distance)
           ;; Left line
           (line-to x (+ y radius))
           (third-quadrant (+ x radius) (+ y radius)
                           radius l-distance)
           ;; Bottom line
           (line-to (- (+ x dx) radius) y)
           (fourth-quadrant (- (+ x dx) radius) (+ y radius)
                            radius l-distance)
           ;;Right line
           (line-to (+ x dx) (- (+ y dy) radius))))))

;;; A sample pdf using this functions can be
;;; crated using this code.

(defun example6 (&optional (file #P"ex6.pdf"))
  (pdf:with-document ()
    (pdf:with-page ()
      (let ((helvetica (make-instance 'pdf:font)))
	(pdf:add-fonts-to-page helvetica)
	(pdf:in-text-mode
	 (pdf:set-font helvetica 36.0)
	 (pdf:move-text 100 800)
	 (pdf:draw-text "cl-pdf: Example 6"))
	(pdf:set-rgb-stroke 0.1 0.1 0.8)
        (pdf:set-rgb-fill 0.8 0.5 0.1)
        (pdf:translate 50 400)
        (pdf:rectangle 100 250 100 100 0)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 300 250 100 100 10)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 100 100 100 100 20)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 300 100 100 100 40)
        (pdf:close-fill-and-stroke)
	(pdf:translate 200 -100)
	(loop repeat 100
	      for i = 0.67 then (* i 1.045)
	      do
              (pdf:set-rgb-fill (* 0.1 i) (* 0.01 i) (* 0.02 i))
              (pdf:circle (* i 3) 0 (* 1.5 i))
              (pdf:close-fill-and-stroke)
	      (pdf:rotate 18))))
    (pdf:write-document file)))


-- 

Eduardo Mu�oz
From: Marc Battyani
Subject: CL-PDF Arc functions (was :Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library))
Date: 
Message-ID: <7AC2668CF8FAC968.65FDBD9423CBE221.58386582B9FE1724@lp.airnews.net>
"Eduardo Mu�oz" <···@jet.es> wrote

> Here we go  :)
>
> The following code adds support for circles and
> rounded rectangles. I welcome any suggestion since
> I'm a newbie with CL. Any corrections to my
> english are welcome too :)
>
> Some comments. The quadrants stuff could be made
> using pure geometry instead of these four
> functions but IMHO it's too complicated (rotation
> matrices) for the gain we would get.
> I haven't added support for rotated elements by
> now because you can handle rotation at a higer
> level (pdf:rotate) and the things get messy very
> quickly. Any curve has to be stroked and/or filled
> with the page still rotated, so the function used
> should be passed as a parameter.
>
>
> (in-package pdf)
>
> (defconstant +kappa+ (* 4 (/ (1- (sqrt 2.0)) 3)))
>
> (defun first-quadrant (center-x center-y radius l-distance)
>   (bezier-to (+ center-x radius) (+ center-y l-distance)
>              (+ center-x l-distance) (+ center-y radius)
>              center-x (+ center-y radius)))
>
> (defun second-quadrant (center-x center-y radius l-distance)
>   (bezier-to (- center-x l-distance) (+ center-y radius)
>              (- center-x radius) (+ center-y l-distance)
>              (- center-x radius) center-y))
>
> (defun third-quadrant (center-x center-y radius l-distance)
>   (bezier-to (- center-x radius) (- center-y l-distance)
>              (- center-x l-distance) (- center-y radius)
>              center-x (- center-y radius)))
>
> (defun fourth-quadrant (center-x center-y radius l-distance)
>   (bezier-to (+ center-x l-distance) (- center-y radius)
>              (+ center-x radius) (- center-y l-distance)
>              (+ center-x radius) center-y))
>
>
> (defun circle (center-x center-y radius)
>   ;; See http://www.whizkidtech.net/bezier/circle/
>   ;; to know what are +kappa+ and l-distance
>   (let ((l-distance (* radius +kappa+)))
>     (move-to (+ center-x radius) center-y)
>     (first-quadrant center-x center-y radius l-distance)
>     (second-quadrant center-x center-y radius l-distance)
>     (third-quadrant center-x center-y radius l-distance)
>     (fourth-quadrant center-x center-y radius l-distance)))
>
>
> (defun rectangle (x y dx dy &optional (radius 0))
>   (cond ((eql radius 0)
>          (format *page-stream* "~,3f ~,3f ~,3f ~,3f re~%" x y dx dy))
>         (t
>          (let ((l-distance (* radius +kappa+)))
>            (move-to (+ x dx) (- (+ y dy) radius))
>            (first-quadrant (- (+ x dx) radius) (- (+ y dy) radius)
>                            radius l-distance)
>            ;; Top line
>            (line-to (+ x radius) (+ y dy))
>            (second-quadrant (+ x radius) (- (+ y dy) radius)
>                             radius l-distance)
>            ;; Left line
>            (line-to x (+ y radius))
>            (third-quadrant (+ x radius) (+ y radius)
>                            radius l-distance)
>            ;; Bottom line
>            (line-to (- (+ x dx) radius) y)
>            (fourth-quadrant (- (+ x dx) radius) (+ y radius)
>                             radius l-distance)
>            ;;Right line
>            (line-to (+ x dx) (- (+ y dy) radius))))))

As a style note, I generally use if when there is only one test condition +
then and else code.
Also I would use #'= 0 or #'ZEROP  instead of #'EQL
ie (if (zerop radius) ...

> ;;; A sample pdf using this functions can be
> ;;; crated using this code.
>
> (defun example6 (&optional (file #P"ex6.pdf"))
>   (pdf:with-document ()
>     (pdf:with-page ()
>       (let ((helvetica (make-instance 'pdf:font)))
> (pdf:add-fonts-to-page helvetica)
> (pdf:in-text-mode
> (pdf:set-font helvetica 36.0)
> (pdf:move-text 100 800)
> (pdf:draw-text "cl-pdf: Example 6"))
> (pdf:set-rgb-stroke 0.1 0.1 0.8)
>         (pdf:set-rgb-fill 0.8 0.5 0.1)
>         (pdf:translate 50 400)
>         (pdf:rectangle 100 250 100 100 0)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 300 250 100 100 10)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 100 100 100 100 20)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 300 100 100 100 40)
>         (pdf:close-fill-and-stroke)
> (pdf:translate 200 -100)
> (loop repeat 100
>       for i = 0.67 then (* i 1.045)
>       do
>               (pdf:set-rgb-fill (* 0.1 i) (* 0.01 i) (* 0.02 i))
>               (pdf:circle (* i 3) 0 (* 1.5 i))
>               (pdf:close-fill-and-stroke)
>       (pdf:rotate 18))))
>     (pdf:write-document file)))

I've put the example here:
http://www.fractalconcept.com/fcweb/download/ex6.pdf

Good Start!

Thanks,

BTW a zlib FLI is also on the way.

Marc
From: Paul Meurer
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <3c5e499e.419099132@nntp.uib.no>
On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"
<·············@fractalconcept.com> wrote:

>
>OK. :external-format is starndard but its values are implementation
>dependent.
>

I have tested your code (v. 0.21) in MCL, and had to comment out the
:external-format keyword arg. Apart from that, it worked out of the
box. Nicely done!

- Paul

____________________________________________
Paul Meurer at HIT UiB no                                   
Humanities Information Technologies Centre,
University of Bergen
All�gaten 27, 5007 Bergen
Norway
From: Marc Battyani
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <77356C682487E8B9.B8541038203BAACF.F7A7486C75C6C7AD@lp.airnews.net>
"Paul Meurer" <···········@hit.uib.no> wrote
> On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"
> <·············@fractalconcept.com> wrote:
>
> >OK. :external-format is starndard but its values are implementation
> >dependent.
>
> I have tested your code (v. 0.21) in MCL, and had to comment out the
> :external-format keyword arg.

OK. Does MCL define a :mcl feature ?

>Apart from that, it worked out of the
> box. Nicely done!

Thanks.

Marc
From: Marc Battyani
Subject: Re: [Announce] CL-PDF 0.3 (The Common Lisp PDF Library)
Date: 
Message-ID: <19F0E871B2AD8FCE.0A9D5CD6840FCE32.3A5072E86872EED1@lp.airnews.net>
"Marc Battyani" <·············@fractalconcept.com> wrote
>
> "Paul Meurer" <···········@hit.uib.no> wrote
> > On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"
> > <·············@fractalconcept.com> wrote:
> >
> > >OK. :external-format is starndard but its values are implementation
> > >dependent.
> >
> > I have tested your code (v. 0.21) in MCL, and had to comment out the
> > :external-format keyword arg.
>
> OK. Does MCL define a :mcl feature ?

Not nedeed anymore. I now put :default by default, so I only need the
external-format values for the Lisp implementations which need something
different
from :default

Marc