1 ;;; Copyright (c) 2024 Daniel KochmaĆski, 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 ;;; Loading data from the "vhea" table.
29 ;;; https://learn.microsoft.com/en-us/typography/opentype/spec/vhea
30 ;;; https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6vhea.html
33 (in-package #:zpb-ttf
)
35 ;;; Tables 'vhea' and 'vmtx' are not present in some fonts. For that reason we
36 ;;; have a fallback where metrics are supplanted with default values based on
37 ;;; horizontal metrics.
39 (defmethod load-vhea-info ((font-loader font-loader
))
40 (unless (table-info "vhea" font-loader
)
41 (setf (vhea-missing-p font-loader
) t
)
42 (let ((dx (/ (max-width font-loader
) 2)))
43 (with-slots (vascender vdescender
)
47 (return-from load-vhea-info
))
48 (seek-to-table "vhea" font-loader
)
49 (with-slots (input-stream vascender vdescender
)
51 (let ((version (read-fixed input-stream
)))
52 (check-version "\"vhea\" table" version
#x00010000
#x00011000
))
53 (setf vascender
(read-fword input-stream
)
54 vdescender
(read-fword input-stream
))))
56 (defmethod vertical-metrics-count ((font-loader font-loader
))
57 (when (or (vhea-missing-p font-loader
)
58 (null (table-info "vhea" font-loader
)))
59 ;; (warn "Table 'vhea' is missing.")
60 (setf (vhea-missing-p font-loader
) t
)
61 (return-from vertical-metrics-count
))
62 (seek-to-table "vhea" font-loader
)
63 (with-slots (input-stream) font-loader
64 ;; Skip to the end, since all we care about is the last item
65 (advance-file-position input-stream
34)
66 (read-uint16 input-stream
)))