[cl-typesetting-devel] Unicode?

Peter Seibel peter at gigamonkeys.com
Sat Sep 8 02:47:08 UTC 2007


Dmitriy Ivanov wrote:
> Hello Peter,
> 
> | I've got this simple test program which, as you can see, attempts to
> | use one of the LatinModern unicode fonts and tries to render some text
> | that contains a unicode emdash (code-point #x2014).
> |
> | (defpackage :foo (:use :cl :cl-pdf))
> |
> | (in-package :foo)
> |
> | (defun test-unicode  (&optional (file #P"foo.pdf"))
> |    (pdf:with-document ()
> |      (pdf:with-page ()
> |        (pdf:with-outline-level ("Example"
> | (pdf:register-page-reference)) (let ((font (pdf:get-font
> | "LMRoman12-Regular")))   (pdf:in-text-mode
> |     (pdf:set-font font 14.0)
> |     (pdf:move-text 100 800)
> |     (pdf:draw-text
> |               (format nil "This ~c is a test." (code-char #x2014)))))))
> |      (pdf:write-document file)
> |      file))
> |
> |
> | When I run this function in generates a file without error but the
> | emdash is nowhere to be seen. Is this a problem with the font (which
> | was loaded from an .afm file not a .ufm) or with cl-pdf or with
> | something I'm doing wrong?
> 
> First, I believe that is a cl-pdf-devel question, not cl-typesetting-devel
> :-)

Hmmmm, I thought the lists had been collapsed into a single list. Guess 
I misremembered.

Anyway, after some more investigation, I think the problem goes much 
deeper than just a font metric issue. I looked at the PDF file generated 
when I made the text was (format nil "A~cB" (code-char #x2014). In the 
PDF there's a:

   (A?B) Tj

where the ? is actually the character #x14, i.e. the bottom byte of the 
#x2014 character. It conceivable that through some proper manipulation 
of external-formats somewhere I could fix that but it wouldn't help 
because, as far as I understand the PDF spec, (...) strings can only 
contain ASCII characters. There is obviously some way to include Unicode 
text (uncoded in UTF-16BE, I believe) in PDFs but it's much more 
involved than just throwing some text between ()'s. I think the relevant 
sections of the PDF spec may be 5.6 Composite Fonts and following.

-Peter

-- 
Peter Seibel                     : peter at gigamonkeys.com
A Billion Monkeys Can't be Wrong : http://www.gigamonkeys.com/blog/
Practical Common Lisp            : http://www.gigamonkeys.com/book/
Coders at Work                   : http://www.codersatwork.com/



More information about the cl-typesetting-devel mailing list