From dherring at tentpost.com Wed Feb 11 05:36:34 2009 From: dherring at tentpost.com (Daniel Herring) Date: Wed, 11 Feb 2009 00:36:34 -0500 (EST) Subject: [cl-pdf-devel] [patch] cl-pdf and salza2 Message-ID: I had some problems using cl-pdf because the bundled salza package conflicted with another zlib package. After a little hacking, I got cl-pdf working with salza2 instead. See the attached diffs (based on git fd24e80 ~ SVN revision 174) for details. Later, Daniel -------------- next part -------------- From 420f3c67c28916fd87aeebb316d36201a31481cd Mon Sep 17 00:00:00 2001 From: D Herring Date: Wed, 11 Feb 2009 00:20:28 -0500 Subject: [PATCH] changes to use salza2 The included salza conflicts with Matthieu Villeneuve's zlib package. --- cl-pdf.asd | 7 ++++--- zlib.lisp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/cl-pdf.asd b/cl-pdf.asd index 68aa9d7..7e40719 100644 --- a/cl-pdf.asd +++ b/cl-pdf.asd @@ -13,13 +13,14 @@ ;;;Choose the zlib implementation you want to use (only one!) (eval-when (:load-toplevel :compile-toplevel :execute) - (pushnew :use-salza-zlib *features*) + (pushnew :use-salza2-zlib *features*) + ;;(pushnew :use-salza-zlib *features*) ;;(pushnew :use-uffi-zlib *features*) ;;(pushnew :use-abcl-zlib *features*) ;;(pushnew :use-no-zlib *features*) ) -#-(or use-uffi-zlib use-salza-zlib use-abcl-zlib use-no-zlib) +#-(or use-uffi-zlib use-salza-zlib use-salza2-zlib use-abcl-zlib use-no-zlib) (error "You must choose which zlib implementation you want to use!") #+(and (not uffi) use-uffi-zlib) @@ -63,4 +64,4 @@ (:file "text" :depends-on ("pdf-base")) (:file "bar-codes" :depends-on ("pdf-geom")) (:file "chart" :depends-on ("text" "pdf-geom"))) - :depends-on (:iterate #+use-salza-zlib :salza)) + :depends-on (:iterate #+use-salza-zlib :salza #+use-salza2-zlib :salza2)) diff --git a/zlib.lisp b/zlib.lisp index e54ec03..76c2f45 100644 --- a/zlib.lisp +++ b/zlib.lisp @@ -102,6 +102,50 @@ (salza::finish-zlib-stream zlib-stream) (nreverse chunks))))) +#+use-salza2-zlib +(defun load-zlib (&optional force) + (declare (ignore force)) + (setf *compress-streams* t)) + +;; string-to-octets copied from the original salza +#+use-salza2-zlib +(defun string-to-octets (string start end) + "Convert STRING to a sequence of octets, if possible." + (declare (type string string) + (type buffer-offset start end) + (optimize (speed 3) (safety 0))) + #+(and sbcl (not octet-characters)) + (sb-ext:string-to-octets string :external-format :iso-8859-1 :start start :end end) + #+(and allegro (not octet-characters)) + (excl:string-to-octets string :start start :end end :null-terminate nil) + #+(and clisp (not octet-characters)) + (ext:convert-string-to-bytes string custom:*default-file-encoding* :start start :end end) + #+(or octet-characters lispworks) + (let* ((length (- end start)) + (result (make-array length :element-type 'octet))) + (loop for i fixnum from start below end + for j fixnum from 0 + do (setf (aref result j) (char-code (aref string i)))) + result) + #+(and (not octet-characters) (not (or sbcl allegro clisp lispworks))) + (error "Do not know how to convert a string to octets.")) + +#+use-salza2-zlib +(defun compress-string (string) + (let ((input (if (stringp string) + (string-to-octets string 0 (length string)) + string)) + (chunks ())) + (flet ((cb (octet-vector end) + (push (subseq octet-vector 0 end) + chunks))) + (let ((compressor + (make-instance 'salza2:zlib-compressor + :callback #'cb))) + (salza2:compress-octet-vector input compressor) + (salza2:finish-compression compressor))) + (reverse chunks))) + ;;; no-zlib #+use-no-zlib (defun load-zlib (&optional force) -- 1.6.0.2