hb-ot-layout-gdef-private.hh 10.6 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
  inline bool get_attach_points (hb_codepoint_t glyph_id,
B
Behdad Esfahbod 已提交
46 47
				 unsigned int *point_count /* IN/OUT */,
				 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
48
  {
B
Behdad Esfahbod 已提交
49
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
50 51 52 53 54
    if (index == NOT_COVERED)
    {
      *point_count = 0;
      return false;
    }
B
Behdad Esfahbod 已提交
55 56 57 58 59 60 61
    const AttachPoint &points = this+attachPoint[index];

    unsigned int count = MIN (points.len, *point_count);
    for (unsigned int i = 0; i < count; i++)
      point_array[i] = points[i];

    *point_count = points.len;
B
Behdad Esfahbod 已提交
62 63

    return true;
B
Behdad Esfahbod 已提交
64
  }
B
Behdad Esfahbod 已提交
65

B
Behdad Esfahbod 已提交
66
  inline bool sanitize (SANITIZE_ARG_DEF) {
67
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
68 69 70
    return SANITIZE_THIS2 (coverage, attachPoint);
  }

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

/*
 * Ligature Caret Table
 */

B
Behdad Esfahbod 已提交
85 86
struct CaretValueFormat1
{
B
Minor  
Behdad Esfahbod 已提交
87 88 89
  friend struct CaretValue;

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

B
Behdad Esfahbod 已提交
96
  inline bool sanitize (SANITIZE_ARG_DEF) {
97
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
98 99 100
    return SANITIZE_SELF ();
  }

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

B
Behdad Esfahbod 已提交
107 108
struct CaretValueFormat2
{
B
Minor  
Behdad Esfahbod 已提交
109 110 111
  friend struct CaretValue;

  private:
112
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
113
  {
114
    return /* TODO contour point */ 0;
B
Behdad Esfahbod 已提交
115
  }
B
Behdad Esfahbod 已提交
116

B
Behdad Esfahbod 已提交
117
  inline bool sanitize (SANITIZE_ARG_DEF) {
118
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
119 120 121
    return SANITIZE_SELF ();
  }

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

B
Behdad Esfahbod 已提交
128 129
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
130 131
  friend struct CaretValue;

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

B
Behdad Esfahbod 已提交
139
  inline bool sanitize (SANITIZE_ARG_DEF) {
140
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
141 142 143
    return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
  }

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

B
Behdad Esfahbod 已提交
154 155
struct CaretValue
{
156
  int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
157
  {
B
Behdad Esfahbod 已提交
158
    switch (u.format) {
159 160 161
    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 已提交
162 163 164 165
    default:return 0;
    }
  }

B
Behdad Esfahbod 已提交
166
  inline bool sanitize (SANITIZE_ARG_DEF) {
167
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
168 169 170 171 172 173 174 175 176
    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 已提交
177
  private:
B
Behdad Esfahbod 已提交
178
  union {
B
Behdad Esfahbod 已提交
179 180 181 182
  USHORT		format;		/* Format identifier */
  CaretValueFormat1	format1[];
  CaretValueFormat2	format2[];
  CaretValueFormat3	format3[];
B
Behdad Esfahbod 已提交
183 184
  } u;
};
B
Behdad Esfahbod 已提交
185
ASSERT_SIZE (CaretValue, 2);
186

B
Behdad Esfahbod 已提交
187 188
struct LigGlyph
{
189
  inline void get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
190 191 192 193 194 195 196
			      hb_codepoint_t glyph_id,
			      unsigned int *caret_count /* IN/OUT */,
			      int *caret_array /* OUT */) const
  {

    unsigned int count = MIN (carets.len, *caret_count);
    for (unsigned int i = 0; i < count; i++)
197
      caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
B
Behdad Esfahbod 已提交
198 199 200

    *caret_count = carets.len;
  }
B
Minor  
Behdad Esfahbod 已提交
201

B
Behdad Esfahbod 已提交
202
  inline bool sanitize (SANITIZE_ARG_DEF) {
203
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
204 205 206
    return SANITIZE (carets);
  }

B
Behdad Esfahbod 已提交
207
  private:
B
Behdad Esfahbod 已提交
208
  OffsetArrayOf<CaretValue>
B
Behdad Esfahbod 已提交
209
		carets;			/* Offset rrray of CaretValue tables
210 211
					 * --from beginning of LigGlyph table
					 * --in increasing coordinate order */
212
};
213
ASSERT_SIZE (LigGlyph, 2);
B
Behdad Esfahbod 已提交
214

B
Behdad Esfahbod 已提交
215 216
struct LigCaretList
{
217
  inline bool get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
218 219 220
			      hb_codepoint_t glyph_id,
			      unsigned int *caret_count /* IN/OUT */,
			      int *caret_array /* OUT */) const
B
Behdad Esfahbod 已提交
221
  {
B
Behdad Esfahbod 已提交
222
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
223 224 225 226 227 228
    if (index == NOT_COVERED)
    {
      *caret_count = 0;
      return false;
    }
    const LigGlyph &lig_glyph = this+ligGlyph[index];
229
    lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
B
Behdad Esfahbod 已提交
230
    return true;
B
Behdad Esfahbod 已提交
231
  }
232

B
Behdad Esfahbod 已提交
233
  inline bool sanitize (SANITIZE_ARG_DEF) {
234
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
235 236 237
    return SANITIZE_THIS2 (coverage, ligGlyph);
  }

238
  private:
239 240
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
241
					 * beginning of LigCaretList table */
B
Behdad Esfahbod 已提交
242 243 244
  OffsetArrayOf<LigGlyph>
		ligGlyph;		/* Array of LigGlyph tables
					 * in Coverage Index order */
245
};
246
ASSERT_SIZE (LigCaretList, 4);
247

248 249 250 251 252 253

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 已提交
254
  inline bool sanitize (SANITIZE_ARG_DEF) {
255
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
256 257 258
    return SANITIZE_THIS (coverage);
  }

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
  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 已提交
277
  inline bool sanitize (SANITIZE_ARG_DEF) {
278
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
279 280 281 282 283 284 285
    if (!SANITIZE (u.format)) return false;
    switch (u.format) {
    case 1: return u.format1->sanitize (SANITIZE_ARG);
    default:return true;
    }
  }

286 287 288 289 290 291 292 293 294
  private:
  union {
  USHORT		format;		/* Format identifier */
  MarkGlyphSetsFormat1	format1[];
  } u;
};
ASSERT_SIZE (MarkGlyphSets, 2);


295
/*
B
Behdad Esfahbod 已提交
296
 * GDEF
297
 */
B
Behdad Esfahbod 已提交
298

B
Behdad Esfahbod 已提交
299 300
struct GDEF
{
B
Behdad Esfahbod 已提交
301
  static const hb_tag_t Tag	= HB_OT_TAG_GDEF;
302

B
Behdad Esfahbod 已提交
303 304 305 306 307 308 309
  enum {
    UnclassifiedGlyph	= 0,
    BaseGlyph		= 1,
    LigatureGlyph	= 2,
    MarkGlyph		= 3,
    ComponentGlyph	= 4,
  };
B
Behdad Esfahbod 已提交
310

B
Behdad Esfahbod 已提交
311
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
B
Behdad Esfahbod 已提交
312

B
Behdad Esfahbod 已提交
313
  inline bool has_glyph_classes () const { return glyphClassDef != 0; }
314
  inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
315
  { return (this+glyphClassDef).get_class (glyph); }
B
Behdad Esfahbod 已提交
316

B
Behdad Esfahbod 已提交
317
  inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
318
  inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
319 320 321
  { return (this+markAttachClassDef).get_class (glyph); }

  inline bool has_attach_points () const { return attachList != 0; }
322
  inline bool get_attach_points (hb_codepoint_t glyph_id,
B
Behdad Esfahbod 已提交
323 324
				 unsigned int *point_count /* IN/OUT */,
				 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
325
  { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
B
Behdad Esfahbod 已提交
326

B
Behdad Esfahbod 已提交
327
  inline bool has_lig_carets () const { return ligCaretList != 0; }
328
  inline bool get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
329 330 331
			      hb_codepoint_t glyph_id,
			      unsigned int *caret_count /* IN/OUT */,
			      int *caret_array /* OUT */) const
332
  { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
B
Behdad Esfahbod 已提交
333

334 335 336 337
  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 已提交
338
  bool sanitize (SANITIZE_ARG_DEF) {
339
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
340 341 342 343 344 345 346
    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 已提交
347
  private:
348 349
  FixedVersion	version;		/* Version of the GDEF table--currently
					 * 0x00010002 */
B
Behdad Esfahbod 已提交
350 351
  OffsetTo<ClassDef>
		glyphClassDef;		/* Offset to class definition table
B
Behdad Esfahbod 已提交
352
					 * for glyph type--from beginning of
353
					 * GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
354 355
  OffsetTo<AttachList>
		attachList;		/* Offset to list of glyphs with
B
Behdad Esfahbod 已提交
356
					 * attachment points--from beginning
357
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
358 359
  OffsetTo<LigCaretList>
		ligCaretList;		/* Offset to list of positioning points
B
Behdad Esfahbod 已提交
360
					 * for ligature carets--from beginning
361
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
362 363
  OffsetTo<ClassDef>
		markAttachClassDef;	/* Offset to class definition table for
B
Behdad Esfahbod 已提交
364
					 * mark attachment type--from beginning
365
					 * of GDEF header (may be Null) */
366 367 368 369 370
  OffsetTo<MarkGlyphSets>
		markGlyphSetsDef[0];	/* Offset to the table of mark set
					 * definitions--from beginning of GDEF
					 * header (may be NULL).  Introduced
					 * in version 00010002. */
B
Behdad Esfahbod 已提交
371
};
372
ASSERT_SIZE (GDEF, 12);
B
Behdad Esfahbod 已提交
373

374

375
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */