[cl-typesetting-devel] Paragraph

Gary King gwking at metabang.com
Sat Oct 13 01:42:26 UTC 2007


The paragraph macro doesn't evaluate its arguments which seems to  
make it hard to use programatically. I've hardly scratched the  
surface of CL-PDF and CL-Typesetting but the following change would  
allow the paragraph macro to take either a property list  
(unevaluated) or a symbol (evaluated) as argument. (Another, perhaps  
better, alternative would be to have two macros -- paragraph and  
paragraph*? -- one of which didn't evaluate its arguments and one of  
which did... Am I missing something? Is there another way to modify  
the styles "programmatically".

thanks,

(defmacro paragraph ((&rest style) &body body)
   (print (list :x style
	       (and (null (rest style))
				(symbolp (first style)))))
   (with-gensyms (gstyle new-style restore-style first-indent
			top-margin bottom-margin first-line-indent)
     `(let* ((,gstyle ,@(if (and (null (rest style))
				(symbolp (first style)))
			   style `(', at style)))
	    (,top-margin (getf ,gstyle :top-margin 0))
	    (,bottom-margin (getf ,gstyle :bottom-margin 0))
	    (,first-line-indent (getf ,gstyle :first-line-indent 0))
	    (,new-style (apply #'make-instance 'text-style ,gstyle))
	    (,restore-style (make-restore-style ,new-style))
	    (,first-indent ,first-line-indent))
        (add-box ,new-style)
        (use-style ,new-style)
        (add-box (make-instance 'v-spacing :dy ,top-margin))
        (unless (zerop ,first-indent)
	 (add-box (make-instance 'h-spacing :dx ,first-indent)))
        ,@(mapcar 'insert-stuff body)
        (unless (eq (first (boxes-tail *content*)) :eol)
	 (add-box :eol))
        (add-box (make-instance 'v-spacing :dy ,bottom-margin))
        (add-box ,restore-style)
        (use-style ,restore-style))))

--
Gary Warren King, metabang.com
Cell: (413) 559 8738
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM







More information about the cl-typesetting-devel mailing list