hb-ot-layout-gdef-private.hh 11.0 KB
Newer Older
B
Behdad Esfahbod 已提交
1
/*
B
Behdad Esfahbod 已提交
2
 * Copyright (C) 2007,2008,2009  Red Hat, Inc.
B
Behdad Esfahbod 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 *  This is part of HarfBuzz, an OpenType Layout engine library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
 */

27 28
#ifndef HB_OT_LAYOUT_GDEF_PRIVATE_HH
#define HB_OT_LAYOUT_GDEF_PRIVATE_HH
B
Behdad Esfahbod 已提交
29

30
#include "hb-ot-layout-common-private.hh"
B
Behdad Esfahbod 已提交
31

32 33
#include "hb-font-private.h"

34

35 36 37
/*
 * Attachment List Table
 */
B
Behdad Esfahbod 已提交
38

39
typedef ArrayOf<USHORT> AttachPoint;	/* Array of contour point indices--in
40
					 * increasing numerical order */
41
ASSERT_SIZE (AttachPoint, 2);
B
Behdad Esfahbod 已提交
42

B
Behdad Esfahbod 已提交
43 44
struct AttachList
{
B
Behdad Esfahbod 已提交
45 46 47 48
  inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
					 unsigned int start_offset,
					 unsigned int *point_count /* IN/OUT */,
					 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
49
  {
B
Behdad Esfahbod 已提交
50
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
51 52
    if (index == NOT_COVERED)
    {
B
Behdad Esfahbod 已提交
53 54 55
      if (point_count)
	*point_count = 0;
      return 0;
B
Behdad Esfahbod 已提交
56
    }
B
Behdad Esfahbod 已提交
57

B
Behdad Esfahbod 已提交
58 59
    const AttachPoint &points = this+attachPoint[index];

B
Behdad Esfahbod 已提交
60
    if (point_count) {
B
Behdad Esfahbod 已提交
61 62
      const USHORT *array = points.const_sub_array (start_offset, point_count);
      unsigned int count = *point_count;
B
Behdad Esfahbod 已提交
63 64 65
      for (unsigned int i = 0; i < count; i++)
	point_array[i] = array[i];
    }
B
Behdad Esfahbod 已提交
66

B
Behdad Esfahbod 已提交
67
    return points.len;
B
Behdad Esfahbod 已提交
68
  }
B
Behdad Esfahbod 已提交
69

B
Behdad Esfahbod 已提交
70
  inline bool sanitize (SANITIZE_ARG_DEF) {
71
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
72 73 74
    return SANITIZE_THIS2 (coverage, attachPoint);
  }

B
Behdad Esfahbod 已提交
75
  private:
76 77
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table -- from
B
Behdad Esfahbod 已提交
78
					 * beginning of AttachList table */
B
Behdad Esfahbod 已提交
79 80 81
  OffsetArrayOf<AttachPoint>
		attachPoint;		/* Array of AttachPoint tables
					 * in Coverage Index order */
B
Behdad Esfahbod 已提交
82
};
83
ASSERT_SIZE (AttachList, 4);
B
Behdad Esfahbod 已提交
84 85 86 87 88

/*
 * Ligature Caret Table
 */

B
Behdad Esfahbod 已提交
89 90
struct CaretValueFormat1
{
B
Minor  
Behdad Esfahbod 已提交
91 92 93
  friend struct CaretValue;

  private:
94
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
95
  {
B
Behdad Esfahbod 已提交
96
    /* TODO vertical */
97
    return context->font->x_scale * coordinate / 0x10000;
B
Behdad Esfahbod 已提交
98
  }
B
Behdad Esfahbod 已提交
99

B
Behdad Esfahbod 已提交
100
  inline bool sanitize (SANITIZE_ARG_DEF) {
101
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
102 103 104
    return SANITIZE_SELF ();
  }

B
Behdad Esfahbod 已提交
105 106 107
  private:
  USHORT	caretValueFormat;	/* Format identifier--format = 1 */
  SHORT		coordinate;		/* X or Y value, in design units */
B
Behdad Esfahbod 已提交
108
};
109
ASSERT_SIZE (CaretValueFormat1, 4);
B
Behdad Esfahbod 已提交
110

B
Behdad Esfahbod 已提交
111 112
struct CaretValueFormat2
{
B
Minor  
Behdad Esfahbod 已提交
113 114 115
  friend struct CaretValue;

  private:
116
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
117
  {
118
    return /* TODO contour point */ 0;
B
Behdad Esfahbod 已提交
119
  }
B
Behdad Esfahbod 已提交
120

B
Behdad Esfahbod 已提交
121
  inline bool sanitize (SANITIZE_ARG_DEF) {
122
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
123 124 125
    return SANITIZE_SELF ();
  }

B
Behdad Esfahbod 已提交
126 127 128
  private:
  USHORT	caretValueFormat;	/* Format identifier--format = 2 */
  USHORT	caretValuePoint;	/* Contour point index on glyph */
B
Behdad Esfahbod 已提交
129
};
130
ASSERT_SIZE (CaretValueFormat2, 4);
B
Behdad Esfahbod 已提交
131

B
Behdad Esfahbod 已提交
132 133
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
134 135
  friend struct CaretValue;

136
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
137
  {
B
Behdad Esfahbod 已提交
138
    /* TODO vertical */
139
    return context->font->x_scale * coordinate / 0x10000 +
B
Behdad Esfahbod 已提交
140
	   ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
B
Behdad Esfahbod 已提交
141 142
  }

B
Behdad Esfahbod 已提交
143
  inline bool sanitize (SANITIZE_ARG_DEF) {
144
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
145 146 147
    return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
  }

B
Behdad Esfahbod 已提交
148
  private:
B
Behdad Esfahbod 已提交
149 150
  USHORT	caretValueFormat;	/* Format identifier--format = 3 */
  SHORT		coordinate;		/* X or Y value, in design units */
B
Behdad Esfahbod 已提交
151 152
  OffsetTo<Device>
		deviceTable;		/* Offset to Device table for X or Y
B
Behdad Esfahbod 已提交
153 154 155
					 * value--from beginning of CaretValue
					 * table */
};
156
ASSERT_SIZE (CaretValueFormat3, 6);
B
Behdad Esfahbod 已提交
157

B
Behdad Esfahbod 已提交
158 159
struct CaretValue
{
B
Behdad Esfahbod 已提交
160
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
161
  {
B
Behdad Esfahbod 已提交
162
    switch (u.format) {
163 164 165
    case 1: return u.format1->get_caret_value (context, glyph_id);
    case 2: return u.format2->get_caret_value (context, glyph_id);
    case 3: return u.format3->get_caret_value (context, glyph_id);
B
Behdad Esfahbod 已提交
166 167 168 169
    default:return 0;
    }
  }

B
Behdad Esfahbod 已提交
170
  inline bool sanitize (SANITIZE_ARG_DEF) {
171
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
172 173 174 175 176 177 178 179 180
    if (!SANITIZE (u.format)) return false;
    switch (u.format) {
    case 1: return u.format1->sanitize (SANITIZE_ARG);
    case 2: return u.format2->sanitize (SANITIZE_ARG);
    case 3: return u.format3->sanitize (SANITIZE_ARG);
    default:return true;
    }
  }

B
Behdad Esfahbod 已提交
181
  private:
B
Behdad Esfahbod 已提交
182
  union {
B
Behdad Esfahbod 已提交
183
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
184 185 186
  CaretValueFormat1	format1[VAR];
  CaretValueFormat2	format2[VAR];
  CaretValueFormat3	format3[VAR];
B
Behdad Esfahbod 已提交
187 188
  } u;
};
189

B
Behdad Esfahbod 已提交
190 191
struct LigGlyph
{
B
Behdad Esfahbod 已提交
192 193 194 195 196
  inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
				      hb_codepoint_t glyph_id,
				      unsigned int start_offset,
				      unsigned int *caret_count /* IN/OUT */,
				      int *caret_array /* OUT */) const
B
Behdad Esfahbod 已提交
197
  {
B
Behdad Esfahbod 已提交
198
    if (caret_count) {
B
Behdad Esfahbod 已提交
199 200
      const OffsetTo<CaretValue> *array = carets.const_sub_array (start_offset, caret_count);
      unsigned int count = *caret_count;
B
Behdad Esfahbod 已提交
201 202 203
      for (unsigned int i = 0; i < count; i++)
	caret_array[i] = (this+array[i]).get_caret_value (context, glyph_id);
    }
B
Behdad Esfahbod 已提交
204

B
Behdad Esfahbod 已提交
205
    return carets.len;
B
Behdad Esfahbod 已提交
206
  }
B
Minor  
Behdad Esfahbod 已提交
207

B
Behdad Esfahbod 已提交
208
  inline bool sanitize (SANITIZE_ARG_DEF) {
209
    TRACE_SANITIZE ();
210
    return SANITIZE_THIS (carets);
B
Behdad Esfahbod 已提交
211 212
  }

B
Behdad Esfahbod 已提交
213
  private:
B
Behdad Esfahbod 已提交
214
  OffsetArrayOf<CaretValue>
215
		carets;			/* Offset array of CaretValue tables
216 217
					 * --from beginning of LigGlyph table
					 * --in increasing coordinate order */
218
};
219
ASSERT_SIZE (LigGlyph, 2);
B
Behdad Esfahbod 已提交
220

B
Behdad Esfahbod 已提交
221 222
struct LigCaretList
{
B
Behdad Esfahbod 已提交
223 224 225 226 227
  inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
				      hb_codepoint_t glyph_id,
				      unsigned int start_offset,
				      unsigned int *caret_count /* IN/OUT */,
				      int *caret_array /* OUT */) const
B
Behdad Esfahbod 已提交
228
  {
B
Behdad Esfahbod 已提交
229
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
230 231
    if (index == NOT_COVERED)
    {
B
Behdad Esfahbod 已提交
232 233 234
      if (caret_count)
	*caret_count = 0;
      return 0;
B
Behdad Esfahbod 已提交
235 236
    }
    const LigGlyph &lig_glyph = this+ligGlyph[index];
B
Behdad Esfahbod 已提交
237
    return lig_glyph.get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array);
B
Behdad Esfahbod 已提交
238
  }
239

B
Behdad Esfahbod 已提交
240
  inline bool sanitize (SANITIZE_ARG_DEF) {
241
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
242 243 244
    return SANITIZE_THIS2 (coverage, ligGlyph);
  }

245
  private:
246 247
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
248
					 * beginning of LigCaretList table */
B
Behdad Esfahbod 已提交
249 250 251
  OffsetArrayOf<LigGlyph>
		ligGlyph;		/* Array of LigGlyph tables
					 * in Coverage Index order */
252
};
253
ASSERT_SIZE (LigCaretList, 4);
254

255 256 257 258 259 260

struct MarkGlyphSetsFormat1
{
  inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
  { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }

B
Behdad Esfahbod 已提交
261
  inline bool sanitize (SANITIZE_ARG_DEF) {
262
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
263 264 265
    return SANITIZE_THIS (coverage);
  }

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  private:
  USHORT	format;			/* Format identifier--format = 1 */
  LongOffsetArrayOf<Coverage>
		coverage;		/* Array of long offsets to mark set
					 * coverage tables */
};
ASSERT_SIZE (MarkGlyphSetsFormat1, 4);

struct MarkGlyphSets
{
  inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
  {
    switch (u.format) {
    case 1: return u.format1->covers (set_index, glyph_id);
    default:return false;
    }
  }

B
Behdad Esfahbod 已提交
284
  inline bool sanitize (SANITIZE_ARG_DEF) {
285
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
286 287 288 289 290 291 292
    if (!SANITIZE (u.format)) return false;
    switch (u.format) {
    case 1: return u.format1->sanitize (SANITIZE_ARG);
    default:return true;
    }
  }

293 294 295
  private:
  union {
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
296
  MarkGlyphSetsFormat1	format1[VAR];
297 298 299 300
  } u;
};


301
/*
B
Behdad Esfahbod 已提交
302
 * GDEF
303
 */
B
Behdad Esfahbod 已提交
304

B
Behdad Esfahbod 已提交
305 306
struct GDEF
{
B
Behdad Esfahbod 已提交
307
  static const hb_tag_t Tag	= HB_OT_TAG_GDEF;
308

B
Behdad Esfahbod 已提交
309 310 311 312 313
  enum {
    UnclassifiedGlyph	= 0,
    BaseGlyph		= 1,
    LigatureGlyph	= 2,
    MarkGlyph		= 3,
314
    ComponentGlyph	= 4
B
Behdad Esfahbod 已提交
315
  };
B
Behdad Esfahbod 已提交
316

B
Behdad Esfahbod 已提交
317
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
B
Behdad Esfahbod 已提交
318

B
Behdad Esfahbod 已提交
319
  inline bool has_glyph_classes () const { return glyphClassDef != 0; }
320
  inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
321
  { return (this+glyphClassDef).get_class (glyph); }
B
Behdad Esfahbod 已提交
322

B
Behdad Esfahbod 已提交
323
  inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
324
  inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
325 326 327
  { return (this+markAttachClassDef).get_class (glyph); }

  inline bool has_attach_points () const { return attachList != 0; }
B
Behdad Esfahbod 已提交
328 329 330 331 332
  inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
					 unsigned int start_offset,
					 unsigned int *point_count /* IN/OUT */,
					 unsigned int *point_array /* OUT */) const
  { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
B
Behdad Esfahbod 已提交
333

B
Behdad Esfahbod 已提交
334
  inline bool has_lig_carets () const { return ligCaretList != 0; }
B
Behdad Esfahbod 已提交
335 336 337 338 339 340
  inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
				      hb_codepoint_t glyph_id,
				      unsigned int start_offset,
				      unsigned int *caret_count /* IN/OUT */,
				      int *caret_array /* OUT */) const
  { return (this+ligCaretList).get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array); }
B
Behdad Esfahbod 已提交
341

342 343 344 345
  inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
  inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
  { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }

B
Behdad Esfahbod 已提交
346
  inline bool sanitize (SANITIZE_ARG_DEF) {
347
    TRACE_SANITIZE ();
B
Behdad Esfahbod 已提交
348 349 350 351 352 353 354
    if (!SANITIZE (version)) return false;
    if (version.major != 1) return true;
    return SANITIZE_THIS2 (glyphClassDef, attachList) &&
	   SANITIZE_THIS2 (ligCaretList, markAttachClassDef) &&
	   (version < 0x00010002 || SANITIZE_THIS (markGlyphSetsDef[0]));
  }

B
Behdad Esfahbod 已提交
355
  private:
356 357
  FixedVersion	version;		/* Version of the GDEF table--currently
					 * 0x00010002 */
B
Behdad Esfahbod 已提交
358 359
  OffsetTo<ClassDef>
		glyphClassDef;		/* Offset to class definition table
B
Behdad Esfahbod 已提交
360
					 * for glyph type--from beginning of
361
					 * GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
362 363
  OffsetTo<AttachList>
		attachList;		/* Offset to list of glyphs with
B
Behdad Esfahbod 已提交
364
					 * attachment points--from beginning
365
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
366 367
  OffsetTo<LigCaretList>
		ligCaretList;		/* Offset to list of positioning points
B
Behdad Esfahbod 已提交
368
					 * for ligature carets--from beginning
369
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
370 371
  OffsetTo<ClassDef>
		markAttachClassDef;	/* Offset to class definition table for
B
Behdad Esfahbod 已提交
372
					 * mark attachment type--from beginning
373
					 * of GDEF header (may be Null) */
374
  OffsetTo<MarkGlyphSets>
B
Behdad Esfahbod 已提交
375
		markGlyphSetsDef[VAR];	/* Offset to the table of mark set
376 377 378
					 * definitions--from beginning of GDEF
					 * header (may be NULL).  Introduced
					 * in version 00010002. */
B
Behdad Esfahbod 已提交
379
};
B
Behdad Esfahbod 已提交
380
ASSERT_SIZE_VAR (GDEF, 12, OffsetTo<MarkGlyphSets>);
B
Behdad Esfahbod 已提交
381

382

383
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */