Updated version to 1.0.3.
[zpb-ttf.git] / head.lisp
blob6b90c473b439f7a9ca88d79c83b2f236b686f8e6
1 ;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved
2 ;;;
3 ;;; Redistribution and use in source and binary forms, with or without
4 ;;; modification, are permitted provided that the following conditions
5 ;;; are met:
6 ;;;
7 ;;; * Redistributions of source code must retain the above copyright
8 ;;; notice, this list of conditions and the following disclaimer.
9 ;;;
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.
14 ;;;
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.
26 ;;;
27 ;;; Loading data from the "head" table.
28 ;;;
29 ;;; http://www.microsoft.com/OpenType/OTSpec/head.htm
30 ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6head.html
31 ;;;
32 ;;; $Id: head.lisp,v 1.5 2006/02/18 23:13:43 xach Exp $
34 (in-package #:zpb-ttf)
36 (defmethod load-head-info ((font-loader font-loader))
37 (seek-to-table "head" font-loader)
38 (with-slots (input-stream units/em bounding-box loca-offset-format)
39 font-loader
40 (flet ((skip-bytes (count)
41 (file-position input-stream (+ count
42 (file-position input-stream)))))
43 (let ((version (read-uint32 input-stream)))
44 (check-version "\"head\" table" version #x00010000))
45 ;; skip fontRevsion and checkSumAdjustment (both uint32)
46 (skip-bytes 8)
47 ;; check the magicNumber
48 (let ((magic-number (read-uint32 input-stream)))
49 (when (/= magic-number #x5F0F3CF5)
50 (error 'bad-magic
51 :location "\"head\" table"
52 :expected-values (list #x5F0F3CF5)
53 :actual-value magic-number)))
54 ;; skip flags
55 (skip-bytes 2)
56 (setf units/em (read-uint16 input-stream))
57 ;; skip created and modified dates
58 (skip-bytes 16)
59 (setf bounding-box (vector (read-int16 input-stream)
60 (read-int16 input-stream)
61 (read-int16 input-stream)
62 (read-int16 input-stream)))
63 ;; skip macStyle, lowestRecPPEM, fontDirectionHint
64 (skip-bytes 6)
65 ;; set the loca-offset-format
66 (if (zerop (read-int16 input-stream))
67 (setf loca-offset-format :short)
68 (setf loca-offset-format :long)))))