[cl-pdf-devel] Unicode issue

Andrey Moskvitin archimag at gmail.com
Sat Dec 29 12:48:35 UTC 2007


>>* The example uses a unicode font and simply puts a string into the
*>>* output document which contains #\Space #\(  #\) and a few other
*>>* characters. Both parenthesis and space are needed to produce the wrong
*>>* pdf.*

> Unfortunately, the unicode integration is still in an alpha state as
> I've never found the time to continue it :(
> I will look at your example to see if I can make a fix for it.

I encountered the same problem with unbalanced parentheses in text.

Sample code (Gentoo Linux, sbcl-1.0.12):

(pdf:load-ttu-font #P"/usr/local/fonts/arial.ufm"
#P"/usr/local/fonts/arial.ttf")

(with-open-file (out #P"/tmp/bad.pdf" :direction :output :if-exists
:supersede :element-type :default :external-format :latin-1)
  (pdf:with-document ()
    (pdf:with-page ()
      (pdf:in-text-mode
        (pdf:move-text 20 20)
        (pdf:set-font (pdf:get-font "ArialMT") 12)
        (pdf::show-text "hello (")))
    (pdf:write-document out)))

The problem in the function of write-cid-string. I change it and
solved the problem:

--- /usr/share/common-lisp/source/cl-pdf/pdf-base.lisp  2007-10-10
12:50:45.000000000 +0000
+++ pdf-base.lisp       2007-12-29 16:38:18.000000000 +0000
@@ -25,11 +25,14 @@
   (write-char #\( *page-stream*)
   (if (and *font* (typep (font-metrics *font*) 'ttu-font-metrics))
       (loop for c across string do
-          (let* ((code (char-code c))
-                 (hi (ldb (byte 8 8) code))
-                 (lo (ldb (byte 8 0) code)))
-            (write-char (code-char hi) *page-stream*)
-            (write-char (code-char lo) *page-stream*)))
+           (let* ((code (char-code c))
+              (hi (ldb (byte 8 8) code))
+              (lo (ldb (byte 8 0) code))
+              (is-bracket (or (eql c #\() (eql c #\)))))
+             (if is-bracket (write-char #\\ *page-stream*))
+             (write-char (code-char hi) *page-stream*)
+             (if is-bracket (write-char #\\ *page-stream*))
+             (write-char (code-char lo) *page-stream*)))
       (princ string *page-stream*))
   (write-string ") " *page-stream*))



Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-pdf-devel/attachments/20071229/9efeccaf/attachment.html>


More information about the cl-pdf-devel mailing list