From tim at tenkan.org Sun Oct 23 12:54:10 2005 From: tim at tenkan.org (Tim Daly Jr.) Date: 23 Oct 2005 14:54:10 +0200 Subject: [cl-pdf-devel] patch, pdf templates Message-ID: <87ek6cfl71.fsf@beer.intern> Hi everybody, I'd like to contribute a small patch, and some code for creating "templates" from pdf pages. The patch mostly changes pdf-parser.lisp. It adds location information to a couple of error messages, a couple of comments, names a constant, and fixes a couple of small parsing bugs. There is one change in pdf.lisp -- when printing numbers, we have to make sure that they are printed in a form that's legal PDF syntax. -------------- next part -------------- A non-text attachment was scrubbed... Name: cl-pdf.patch Type: text/x-patch Size: 3994 bytes Desc: miscellaneous patch URL: -------------- next part -------------- The template code allows you to create a "Form XObject" from a PDF page which can then be drawn onto new PDF pages. The file stands alone, but it might be nicer to integrate it into the cl-pdf system and package definitions. -------------- next part -------------- A non-text attachment was scrubbed... Name: pdf-template.lisp Type: application/octet-stream Size: 12318 bytes Desc: pdf templates URL: -------------- next part -------------- The source itself can be converted into a PDF using pbook.el, which might be a nicer way to read it: http://tenkan.org/~tim/pdf-template.pdf This is an example output file, created with (pdf:test-template "/tmp/pdf-template.pdf" 0 "/tmp/example.pdf"): http://tenkan.org/~tim/example.pdf Thanks for cl-pdf. It's beautiful code, and a lot of fun to work with! :) -- -Tim From marc.battyani at fractalconcept.com Sun Oct 23 20:36:54 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 23 Oct 2005 22:36:54 +0200 Subject: [cl-pdf-devel] patch, pdf templates References: <87ek6cfl71.fsf@beer.intern> Message-ID: <021301c5d811$94bd3a40$1401a8c0@marcxp> "Tim Daly Jr." wrote: > > Hi everybody, > > I'd like to contribute a small patch, and some code for creating > "templates" from pdf pages. Good idea! > The patch mostly changes pdf-parser.lisp. It adds location > information to a couple of error messages, a couple of comments, names > a constant, and fixes a couple of small parsing bugs. There is one > change in pdf.lisp -- when printing numbers, we have to make sure that > they are printed in a form that's legal PDF syntax. OK > The template code allows you to create a "Form XObject" from a PDF > page which can then be drawn onto new PDF pages. The file stands > alone, but it might be nicer to integrate it into the cl-pdf system > and package definitions. This is great. It was on my to-do list, so I'm glad you did it before me ;-) I will look at this. > The source itself can be converted into a PDF using pbook.el, which > might be a nicer way to read it: > > http://tenkan.org/~tim/pdf-template.pdf > > This is an example output file, created with > (pdf:test-template "/tmp/pdf-template.pdf" 0 "/tmp/example.pdf"): > > http://tenkan.org/~tim/example.pdf > > Thanks for cl-pdf. It's beautiful code, and a lot of fun to work > with! :) You're welcome! Thanks for your contribution. ;-) Marc From a_bakic at yahoo.com Sat Oct 29 23:38:12 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Sat, 29 Oct 2005 16:38:12 -0700 (PDT) Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) Message-ID: <20051029233813.68666.qmail@web40627.mail.yahoo.com> Hi, Attached is my attempt at adding Unicode support to cl-pdf. (I noticed that it does not work correctly when pdf:*compress-streams* is true; I am using salza with sbcl compiled for x86 on AMD64...) One needs a Unicode TrueType font, such as MS Windows Arial and Times New Roman. Then, one needs ttf2ufm (included in http://www.acko.net/files/ufpdf.zip) to generate an ufm file. For example, $ ttf2ufm -a -F arial.ttf arial The rest should be relatively easy to figure out from the example (and a comment in ttu-font.lisp at the end of the attachment). So, without compression, it worked for me. I haven't tested it much, and the patch is probably incomplete. BTW, does anyone know how I can make a smaller font out of a TrueType one, containing only desired characters? Regards, Alex __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com -------------- next part -------------- A non-text attachment was scrubbed... Name: cl-pdf-diffs Type: application/octet-stream Size: 16139 bytes Desc: 1381307520-cl-pdf-diffs URL: From a_bakic at yahoo.com Sat Oct 29 23:47:39 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Sat, 29 Oct 2005 16:47:39 -0700 (PDT) Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) In-Reply-To: <20051029233813.68666.qmail@web40627.mail.yahoo.com> Message-ID: <20051029234739.42323.qmail@web40624.mail.yahoo.com> > patch is probably incomplete I forgot to mention that the patch includes someone else's patch that I picked from this list's archive a few days ago. Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From a_bakic at yahoo.com Sun Oct 30 13:24:49 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Sun, 30 Oct 2005 05:24:49 -0800 (PST) Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) In-Reply-To: <20051029233813.68666.qmail@web40627.mail.yahoo.com> Message-ID: <20051030132449.45801.qmail@web34604.mail.mud.yahoo.com> > BTW, does anyone know how I can make a smaller > font out of a TrueType one, containing only desired characters? This can be done using fontforge, although it is tedious... Alex __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From marc.battyani at fractalconcept.com Sun Oct 30 19:15:22 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 30 Oct 2005 20:15:22 +0100 Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) References: <20051029233813.68666.qmail@web40627.mail.yahoo.com> Message-ID: <010301c5dd86$473f63e0$0a02a8c0@marcxp> Aleksandar Bakic wrote: >Attached is my attempt at adding Unicode support to cl-pdf. Great! >(I noticed that it >does not work correctly when pdf:*compress-streams* is true; I am using salza >with sbcl compiled for x86 on AMD64...) I fixed that. >One needs a Unicode TrueType font, such as MS Windows Arial and Times New >Roman. Then, one needs ttf2ufm (included in >http://www.acko.net/files/ufpdf.zip) to generate an ufm file. For example, > >$ ttf2ufm -a -F arial.ttf arial > >The rest should be relatively easy to figure out from the example (and a >comment in ttu-font.lisp at the end of the attachment). > >So, without compression, it worked for me. I haven't tested it much, and the >patch is probably incomplete. It's OK for the compression now, I also made some changes for the different functions to show strings, characters, etc. So I think the base Unicode stuff is OK. I will look at making a full Unicode support (Encoding stuff mostly) and also add Unicode support to cl-typesetting. >BTW, does anyone know how I can make a smaller >font out of a TrueType one, containing only desired characters? Sorry no. Marc From marc.battyani at fractalconcept.com Sun Oct 30 19:15:47 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 30 Oct 2005 20:15:47 +0100 Subject: [cl-pdf-devel] cl-pdf version 2.90 References: <074c01c503f3$13b432c0$0a02a8c0@marcxp> <08b301c5198a$52a9fb20$0a02a8c0@marcxp> Message-ID: <010401c5dd86$555ecec0$0a02a8c0@marcxp> I've commited the latest version of cl-pdf to the cl-pdf repository. In addition to the usual bunch of fixes and small improvements, this release contains 2 new functionnalities: -Support for basic Unicode TrueType fonts and handling [Aleksandar Bakic] -The transformation of pages of existing pdf files as graphic templates [Tim Daly Jr] As usual, patches welcome ;-) Rev 103: cl-pdf: Version 2.9 -Added base Unicode support [Aleksandar Bakic] -Added Unicode TrueType font support [Aleksandar Bakic] -Extraction and transformation of pages from existing pdf files as templates which can be drawn as graphic objects (in pdf-parser). [Tim Daly Jr] -Change in the floting point formats for a better to improve precision -Nil values are now allowed in the xy-charts -Modifications for SBCL -New examples (l-system.lisp and example9) -Added all the small patches and fixes sent to me by a lot of cool guys ;-) The full repository is here: http://www.fractalconcept.com:8000/public/open-source/ (It's a subversion 1.0 repository.) The cl-pdf part: http://www.fractalconcept.com:8000/public/open-source/cl-pdf/ The cl-typesetting part: http://www.fractalconcept.com:8000/public/open-source/cl-typesetting/ The mod_lisp part: http://www.fractalconcept.com:8000/public/open-source/mod_lisp/ There are also tarballs for cl-pdf and cl-typesetting: http://www.fractalconcept.com/download/cl-pdf-current.tgz http://www.fractalconcept.com/download/cl-typesetting-current.tgz BTW the (somewhat outdated) home pages for these projects are here: http://www.fractalconcept.com/asp/html/cl-pdf.html http://www.fractalconcept.com/asp/html/cl-typesetting.html http://www.fractalconcept.com/asp/html/mod_lisp.html Marc From a_bakic at yahoo.com Sun Oct 30 20:08:40 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Sun, 30 Oct 2005 12:08:40 -0800 (PST) Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) In-Reply-To: <010301c5dd86$473f63e0$0a02a8c0@marcxp> Message-ID: <20051030200841.90278.qmail@web34615.mail.mud.yahoo.com> > >(I noticed that it > >does not work correctly when pdf:*compress-streams* is true; I am using > salza > >with sbcl compiled for x86 on AMD64...) > > I fixed that. I fixed it, too: first made byte arrays be strings of simple characters (code < 256), then modified zlib.lisp a bit (not using salza), and finally modified sbcl-naturalize-cstring from uffi a bit. I did not like the last part because I am not very familiar with cl-pdf and uffi, so I will probably use your solution. Or, anyway, attached is a patch to my previous solution. > >BTW, does anyone know how I can make a smaller > >font out of a TrueType one, containing only desired characters? > > Sorry no. Using fontforge and Times New Roman to make a TTF font with three alphabets, together with the fixed compression, I got ex1-ttu.pdf drop from around 470kB to around 86kB. Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com -------------- next part -------------- A non-text attachment was scrubbed... Name: new-diffs Type: application/octet-stream Size: 11989 bytes Desc: 3194234562-new-diffs URL: From marc.battyani at fractalconcept.com Sun Oct 30 21:32:07 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 30 Oct 2005 22:32:07 +0100 Subject: [cl-pdf-devel] unicode support (ttf + sb-unicode) References: <20051030200841.90278.qmail@web34615.mail.mud.yahoo.com> Message-ID: <015701c5dd99$60d8c180$0a02a8c0@marcxp> Aleksandar Bakic wrote: >I fixed it, too: first made byte arrays be strings of simple characters (code < >256), then modified zlib.lisp a bit (not using salza), and finally modified >sbcl-naturalize-cstring from uffi a bit. I did not like the last part because I >am not very familiar with cl-pdf and uffi, so I will probably use your >solution. Or, anyway, attached is a patch to my previous solution. Seems a little bit too complex. ;-) And doing this would need to be done for the other versions of zlib... There are more important things to look at IMO. The encoding stuff and the various functions to get the sizes, kerning information, etc. don't work with the ttu-font-metrics. In a second time it would probably be a good idea to try to optimize somewhat the in-memory representation of the font data. (If it is possible of course.) I will look at that. >Using fontforge and Times New Roman to make a TTF font with three alphabets, >together with the fixed compression, I got ex1-ttu.pdf drop from around 470kB >to around 86kB. Good to know. Marc From a_bakic at yahoo.com Mon Oct 31 11:43:09 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Mon, 31 Oct 2005 03:43:09 -0800 (PST) Subject: [cl-pdf-devel] a small patch, perhaps Message-ID: <20051031114309.71966.qmail@web34614.mail.mud.yahoo.com> Hi, I had to make this patch to make cl-typesetting test.lisp work. Index: pdf-base.lisp =================================================================== --- pdf-base.lisp (revision 103) +++ pdf-base.lisp (working copy) @@ -35,7 +35,7 @@ (defun write-cid-char (char) (write-char #\( *page-stream*) - (if (typep (font-metrics *font*) 'ttu-font-metrics) + (if (and *font* (typep (font-metrics *font*) 'ttu-font-metrics)) (let* ((code (char-code char)) (hi (ldb (byte 8 8) code)) (lo (ldb (byte 8 0) code))) Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From marc.battyani at fractalconcept.com Mon Oct 31 14:13:41 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Mon, 31 Oct 2005 15:13:41 +0100 Subject: [cl-pdf-devel] a small patch, perhaps References: <20051031114309.71966.qmail@web34614.mail.mud.yahoo.com> Message-ID: <032f01c5de25$4b9bb8e0$0a02a8c0@marcxp> Aleksandar Bakic wrote: >I had to make this patch to make cl-typesetting test.lisp work. > (defun write-cid-char (char) > (write-char #\( *page-stream*) >- (if (typep (font-metrics *font*) 'ttu-font-metrics) >+ (if (and *font* (typep (font-metrics *font*) 'ttu-font-metrics)) OK. I will do the same for write-cid-string too. Marc From a_bakic at yahoo.com Mon Oct 31 17:55:07 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Mon, 31 Oct 2005 09:55:07 -0800 (PST) Subject: [cl-pdf-devel] a small patch, perhaps In-Reply-To: <032f01c5de25$4b9bb8e0$0a02a8c0@marcxp> Message-ID: <20051031175507.33012.qmail@web34615.mail.mud.yahoo.com> > OK. I will do the same for write-cid-string too. BTW, I have been trying to write-document into a string instead of a file (I need not save the PDf into a file), using sbcl with sb-unicode. There is a problem with it because a string cannot have :external-format set to an 8-bit type. When compression is turned on, the resulting PDF string is for some reason truncated (I guess, some sequences of bytes are interpreted as Unicode characters; it's strange that I haven't hit an invalid one yet). On the other hand, I think I've read that PDF is essentially a binary format (it allows compression, and whatever is human-readable is "by chance"). How about using write-byte instead of write-char all over the code? There would probably still be a problem with strings: I can (MAKE-STRING-OUTPUT-STREAM :ELEMENT-TYPE '(UNSIGNED-BYTE 8)) but GET-OUTPUT-STREAM-STRING expects a string of characters... Perhaps there is way around the problem? Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From marc.battyani at fractalconcept.com Mon Oct 31 20:24:17 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Mon, 31 Oct 2005 21:24:17 +0100 Subject: [cl-pdf-devel] a small patch, perhaps References: <20051031175507.33012.qmail@web34615.mail.mud.yahoo.com> Message-ID: <040801c5de59$11e71660$0a02a8c0@marcxp> Aleksandar Bakic wrote: > > OK. I will do the same for write-cid-string too. > > BTW, I have been trying to write-document into a string instead of a file (I > need not save the PDf into a file), using sbcl with sb-unicode. There is a > problem with it because a string cannot have :external-format set to an 8-bit > type. When compression is turned on, the resulting PDF string is for some > reason truncated (I guess, some sequences of bytes are interpreted as Unicode > characters; it's strange that I haven't hit an invalid one yet). On what Lisp ? > On the other hand, I think I've read that PDF is essentially a binary format > (it allows compression, and whatever is human-readable is "by chance"). How > about using write-byte instead of write-char all over the code? There would > probably still be a problem with strings: I can (MAKE-STRING-OUTPUT-STREAM > :ELEMENT-TYPE '(UNSIGNED-BYTE 8)) but GET-OUTPUT-STREAM-STRING expects a string > of characters... Perhaps there is way around the problem? Dmitri is a fan of turning cl-pdf in binary mode. ;-) I'm convinced too that it's the way to go but I fear it would break on a lot of implementations. So why not, but this needs to have enough people to test on all the impementations. Anyway let's finish the Unicode stuff first. I'm working on the unicode-encoding now. Marc From a_bakic at yahoo.com Mon Oct 31 22:56:30 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Mon, 31 Oct 2005 14:56:30 -0800 (PST) Subject: [cl-pdf-devel] a small patch, perhaps In-Reply-To: <040801c5de59$11e71660$0a02a8c0@marcxp> Message-ID: <20051031225630.67271.qmail@web34612.mail.mud.yahoo.com> > On what Lisp ? SBCL. I figured it out. It is always due to mixing characters and bytes... > Dmitri is a fan of turning cl-pdf in binary mode. ;-) > I'm convinced too that it's the way to go but I fear it would break on a lot > of implementations. So why not, but this needs to have enough people to test > on all the impementations. On SBCL, I have found a way: using arrays of (unsigned-byte 8) instead of strings of (unsigned-byte 8). That would require using vector-push-extend instead of write-byte. Once you have a binary array, write-sequence dumps it nicely into a file; whereas, if it were a binary string, that would not work in SBCL for some reason (maybe it will in the future). > Anyway let's finish the Unicode stuff first. I'm working on the > unicode-encoding now. Great, I am looking forward to it (and am not sure what is all there to finish). I am also trying to generate PDFs dynamically using cl-typesetting in the meantime. Are all those macros involving *document*, *page*, etc., necessary? Could some of them be turned into functions? I would also like if it were possible to link objects (even) later (I am happy to notice that the PDF macros do not generate PDF result immediately, unlike many HTML-generating libraries), so that I can build pieces of a documents independently and then compose them. Now, I cannot just build a page, because whenever I make an instance of indirect-object (sub)class, *document* is used for linking... (or something along those lines). Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From marc.battyani at fractalconcept.com Mon Oct 31 23:32:32 2005 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Tue, 1 Nov 2005 00:32:32 +0100 Subject: [cl-pdf-devel] a small patch, perhaps References: <20051031225630.67271.qmail@web34612.mail.mud.yahoo.com> Message-ID: <04aa01c5de73$61230ee0$0a02a8c0@marcxp> Aleksandar Bakic wrote: > On SBCL, I have found a way: using arrays of (unsigned-byte 8) instead of > strings of (unsigned-byte 8). That would require using vector-push-extend > instead of write-byte. Once you have a binary array, write-sequence dumps it > nicely into a file; whereas, if it were a binary string, that would not work in > SBCL for some reason (maybe it will in the future). > > > Anyway let's finish the Unicode stuff first. I'm working on the > > unicode-encoding now. > > Great, I am looking forward to it (and am not sure what is all there to > finish). I've almost finished. In fact there is a problem with the ufm file. This file does not contains the bounding boxes for the characters. So both the afm and ufm files must be parsed. > I am also trying to generate PDFs dynamically using cl-typesetting in > the meantime. Good idea, it's made for that. ;-) > Are all those macros involving *document*, *page*, etc., > necessary? Could some of them be turned into functions? It's always possible but then you will have to create lambda functions to pass to them. Maybe a functional version in addition to the macros would be good. > I would also like if it > were possible to link objects (even) later (I am happy to notice that the PDF > macros do not generate PDF result immediately, unlike many HTML-generating > libraries), so that I can build pieces of a documents independently and then > compose them. Now, I cannot just build a page, because whenever I make an > instance of indirect-object (sub)class, *document* is used for linking... (or > something along those lines). I don't see where is the problem, do you have an example. Marc From a_bakic at yahoo.com Mon Oct 31 23:58:25 2005 From: a_bakic at yahoo.com (Aleksandar Bakic) Date: Mon, 31 Oct 2005 15:58:25 -0800 (PST) Subject: [cl-pdf-devel] a small patch, perhaps In-Reply-To: <04aa01c5de73$61230ee0$0a02a8c0@marcxp> Message-ID: <20051031235825.55646.qmail@web34607.mail.mud.yahoo.com> > Maybe a functional version in addition to the macros would be good. OK, I'll assume there are no fundamental issues with this and give it a try soon. > I don't see where is the problem, do you have an example. Well, take the first example in test.lisp and remove the wrapping with-document. Just try to evaluate the with-page form (with its contents or not). Alex __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com