/src/harfbuzz/src/hb-ot-vorg-table.hh
Line | Count | Source (jump to first uncovered line) |
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 | 0 | int cmp (hb_codepoint_t g) const { return glyph.cmp (g); } |
43 | | |
44 | | bool sanitize (hb_sanitize_context_t *c) const |
45 | 0 | { |
46 | 0 | TRACE_SANITIZE (this); |
47 | 0 | return_trace (c->check_struct (this)); |
48 | 0 | } |
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 | 0 | bool has_data () const { return version.to_int (); } |
63 | | |
64 | | int get_y_origin (hb_codepoint_t glyph) const |
65 | 0 | { |
66 | 0 | unsigned int i; |
67 | 0 | if (!vertYOrigins.bfind (glyph, &i)) |
68 | 0 | return defaultVertOriginY; |
69 | 0 | return vertYOrigins[i].vertOriginY; |
70 | 0 | } |
71 | | |
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) |
77 | 0 | { |
78 | 0 |
|
79 | 0 | if (unlikely (!c->extend_min ((*this)))) return; |
80 | 0 |
|
81 | 0 | this->version.major = 1; |
82 | 0 | this->version.minor = 0; |
83 | 0 |
|
84 | 0 | this->defaultVertOriginY = defaultVertOriginY; |
85 | 0 | this->vertYOrigins.len = it.len (); |
86 | 0 |
|
87 | 0 | c->copy_all (it); |
88 | 0 | } |
89 | | |
90 | | bool subset (hb_subset_context_t *c) const |
91 | 0 | { |
92 | 0 | TRACE_SUBSET (this); |
93 | 0 | auto *vorg_prime = c->serializer->start_embed<VORG> (); |
94 | 0 | if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false); |
95 | 0 |
|
96 | 0 | auto it = |
97 | 0 | + vertYOrigins.as_array () |
98 | 0 | | hb_filter (c->plan->glyphset (), &VertOriginMetric::glyph) |
99 | 0 | | hb_map ([&] (const VertOriginMetric& _) |
100 | 0 | { |
101 | 0 | hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID; |
102 | 0 | c->plan->new_gid_for_old_gid (_.glyph, &new_glyph); |
103 | 0 |
|
104 | 0 | VertOriginMetric metric; |
105 | 0 | metric.glyph = new_glyph; |
106 | 0 | metric.vertOriginY = _.vertOriginY; |
107 | 0 | return metric; |
108 | 0 | }) |
109 | 0 | ; |
110 | 0 |
|
111 | 0 | /* serialize the new table */ |
112 | 0 | vorg_prime->serialize (c->serializer, it, defaultVertOriginY); |
113 | 0 | return_trace (true); |
114 | 0 | } |
115 | | |
116 | | bool sanitize (hb_sanitize_context_t *c) const |
117 | 0 | { |
118 | 0 | TRACE_SANITIZE (this); |
119 | 0 | return_trace (c->check_struct (this) && |
120 | 0 | version.major == 1 && |
121 | 0 | vertYOrigins.sanitize (c)); |
122 | 0 | } |
123 | | |
124 | | protected: |
125 | | FixedVersion<>version; /* Version of VORG table. Set to 0x00010000u. */ |
126 | | FWORD defaultVertOriginY; |
127 | | /* The default vertical origin. */ |
128 | | SortedArray16Of<VertOriginMetric> |
129 | | vertYOrigins; /* The array of vertical origins. */ |
130 | | |
131 | | public: |
132 | | DEFINE_SIZE_ARRAY(8, vertYOrigins); |
133 | | }; |
134 | | } /* namespace OT */ |
135 | | |
136 | | #endif /* HB_OT_VORG_TABLE_HH */ |