blob: cd36fc895325edc83d58eef0643f00c1b726fdfe [file] [log] [blame]
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +04301/*
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
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070028#include "hb-aat-layout-common.hh"
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043029
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +043030/*
31 * bsln -- Baseline
32 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bsln.html
33 */
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043034#define HB_AAT_TAG_bsln HB_TAG('b','s','l','n')
35
36
37namespace AAT {
38
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +043039
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043040struct BaselineTableFormat0Part
41{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033042 bool sanitize (hb_sanitize_context_t *c) const
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043043 {
44 TRACE_SANITIZE (this);
Ebrahim Byagowia47070c2018-04-18 12:09:37 +043045 return_trace (likely (c->check_struct (this)));
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043046 }
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{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033060 bool sanitize (hb_sanitize_context_t *c) const
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043061 {
62 TRACE_SANITIZE (this);
Ebrahim Byagowia47070c2018-04-18 12:09:37 +043063 return_trace (likely (c->check_struct (this) &&
64 lookupTable.sanitize (c)));
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043065 }
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{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033078 bool sanitize (hb_sanitize_context_t *c) const
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043079 {
80 TRACE_SANITIZE (this);
Ebrahim Byagowia47070c2018-04-18 12:09:37 +043081 return_trace (likely (c->check_struct (this)));
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043082 }
83
84 protected:
Ebrahim Byagowid5120872019-09-14 10:36:29 +043085 HBGlyphID stdGlyph; /* The specific glyph index number in this
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +043086 * 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{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330101 bool sanitize (hb_sanitize_context_t *c) const
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430102 {
103 TRACE_SANITIZE (this);
Ebrahim Byagowid0e2add2020-07-18 22:14:52 +0430104 return_trace (likely (c->check_struct (this) && lookupTable.sanitize (c)));
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430105 }
106
107 protected:
Ebrahim Byagowid5120872019-09-14 10:36:29 +0430108 HBGlyphID stdGlyph; /* ditto */
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430109 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
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430117struct bsln
118{
Behdad Esfahbodef006542019-01-22 12:08:57 +0100119 static constexpr hb_tag_t tableTag = HB_AAT_TAG_bsln;
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430120
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330121 bool sanitize (hb_sanitize_context_t *c) const
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430122 {
123 TRACE_SANITIZE (this);
Ebrahim Byagowia47070c2018-04-18 12:09:37 +0430124 if (unlikely (!(c->check_struct (this) && defaultBaseline < 32)))
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430125 return_trace (false);
126
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330127 switch (format)
128 {
Ebrahim Byagowi0e230a82018-03-30 19:36:00 +0430129 case 0: return_trace (parts.format0.sanitize (c));
130 case 1: return_trace (parts.format1.sanitize (c));
131 case 2: return_trace (parts.format2.sanitize (c));
132 case 3: return_trace (parts.format3.sanitize (c));
133 default:return_trace (true);
134 }
135 }
136
137 protected:
138 FixedVersion<>version; /* Version number of the Baseline table. */
139 HBUINT16 format; /* Format of the baseline table. Only one baseline
140 * format may be selected for the font. */
141 HBUINT16 defaultBaseline;/* Default baseline value for all glyphs.
142 * This value can be from 0 through 31. */
143 union {
144 // Distance-Based Formats
145 BaselineTableFormat0Part format0;
146 BaselineTableFormat1Part format1;
147 // Control Point-based Formats
148 BaselineTableFormat2Part format2;
149 BaselineTableFormat3Part format3;
150 } parts;
151 public:
152 DEFINE_SIZE_MIN (8);
153};
154
155} /* namespace AAT */
156
157
158#endif /* HB_AAT_LAYOUT_BSLN_TABLE_HH */