hb-ot-layout-gdef-private.hh 10.8 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

B
Behdad Esfahbod 已提交
35 36
struct GlyphClassDef : ClassDef
{
B
Behdad Esfahbod 已提交
37 38 39 40 41 42
  enum {
    BaseGlyph		= 0x0001u,
    LigatureGlyph	= 0x0002u,
    MarkGlyph		= 0x0003u,
    ComponentGlyph	= 0x0004u,
  };
B
Behdad Esfahbod 已提交
43 44
};

45 46 47
/*
 * Attachment List Table
 */
B
Behdad Esfahbod 已提交
48

49
typedef ArrayOf<USHORT> AttachPoint;	/* Array of contour point indices--in
50
					 * increasing numerical order */
51
ASSERT_SIZE (AttachPoint, 2);
B
Behdad Esfahbod 已提交
52

B
Behdad Esfahbod 已提交
53 54
struct AttachList
{
B
Behdad Esfahbod 已提交
55
  inline bool get_attach_points (hb_codepoint_t glyph_id,
B
Behdad Esfahbod 已提交
56 57
				 unsigned int *point_count /* IN/OUT */,
				 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
58
  {
B
Behdad Esfahbod 已提交
59
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
60 61 62 63 64
    if (index == NOT_COVERED)
    {
      *point_count = 0;
      return false;
    }
B
Behdad Esfahbod 已提交
65 66 67 68 69 70 71
    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 已提交
72 73

    return true;
B
Behdad Esfahbod 已提交
74
  }
B
Behdad Esfahbod 已提交
75

B
Behdad Esfahbod 已提交
76
  inline bool sanitize (SANITIZE_ARG_DEF) {
77
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
78 79 80
    return SANITIZE_THIS2 (coverage, attachPoint);
  }

B
Behdad Esfahbod 已提交
81
  private:
82 83
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table -- from
B
Behdad Esfahbod 已提交
84
					 * beginning of AttachList table */
B
Behdad Esfahbod 已提交
85 86 87
  OffsetArrayOf<AttachPoint>
		attachPoint;		/* Array of AttachPoint tables
					 * in Coverage Index order */
B
Behdad Esfahbod 已提交
88
};
89
ASSERT_SIZE (AttachList, 4);
B
Behdad Esfahbod 已提交
90 91 92 93 94

/*
 * Ligature Caret Table
 */

B
Behdad Esfahbod 已提交
95 96
struct CaretValueFormat1
{
B
Minor  
Behdad Esfahbod 已提交
97 98 99
  friend struct CaretValue;

  private:
100
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
101
  {
102
    /* XXX vertical */
103
    return context->font->x_scale * coordinate / 0x10000;
B
Behdad Esfahbod 已提交
104
  }
B
Behdad Esfahbod 已提交
105

B
Behdad Esfahbod 已提交
106
  inline bool sanitize (SANITIZE_ARG_DEF) {
107
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
108 109 110
    return SANITIZE_SELF ();
  }

B
Behdad Esfahbod 已提交
111 112 113
  private:
  USHORT	caretValueFormat;	/* Format identifier--format = 1 */
  SHORT		coordinate;		/* X or Y value, in design units */
B
Behdad Esfahbod 已提交
114
};
115
ASSERT_SIZE (CaretValueFormat1, 4);
B
Behdad Esfahbod 已提交
116

B
Behdad Esfahbod 已提交
117 118
struct CaretValueFormat2
{
B
Minor  
Behdad Esfahbod 已提交
119 120 121
  friend struct CaretValue;

  private:
122
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
123
  {
124
    return /* TODO contour point */ 0;
B
Behdad Esfahbod 已提交
125
  }
B
Behdad Esfahbod 已提交
126

B
Behdad Esfahbod 已提交
127
  inline bool sanitize (SANITIZE_ARG_DEF) {
128
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
129 130 131
    return SANITIZE_SELF ();
  }

B
Behdad Esfahbod 已提交
132 133 134
  private:
  USHORT	caretValueFormat;	/* Format identifier--format = 2 */
  USHORT	caretValuePoint;	/* Contour point index on glyph */
B
Behdad Esfahbod 已提交
135
};
136
ASSERT_SIZE (CaretValueFormat2, 4);
B
Behdad Esfahbod 已提交
137

B
Behdad Esfahbod 已提交
138 139
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
140 141
  friend struct CaretValue;

142
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
143
  {
144
    /* XXX vertical */
145
    return context->font->x_scale * coordinate / 0x10000 +
B
Behdad Esfahbod 已提交
146
	   ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
B
Behdad Esfahbod 已提交
147 148
  }

B
Behdad Esfahbod 已提交
149
  inline bool sanitize (SANITIZE_ARG_DEF) {
150
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
151 152 153
    return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
  }

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

B
Behdad Esfahbod 已提交
164 165
struct CaretValue
{
B
Behdad Esfahbod 已提交
166
  /* XXX  we need access to a load-contour-point vfunc here */
167
  int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
168
  {
B
Behdad Esfahbod 已提交
169
    switch (u.format) {
170 171 172
    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 已提交
173 174 175 176
    default:return 0;
    }
  }

B
Behdad Esfahbod 已提交
177
  inline bool sanitize (SANITIZE_ARG_DEF) {
178
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
179 180 181 182 183 184 185 186 187
    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 已提交
188
  private:
B
Behdad Esfahbod 已提交
189
  union {
B
Behdad Esfahbod 已提交
190 191 192 193
  USHORT		format;		/* Format identifier */
  CaretValueFormat1	format1[];
  CaretValueFormat2	format2[];
  CaretValueFormat3	format3[];
B
Behdad Esfahbod 已提交
194 195
  } u;
};
B
Behdad Esfahbod 已提交
196
ASSERT_SIZE (CaretValue, 2);
197

B
Behdad Esfahbod 已提交
198 199
struct LigGlyph
{
200
  inline void get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
201 202 203 204 205 206 207
			      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++)
208
      caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
B
Behdad Esfahbod 已提交
209 210 211

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

B
Behdad Esfahbod 已提交
213
  inline bool sanitize (SANITIZE_ARG_DEF) {
214
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
215 216 217
    return SANITIZE (carets);
  }

B
Behdad Esfahbod 已提交
218
  private:
B
Behdad Esfahbod 已提交
219
  OffsetArrayOf<CaretValue>
B
Behdad Esfahbod 已提交
220
		carets;			/* Offset rrray of CaretValue tables
221 222
					 * --from beginning of LigGlyph table
					 * --in increasing coordinate order */
223
};
224
ASSERT_SIZE (LigGlyph, 2);
B
Behdad Esfahbod 已提交
225

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

B
Behdad Esfahbod 已提交
244
  inline bool sanitize (SANITIZE_ARG_DEF) {
245
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
246 247 248
    return SANITIZE_THIS2 (coverage, ligGlyph);
  }

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

259 260 261 262 263 264

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 已提交
265
  inline bool sanitize (SANITIZE_ARG_DEF) {
266
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
267 268 269
    return SANITIZE_THIS (coverage);
  }

270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
  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 已提交
288
  inline bool sanitize (SANITIZE_ARG_DEF) {
289
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
290 291 292 293 294 295 296
    if (!SANITIZE (u.format)) return false;
    switch (u.format) {
    case 1: return u.format1->sanitize (SANITIZE_ARG);
    default:return true;
    }
  }

297 298 299 300 301 302 303 304 305
  private:
  union {
  USHORT		format;		/* Format identifier */
  MarkGlyphSetsFormat1	format1[];
  } u;
};
ASSERT_SIZE (MarkGlyphSets, 2);


306
/*
B
Behdad Esfahbod 已提交
307
 * GDEF
308
 */
B
Behdad Esfahbod 已提交
309

B
Behdad Esfahbod 已提交
310 311
struct GDEF
{
B
Behdad Esfahbod 已提交
312
  static const hb_tag_t Tag	= HB_OT_TAG_GDEF;
313

B
Behdad Esfahbod 已提交
314 315 316 317 318 319 320
  enum {
    UnclassifiedGlyph	= 0,
    BaseGlyph		= 1,
    LigatureGlyph	= 2,
    MarkGlyph		= 3,
    ComponentGlyph	= 4,
  };
B
Behdad Esfahbod 已提交
321

B
Behdad Esfahbod 已提交
322
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
B
Behdad Esfahbod 已提交
323

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

B
Behdad Esfahbod 已提交
328
  inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
329
  inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
330 331 332
  { return (this+markAttachClassDef).get_class (glyph); }

  inline bool has_attach_points () const { return attachList != 0; }
333
  inline bool get_attach_points (hb_codepoint_t glyph_id,
B
Behdad Esfahbod 已提交
334 335
				 unsigned int *point_count /* IN/OUT */,
				 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
336
  { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
B
Behdad Esfahbod 已提交
337

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

345 346 347 348
  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 已提交
349
  bool sanitize (SANITIZE_ARG_DEF) {
350
    SANITIZE_DEBUG ();
B
Behdad Esfahbod 已提交
351 352 353 354 355 356 357
    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 已提交
358
  private:
359 360
  FixedVersion	version;		/* Version of the GDEF table--currently
					 * 0x00010002 */
B
Behdad Esfahbod 已提交
361 362
  OffsetTo<ClassDef>
		glyphClassDef;		/* Offset to class definition table
B
Behdad Esfahbod 已提交
363
					 * for glyph type--from beginning of
364
					 * GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
365 366
  OffsetTo<AttachList>
		attachList;		/* Offset to list of glyphs with
B
Behdad Esfahbod 已提交
367
					 * attachment points--from beginning
368
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
369 370
  OffsetTo<LigCaretList>
		ligCaretList;		/* Offset to list of positioning points
B
Behdad Esfahbod 已提交
371
					 * for ligature carets--from beginning
372
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
373 374
  OffsetTo<ClassDef>
		markAttachClassDef;	/* Offset to class definition table for
B
Behdad Esfahbod 已提交
375
					 * mark attachment type--from beginning
376
					 * of GDEF header (may be Null) */
377 378 379 380 381
  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 已提交
382
};
383
ASSERT_SIZE (GDEF, 12);
B
Behdad Esfahbod 已提交
384

385

386
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */