tor-browser

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

CoverageFormat1.hh (4098B)


      1 /*
      2 * Copyright © 2007,2008,2009  Red Hat, Inc.
      3 * Copyright © 2010,2012  Google, Inc.
      4 *
      5 *  This is part of HarfBuzz, a text shaping library.
      6 *
      7 * Permission is hereby granted, without written agreement and without
      8 * license or royalty fees, to use, copy, modify, and distribute this
      9 * software and its documentation for any purpose, provided that the
     10 * above copyright notice and the following two paragraphs appear in
     11 * all copies of this software.
     12 *
     13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
     14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
     16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
     17 * DAMAGE.
     18 *
     19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
     20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     21 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
     23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
     24 *
     25 * Red Hat Author(s): Behdad Esfahbod
     26 * Google Author(s): Behdad Esfahbod, Garret Rieger
     27 */
     28 
     29 
     30 #ifndef OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH
     31 #define OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH
     32 
     33 namespace OT {
     34 namespace Layout {
     35 namespace Common {
     36 
     37 #define NOT_COVERED             ((unsigned int) -1)
     38 
     39 template <typename Types>
     40 struct CoverageFormat1_3
     41 {
     42  friend struct Coverage;
     43 
     44  public:
     45  HBUINT16      coverageFormat; /* Format identifier--format = 1 */
     46  SortedArray16Of<typename Types::HBGlyphID>
     47                glyphArray;     /* Array of GlyphIDs--in numerical order */
     48 
     49  DEFINE_SIZE_ARRAY (4, glyphArray);
     50 
     51  private:
     52  bool sanitize (hb_sanitize_context_t *c) const
     53  {
     54    TRACE_SANITIZE (this);
     55    return_trace (glyphArray.sanitize (c));
     56  }
     57 
     58  unsigned int get_coverage (hb_codepoint_t glyph_id) const
     59  {
     60    unsigned int i;
     61    glyphArray.bfind (glyph_id, &i, HB_NOT_FOUND_STORE, NOT_COVERED);
     62    return i;
     63  }
     64 
     65  unsigned get_population () const
     66  {
     67    return glyphArray.len;
     68  }
     69 
     70  template <typename Iterator,
     71      hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
     72  bool serialize (hb_serialize_context_t *c, Iterator glyphs)
     73  {
     74    TRACE_SERIALIZE (this);
     75    return_trace (glyphArray.serialize (c, glyphs));
     76  }
     77 
     78  bool intersects (const hb_set_t *glyphs) const
     79  {
     80    if (glyphArray.len > glyphs->get_population () * hb_bit_storage ((unsigned) glyphArray.len))
     81    {
     82      for (auto g : *glyphs)
     83        if (get_coverage (g) != NOT_COVERED)
     84   return true;
     85      return false;
     86    }
     87 
     88    for (const auto& g : glyphArray.as_array ())
     89      if (glyphs->has (g))
     90        return true;
     91    return false;
     92  }
     93  bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
     94  { return glyphs->has (glyphArray[index]); }
     95 
     96  template <typename IterableOut,
     97     hb_requires (hb_is_sink_of (IterableOut, hb_codepoint_t))>
     98  void intersect_set (const hb_set_t &glyphs, IterableOut&& intersect_glyphs) const
     99  {
    100    unsigned count = glyphArray.len;
    101    for (unsigned i = 0; i < count; i++)
    102      if (glyphs.has (glyphArray[i]))
    103        intersect_glyphs << glyphArray[i];
    104  }
    105 
    106  unsigned cost () const { return hb_bit_storage ((unsigned) glyphArray.len); /* bsearch cost */ }
    107 
    108  template <typename set_t>
    109  bool collect_coverage (set_t *glyphs) const
    110  { return glyphs->add_sorted_array (glyphArray.as_array ()); }
    111 
    112  public:
    113  /* Older compilers need this to be public. */
    114  struct iter_t
    115  {
    116    void init (const struct CoverageFormat1_3 &c_) { c = &c_; i = 0; }
    117    bool __more__ () const { return i < c->glyphArray.len; }
    118    void __next__ () { i++; }
    119    hb_codepoint_t get_glyph () const { return c->glyphArray[i]; }
    120    bool operator != (const iter_t& o) const
    121    { return i != o.i; }
    122    iter_t __end__ () const { iter_t it; it.init (*c); it.i = c->glyphArray.len; return it; }
    123 
    124    private:
    125    const struct CoverageFormat1_3 *c;
    126    unsigned int i;
    127  };
    128  private:
    129 };
    130 
    131 }
    132 }
    133 }
    134 
    135 #endif  // #ifndef OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH