2 * Copyright © 2017 Google, 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
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 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_OT_VAR_MVAR_TABLE_HH
28 #define HB_OT_VAR_MVAR_TABLE_HH
30 #include "hb-ot-layout-common.hh"
36 struct VariationValueRecord
38 bool sanitize (hb_sanitize_context_t *c) const
40 TRACE_SANITIZE (this);
41 return_trace (c->check_struct (this));
45 Tag valueTag; /* Four-byte tag identifying a font-wide measure. */
46 HBUINT32 varIdx; /* Outer/inner index into VariationStore item. */
49 DEFINE_SIZE_STATIC (8);
54 * MVAR -- Metrics Variations
55 * https://docs.microsoft.com/en-us/typography/opentype/spec/mvar
57 #define HB_OT_TAG_MVAR HB_TAG('M','V','A','R')
61 static constexpr hb_tag_t tableTag = HB_OT_TAG_MVAR;
63 bool sanitize (hb_sanitize_context_t *c) const
65 TRACE_SANITIZE (this);
66 return_trace (version.sanitize (c) &&
67 likely (version.major == 1) &&
68 c->check_struct (this) &&
69 valueRecordSize >= VariationValueRecord::static_size &&
70 varStore.sanitize (c, this) &&
71 c->check_range (valuesZ.arrayZ,
76 float get_var (hb_tag_t tag,
77 const int *coords, unsigned int coord_count) const
79 const VariationValueRecord *record;
80 record = (VariationValueRecord *) bsearch (&tag, valuesZ.arrayZ,
81 valueRecordCount, valueRecordSize,
86 return (this+varStore).get_delta (record->varIdx, coords, coord_count);
90 static int tag_compare (const void *pa, const void *pb)
92 const hb_tag_t *a = (const hb_tag_t *) pa;
93 const Tag *b = (const Tag *) pb;
98 FixedVersion<>version; /* Version of the metrics variation table
99 * initially set to 0x00010000u */
100 HBUINT16 reserved; /* Not used; set to 0. */
101 HBUINT16 valueRecordSize;/* The size in bytes of each value record —
102 * must be greater than zero. */
103 HBUINT16 valueRecordCount;/* The number of value records — may be zero. */
104 OffsetTo<VariationStore>
105 varStore; /* Offset to item variation store table. */
106 UnsizedArrayOf<HBUINT8>
107 valuesZ; /* Array of value records. The records must be
108 * in binary order of their valueTag field. */
111 DEFINE_SIZE_ARRAY (12, valuesZ);
117 #endif /* HB_OT_VAR_MVAR_TABLE_HH */