tor-browser

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

hb-ot-vorg-table.hh (3721B)


      1 /*
      2 * Copyright © 2018 Adobe Inc.
      3 *
      4 *  This is part of HarfBuzz, a text shaping library.
      5 *
      6 * Permission is hereby granted, without written agreement and without
      7 * license or royalty fees, to use, copy, modify, and distribute this
      8 * software and its documentation for any purpose, provided that the
      9 * above copyright notice and the following two paragraphs appear in
     10 * all copies of this software.
     11 *
     12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
     13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
     15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
     16 * DAMAGE.
     17 *
     18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
     19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     20 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
     22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
     23 *
     24 * Adobe Author(s): Michiharu Ariza
     25 */
     26 
     27 #ifndef HB_OT_VORG_TABLE_HH
     28 #define HB_OT_VORG_TABLE_HH
     29 
     30 #include "hb-open-type.hh"
     31 
     32 /*
     33 * VORG -- Vertical Origin Table
     34 * https://docs.microsoft.com/en-us/typography/opentype/spec/vorg
     35 */
     36 #define HB_OT_TAG_VORG HB_TAG('V','O','R','G')
     37 
     38 namespace OT {
     39 
     40 struct VertOriginMetric
     41 {
     42  int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
     43 
     44  bool sanitize (hb_sanitize_context_t *c) const
     45  {
     46    TRACE_SANITIZE (this);
     47    return_trace (c->check_struct (this));
     48  }
     49 
     50  public:
     51  HBGlyphID16	glyph;
     52  FWORD		vertOriginY;
     53 
     54  public:
     55  DEFINE_SIZE_STATIC (4);
     56 };
     57 
     58 struct VORG
     59 {
     60  static constexpr hb_tag_t tableTag = HB_OT_TAG_VORG;
     61 
     62  bool has_data () const { return version.to_int (); }
     63 
     64  HB_ALWAYS_INLINE
     65  int get_y_origin (hb_codepoint_t glyph) const
     66  {
     67    unsigned int i;
     68    if (!vertYOrigins.bfind (glyph, &i))
     69      return defaultVertOriginY;
     70    return vertYOrigins[i].vertOriginY;
     71  }
     72 
     73  template <typename Iterator,
     74     hb_requires (hb_is_iterator (Iterator))>
     75  void serialize (hb_serialize_context_t *c,
     76 	  Iterator it,
     77 	  FWORD defaultVertOriginY)
     78  {
     79 
     80    if (unlikely (!c->extend_min ((*this))))  return;
     81 
     82    this->version.major = 1;
     83    this->version.minor = 0;
     84 
     85    this->defaultVertOriginY = defaultVertOriginY;
     86    this->vertYOrigins.len = it.len ();
     87 
     88    c->copy_all (it);
     89  }
     90 
     91  bool subset (hb_subset_context_t *c) const
     92  {
     93    TRACE_SUBSET (this);
     94    auto *vorg_prime = c->serializer->start_embed<VORG> ();
     95    if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false);
     96 
     97    auto it =
     98    + vertYOrigins.as_array ()
     99    | hb_filter (c->plan->glyphset (), &VertOriginMetric::glyph)
    100    | hb_map ([&] (const VertOriginMetric& _)
    101       {
    102 	hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID;
    103 	c->plan->new_gid_for_old_gid (_.glyph, &new_glyph);
    104 
    105 	VertOriginMetric metric;
    106 	metric.glyph = new_glyph;
    107 	metric.vertOriginY = _.vertOriginY;
    108 	return metric;
    109       })
    110    ;
    111 
    112    /* serialize the new table */
    113    vorg_prime->serialize (c->serializer, it, defaultVertOriginY);
    114    return_trace (true);
    115  }
    116 
    117  bool sanitize (hb_sanitize_context_t *c) const
    118  {
    119    TRACE_SANITIZE (this);
    120    return_trace (c->check_struct (this) &&
    121 	  hb_barrier () &&
    122 	  version.major == 1 &&
    123 	  vertYOrigins.sanitize (c));
    124  }
    125 
    126  protected:
    127  FixedVersion<>version;	/* Version of VORG table. Set to 0x00010000u. */
    128  FWORD		defaultVertOriginY;
    129 			/* The default vertical origin. */
    130  SortedArray16Of<VertOriginMetric>
    131 	vertYOrigins;	/* The array of vertical origins. */
    132 
    133  public:
    134  DEFINE_SIZE_ARRAY(8, vertYOrigins);
    135 };
    136 } /* namespace OT */
    137 
    138 #endif /* HB_OT_VORG_TABLE_HH */