[cl-typesetting-devel] Re: [cl-pdf-devel] Character encoding?

Peter Seibel peter at gigamonkeys.com
Mon Feb 25 06:31:33 UTC 2008


Okay, here's the patch mentioned in my previous message:

diff -r 81aa27926362 cl-typesetting/typo.lisp
--- a/cl-typesetting/typo.lisp	Sat Feb 23 21:17:20 2008 -0800
+++ b/cl-typesetting/typo.lisp	Sun Feb 24 22:25:44 2008 -0800
@@ -151,6 +151,7 @@
  (defclass text-line (hbox)
    ())

+
  (defun make-char-box (char)
    (if *use-exact-char-boxes*
        (multiple-value-bind (width ascender descender) 
(pdf:get-char-size char *font* *font-size*)
@@ -225,12 +226,58 @@
  (defun white-char-p (char)
    (find char *white-chars*))

+(defgeneric convert-code-point (code-point font-encoding lisp-encoding))
+
+(defmethod convert-code-point (code-point font-encoding lisp-encoding)
+  (unless (eql font-encoding lisp-encoding)
+    (warn "Don't know how to convert ~a code points to ~a. Using 
identity." lisp-encoding font-encoding))
+  code-point)
+
+(defmethod convert-code-point (code-point (font-encoding (eql 
:win-ansi-encoding)) (lisp-encoding (eql :unicode-encoding)))
+  (case code-point
+    (338 140) ; #\LATIN_CAPITAL_LIGATURE_OE
+    (339 156) ; #\LATIN_SMALL_LIGATURE_OE
+    (352 138) ; #\LATIN_CAPITAL_LETTER_S_WITH_CARON
+    (353 154) ; #\LATIN_SMALL_LETTER_S_WITH_CARON
+    (376 159) ; #\LATIN_CAPITAL_LETTER_Y_WITH_DIAERESIS
+    (381 142) ; #\LATIN_CAPITAL_LETTER_Z_WITH_CARON
+    (382 158) ; #\LATIN_SMALL_LETTER_Z_WITH_CARON
+    (402 131) ; #\LATIN_SMALL_LETTER_F_WITH_HOOK
+    (710 136) ; #\MODIFIER_LETTER_CIRCUMFLEX_ACCENT
+    (732 152) ; #\SMALL_TILDE
+    (8211 150) ; #\EN_DASH
+    (8212 151) ; #\EM_DASH
+    (8216 145) ; #\LEFT_SINGLE_QUOTATION_MARK
+    (8217 146) ; #\RIGHT_SINGLE_QUOTATION_MARK
+    (8218 130) ; #\SINGLE_LOW-9_QUOTATION_MARK
+    (8220 147) ; #\LEFT_DOUBLE_QUOTATION_MARK
+    (8221 148) ; #\RIGHT_DOUBLE_QUOTATION_MARK
+    (8222 132) ; #\DOUBLE_LOW-9_QUOTATION_MARK
+    (8224 134) ; #\DAGGER
+    (8225 135) ; #\DOUBLE_DAGGER
+    (8226 149) ; #\BULLET
+    (8230 133) ; #\HORIZONTAL_ELLIPSIS
+    (8240 137) ; #\PER_MILLE_SIGN
+    (8249 139) ; #\SINGLE_LEFT-POINTING_ANGLE_QUOTATION_MARK
+    (8250 155) ; #\SINGLE_RIGHT-POINTING_ANGLE_QUOTATION_MARK
+    (8364 128) ; #\EURO_SIGN
+    (8482 153) ; #\TRADE_MARK_SIGN
+    (t code-point)))
+
+(defun convert-char-encoding (char)
+  (code-char
+   (convert-code-point
+    (char-code char)
+    (pdf::keyword-name (pdf::encoding *font*))
+    :unicode-encoding)))
+
  (defun put-string (string)
    (when (stringp string)
      (let ((hyphen-points (hyphenate-string string)))
        (loop with hyphen-point = (pop hyphen-points)
  	  for prev-char = #\I then char
-	  for char across string
+	  for actual-char across string
+	  for char = (convert-char-encoding actual-char)
  	  for i from 0
  	  for kerning = (* (pdf:get-kerning prev-char char *font* 
*font-size*) *text-x-scale*)
  	  do
@@ -251,7 +298,8 @@
  (defun verbatim (string)
    "put a string in a 'verbatim' way: no kerning, no hyphenation, 
significant whitespaces, significant newlines"
    (when (stringp string)
-    (loop for char across string
+    (loop for actual-char across string
+	  for char = (convert-char-encoding actual-char)
  	  for i from 0
  	  do
  	    (cond

-- 
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