root/trunk/thirdparty/cl-pdf/encodings.lisp

Revision 2636, 29.3 kB (checked in by hans, 10 months ago)

add cl-pdf for pixel->pdf converter

Line 
1 ;;; cl-pdf copyright 2002-2003 Marc Battyani see license.txt for the details
2 ;;; You can reach me at marc.battyani@fractalconcept.com or marc@battyani.net
3 ;;; The homepage of cl-pdf is here: http://www.fractalconcept.com/asp/html/cl-pdf.html
4
5 (in-package #:pdf)
6
7 (defvar *default-encoding* :win-ansi-encoding)
8
9 (defvar *encodings* (make-hash-table :test #'equal))
10
11 (defun get-encoding (encoding-designator)
12   (gethash encoding-designator *encodings*))
13
14 ;;; Abstract encoding
15
16 (defclass encoding ()
17  ((name :accessor name :initform nil :initarg :name)
18   (keyword-name :accessor keyword-name :initform nil :initarg :keyword-name)
19   (standard-encoding :accessor standard-encoding :initform nil :initarg :standard-encoding)))
20
21 (defmethod initialize-instance :after ((encoding encoding) &key &allow-other-keys)
22   (unless (name encoding)
23     (error "You must provide a name when you create an encoding."))
24   (unless (keyword-name encoding)
25     (setf (keyword-name encoding)(intern (string-upcase (name encoding)) :keyword)))
26   (setf (gethash encoding *encodings*) encoding
27         (gethash (name encoding) *encodings*) encoding
28         (gethash (keyword-name encoding) *encodings*) encoding))
29
30 (defmethod print-object ((self encoding) stream)
31   (print-unreadable-object (self stream :identity t :type t)
32     (format stream "~a" (name self))))
33
34 ;;; Single-byte encoding
35
36 (defclass single-byte-encoding (encoding)
37  ((char-names :accessor char-names :initform nil :initarg :char-names)
38   (char-codes :accessor char-codes :initform (make-hash-table :test #'equal))))
39
40 (defmethod initialize-instance :after ((encoding single-byte-encoding) &key &allow-other-keys)
41   (unless (char-names encoding)
42     (error "You must provide code-to-char-name array (256) when you create a single-byte encoding."))
43   (loop with char-codes = (char-codes encoding)
44         for char-name across (char-names encoding)
45         for code from 0
46         when char-name do (setf (gethash char-name char-codes) code)))
47
48 (defmethod make-dictionary ((encoding encoding) &key &allow-other-keys)
49   (with-slots (base-encoding) encoding
50     (make-instance 'dictionary :dict-values
51       `(("/Type" . "/Encoding")
52         ("/Differences" . ,(compute-encoding-differences encoding nil))))))
53
54 ;; Charset is an atom or "extended charset" - an alist storing (char . code) pairs
55 (defgeneric charset (encoding))
56
57 (defmethod charset ((encoding single-byte-encoding))
58   (declare (ignorable encoding))
59   *char-single-byte-codes*)
60
61 (defun char-external-code (char charset)
62   (cond ((null charset)
63          (char-code char))
64         ((atom charset)
65          #+lispworks (ef:char-external-code char charset)
66          #+allegro   (aref (excl:string-to-octets (coerce `(,char) 'string)
67                                                   :external-format charset)
68                            0)
69          #+sbcl      (aref (sb-ext:string-to-octets (coerce `(,char) 'string)
70                                                     :external-format charset)
71                            0)
72          #-(or lispworks allegro sbcl)  (char-code char))
73         ((cdr (assoc char charset)))            ; map to single-byte if possible
74         (t (char-code char))))
75
76 ;;; Built-in encoding instances
77
78 (defparameter *standard-encoding*
79   (make-instance 'single-byte-encoding
80                  :name "StandardEncoding"  :keyword-name :standard-encoding
81                  :standard-encoding t :char-names #(
82 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
83 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
84 "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand"
85 "quoteright" "parenleft" "parenright" "asterisk" "plus" "comma"
86 "hyphen" "period" "slash" "zero" "one" "two" "three" "four" "five"
87 "six" "seven" "eight" "nine" "colon" "semicolon" "less" "equal"
88 "greater" "question" "at" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K"
89 "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
90 "bracketleft" "backslash" "bracketright" "asciicircum" "underscore"
91 "quoteleft" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
92 "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar"
93 "braceright" "asciitilde" nil nil nil nil nil nil nil nil nil nil nil
94 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
95 nil nil nil nil nil "exclamdown" "cent" "sterling" "fraction" "yen"
96 "florin" "section" "currency" "quotesingle" "quotedblleft"
97 "guillemotleft" "guilsinglleft" "guilsinglright" "fi" "fl" nil "endash"
98 "dagger" "daggerdbl" "periodcentered" nil "paragraph" "bullet"
99 "quotesinglbase" "quotedblbase" "quotedblright" "guillemotright"
100 "ellipsis" "perthousand" nil "questiondown" nil "grave" "acute"
101 "circumflex" "tilde" "macron" "breve" "dotaccent" "dieresis" nil "ring"
102 "cedilla" nil "hungarumlaut" "ogonek" "caron" "emdash" nil nil nil nil
103 nil nil nil nil nil nil nil nil nil nil nil nil "AE" nil "ordfeminine"
104 nil nil nil nil "Lslash" "Oslash" "OE" "ordmasculine" nil nil nil nil
105 nil "ae" nil nil nil "dotlessi" nil nil "lslash" "oslash" "oe"
106 "germandbls" nil nil nil nil )))
107
108 (defparameter *mac-roman-encoding*
109   (make-instance 'single-byte-encoding
110                  :name "MacRomanEncoding"  :keyword-name :mac-roman-encoding
111                  :standard-encoding t  :char-names #(
112 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
113 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
114 "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand"
115 "quotesingle" "parenleft" "parenright" "asterisk" "plus" "comma"
116 "hyphen" "period" "slash" "zero" "one" "two" "three" "four" "five"
117 "six" "seven" "eight" "nine" "colon" "semicolon" "less" "equal"
118 "greater" "question" "at" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K"
119 "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
120 "bracketleft" "backslash" "bracketright" "asciicircum" "underscore"
121 "grave" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
122 "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar" "braceright"
123 "asciitilde" nil "Adieresis" "Aring" "Ccedilla" "Eacute" "Ntilde"
124 "Odieresis" "Udieresis" "aacute" "agrave" "acircumflex" "adieresis"
125 "atilde" "aring" "ccedilla" "eacute" "egrave" "ecircumflex" "edieresis"
126 "iacute" "igrave" "icircumflex" "idieresis" "ntilde" "oacute" "ograve"
127 "ocircumflex" "odieresis" "otilde" "uacute" "ugrave" "ucircumflex"
128 "udieresis" "dagger" "degree" "cent" "sterling" "section" "bullet"
129 "paragraph" "germandbls" "registered" "copyright" "trademark" "acute"
130 "dieresis" nil "AE" "Oslash" nil "plusminus" nil nil "yen" "mu" nil nil
131 nil nil nil "ordfeminine" "ordmasculine" nil "ae" "oslash"
132 "questiondown" "exclamdown" "logicalnot" nil "florin" nil nil
133 "guillemotleft" "guillemotright" "ellipsis" "space" "Agrave" "Atilde"
134 "Otilde" "OE" "oe" "endash" "emdash" "quotedblleft" "quotedblright"
135 "quoteleft" "quoteright" "divide" nil "ydieresis" "Ydieresis"
136 "fraction" "currency" "guilsinglleft" "guilsinglright" "fi" "fl"
137 "daggerdbl" "periodcentered" "quotesinglbase" "quotedblbase"
138 "perthousand" "Acircumflex" "Ecircumflex" "Aacute" "Edieresis" "Egrave"
139 "Iacute" "Icircumflex" "Idieresis" "Igrave" "Oacute" "Ocircumflex" nil
140 "Ograve" "Uacute" "Ucircumflex" "Ugrave" "dotlessi" "circumflex"
141 "tilde" "macron" "breve" "dotaccent" "ring" "cedilla" "hungarumlaut"
142 "ogonek" "caron" )))
143
144 (defparameter *win-ansi-encoding*
145   (make-instance 'single-byte-encoding
146                  :name "WinAnsiEncoding"  :keyword-name :win-ansi-encoding
147                  :standard-encoding t  :char-names #(
148 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
149 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
150 "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand"
151 "quotesingle" "parenleft" "parenright" "asterisk" "plus" "comma"
152 "hyphen" "period" "slash" "zero" "one" "two" "three" "four" "five"
153 "six" "seven" "eight" "nine" "colon" "semicolon" "less" "equal"
154 "greater" "question" "at" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K"
155 "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
156 "bracketleft" "backslash" "bracketright" "asciicircum" "underscore"
157 "grave" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
158 "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar" "braceright"
159 "asciitilde" "bullet" "Euro" "bullet" "quotesinglbase" "florin"
160 "quotedblbase" "ellipsis" "dagger" "daggerdbl" "circumflex"
161 "perthousand" "Scaron" "guilsinglleft" "OE" "bullet" "Zcaron" "bullet"
162 "bullet" "quoteleft" "quoteright" "quotedblleft" "quotedblright"
163 "bullet" "endash" "emdash" "tilde" "trademark" "scaron"
164 "guilsinglright" "oe" "bullet" "zcaron" "Ydieresis" "space"
165 "exclamdown" "cent" "sterling" "currency" "yen" "brokenbar" "section"
166 "dieresis" "copyright" "ordfeminine" "guillemotleft" "logicalnot"
167 "hyphen" "registered" "macron" "degree" "plusminus" "twosuperior"
168 "threesuperior" "acute" "mu" "paragraph" "periodcentered" "cedilla"
169 "onesuperior" "ordmasculine" "guillemotright" "onequarter" "onehalf"
170 "threequarters" "questiondown" "Agrave" "Aacute" "Acircumflex" "Atilde"
171 "Adieresis" "Aring" "AE" "Ccedilla" "Egrave" "Eacute" "Ecircumflex"
172 "Edieresis" "Igrave" "Iacute" "Icircumflex" "Idieresis" "Eth" "Ntilde"
173 "Ograve" "Oacute" "Ocircumflex" "Otilde" "Odieresis" "multiply"
174 "Oslash" "Ugrave" "Uacute" "Ucircumflex" "Udieresis" "Yacute" "Thorn"
175 "germandbls" "agrave" "aacute" "acircumflex" "atilde" "adieresis"
176 "aring" "ae" "ccedilla" "egrave" "eacute" "ecircumflex" "edieresis"
177 "igrave" "iacute" "icircumflex" "idieresis" "eth" "ntilde" "ograve"
178 "oacute" "ocircumflex" "otilde" "odieresis" "divide" "oslash" "ugrave"
179 "uacute" "ucircumflex" "udieresis" "yacute" "thorn" "ydieresis" )))
180
181 (defparameter *pdf-doc-encoding*
182   (make-instance 'single-byte-encoding
183                  :name "PDFDocEncoding"  :keyword-name :pdf-doc-encoding
184                  :standard-encoding t  :char-names #(
185 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
186 nil nil nil nil nil nil "breve" "caron" "circumflex" "dotaccent"
187 "hungarumlaut" "ogonek" "ring" "tilde" "space" "exclam" "quotedbl"
188 "numbersign" "dollar" "percent" "ampersand" "quotesingle" "parenleft"
189 "parenright" "asterisk" "plus" "comma" "hyphen" "period" "slash" "zero"
190 "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "colon"
191 "semicolon" "less" "equal" "greater" "question" "at" "A" "B" "C" "D"
192 "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V"
193 "W" "X" "Y" "Z" "bracketleft" "backslash" "bracketright" "asciicircum"
194 "underscore" "grave" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
195 "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft"
196 "bar" "braceright" "asciitilde" nil "bullet" "dagger" "daggerdbl"
197 "ellipsis" "emdash" "endash" "florin" "fraction" "guilsinglleft"
198 "guilsinglright" "minus" "perthousand" "quotedblbase" "quotedblleft"
199 "quotedblright" "quoteleft" "quoteright" "quotesinglbase" "trademark"
200 "fi" "fl" "Lslash" "OE" "Scaron" "Ydieresis" "Zcaron" "dotlessi"
201 "lslash" "oe" "scaron" "zcaron" nil "Euro" "exclamdown" "cent"
202 "sterling" "currency" "yen" "brokenbar" "section" "dieresis"
203 "copyright" "ordfeminine" "guillemotleft" "logicalnot" nil "registered"
204 "macron" "degree" "plusminus" "twosuperior" "threesuperior" "acute"
205 "mu" "paragraph" "periodcentered" "cedilla" "onesuperior"
206 "ordmasculine" "guillemotright" "onequarter" "onehalf" "threequarters"
207 "questiondown" "Agrave" "Aacute" "Acircumflex" "Atilde" "Adieresis"
208 "Aring" "AE" "Ccedilla" "Egrave" "Eacute" "Ecircumflex" "Edieresis"
209 "Igrave" "Iacute" "Icircumflex" "Idieresis" "Eth" "Ntilde" "Ograve"
210 "Oacute" "Ocircumflex" "Otilde" "Odieresis" "multiply" "Oslash"
211 "Ugrave" "Uacute" "Ucircumflex" "Udieresis" "Yacute" "Thorn"
212 "germandbls" "agrave" "aacute" "acircumflex" "atilde" "adieresis"
213 "aring" "ae" "ccedilla" "egrave" "eacute" "ecircumflex" "edieresis"
214 "igrave" "iacute" "icircumflex" "idieresis" "eth" "ntilde" "ograve"
215 "oacute" "ocircumflex" "otilde" "odieresis" "divide" "oslash" "ugrave"
216 "uacute" "ucircumflex" "udieresis" "yacute" "thorn" "ydieresis" )))
217
218 (defparameter *mac-expert-encoding*
219   (make-instance 'single-byte-encoding
220                  :name "MacExpertEncoding"  :keyword-name :mac-expert-encoding
221                  :standard-encoding t  :char-names #(
222 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
223 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
224 "exclamsmall" "Hungarumlautsmall" "centoldstyle" "dollaroldstyle"
225 "dollarsuperior" "ampersandsmall" "Acutesmall" "parenleftsuperior"
226 "parenrightsuperior" "twodotenleader" "onedotenleader" "comma" "hyphen"
227 "period" "fraction" "zerooldstyle" "oneoldstyle" "twooldstyle"
228 "threeoldstyle" "fouroldstyle" "fiveoldstyle" "sixoldstyle"
229 "sevenoldstyle" "eightoldstyle" "nineoldstyle" "colon" "semicolon" nil
230 "threequartersemdash" nil "questionsmall" nil nil nil nil "Ethsmall"
231 nil nil "onequarter" "onehalf" "threequarters" "oneeighth"
232 "threeeighths" "fiveeighths" "seveneighths" "onethird" "twothirds" nil
233 nil nil nil nil nil "ff" "fi" "fl" "ffi" "ffl" "parenleftinferior" nil
234 "parenrightinferior" "Circumflexsmall" "hypheninferior" "Gravesmall"
235 "Asmall" "Bsmall" "Csmall" "Dsmall" "Esmall" "Fsmall" "Gsmall" "Hsmall"
236 "Ismall" "Jsmall" "Ksmall" "Lsmall" "Msmall" "Nsmall" "Osmall" "Psmall"
237 "Qsmall" "Rsmall" "Ssmall" "Tsmall" "Usmall" "Vsmall" "Wsmall" "Xsmall"
238 "Ysmall" "Zsmall" "colonmonetary" "onefitted" "rupiah" "Tildesmall" nil
239 nil "asuperior" "centsuperior" nil nil nil nil "Aacutesmall"
240 "Agravesmall" "Acircumflexsmall" "Adieresissmall" "Atildesmall"
241 "Aringsmall" "Ccedillasmall" "Eacutesmall" "Egravesmall"
242 "Ecircumflexsmall" "Edieresissmall" "Iacutesmall" "Igravesmall"
243 "Icircumflexsmall" "Idieresissmall" "Ntildesmall" "Oacutesmall"
244 "Ogravesmall" "Ocircumflexsmall" "Odieresissmall" "Otildesmall"
245 "Uacutesmall" "Ugravesmall" "Ucircumflexsmall" "Udieresissmall" nil
246 "eightsuperior" "fourinferior" "threeinferior" "sixinferior"
247 "eightinferior" "seveninferior" "Scaronsmall" nil "centinferior"
248 "twoinferior" nil "Dieresissmall" nil "Caronsmall" "osuperior"
249 "fiveinferior" nil "commainferior" "periodinferior" "Yacutesmall" nil
250 "dollarinferior" nil nil "Thornsmall" nil "nineinferior" "zeroinferior"
251 "Zcaronsmall" "AEsmall" "Oslashsmall" "questiondownsmall" "oneinferior"
252 "Lslashsmall" nil nil nil nil nil nil "Cedillasmall" nil nil nil nil
253 nil "OEsmall" "figuredash" "hyphensuperior" nil nil nil nil
254 "exclamdownsmall" nil "Ydieresissmall" nil "onesuperior" "twosuperior"
255 "threesuperior" "foursuperior" "fivesuperior" "sixsuperior"
256 "sevensuperior" "ninesuperior" "zerosuperior" nil "esuperior"
257 "rsuperior" "tsuperior" nil nil "isuperior" "ssuperior" "dsuperior" nil
258 nil nil nil nil "lsuperior" "Ogoneksmall" "Brevesmall" "Macronsmall"
259 "bsuperior" "nsuperior" "msuperior" "commasuperior" "periodsuperior"
260 "Dotaccentsmall" "Ringsmall" nil nil nil nil )))
261
262 (defparameter *symbol-encoding*
263   (make-instance 'single-byte-encoding
264                  :name "SymbolEncoding"  :keyword-name :symbol-encoding
265                  :standard-encoding t  :char-names #(
266 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
267 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
268 "exclam" "universal" "numbersign" "existential" "percent" "ampersand"
269 "suchthat" "parenleft" "parenright" "asteriskmath" "plus" "comma"
270 "minus" "period" "slash" "zero" "one" "two" "three" "four" "five" "six"
271 "seven" "eight" "nine" "colon" "semicolon" "less" "equal" "greater"
272 "question" "congruent" "Alpha" "Beta" "Chi" "Delta" "Epsilon" "Phi"
273 "Gamma" "Eta" "Iota" "theta1" "Kappa" "Lambda" "Mu" "Nu" "Omicron" "Pi"
274 "Theta" "Rho" "Sigma" "Tau" "Upsilon" "sigma1" "Omega" "Xi" "Psi"
275 "Zeta" "bracketleft" "therefore" "bracketright" "perpendicular"
276 "underscore" "radicalex" "alpha" "beta" "chi" "delta" "epsilon" "phi"
277 "gamma" "eta" "iota" "phi1" "kappa" "lambda" "mu" "nu" "omicron" "pi"
278 "theta" "rho" "sigma" "tau" "upsilon" "omega1" "omega" "xi" "psi"
279 "zeta" "braceleft" "bar" "braceright" "similar" nil nil nil nil nil nil
280 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
281 nil nil nil nil nil nil nil nil nil "Euro" "Upsilon1" "minute"
282 "lessequal" "fraction" "infinity" "florin" "club" "diamond" "heart"
283 "spade" "arrowboth" "arrowleft" "arrowup" "arrowright" "arrowdown"
284 "degree" "plusminus" "second" "greaterequal" "multiply" "proportional"
285 "partialdiff" "bullet" "divide" "notequal" "equivalence" "approxequal"
286 "ellipsis" "arrowvertex" "arrowhorizex" "carriagereturn" "aleph"
287 "Ifraktur" "Rfraktur" "weierstrass" "circlemultiply" "circleplus"
288 "emptyset" "intersection" "union" "propersuperset" "reflexsuperset"
289 "notsubset" "propersubset" "reflexsubset" "element" "notelement"
290 "angle" "gradient" "registerserif" "copyrightserif" "trademarkserif"
291 "product" "radical" "dotmath" "logicalnot" "logicaland" "logicalor"
292 "arrowdblboth" "arrowdblleft" "arrowdblup" "arrowdblright"
293 "arrowdbldown" "lozenge" "angleleft" "registersans" "copyrightsans"
294 "trademarksans" "summation" "parenlefttp" "parenleftex" "parenleftbt"
295 "bracketlefttp" "bracketleftex" "bracketleftbt" "bracelefttp"
296 "braceleftmid" "braceleftbt" "braceex" nil "angleright" "integral"
297 "integraltp" "integralex" "integralbt" "parenrighttp" "parenrightex"
298 "parenrightbt" "bracketrighttp" "bracketrightex" "bracketrightbt"
299 "bracerighttp" "bracerightmid" "bracerightbt" nil )))
300
301 (defvar *zapf-dingbats-encoding*
302   (make-instance 'single-byte-encoding
303                  :name "ZapfDingbatsEncoding"  :keyword-name :zapf-dingbats-encoding
304                  :standard-encoding t  :char-names #(
305 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
306 nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space" "a1"
307 "a2" "a202" "a3" "a4" "a5" "a119" "a118" "a117" "a11" "a12" "a13" "a14"
308 "a15" "a16" "a105" "a17" "a18" "a19" "a20" "a21" "a22" "a23" "a24"
309 "a25" "a26" "a27" "a28" "a6" "a7" "a8" "a9" "a10" "a29" "a30" "a31"
310 "a32" "a33" "a34" "a35" "a36" "a37" "a38" "a39" "a40" "a41" "a42" "a43"
311 "a44" "a45" "a46" "a47" "a48" "a49" "a50" "a51" "a52" "a53" "a54" "a55"
312 "a56" "a57" "a58" "a59" "a60" "a61" "a62" "a63" "a64" "a65" "a66" "a67"
313 "a68" "a69" "a70" "a71" "a72" "a73" "a74" "a203" "a75" "a204" "a76"
314 "a77" "a78" "a79" "a81" "a82" "a83" "a84" "a97" "a98" "a99" "a100" nil
315 "a89" "a90" "a93" "a94" "a91" "a92" "a205" "a85" "a206" "a86" "a87"
316 "a88" "a95" "a96" nil nil nil nil nil nil nil nil nil nil nil nil nil
317 nil nil nil nil nil nil "a101" "a102" "a103" "a104" "a106" "a107"
318 "a108" "a112" "a111" "a110" "a109" "a120" "a121" "a122" "a123" "a124"
319 "a125" "a126" "a127" "a128" "a129" "a130" "a131" "a132" "a133" "a134"
320 "a135" "a136" "a137" "a138" "a139" "a140" "a141" "a142" "a143" "a144"
321 "a145" "a146" "a147" "a148" "a149" "a150" "a151" "a152" "a153" "a154"
322 "a155" "a156" "a157" "a158" "a159" "a160" "a161" "a163" "a164" "a196"
323 "a165" "a192" "a166" "a167" "a168" "a169" "a170" "a171" "a172" "a173"
324 "a162" "a174" "a175" "a176" "a177" "a178" "a179" "a193" "a180" "a199"
325 "a181" "a200" "a182" nil "a201" "a183" "a184" "a197" "a185" "a194"
326 "a198" "a186" "a195" "a187" "a188" "a189" "a190" "a191" nil )))
327
328
329 (defun compute-encoding-differences (encoding &optional (from *standard-encoding*))
330   (let ((differences (make-array 20 :fill-pointer 0 :adjustable t))
331         (range-started nil))
332     (if from
333         (flet ((start-range (code)
334                  (when (or (and code (not range-started))(and (not code) range-started))
335                    (setf range-started code)
336                    (when code (vector-push-extend code differences)))))
337           (loop ;with start-code = nil
338                 for standard-char-name across (char-names from)
339                 for char-name across (char-names encoding)
340                 for code from 0
341                 do
342                 (cond
343                   ((and (not char-name) standard-char-name)
344                    (start-range code) (vector-push-extend ".notdef" differences))
345                   ((and char-name (not (equal char-name standard-char-name)))
346                    (start-range code)
347                    (vector-push-extend (add-/ char-name) differences))
348                   (t (start-range nil)))))
349         (full-encoding-differences encoding))
350         differences))
351
352 ;;; Just put all...
353 (defun full-encoding-differences (encoding)
354   (let ((differences (make-array 20 :fill-pointer 0 :adjustable t)))
355     (vector-push-extend 0 differences)
356     (loop for char-name across (char-names encoding)
357           for code from 0
358           do (if char-name
359                  (vector-push-extend (concatenate 'string "/" char-name) differences)
360                  (vector-push-extend "/.notdef" differences)))
361     differences))
362
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
364 ;;; Custom encoding
365
366 (defclass custom-encoding (single-byte-encoding)
367  ((base-encoding :initarg :base-encoding :reader base-encoding :initform nil)
368   ;; Implementation-dependent value that specifeis a mapping
369   ;;  from Unicode character codes (Lisp characters)
370   ;;  to one-byte character codes belonging [0-255] range.
371   ;; Q: Store char-to-code hash-table?
372   (charset :accessor charset :initarg :charset :initform nil)))
373
374 (defmethod initialize-instance :after ((encoding custom-encoding) &key &allow-other-keys)
375   (with-slots (base-encoding) encoding
376     (when (and base-encoding
377                (or (stringp base-encoding) (symbolp base-encoding)))
378       (setf base-encoding (gethash base-encoding *encodings* base-encoding)))))
379
380
381 (defmethod make-dictionary ((encoding custom-encoding) &key &allow-other-keys)
382   (with-slots (base-encoding) encoding
383     (make-instance 'dictionary :dict-values
384       `(("/Type" . "/Encoding")
385         ,@(when base-encoding
386             `(("/BaseEncoding" . ,(add-/ (name base-encoding)))
387               ("/Differences" . ,(compute-encoding-differences encoding
388                                                                base-encoding))))))))
389
390 ;;; CAUTION:
391 ;;;  Basing on :win-ansi-encoding fails for embedded Type1 fonts!
392 ;;;  For some installed fonts that are not embedded, :win-ansi-encoding gets better
393 ;;;  results, so it should be specified explicitly for get-font.
394 ;;;  It seems that get-font should not have any default for the encoding parameter.
395
396 (defparameter *win-1251-encoding*
397   (make-instance 'custom-encoding
398                  :name "Win1251Encoding"  :keyword-name :win-1251-encoding
399                  :base-encoding :standard-encoding      ;:win-ansi-encoding doesn't work!
400                  :charset #+lispworks 1251              ; passed to ef:char-external-code
401                           #+allegro :1251
402                           #+sbcl :windows-1251
403                           #-(or lispworks allegro sbcl) nil             ; <- customize your lisp here
404                  :char-names #(
405         nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
406         nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
407         "space" "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand"
408         "quotesingle" "parenleft" "parenright" "asterisk" "plus" "comma" "hyphen"
409         "period" "slash" "zero" "one" "two" "three" "four" "five" "six" "seven"
410         "eight" "nine" "colon" "semicolon" "less" "equal" "greater" "question" "at"
411         "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
412         "T" "U" "V" "W" "X" "Y" "Z" "bracketleft" "backslash" "bracketright"
413         "asciicircum" "underscore" "grave"
414         "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
415         "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar" "braceright" "asciitilde"
416         nil "Djecyrillic" "Gjecyrillic" "quotesinglbase" "gjecyrillic" "quotedblbase"
417         "ellipsis" "dagger" "daggerdbl" "Euro" "perthousand" "Ljecyrillic"
418         "guilsinglleft" "Njecyrillic" "Kjecyrillic" "Tshecyrillic" "Dzhecyrillic"
419         "djecyrillic" "quoteleft" "quoteright" "quotedblleft" "quotedblright" "bullet"
420         "endash" "emdash" NIL "trademark" "ljecyrillic" "guilsinglright" "njecyrillic"
421         "kjecyrillic" "tshecyrillic" "dzhecyrillic" "space" "Ushortcyrillic"
422         "ushortcyrillic" "Jecyrillic" "currency" "Gheupturncyrillic" "brokenbar"
423         "section" "Iocyrillic" "copyright" "Ecyrillic" "guillemotleft" "logicalnot"
424         "hyphen" "registered" "Yicyrillic" "degree" "plusminus" "Icyrillic" "icyrillic"
425         "gheupturncyrillic" "mu" "paragraph" "periodcentered" "iocyrillic" "numero"
426         "ecyrillic" "guillemotright" "jecyrillic" "Dzecyrillic" "dzecyrillic" "yicyrillic"
427         "Acyrillic" "Becyrillic" "Vecyrillic" "Gecyrillic" "Decyrillic" "Iecyrillic"
428         "Zhecyrillic" "Zecyrillic" "Iicyrillic" "Iishortcyrillic" "Kacyrillic"
429         "Elcyrillic" "Emcyrillic" "Encyrillic" "Ocyrillic" "Pecyrillic" "Ercyrillic"
430         "Escyrillic" "Tecyrillic" "Ucyrillic" "Efcyrillic" "Khacyrillic" "Tsecyrillic"
431         "Checyrillic" "Shacyrillic" "Shchacyrillic" "Hardsigncyrillic" "Yericyrillic"
432         "Softsigncyrillic" "Ereversedcyrillic" "IUcyrillic" "IAcyrillic"
433         "acyrillic" "becyrillic" "vecyrillic" "gecyrillic" "decyrillic" "iecyrillic"
434         "zhecyrillic" "zecyrillic" "iicyrillic" "iishortcyrillic" "kacyrillic"
435         "elcyrillic" "emcyrillic" "encyrillic" "ocyrillic" "pecyrillic" "ercyrillic"
436         "escyrillic" "tecyrillic" "ucyrillic" "efcyrillic" "khacyrillic" "tsecyrillic"
437         "checyrillic" "shacyrillic" "shchacyrillic" "hardsigncyrillic" "yericyrillic"
438         "softsigncyrillic" "ereversedcyrillic" "iucyrillic" "iacyrillic")))
439
440
441 (defparameter *latin-2-encoding*
442   (make-instance 'pdf::custom-encoding
443                  :name "Latin2Encoding"
444                  :keyword-name :latin-2-encoding
445                  :base-encoding :standard-encoding
446                  :charset :latin-2
447                  :char-names #( nil nil nil nil nil nil nil nil
448 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
449 nil nil nil nil nil nil nil nil
450 "space" "exclam" "quotedbl" "numbersign" "dollar" "percent"
451 "ampersand" "quoteright" "parenleft" "parenright" "asterisk"
452 "plus" "comma" "minus" "period" "slash" "zero" "one" "two"
453 "three" "four" "five" "six" "seven" "eight" "nine" "colon"
454 "semicolon" "less" "equal" "greater" "question" "at" "A" "B"
455 "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O"
456 "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "bracketleft" "backslash"
457 "bracketright" "asciicircum" "underscore" "quoteleft" "a" "b" "c"
458 "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
459 "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar" "braceright" "asciitilde"
460 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil "dotlessi" "grave"
461 "acute" "circumflex" "tilde" "macron" "cent" "ydieresis" "dieresis" nil "ring"
462 "cedilla" nil "hungarumlaut" "twosuperior" "periodcentered" "nbspace" "Aogonek"
463 "breve" "Lslash" "currency" "Lcaron" "Sacute" "section" "dieresis" "Scaron" "Scedilla"
464 "Tcaron" "Zacute" "hyphen" "Zcaron" "Zdotaccent" "degree" "aogonek" "ogonek" "lslash"
465 "acute" "lcaron" "sacute" "caron" "cedilla" "scaron" "scedilla" "tcaron" "zacute" "dblacute"
466 "zcaron" "zdotaccent" "Racute" "Aacute" "Acircumflex" "Atilde" "Adieresis" "Lacute"
467 "Cacute" "Ccedilla" "Ccaron" "Eacute" "Eogonek" "Edieresis" "Ecaron" "Iacute" "Icircumflex"
468 "Dcaron" "Dbar" "Nacute" "Ncaron" "Oacute" "Ocircumflex" "Odblacute" "Odieresis"
469 "multiply" "Rcaron" "Uring" "Uacute" "Udblacute" "Udieresis" "Yacute" "Tcedilla" "germandbls"
470 "racute" "aacute" "acircumflex" "atilde" "adieresis" "lacute" "cacute" "ccedilla" "ccaron"
471 "eacute" "eogonek" "edieresis" "ecaron" "iacute" "icircumflex" "dcaron" "dbar" "nacute"
472 "ncaron" "oacute" "ocircumflex" "odblacute" "odieresis" "divide" "rcaron" "uring" "uacute"
473 "udblacute" "udieresis" "yacute" "tcedilla" "dotaccent")))
474
475
476 (defparameter *win-1250-encoding*
477   (make-instance 'pdf::custom-encoding
478                  :name "Win1250Encoding"
479                  :keyword-name :win-1250-encoding
480                  :base-encoding :standard-encoding
481                  :charset #+sbcl :windows-1250
482                           #-sbcl :1250
483                  :char-names #(
484 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
485 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil "space"
486 "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand"
487 "quotesingle" "parenleft" "parenright" "asterisk" "plus" "comma"
488 "hyphen" "period" "slash" "zero" "one" "two" "three" "four"
489 "five" "six" "seven" "eight" "nine" "colon" "semicolon" "less"
490 "equal" "greater" "question" "at" "A" "B" "C" "D" "E" "F"
491 "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T"
492 "U" "V" "W" "X" "Y" "Z" "bracketleft" "backslash"
493 "bracketright" "asciicircum" "underscore" "grave" "a" "b" "c"
494 "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
495 "r" "s" "t" "u" "v" "w" "x" "y" "z" "braceleft" "bar"
496 "braceright" "asciitilde" nil nil nil "quotesinglbase" nil
497 "quotedblbase" "ellipsis" "dagger" "daggerdbl" nil "perthousand"
498 "Scaron" "guilsinglleft" "Sacute" "Tcaron" "Zcaron" "Zacute" nil
499 "quoteleft" "quoteright" "quotedblleft" "quotedblright" "bullet"
500 "endash" "emdash" nil "trademark" "scaron" "guilsinglright"
501 "sacute" "tcaron" "zcaron" "zacute" "space" "caron" "breve"
502 "Lslash" "currency" "Aogonek" "brokenbar" "section" "dieresis"
503 "copyright" "Scommaaccent" "guillemotleft" "logicalnot" "hyphen"
504 "registered" "Zdotaccent" "degree" "plusminus" "ogonek" "lslash"
505 "acute" "mu" "paragraph" "periodcentered" "cedilla" "aogonek"
506 "scommaaccent" "guillemotright" "Lcaron" "hungarumlaut" "lcaron"
507 "zdotaccent" "Racute" "Aacute" "Acircumflex" "Abreve"
508 "Adieresis" "Lacute" "Cacute" "Ccedilla" "Ccaron" "Eacute"
509 "Eogonek" "Edieresis" "Ecaron" "Iacute" "Icircumflex" "Dcaron"
510 "Dcroat" "Nacute" "Ncaron" "Oacute" "Ocircumflex"
511 "Ohungarumlaut" "Odieresis" "multiply" "Rcaron" "Uring" "Uacute"
512 "Uhungarumlaut" "Udieresis" "Yacute" "Tcommaaccent" "germandbls"
513 "racute" "aacute" "acircumflex" "abreve" "adieresis" "lacute"
514 "cacute" "ccedilla" "ccaron" "eacute" "eogonek" "edieresis"
515 "ecaron" "iacute" "icircumflex" "dcaron" "dcroat" "nacute"
516 "ncaron" "oacute" "ocircumflex" "ohungarumlaut" "odieresis"
517 "divide" "rcaron" "uring" "uacute" "uhungarumlaut" "udieresis"
518 "yacute" "tcommaaccent" "dotaccent"
519 )))
520
521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
522 ;;; Double-byte encodings
523
524 (defclass unicode-encoding (encoding) ()
525  (:default-initargs
526   :name "UnicodeEncoding"
527   :keyword-name :unicode-encoding
528   :standard-encoding t))
529
530 (defparameter *unicode-encoding* (make-instance 'unicode-encoding))
531
532
Note: See TracBrowser for help on using the browser.