1/*
2 * Copyright © 2018 Ebrahim Byagowi
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 */
24
25#ifndef HB_AAT_LAYOUT_BSLN_TABLE_HH
26#define HB_AAT_LAYOUT_BSLN_TABLE_HH
27
28#include "hb-aat-layout-common.hh"
29
30/*
31 * bsln -- Baseline
32 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bsln.html
33 */
34#define HB_AAT_TAG_bsln HB_TAG('b','s','l','n')
35
36
37namespace AAT {
38
39
40struct BaselineTableFormat0Part
41{
42 inline bool sanitize (hb_sanitize_context_t *c) const
43 {
44 TRACE_SANITIZE (this);
45 return_trace (likely (c->check_struct (this)));
46 }
47
48 protected:
49 // Roman, Ideographic centered, Ideographic low, Hanging and Math
50 // are the default defined ones, but any other maybe accessed also.
51 HBINT16 deltas[32]; /* These are the FUnit distance deltas from
52 * the font's natural baseline to the other
53 * baselines used in the font. */
54 public:
55 DEFINE_SIZE_STATIC (64);
56};
57
58struct BaselineTableFormat1Part
59{
60 inline bool sanitize (hb_sanitize_context_t *c) const
61 {
62 TRACE_SANITIZE (this);
63 return_trace (likely (c->check_struct (this) &&
64 lookupTable.sanitize (c)));
65 }
66
67 protected:
68 HBINT16 deltas[32]; /* ditto */
69 Lookup<HBUINT16>
70 lookupTable; /* Lookup table that maps glyphs to their
71 * baseline values. */
72 public:
73 DEFINE_SIZE_MIN (66);
74};
75
76struct BaselineTableFormat2Part
77{
78 inline bool sanitize (hb_sanitize_context_t *c) const
79 {
80 TRACE_SANITIZE (this);
81 return_trace (likely (c->check_struct (this)));
82 }
83
84 protected:
85 GlyphID stdGlyph; /* The specific glyph index number in this
86 * font that is used to set the baseline values.
87 * This is the standard glyph.
88 * This glyph must contain a set of control points
89 * (whose numbers are contained in the ctlPoints field)
90 * that are used to determine baseline distances. */
91 HBUINT16 ctlPoints[32]; /* Set of control point numbers,
92 * associated with the standard glyph.
93 * A value of 0xFFFF means there is no corresponding
94 * control point in the standard glyph. */
95 public:
96 DEFINE_SIZE_STATIC (66);
97};
98
99struct BaselineTableFormat3Part
100{
101 inline bool sanitize (hb_sanitize_context_t *c) const
102 {
103 TRACE_SANITIZE (this);
104 return_trace (c->check_struct (this) && lookupTable.sanitize (c));
105 }
106
107 protected:
108 GlyphID stdGlyph; /* ditto */
109 HBUINT16 ctlPoints[32]; /* ditto */
110 Lookup<HBUINT16>
111 lookupTable; /* Lookup table that maps glyphs to their
112 * baseline values. */
113 public:
114 DEFINE_SIZE_MIN (68);
115};
116
117struct bsln
118{
119 static const hb_tag_t tableTag = HB_AAT_TAG_bsln;
120
121 inline bool sanitize (hb_sanitize_context_t *c) const
122 {
123 TRACE_SANITIZE (this);
124 if (unlikely (!(c->check_struct (this) && defaultBaseline < 32)))
125 return_trace (false);
126
127 switch (format) {
128 case 0: return_trace (parts.format0.sanitize (c));
129 case 1: return_trace (parts.format1.sanitize (c));
130 case 2: return_trace (parts.format2.sanitize (c));
131 case 3: return_trace (parts.format3.sanitize (c));
132 default:return_trace (true);
133 }
134 }
135
136 protected:
137 FixedVersion<>version; /* Version number of the Baseline table. */
138 HBUINT16 format; /* Format of the baseline table. Only one baseline
139 * format may be selected for the font. */
140 HBUINT16 defaultBaseline;/* Default baseline value for all glyphs.
141 * This value can be from 0 through 31. */
142 union {
143 // Distance-Based Formats
144 BaselineTableFormat0Part format0;
145 BaselineTableFormat1Part format1;
146 // Control Point-based Formats
147 BaselineTableFormat2Part format2;
148 BaselineTableFormat3Part format3;
149 } parts;
150 public:
151 DEFINE_SIZE_MIN (8);
152};
153
154} /* namespace AAT */
155
156
157#endif /* HB_AAT_LAYOUT_BSLN_TABLE_HH */
158