From read at robertlread.net Sun Jan 20 21:32:18 2008 From: read at robertlread.net (Robert L. Read) Date: Sun, 20 Jan 2008 15:32:18 -0600 Subject: [cl-typesetting-devel] An interesting problem from a neophyte... Message-ID: <1200864738.7638.197.camel@penguin.yourdomain.com> Thanks for making cl-pdf and cl-typesetting; they are a great idea. I'm attempting to use them now. However, I am implementing a website, and I want to render the PDFs on demand, not store them in files. The API to cl-pdf is stream-based, which in theory should allow me to send in an "in-memory" stream, rather than a "file-based-stream". For example, I can almost get it to work by using the "IN-MEMORY-OUTPUT-STREAM" of the "flexi-streams" package. However, flexi-streams does not support file-position, which is used by cl-pdf to write the "xrefs" section of the PDF. I thought about attempting to extend a flexi-stream class to support file-position, but that is little more than I want to take on right now. So my questions are: 1) Am I crazy to want to do this in-memory? 2) What are the xrefs, and do I need them? 3) Is it necessary to use "file-position" to compute this? (perhaps the PDF spec and character encoding issues basically for the answer to be "yes") 4) Is there some package that supports "in-memory" files that corectly computes file-position that I may not know about? -- Robert L. Read Konsenti.com From marc.battyani at fractalconcept.com Sun Jan 20 21:55:08 2008 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 20 Jan 2008 22:55:08 +0100 Subject: [cl-typesetting-devel] Acrobat 5.1: Broken space strings (PDF operator TJ) In-Reply-To: <001201c847af$3121d990$8100a8c0@digo> References: <001201c847af$3121d990$8100a8c0@digo> Message-ID: <4793C33C.1070300@fractalconcept.com> Dmitriy Ivanov wrote: > Hello, > > Please take a look at the attached pdf-file in various viewers. It was > generated by paragraphs with :h-align :fill and explicit :hfill, i.e. > > (tt:paragraph (:h-align :fill) > (tt:format-string "Nr of words ~d - ~a" count comment) > :hfill > "Words:" (dotimes (i count) (tt:format-string " wrd:~d" (1+ i))) > > To me, the file looks fine in GSview 4.3. But Acrobat Reader 5.1 renders > three lines as follows. > > (line 1) The right words are shown not at the right margin. > > (line 2) There is a spurious space between wrd:1 and wrd:2. > Such a break can potentially emerge at an arbitrary place in the text line, > even within a word. > > (line 3) Look fine. > > Actually, the mentioned Acrobat version seems to wrongly compute size back > from the negative unit of space amount. The space is computed in > #. > I have got a new version of stroke.lisp with a workaround but not committed > it yet. > Looks fine for me in Acrobat 8.1. If only the old versions of Acrobat have this problem, then let's keep it that way. Anyway, people should download a more recent version of acrobat as it's free. > BTW, why is maximum of nb-spaces, the number of spaces within one > text-chunk, limited to 10? Is this an experimental value or due to the TJ > operator limitation? > I don't remember if there was a reason for this but it's probably not a good thing anyway. Marc From marc.battyani at fractalconcept.com Sun Jan 20 22:01:12 2008 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 20 Jan 2008 23:01:12 +0100 Subject: [cl-typesetting-devel] An interesting problem from a neophyte... In-Reply-To: <1200864738.7638.197.camel@penguin.yourdomain.com> References: <1200864738.7638.197.camel@penguin.yourdomain.com> Message-ID: <4793C4A8.50102@fractalconcept.com> Robert L. Read wrote: > Thanks for making cl-pdf and cl-typesetting; they are a great idea. > > I'm attempting to use them now. However, I am implementing a website, > and I want to render the PDFs on demand, not store them in files. The > API to cl-pdf is stream-based, which in theory should allow me to send > in an "in-memory" stream, rather than a "file-based-stream". For > example, I can almost get it to work by using the > "IN-MEMORY-OUTPUT-STREAM" of the "flexi-streams" package. > > However, flexi-streams does not support file-position, which is used by > cl-pdf to write the "xrefs" section of the PDF. > > I thought about attempting to extend a flexi-stream class to support > file-position, but that is little more than I want to take on right now. > > So my questions are: > > 1) Am I crazy to want to do this in-memory? > No, I do this all the time. ;-) > 2) What are the xrefs, and do I need them? > It's the positions of the objects in the file. I'm sure you need them. :) > 3) Is it necessary to use "file-position" to compute this? (perhaps the > PDF spec and character encoding issues basically for the answer to be > "yes") > It's mush easier to implement file-position in flexi-streams than trying to try to compute it at the cl-pdf level. > 4) Is there some package that supports "in-memory" files that corectly > computes file-position that I may not know about? > Sure, just write the pdf to a string. It's what I do in my web applications. Marc From read at robertlread.net Sun Jan 20 22:06:29 2008 From: read at robertlread.net (Robert L. Read) Date: Sun, 20 Jan 2008 16:06:29 -0600 Subject: [cl-typesetting-devel] An interesting problem from a neophyte... In-Reply-To: <4793C4A8.50102@fractalconcept.com> References: <1200864738.7638.197.camel@penguin.yourdomain.com> <4793C4A8.50102@fractalconcept.com> Message-ID: <1200866789.7638.202.camel@penguin.yourdomain.com> On Sun, 2008-01-20 at 23:01 +0100, Marc Battyani wrote: > > 4) Is there some package that supports "in-memory" files that > corectly > > computes file-position that I may not know about? > > > Sure, just write the pdf to a string. It's what I do in my web > applications. > > Marc > Do you mean generate the file, and then read it into a string? I understand that will work --- my goal is to avoid writing a file at all. Does the API allow you to write directly to a string? I don't see that it does. From marc.battyani at fractalconcept.com Mon Jan 21 08:04:19 2008 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Mon, 21 Jan 2008 09:04:19 +0100 Subject: [cl-typesetting-devel] An interesting problem from a neophyte... In-Reply-To: <1200866789.7638.202.camel@penguin.yourdomain.com> References: <1200864738.7638.197.camel@penguin.yourdomain.com> <4793C4A8.50102@fractalconcept.com> <1200866789.7638.202.camel@penguin.yourdomain.com> Message-ID: <47945203.2050706@fractalconcept.com> Robert L. Read wrote: > On Sun, 2008-01-20 at 23:01 +0100, Marc Battyani wrote: > >>> 4) Is there some package that supports "in-memory" files that >>> >> corectly >> >>> computes file-position that I may not know about? >>> >>> >> Sure, just write the pdf to a string. It's what I do in my web >> applications. >> >> Marc >> > Do you mean generate the file, and then read it into a string? I > understand that will work --- my goal is to avoid writing a file at all. > > Does the API allow you to write directly to a string? I don't see that > it does. > Sure, you can use (defmethod write-document ((s stream) &optional (document *document*)) to write to a string: (with-output-to-string (s) (pdf:with-document () ... (pdf:write-document s))) Marc From read at robertlread.net Mon Jan 21 17:51:24 2008 From: read at robertlread.net (Robert L. Read) Date: Mon, 21 Jan 2008 11:51:24 -0600 Subject: [cl-typesetting-devel] An interesting problem from a neophyte... In-Reply-To: <47945203.2050706@fractalconcept.com> References: <1200864738.7638.197.camel@penguin.yourdomain.com> <4793C4A8.50102@fractalconcept.com> <1200866789.7638.202.camel@penguin.yourdomain.com> <47945203.2050706@fractalconcept.com> Message-ID: <1200937884.4276.16.camel@penguin.yourdomain.com> Sure, you can use (defmethod write-document ((s stream) &optional > (document *document*)) to write to a string: > > (with-output-to-string (s) > (pdf:with-document () > ... > (pdf:write-document s))) > > Marc Unfortunately, this fails for me on SBCL 1.0.13, with the following error. Below this trace is an example of what I am doing with flexi-streams, which seems to work, but is hideous (function "third-doc"). It seems likely that some change in SBCL's stream typing has lead to this error. I have also tried removing :pdf-binary from *features*. I notice in config.lisp that for sbcl the +external-format+ is set to :latin-1, which seems a bit antiquated, in that SBCL is now fully unicode-compatible. # is not a binary output stream. [Condition of type SIMPLE-TYPE-ERROR] Restarts: 0: [ABORT] Return to SLIME's top level. 1: [TERMINATE-THREAD] Terminate this thread (#) Backtrace: 0: (SB-KERNEL:ILL-BOUT #) 1: (WRITE-BYTE 66 #) 2: ((SB-PCL::FAST-METHOD PDF::WRITE-STREAM-CONTENT (STRING)) # # "BT 0.0 829.0 Td /CLF101 12.00 Tf 100.0 Tz [ (Gener) 10 (ated) -278 (with) -278 (Cl-Pdf) -278 (and) -278 (Cl-typesetting) -31419 ] TJ ET BT ..) 3: ((SB-PCL::FAST-METHOD PDF::WRITE-OBJECT (PDF::PDF-STREAM)) # #S(SB-PCL::FAST-METHOD-CALL :FUNCTION # :PV NIL :NEXT-METHOD-CALL #S(SB-PCL::FAST-METHOD-CALL :FUNCTION # :PV NIL :NEXT-METHOD-CALL NIL :ARG-INFO (1 . T)) ..)) 4: ((SB-PCL::FAST-METHOD PDF::WRITE-OBJECT (PDF::INDIRECT-OBJECT)) # # # T) 5: ((LAMBDA ())) 6: (SB-IMPL::%WITH-STANDARD-IO-SYNTAX #) 7: ((SB-PCL::FAST-METHOD PDF:WRITE-DOCUMENT (STREAM)) # # # #) 8: (FOURTH-DOC) (defmethod flexi-streams::stream-write-char ((imo flexi-streams::in-memory-output-stream) c) (format t "trying to write: ~A~%" c) (format t "trying to type: ~A~%" (type-of c)) (flexi-streams::stream-write-byte imo (char-code c)) ) (defun third-doc () (let ((str (flexi-streams::make-in-memory-output-stream :element-type :character))) (tt:with-document () (let ((content (tt:compile-text () (tt:paragraph () "Generated with Cl-Pdf and Cl-typesetting") (tt::with-style (:font "Helvetica" :font-size 8) (tt:paragraph () "Spudalicious") ) ))) (tt:draw-pages content) (when pdf:*page* (typeset:finalize-page pdf:*page*)) (tt:write-document str)) ) (let ((output (make-string-output-stream))) (loop for obj across (flexi-streams::get-output-stream-sequence str) do (if (typep obj 'character) (write-char obj output) (write-char (code-char obj) output))) (get-output-stream-string output) ) )) (defun fourth-doc () (with-output-to-string (str) (tt:with-document () (let ((content (tt:compile-text () (tt:paragraph () "Generated with Cl-Pdf and Cl-typesetting") (tt::with-style (:font "Helvetica" :font-size 8) (tt:paragraph () "Spudalicious") ) ))) (tt:draw-pages content) (when pdf:*page* (typeset:finalize-page pdf:*page*)) (tt:write-document str)) ) str) ) From jan.marecek at gmail.com Mon Jan 28 06:12:09 2008 From: jan.marecek at gmail.com (jan) Date: Mon, 28 Jan 2008 17:12:09 +1100 Subject: [cl-typesetting-devel] bullet character Message-ID: <200801281712.10560.jan.marecek@gmail.com> How do I add a bullet character to a document? -- jan From philpot at ISI.EDU Mon Jan 28 17:44:49 2008 From: philpot at ISI.EDU (Andrew Philpot) Date: Mon, 28 Jan 2008 09:44:49 -0800 Subject: [cl-typesetting-devel] bullet character In-Reply-To: Your message of "Mon, 28 Jan 2008 17:12:09 +1100." <200801281712.10560.jan.marecek@gmail.com> Message-ID: <200801281744.m0SHinFv001770@blombos.isi.edu> How do I add a bullet character to a document? -- jan I use (code-char #XB7), aka #\middle_dot (at least in ACL). Andrew From jan.marecek at gmail.com Mon Jan 28 23:10:02 2008 From: jan.marecek at gmail.com (jan) Date: Tue, 29 Jan 2008 10:10:02 +1100 Subject: [cl-typesetting-devel] bullet character In-Reply-To: <200801281744.m0SHinFv001770@blombos.isi.edu> References: <200801281744.m0SHinFv001770@blombos.isi.edu> Message-ID: <200801291010.03158.jan.marecek@gmail.com> >> How do I add a bullet character to a document? > I use (code-char #XB7), aka #\middle_dot (at least in ACL). That doesn't work for me, I'm using unicode enabled sbcl such that (format nil "~c" #\middle_dot) => "?" however (tt:format-string "~c" #\middle_dot) outputs ?? I also tried using symbol font but that produced no output at all. I've decided to render circles instead, it just works and gives better control over size as well. -- jan From divanov at aha.ru Tue Jan 29 07:51:38 2008 From: divanov at aha.ru (Dmitriy Ivanov) Date: Tue, 29 Jan 2008 10:51:38 +0300 Subject: [cl-typesetting-devel] bullet character References: <200801281744.m0SHinFv001770@blombos.isi.edu> <200801291010.03158.jan.marecek@gmail.com> Message-ID: <000001c8624b$ca6ab840$8100a8c0@digo> Hello jan, | >> How do I add a bullet character to a document? | |> I use (code-char #XB7), aka #\middle_dot (at least in ACL). | | That doesn't work for me, I'm using unicode enabled sbcl such that | (format nil "~c" #\middle_dot) => "?" | however | (tt:format-string "~c" #\middle_dot) outputs ?? I would recommend using Bullet character #\U+2022 in LispWorks ((code-char #x2022) should wokr in other implementations). In latin-1 and some Windows code pages, it corresponds to #x95 = 149. But in Type1 fonts like Helvetica or Symbols the corresponding code is #xB7=183. The expanded mapping of useful characters seems like this: (defparameter *char-single-byte-codes* '((#.(code-char #x2013) . #x96) ; En dash: 8211 -> 150 (#.(code-char #x2014) . #x97) ; Em dash: 8212 -> 151 (#.(code-char #x2022) . #xB7) ; Bullet: 8226 -> 183 (#.(code-char #x2026) . #x85) ; Ellipsis: 8230 -> 133 (#.(code-char #x2039) . #x8B) ; Single left angle quotation mark: 8249 -> 139 (#.(code-char #x203A) . #x9B) ; Single right angle quotation mark: 8250 -> 155 (#.(code-char #x2122) . #x99) ; Trademark: 8482 -> 153 ) ) I have just committed the addition. -- Sincerely, Dmitriy Ivanov lisp.ystok.ru