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