tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Anchor.hh (2244B)


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