1/*
2 * Copyright © 2017 Google, 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 * Google Author(s): Behdad Esfahbod
25 */
26
27#ifndef HB_OT_VAR_MVAR_TABLE_HH
28#define HB_OT_VAR_MVAR_TABLE_HH
29
30#include "hb-ot-layout-common-private.hh"
31
32
33namespace OT {
34
35
36struct VariationValueRecord
37{
38 inline bool sanitize (hb_sanitize_context_t *c) const
39 {
40 TRACE_SANITIZE (this);
41 return_trace (c->check_struct (this));
42 }
43
44 public:
45 Tag valueTag; /* Four-byte tag identifying a font-wide measure. */
46 UINT32 varIdx; /* Outer/inner index into VariationStore item. */
47
48 public:
49 DEFINE_SIZE_STATIC (8);
50};
51
52
53/*
54 * MVAR -- Metrics Variations Table
55 */
56
57#define HB_OT_TAG_MVAR HB_TAG('M','V','A','R')
58
59struct MVAR
60{
61 static const hb_tag_t tableTag = HB_OT_TAG_MVAR;
62
63 inline bool sanitize (hb_sanitize_context_t *c) const
64 {
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_array (values, valueRecordSize, valueRecordCount));
72 }
73
74 inline float get_var (hb_tag_t tag,
75 int *coords, unsigned int coord_count) const
76 {
77 const VariationValueRecord *record;
78 record = (VariationValueRecord *) bsearch (key: &tag, base: values,
79 nmemb: valueRecordCount, size: valueRecordSize,
80 compar: tag_compare);
81 if (!record)
82 return 0.;
83
84 return (this+varStore).get_delta (index: record->varIdx, coords, coord_count);
85 }
86
87protected:
88 static inline int tag_compare (const void *pa, const void *pb)
89 {
90 const hb_tag_t *a = (const hb_tag_t *) pa;
91 const Tag *b = (const Tag *) pb;
92 return b->cmp (a: *a);
93 }
94
95 protected:
96 FixedVersion<>version; /* Version of the metrics variation table
97 * initially set to 0x00010000u */
98 UINT16 reserved; /* Not used; set to 0. */
99 UINT16 valueRecordSize;/* The size in bytes of each value record —
100 * must be greater than zero. */
101 UINT16 valueRecordCount;/* The number of value records — may be zero. */
102 OffsetTo<VariationStore>
103 varStore; /* Offset to item variation store table. */
104 UINT8 values[VAR]; /* Array of value records. The records must be
105 * in binary order of their valueTag field. */
106
107 public:
108 DEFINE_SIZE_ARRAY (12, values);
109};
110
111} /* namespace OT */
112
113
114#endif /* HB_OT_VAR_MVAR_TABLE_HH */
115

source code of qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-var-mvar-table.hh