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

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

43 44 45
/*
 * Attachment List Table
 */
B
Behdad Esfahbod 已提交
46

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

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

    return true;
B
Behdad Esfahbod 已提交
72
  }
B
Behdad Esfahbod 已提交
73

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

/*
 * Ligature Caret Table
 */

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

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

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

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

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

  private:
  USHORT	caretValueFormat;	/* Format identifier--format = 2 */
  USHORT	caretValuePoint;	/* Contour point index on glyph */
B
Behdad Esfahbod 已提交
118
};
119
ASSERT_SIZE (CaretValueFormat2, 4);
B
Behdad Esfahbod 已提交
120

B
Behdad Esfahbod 已提交
121 122
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
123 124
  friend struct CaretValue;

125
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
126
  {
127
    /* XXX vertical */
128 129
    return context->font->x_scale * coordinate / 0x10000 +
	   (this+deviceTable).get_delta (context->font->x_ppem) << 6;
B
Behdad Esfahbod 已提交
130 131 132
  }

  private:
B
Behdad Esfahbod 已提交
133 134
  USHORT	caretValueFormat;	/* Format identifier--format = 3 */
  SHORT		coordinate;		/* X or Y value, in design units */
B
Behdad Esfahbod 已提交
135 136
  OffsetTo<Device>
		deviceTable;		/* Offset to Device table for X or Y
B
Behdad Esfahbod 已提交
137 138 139
					 * value--from beginning of CaretValue
					 * table */
};
140
ASSERT_SIZE (CaretValueFormat3, 6);
B
Behdad Esfahbod 已提交
141

B
Behdad Esfahbod 已提交
142 143
struct CaretValue
{
B
Behdad Esfahbod 已提交
144
  /* XXX  we need access to a load-contour-point vfunc here */
145
  int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
146
  {
B
Behdad Esfahbod 已提交
147
    switch (u.format) {
148 149 150
    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 已提交
151 152 153 154
    default:return 0;
    }
  }

B
Behdad Esfahbod 已提交
155
  private:
B
Behdad Esfahbod 已提交
156
  union {
B
Behdad Esfahbod 已提交
157 158 159 160
  USHORT		format;		/* Format identifier */
  CaretValueFormat1	format1[];
  CaretValueFormat2	format2[];
  CaretValueFormat3	format3[];
B
Behdad Esfahbod 已提交
161 162
  } u;
};
B
Behdad Esfahbod 已提交
163
ASSERT_SIZE (CaretValue, 2);
164

B
Behdad Esfahbod 已提交
165 166
struct LigGlyph
{
167
  inline void get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
168 169 170 171 172 173 174
			      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++)
175
      caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
B
Behdad Esfahbod 已提交
176 177 178

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

B
Behdad Esfahbod 已提交
180
  private:
B
Behdad Esfahbod 已提交
181
  OffsetArrayOf<CaretValue>
B
Behdad Esfahbod 已提交
182
		carets;			/* Offset rrray of CaretValue tables
183 184
					 * --from beginning of LigGlyph table
					 * --in increasing coordinate order */
185
};
186
ASSERT_SIZE (LigGlyph, 2);
B
Behdad Esfahbod 已提交
187

B
Behdad Esfahbod 已提交
188 189
struct LigCaretList
{
190
  inline bool get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
191 192 193
			      hb_codepoint_t glyph_id,
			      unsigned int *caret_count /* IN/OUT */,
			      int *caret_array /* OUT */) const
B
Behdad Esfahbod 已提交
194
  {
B
Behdad Esfahbod 已提交
195
    unsigned int index = (this+coverage) (glyph_id);
B
Behdad Esfahbod 已提交
196 197 198 199 200 201
    if (index == NOT_COVERED)
    {
      *caret_count = 0;
      return false;
    }
    const LigGlyph &lig_glyph = this+ligGlyph[index];
202
    lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
B
Behdad Esfahbod 已提交
203
    return true;
B
Behdad Esfahbod 已提交
204
  }
205 206

  private:
207 208
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
209
					 * beginning of LigCaretList table */
B
Behdad Esfahbod 已提交
210 211 212
  OffsetArrayOf<LigGlyph>
		ligGlyph;		/* Array of LigGlyph tables
					 * in Coverage Index order */
213
};
214
ASSERT_SIZE (LigCaretList, 4);
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

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; }

  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;
    }
  }

  private:
  union {
  USHORT		format;		/* Format identifier */
  MarkGlyphSetsFormat1	format1[];
  } u;
};
ASSERT_SIZE (MarkGlyphSets, 2);


249
/*
B
Behdad Esfahbod 已提交
250
 * GDEF
251
 */
B
Behdad Esfahbod 已提交
252

B
Behdad Esfahbod 已提交
253 254
struct GDEF
{
B
Minor  
Behdad Esfahbod 已提交
255
  static const hb_tag_t Tag		= HB_TAG ('G','D','E','F');
256

B
Behdad Esfahbod 已提交
257 258 259 260 261 262 263
  enum {
    UnclassifiedGlyph	= 0,
    BaseGlyph		= 1,
    LigatureGlyph	= 2,
    MarkGlyph		= 3,
    ComponentGlyph	= 4,
  };
B
Behdad Esfahbod 已提交
264

265
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1);
B
Behdad Esfahbod 已提交
266

B
Behdad Esfahbod 已提交
267
  inline bool has_glyph_classes () const { return glyphClassDef != 0; }
268
  inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
269
  { return (this+glyphClassDef).get_class (glyph); }
B
Behdad Esfahbod 已提交
270

B
Behdad Esfahbod 已提交
271
  inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
272
  inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
B
Behdad Esfahbod 已提交
273 274 275
  { return (this+markAttachClassDef).get_class (glyph); }

  inline bool has_attach_points () const { return attachList != 0; }
276
  inline bool get_attach_points (hb_codepoint_t glyph_id,
B
Behdad Esfahbod 已提交
277 278
				 unsigned int *point_count /* IN/OUT */,
				 unsigned int *point_array /* OUT */) const
B
Behdad Esfahbod 已提交
279
  { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
B
Behdad Esfahbod 已提交
280

B
Behdad Esfahbod 已提交
281
  inline bool has_lig_carets () const { return ligCaretList != 0; }
282
  inline bool get_lig_carets (hb_ot_layout_context_t *context,
B
Behdad Esfahbod 已提交
283 284 285
			      hb_codepoint_t glyph_id,
			      unsigned int *caret_count /* IN/OUT */,
			      int *caret_array /* OUT */) const
286
  { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
B
Behdad Esfahbod 已提交
287

288 289 290 291
  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 已提交
292
  private:
293 294
  FixedVersion	version;		/* Version of the GDEF table--currently
					 * 0x00010002 */
B
Behdad Esfahbod 已提交
295 296
  OffsetTo<ClassDef>
		glyphClassDef;		/* Offset to class definition table
B
Behdad Esfahbod 已提交
297
					 * for glyph type--from beginning of
298
					 * GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
299 300
  OffsetTo<AttachList>
		attachList;		/* Offset to list of glyphs with
B
Behdad Esfahbod 已提交
301
					 * attachment points--from beginning
302
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
303 304
  OffsetTo<LigCaretList>
		ligCaretList;		/* Offset to list of positioning points
B
Behdad Esfahbod 已提交
305
					 * for ligature carets--from beginning
306
					 * of GDEF header (may be Null) */
B
Behdad Esfahbod 已提交
307 308
  OffsetTo<ClassDef>
		markAttachClassDef;	/* Offset to class definition table for
B
Behdad Esfahbod 已提交
309
					 * mark attachment type--from beginning
310
					 * of GDEF header (may be Null) */
311 312 313 314 315
  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 已提交
316
};
317
ASSERT_SIZE (GDEF, 12);
B
Behdad Esfahbod 已提交
318

319

320
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */