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

/*
 * Ligature Caret Table
 */

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

  private:
95
  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
B
Behdad Esfahbod 已提交
96
  {
97
    /* XXX vertical */
98
    return context->font->x_scale * coordinate / 0x10000;
B
Behdad Esfahbod 已提交
99
  }
B
Behdad Esfahbod 已提交
100 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 117 118 119

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

B
Behdad Esfahbod 已提交
123 124
struct CaretValueFormat3
{
B
Minor  
Behdad Esfahbod 已提交
125 126
  friend struct CaretValue;

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

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

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

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

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

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

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

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

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

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


251
/*
B
Behdad Esfahbod 已提交
252
 * GDEF
253
 */
B
Behdad Esfahbod 已提交
254

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

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

B
Behdad Esfahbod 已提交
267
  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
B
Behdad Esfahbod 已提交
268

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

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

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

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

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

321

322
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */