hb-ot-layout-gdef-table.hh revision e49a84c9e37c08808880e74e94c8160731ababa1
164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod/*
2ee58aaebd296ea8237516754fd4e825d524b11b7Behdad Esfahbod * Copyright (C) 2007,2008,2009  Red Hat, Inc.
364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *  This is part of HarfBuzz, an OpenType Layout engine library.
564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Permission is hereby granted, without written agreement and without
764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * software and its documentation for any purpose, provided that the
964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
1064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * all copies of this software.
1164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
1264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
1364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
1564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
1664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DAMAGE.
1764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
1864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
1964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
2164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
2264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
2464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
2564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod */
2664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod
275f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#ifndef HB_OT_LAYOUT_GDEF_PRIVATE_HH
285f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#define HB_OT_LAYOUT_GDEF_PRIVATE_HH
295b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod
305f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#include "hb-ot-layout-common-private.hh"
315b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod
3223c86aa0009324433e78fcd0c47f2c0ff14b1949Behdad Esfahbod#include "hb-font-private.h"
3323c86aa0009324433e78fcd0c47f2c0ff14b1949Behdad Esfahbod
3412360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod
3560d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct GlyphClassDef : ClassDef
3660d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
374fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod  enum {
384fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    BaseGlyph		= 0x0001u,
394fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    LigatureGlyph	= 0x0002u,
404fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    MarkGlyph		= 0x0003u,
414fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    ComponentGlyph	= 0x0004u,
424fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod  };
434c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
444c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
451f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod/*
461f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod * Attachment List Table
471f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod */
484c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
49e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbodtypedef ArrayOf<USHORT> AttachPoint;	/* Array of contour point indices--in
501f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod					 * increasing numerical order */
518b8358033184198ff638ee1379093717596e162dBehdad EsfahbodASSERT_SIZE (AttachPoint, 2);
52303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
5360d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct AttachList
5460d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
5562964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod  inline bool get_attach_points (hb_codepoint_t glyph_id,
5679420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod				 unsigned int *point_count /* IN/OUT */,
5779420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod				 unsigned int *point_array /* OUT */) const
58855720ca47bf5a7a44eb5b84dce9f7da6e7156bdBehdad Esfahbod  {
5979420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    unsigned int index = (this+coverage) (glyph_id);
6062964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    if (index == NOT_COVERED)
6162964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    {
6262964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod      *point_count = 0;
6362964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod      return false;
6462964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    }
6579420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    const AttachPoint &points = this+attachPoint[index];
6679420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod
6779420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    unsigned int count = MIN (points.len, *point_count);
6879420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    for (unsigned int i = 0; i < count; i++)
6979420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod      point_array[i] = points[i];
7079420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod
7179420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    *point_count = points.len;
7262964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod
7362964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    return true;
74855720ca47bf5a7a44eb5b84dce9f7da6e7156bdBehdad Esfahbod  }
754c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
76e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
77e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_THIS2 (coverage, attachPoint);
78e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
79e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
80855720ca47bf5a7a44eb5b84dce9f7da6e7156bdBehdad Esfahbod  private:
813d54bd1293069fc3d3bdeeea8ad45036f3ee65f3Behdad Esfahbod  OffsetTo<Coverage>
823d54bd1293069fc3d3bdeeea8ad45036f3ee65f3Behdad Esfahbod		coverage;		/* Offset to Coverage table -- from
834c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod					 * beginning of AttachList table */
845f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod  OffsetArrayOf<AttachPoint>
855f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod		attachPoint;		/* Array of AttachPoint tables
865f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod					 * in Coverage Index order */
874c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
888b8358033184198ff638ee1379093717596e162dBehdad EsfahbodASSERT_SIZE (AttachList, 4);
894c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
904c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod/*
914c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod * Ligature Caret Table
924c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod */
934c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
9460d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct CaretValueFormat1
9560d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
967586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  friend struct CaretValue;
977586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod
987586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  private:
990ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
10060d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod  {
101e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbod    /* XXX vertical */
1020ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    return context->font->x_scale * coordinate / 0x10000;
1034c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  }
104303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
105e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
106e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_SELF ();
107e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
108e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
109303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  private:
110303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  USHORT	caretValueFormat;	/* Format identifier--format = 1 */
111303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  SHORT		coordinate;		/* X or Y value, in design units */
1124c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
11312360f7c159826ae72271b34486dee59d96aa8caBehdad EsfahbodASSERT_SIZE (CaretValueFormat1, 4);
1144c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
11560d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct CaretValueFormat2
11660d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
1177586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  friend struct CaretValue;
1187586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod
1197586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  private:
1200ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
12160d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod  {
122e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbod    return /* TODO contour point */ 0;
1234c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  }
124303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
125e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
126e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_SELF ();
127e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
128e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
129303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  private:
130303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  USHORT	caretValueFormat;	/* Format identifier--format = 2 */
131303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  USHORT	caretValuePoint;	/* Contour point index on glyph */
1324c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
13312360f7c159826ae72271b34486dee59d96aa8caBehdad EsfahbodASSERT_SIZE (CaretValueFormat2, 4);
1344c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
13560d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct CaretValueFormat3
13660d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
1377586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  friend struct CaretValue;
1387586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod
1390ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
14060d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod  {
141e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbod    /* XXX vertical */
1420ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    return context->font->x_scale * coordinate / 0x10000 +
14315164d9258a74122a4db748d35532bd72c47cec2Behdad Esfahbod	   ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
144303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  }
145303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
146e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
147e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
148e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
149e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
150303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  private:
1514c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  USHORT	caretValueFormat;	/* Format identifier--format = 3 */
1524c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  SHORT		coordinate;		/* X or Y value, in design units */
153263bbef7670b59aa88ef9ba910579dfa51226524Behdad Esfahbod  OffsetTo<Device>
154263bbef7670b59aa88ef9ba910579dfa51226524Behdad Esfahbod		deviceTable;		/* Offset to Device table for X or Y
1554c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod					 * value--from beginning of CaretValue
1564c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod					 * table */
1574c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
15812360f7c159826ae72271b34486dee59d96aa8caBehdad EsfahbodASSERT_SIZE (CaretValueFormat3, 6);
1594c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
16060d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct CaretValue
16160d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
1624c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  /* XXX  we need access to a load-contour-point vfunc here */
1630ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
16460d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod  {
165f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad Esfahbod    switch (u.format) {
1660ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    case 1: return u.format1->get_caret_value (context, glyph_id);
1670ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    case 2: return u.format2->get_caret_value (context, glyph_id);
1680ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    case 3: return u.format3->get_caret_value (context, glyph_id);
1694c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod    default:return 0;
1704c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod    }
1714c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  }
1724c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod
173e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
174e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    if (!SANITIZE (u.format)) return false;
175e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    switch (u.format) {
176e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    case 1: return u.format1->sanitize (SANITIZE_ARG);
177e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    case 2: return u.format2->sanitize (SANITIZE_ARG);
178e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    case 3: return u.format3->sanitize (SANITIZE_ARG);
179e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    default:return true;
180e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    }
181e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
182e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
183303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod  private:
1844c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  union {
185f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad Esfahbod  USHORT		format;		/* Format identifier */
186f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad Esfahbod  CaretValueFormat1	format1[];
187f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad Esfahbod  CaretValueFormat2	format2[];
188f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad Esfahbod  CaretValueFormat3	format3[];
1894c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod  } u;
1904c2556cb4c38a56c3a5087deb54aa6262ab3aff9Behdad Esfahbod};
191f8dc67b3c24dfc805da756a73cb217b36e16b4b8Behdad EsfahbodASSERT_SIZE (CaretValue, 2);
1921f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod
19360d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct LigGlyph
19460d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
1950ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline void get_lig_carets (hb_ot_layout_context_t *context,
19662964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      hb_codepoint_t glyph_id,
19762964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      unsigned int *caret_count /* IN/OUT */,
19862964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      int *caret_array /* OUT */) const
19962964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod  {
20062964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod
20162964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    unsigned int count = MIN (carets.len, *caret_count);
20262964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    for (unsigned int i = 0; i < count; i++)
2030ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod      caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
20462964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod
20562964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    *caret_count = carets.len;
20662964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod  }
2077586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod
208e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
209e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE (carets);
210e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
211e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
21260d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod  private:
2135f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod  OffsetArrayOf<CaretValue>
21462964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod		carets;			/* Offset rrray of CaretValue tables
215e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbod					 * --from beginning of LigGlyph table
216e4efdd80a8fa4edbcdec9cd84f35f5f4521943c2Behdad Esfahbod					 * --in increasing coordinate order */
2171f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod};
2188b8358033184198ff638ee1379093717596e162dBehdad EsfahbodASSERT_SIZE (LigGlyph, 2);
219b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
22060d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct LigCaretList
22160d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
2220ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline bool get_lig_carets (hb_ot_layout_context_t *context,
22362964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      hb_codepoint_t glyph_id,
22462964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      unsigned int *caret_count /* IN/OUT */,
22562964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      int *caret_array /* OUT */) const
226855720ca47bf5a7a44eb5b84dce9f7da6e7156bdBehdad Esfahbod  {
22779420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod    unsigned int index = (this+coverage) (glyph_id);
22862964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    if (index == NOT_COVERED)
22962964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    {
23062964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod      *caret_count = 0;
23162964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod      return false;
23262964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    }
23362964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    const LigGlyph &lig_glyph = this+ligGlyph[index];
2340ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod    lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
23562964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod    return true;
236855720ca47bf5a7a44eb5b84dce9f7da6e7156bdBehdad Esfahbod  }
23712360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod
238e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
239e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_THIS2 (coverage, ligGlyph);
240e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
241e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
24212360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod  private:
2433d54bd1293069fc3d3bdeeea8ad45036f3ee65f3Behdad Esfahbod  OffsetTo<Coverage>
2443d54bd1293069fc3d3bdeeea8ad45036f3ee65f3Behdad Esfahbod		coverage;		/* Offset to Coverage table--from
24512360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod					 * beginning of LigCaretList table */
2465f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod  OffsetArrayOf<LigGlyph>
2475f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod		ligGlyph;		/* Array of LigGlyph tables
2485f810363acc3ad3cba631a68620e3d37e54c95c4Behdad Esfahbod					 * in Coverage Index order */
24912360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod};
2508b8358033184198ff638ee1379093717596e162dBehdad EsfahbodASSERT_SIZE (LigCaretList, 4);
25112360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod
252e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
253e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbodstruct MarkGlyphSetsFormat1
254e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod{
255e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
256e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
257e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
258e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
259e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_THIS (coverage);
260e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
261e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
262e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  private:
263e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  USHORT	format;			/* Format identifier--format = 1 */
264e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  LongOffsetArrayOf<Coverage>
265e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod		coverage;		/* Array of long offsets to mark set
266e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod					 * coverage tables */
267e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod};
268e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad EsfahbodASSERT_SIZE (MarkGlyphSetsFormat1, 4);
269e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
270e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbodstruct MarkGlyphSets
271e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod{
272e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
273e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  {
274e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod    switch (u.format) {
275e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod    case 1: return u.format1->covers (set_index, glyph_id);
276e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod    default:return false;
277e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod    }
278e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  }
279e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
280e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  inline bool sanitize (SANITIZE_ARG_DEF) {
281e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    if (!SANITIZE (u.format)) return false;
282e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    switch (u.format) {
283e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    case 1: return u.format1->sanitize (SANITIZE_ARG);
284e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    default:return true;
285e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    }
286e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
287e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
288e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  private:
289e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  union {
290e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  USHORT		format;		/* Format identifier */
291e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  MarkGlyphSetsFormat1	format1[];
292e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  } u;
293e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod};
294e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad EsfahbodASSERT_SIZE (MarkGlyphSets, 2);
295e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
296e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
2971f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod/*
298aefaafe5bc4fc6d37a412c135b1079c287be7045Behdad Esfahbod * GDEF
2991f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod */
300b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
30160d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbodstruct GDEF
30260d77cf05fddc5304b4b1fc19cdedba15cbee1e9Behdad Esfahbod{
3037586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod  static const hb_tag_t Tag		= HB_TAG ('G','D','E','F');
304600e5eb80f553ea8eb862e6784133574c74ca513Behdad Esfahbod
3054fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod  enum {
3064fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    UnclassifiedGlyph	= 0,
3074fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    BaseGlyph		= 1,
3084fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    LigatureGlyph	= 2,
3094fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    MarkGlyph		= 3,
3104fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod    ComponentGlyph	= 4,
3114fa77d3c4305a76b956de8c1a9b83a961d035a80Behdad Esfahbod  };
312aff831ed6787abe8e24a977e34d97ff2e0b7dc21Behdad Esfahbod
313cd3827ee567612c5500206b62840702fc956e0f5Behdad Esfahbod  STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
314b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
3159e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  inline bool has_glyph_classes () const { return glyphClassDef != 0; }
316e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
31779420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod  { return (this+glyphClassDef).get_class (glyph); }
318b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
3199e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
320e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
32179420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod  { return (this+markAttachClassDef).get_class (glyph); }
32279420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod
32379420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod  inline bool has_attach_points () const { return attachList != 0; }
324e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline bool get_attach_points (hb_codepoint_t glyph_id,
32579420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod				 unsigned int *point_count /* IN/OUT */,
32679420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod				 unsigned int *point_array /* OUT */) const
32762964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod  { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
328b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
32979420ad9caf2d5fc94c3693e8292edfa27060b2dBehdad Esfahbod  inline bool has_lig_carets () const { return ligCaretList != 0; }
3300ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  inline bool get_lig_carets (hb_ot_layout_context_t *context,
33162964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      hb_codepoint_t glyph_id,
33262964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      unsigned int *caret_count /* IN/OUT */,
33362964afcecd96038cfaa8bc2bc931f43ee83be7eBehdad Esfahbod			      int *caret_array /* OUT */) const
3340ead481a5a8623103565fd7d924666e7342278ddBehdad Esfahbod  { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
335b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
336e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
337e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
338e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
339e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod
340e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  bool sanitize (SANITIZE_ARG_DEF) {
341e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    if (!SANITIZE (version)) return false;
342e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    if (version.major != 1) return true;
343e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod    return SANITIZE_THIS2 (glyphClassDef, attachList) &&
344e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod	   SANITIZE_THIS2 (ligCaretList, markAttachClassDef) &&
345e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod	   (version < 0x00010002 || SANITIZE_THIS (markGlyphSetsDef[0]));
346e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod  }
347e49a84c9e37c08808880e74e94c8160731ababa1Behdad Esfahbod
348238c855fcd4f0ef97a94a8662d2a2f2bb5c21ecbBehdad Esfahbod  private:
349e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  FixedVersion	version;		/* Version of the GDEF table--currently
350e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod					 * 0x00010002 */
3519e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  OffsetTo<ClassDef>
3529e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod		glyphClassDef;		/* Offset to class definition table
353b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod					 * for glyph type--from beginning of
3541f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod					 * GDEF header (may be Null) */
3559e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  OffsetTo<AttachList>
3569e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod		attachList;		/* Offset to list of glyphs with
357b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod					 * attachment points--from beginning
3581f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod					 * of GDEF header (may be Null) */
3599e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  OffsetTo<LigCaretList>
3609e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod		ligCaretList;		/* Offset to list of positioning points
361b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod					 * for ligature carets--from beginning
3621f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod					 * of GDEF header (may be Null) */
3639e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod  OffsetTo<ClassDef>
3649e4d9d7b2721859172bc9c59c1aea27b01eb9c07Behdad Esfahbod		markAttachClassDef;	/* Offset to class definition table for
365b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod					 * mark attachment type--from beginning
3661f437e6f47fb6c15761021bd2078f31778f2179cBehdad Esfahbod					 * of GDEF header (may be Null) */
367e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod  OffsetTo<MarkGlyphSets>
368e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod		markGlyphSetsDef[0];	/* Offset to the table of mark set
369e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod					 * definitions--from beginning of GDEF
370e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod					 * header (may be NULL).  Introduced
371e4b92b85a7750bd4271ad607b3c41f0184e89febBehdad Esfahbod					 * in version 00010002. */
372b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod};
3738b8358033184198ff638ee1379093717596e162dBehdad EsfahbodASSERT_SIZE (GDEF, 12);
374b9d7688fb3d45894901484b74095c4f11cab6196Behdad Esfahbod
3756f20f72e9c58ba23db2e31afa5d331acfea3d77eBehdad Esfahbod
3765f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */
377