Bug 1862332 [wpt PR 42877] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / gfx / harfbuzz / src / hb-ot-vorg-table.hh
blob95ae8ef5590d5274ee07d0ba78bda33597b44186
1 /*
2 * Copyright © 2018 Adobe Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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.
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.
24 * Adobe Author(s): Michiharu Ariza
27 #ifndef HB_OT_VORG_TABLE_HH
28 #define HB_OT_VORG_TABLE_HH
30 #include "hb-open-type.hh"
33 * VORG -- Vertical Origin Table
34 * https://docs.microsoft.com/en-us/typography/opentype/spec/vorg
36 #define HB_OT_TAG_VORG HB_TAG('V','O','R','G')
38 namespace OT {
40 struct VertOriginMetric
42 int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
44 bool sanitize (hb_sanitize_context_t *c) const
46 TRACE_SANITIZE (this);
47 return_trace (c->check_struct (this));
50 public:
51 HBGlyphID16 glyph;
52 FWORD vertOriginY;
54 public:
55 DEFINE_SIZE_STATIC (4);
58 struct VORG
60 static constexpr hb_tag_t tableTag = HB_OT_TAG_VORG;
62 bool has_data () const { return version.to_int (); }
64 int get_y_origin (hb_codepoint_t glyph) const
66 unsigned int i;
67 if (!vertYOrigins.bfind (glyph, &i))
68 return defaultVertOriginY;
69 return vertYOrigins[i].vertOriginY;
72 template <typename Iterator,
73 hb_requires (hb_is_iterator (Iterator))>
74 void serialize (hb_serialize_context_t *c,
75 Iterator it,
76 FWORD defaultVertOriginY)
79 if (unlikely (!c->extend_min ((*this)))) return;
81 this->version.major = 1;
82 this->version.minor = 0;
84 this->defaultVertOriginY = defaultVertOriginY;
85 this->vertYOrigins.len = it.len ();
87 c->copy_all (it);
90 bool subset (hb_subset_context_t *c) const
92 TRACE_SUBSET (this);
93 auto *vorg_prime = c->serializer->start_embed<VORG> ();
94 if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false);
96 auto it =
97 + vertYOrigins.as_array ()
98 | hb_filter (c->plan->glyphset (), &VertOriginMetric::glyph)
99 | hb_map ([&] (const VertOriginMetric& _)
101 hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID;
102 c->plan->new_gid_for_old_gid (_.glyph, &new_glyph);
104 VertOriginMetric metric;
105 metric.glyph = new_glyph;
106 metric.vertOriginY = _.vertOriginY;
107 return metric;
111 /* serialize the new table */
112 vorg_prime->serialize (c->serializer, it, defaultVertOriginY);
113 return_trace (true);
116 bool sanitize (hb_sanitize_context_t *c) const
118 TRACE_SANITIZE (this);
119 return_trace (c->check_struct (this) &&
120 hb_barrier () &&
121 version.major == 1 &&
122 vertYOrigins.sanitize (c));
125 protected:
126 FixedVersion<>version; /* Version of VORG table. Set to 0x00010000u. */
127 FWORD defaultVertOriginY;
128 /* The default vertical origin. */
129 SortedArray16Of<VertOriginMetric>
130 vertYOrigins; /* The array of vertical origins. */
132 public:
133 DEFINE_SIZE_ARRAY(8, vertYOrigins);
135 } /* namespace OT */
137 #endif /* HB_OT_VORG_TABLE_HH */