1 ;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved
3 ;;; Redistribution and use in source and binary forms, with or without
4 ;;; modification, are permitted provided that the following conditions
7 ;;; * Redistributions of source code must retain the above copyright
8 ;;; notice, this list of conditions and the following disclaimer.
10 ;;; * Redistributions in binary form must reproduce the above
11 ;;; copyright notice, this list of conditions and the following
12 ;;; disclaimer in the documentation and/or other materials
13 ;;; provided with the distribution.
15 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
16 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ;;; "post" table functions
29 ;;; http://www.microsoft.com/OpenType/OTSpec/post.htm
30 ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6post.html
32 ;;; $Id: post.lisp,v 1.7 2006/11/09 15:06:16 xach Exp $
34 (in-package #:zpb-ttf
)
36 (defvar *standard-mac-glyph-names
*
56 "zero" "one" "two" "three" "four"
57 "five" "six" "seven" "eight" "nine"
65 "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M"
66 "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
73 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
74 "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
240 (defun load-post-format-2 (names stream
)
241 (let* ((glyph-count (read-uint16 stream
))
242 (new-count glyph-count
))
243 (when (/= glyph-count
(length names
))
244 (warn "Glyph count in \"post\" table (~D) ~
245 does not match glyph count in \"maxp\" table (~D). ~
246 This font may be broken."
247 glyph-count
(length names
))
248 (setf glyph-count
(length names
)
249 new-count
(length names
)))
250 ;; This is done in a couple passes. First, initialize the names
251 ;; tables with indexes into either the standard table or the
252 ;; pstring table. Next, read the pstring table into a vector.
253 ;; Finally, replace the indexes with names.
254 (dotimes (i glyph-count
)
255 (let ((name-index (read-uint16 stream
)))
256 (when (< name-index
258)
258 (setf (aref names i
) name-index
)))
259 (let ((pstrings (make-array new-count
)))
260 (dotimes (i new-count
)
261 (setf (aref pstrings i
) (read-pstring stream
)))
262 (loop for i below glyph-count
267 (aref *standard-mac-glyph-names
* j
)))
270 (aref pstrings
(- j
258)))))))))
272 (defun load-post-format-3 (names stream
)
273 (declare (ignore stream
))
276 (defmethod load-post-info ((font-loader font-loader
))
277 (let ((names (make-array (glyph-count font-loader
)
279 (stream (input-stream font-loader
)))
280 (seek-to-table "post" font-loader
)
281 (let ((format (read-uint32 stream
)))
282 (when (/= format
#x00020000
#x00030000
)
283 (error 'unsupported-format
284 :location
"\"post\" table"
285 :expected-values
(list #x00020000
#x00030000
)
286 :actual-value format
))
287 (setf (italic-angle font-loader
) (read-fixed stream
)
288 (underline-position font-loader
) (read-fword stream
)
289 (underline-thickness font-loader
) (read-fword stream
)
290 (fixed-pitch-p font-loader
) (plusp (read-uint32 stream
))
291 (postscript-glyph-names font-loader
) names
)
292 ;; skip minMemType* fields
293 (advance-file-position stream
16)
295 (#x00020000
(load-post-format-2 names stream
))
296 (#x00030000
(load-post-format-3 names stream
))))))
298 (defun postscript-uni-name-p (name)
299 (let ((end (or (position #\. name
) (length name
))))
301 (= (mismatch "uni" name
) 3)
302 (loop for i from
3 below end
303 always
(digit-char-p (char name i
) 16)))))
305 (defun postscript-name-code-point (name)
306 "Returns, if available, the interpretation of the PostScript name NAME as a Unicode code point specifier.
307 Ref: http://partners.adobe.com/public/developer/opentype/index_glyph.html"
308 (when (postscript-uni-name-p name
)
309 (parse-integer name
:start
3 :end
7 :radix
16)))