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.
28 ;;; Loading data from the 'vmtx' table.
30 ;;; https://learn.microsoft.com/en-us/typography/opentype/spec/vmtx
31 ;;; https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6vmtx.html
34 (in-package #:zpb-ttf
)
36 ;;; Tables 'vhea' and 'vmtx' are not present in some fonts. For that reason we
37 ;;; have a fallback where metrics are supplanted with default values based on
38 ;;; horizontal metrics.
40 (defmethod load-vmtx-info ((font-loader font-loader
))
41 (when (or (vhea-missing-p font-loader
)
42 (null (table-info "vmtx" font-loader
)))
43 (setf (vmtx-missing-p font-loader
) t
)
44 (let ((line-height (- (ascender font-loader
) (descender font-loader
))))
45 ;; TOP-SIDE-BEARING depends on individual glyph metric YMAX.
46 (setf (advance-heights font-loader
)
47 (make-array 1 :initial-element line-height
)))
48 (return-from load-vmtx-info
))
49 (let* ((vertical-metrics-count (vertical-metrics-count font-loader
))
50 (advance-heights (make-array vertical-metrics-count
))
51 (top-side-bearings (make-array vertical-metrics-count
)))
52 (seek-to-table "vmtx" font-loader
)
53 (with-slots (input-stream) font-loader
54 (dotimes (i vertical-metrics-count
)
55 (setf (svref advance-heights i
) (read-uint16 input-stream
))
56 (setf (svref top-side-bearings i
) (read-int16 input-stream
))))
57 (setf (advance-heights font-loader
) advance-heights
58 (top-side-bearings font-loader
) top-side-bearings
)))