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

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 77 78 79
  inline bool sanitize (SANITIZE_ARG_DEF) {
    return SANITIZE_THIS2 (coverage, attachPoint);
  }

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

/*
 * Ligature Caret Table
 */

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

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

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

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

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

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

B
Behdad Esfahbod 已提交
125 126 127 128
  inline bool sanitize (SANITIZE_ARG_DEF) {
    return SANITIZE_SELF ();
  }

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

B
Behdad Esfahbod 已提交
135 136
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
137 138
  friend struct CaretValue;

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

B
Behdad Esfahbod 已提交
146 147 148 149
  inline bool sanitize (SANITIZE_ARG_DEF) {
    return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
  }

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

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

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

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

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

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

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

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

B
Behdad Esfahbod 已提交
238 239 240 241
  inline bool sanitize (SANITIZE_ARG_DEF) {
    return SANITIZE_THIS2 (coverage, ligGlyph);
  }

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

252 253 254 255 256 257

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 已提交
258 259 260 261
  inline bool sanitize (SANITIZE_ARG_DEF) {
    return SANITIZE_THIS (coverage);
  }

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

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


297
/*
B
Behdad Esfahbod 已提交
298
 * GDEF
299
 */
B
Behdad Esfahbod 已提交
300

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

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

B
Behdad Esfahbod 已提交
313
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
B
Behdad Esfahbod 已提交
314

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

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

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

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

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

375

376
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */