1#ifndef OT_LAYOUT_GPOS_ANCHOR_HH
2#define OT_LAYOUT_GPOS_ANCHOR_HH
3
4#include "AnchorFormat1.hh"
5#include "AnchorFormat2.hh"
6#include "AnchorFormat3.hh"
7
8namespace OT {
9namespace Layout {
10namespace GPOS_impl {
11
12struct Anchor
13{
14 protected:
15 union {
16 HBUINT16 format; /* Format identifier */
17 AnchorFormat1 format1;
18 AnchorFormat2 format2;
19 AnchorFormat3 format3;
20 } u;
21 public:
22 DEFINE_SIZE_UNION (2, format);
23
24 bool sanitize (hb_sanitize_context_t *c) const
25 {
26 TRACE_SANITIZE (this);
27 if (!u.format.sanitize (c)) return_trace (false);
28 switch (u.format) {
29 case 1: return_trace (u.format1.sanitize (c));
30 case 2: return_trace (u.format2.sanitize (c));
31 case 3: return_trace (u.format3.sanitize (c));
32 default:return_trace (true);
33 }
34 }
35
36 void get_anchor (hb_ot_apply_context_t *c, hb_codepoint_t glyph_id,
37 float *x, float *y) const
38 {
39 *x = *y = 0;
40 switch (u.format) {
41 case 1: u.format1.get_anchor (c, glyph_id, x, y); return;
42 case 2: u.format2.get_anchor (c, glyph_id, x, y); return;
43 case 3: u.format3.get_anchor (c, glyph_id, x, y); return;
44 default: return;
45 }
46 }
47
48 bool subset (hb_subset_context_t *c) const
49 {
50 TRACE_SUBSET (this);
51 switch (u.format) {
52 case 1: return_trace (bool (reinterpret_cast<Anchor *> (u.format1.copy (c->serializer))));
53 case 2:
54 if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
55 {
56 // AnchorFormat 2 just containins extra hinting information, so
57 // if hints are being dropped convert to format 1.
58 return_trace (bool (reinterpret_cast<Anchor *> (u.format1.copy (c->serializer))));
59 }
60 return_trace (bool (reinterpret_cast<Anchor *> (u.format2.copy (c->serializer))));
61 case 3: return_trace (u.format3.subset (c));
62 default:return_trace (false);
63 }
64 }
65
66 void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
67 {
68 switch (u.format) {
69 case 1: case 2:
70 return;
71 case 3:
72 u.format3.collect_variation_indices (c);
73 return;
74 default: return;
75 }
76 }
77};
78
79}
80}
81}
82
83#endif // OT_LAYOUT_GPOS_ANCHOR_HH
84