blob: e20131b161ac2500b2c6e22b5af2753f65b9ced4 [file] [log] [blame]
Behdad Esfahbod7b399f72017-01-23 11:41:43 -08001/*
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_HVAR_TABLE_HH
28#define HB_OT_VAR_HVAR_TABLE_HH
29
30#include "hb-ot-layout-common-private.hh"
31
32
33namespace OT {
34
35
36struct DeltaSetIndexMap
37{
38 inline bool sanitize (hb_sanitize_context_t *c) const
39 {
40 TRACE_SANITIZE (this);
41 return_trace (c->check_struct (this) &&
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080042 c->check_array (mapData, get_width (), mapCount));
Behdad Esfahbod7b399f72017-01-23 11:41:43 -080043 }
44
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080045 unsigned int map (unsigned int v) const /* Returns 16.16 outer.inner. */
46 {
47 /* If count is zero, pass value unchanged. This takes
48 * care of direct mapping for advance map. */
49 if (!mapCount)
50 return v;
51
52 if (v >= mapCount)
53 v = mapCount - 1;
54
55 unsigned int u = 0;
56 { /* Fetch it. */
57 unsigned int w = get_width ();
Behdad Esfahbod6b191782018-01-10 03:07:30 +010058 const HBUINT8 *p = mapData + w * v;
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080059 for (; w; w--)
60 u = (u << 8) + *p++;
61 }
62
63 { /* Repack it. */
64 unsigned int n = get_inner_bitcount ();
65 unsigned int outer = u >> n;
66 unsigned int inner = u & ((1 << n) - 1);
67 u = (outer<<16) | inner;
68 }
69
70 return u;
71 }
72
73 protected:
Behdad Esfahbod60743402017-01-23 17:55:16 -080074 inline unsigned int get_width (void) const
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080075 { return ((format >> 4) & 3) + 1; }
76
Behdad Esfahbod60743402017-01-23 17:55:16 -080077 inline unsigned int get_inner_bitcount (void) const
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080078 { return (format & 0xF) + 1; }
79
80 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +010081 HBUINT16 format; /* A packed field that describes the compressed
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080082 * representation of delta-set indices. */
Behdad Esfahbod6b191782018-01-10 03:07:30 +010083 HBUINT16 mapCount; /* The number of mapping entries. */
84 HBUINT8 mapData[VAR]; /* The delta-set index mapping data. */
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080085
Behdad Esfahbod7b399f72017-01-23 11:41:43 -080086 public:
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -080087 DEFINE_SIZE_ARRAY (4, mapData);
Behdad Esfahbod7b399f72017-01-23 11:41:43 -080088};
89
90
91/*
92 * HVAR -- The Horizontal Metrics Variations Table
93 * VVAR -- The Vertical Metrics Variations Table
94 */
95
96#define HB_OT_TAG_HVAR HB_TAG('H','V','A','R')
97#define HB_OT_TAG_VVAR HB_TAG('V','V','A','R')
98
99struct HVARVVAR
100{
Behdad Esfahbodbd3b11d2017-01-23 17:34:44 -0800101 static const hb_tag_t HVARTag = HB_OT_TAG_HVAR;
102 static const hb_tag_t VVARTag = HB_OT_TAG_VVAR;
Behdad Esfahbod7b399f72017-01-23 11:41:43 -0800103
104 inline bool sanitize (hb_sanitize_context_t *c) const
105 {
106 TRACE_SANITIZE (this);
107 return_trace (version.sanitize (c) &&
108 likely (version.major == 1) &&
109 varStore.sanitize (c, this) &&
110 advMap.sanitize (c, this) &&
111 lsbMap.sanitize (c, this) &&
112 rsbMap.sanitize (c, this));
113 }
114
Behdad Esfahbodbd3b11d2017-01-23 17:34:44 -0800115 inline float get_advance_var (hb_codepoint_t glyph,
116 int *coords, unsigned int coord_count) const
Behdad Esfahboda4fca9f2017-01-23 11:56:08 -0800117 {
118 unsigned int varidx = (this+advMap).map (glyph);
119 return (this+varStore).get_delta (varidx, coords, coord_count);
120 }
121
122 inline bool has_sidebearing_deltas (void) const
123 { return lsbMap && rsbMap; }
124
Behdad Esfahbod7b399f72017-01-23 11:41:43 -0800125 protected:
126 FixedVersion<>version; /* Version of the metrics variation table
127 * initially set to 0x00010000u */
128 LOffsetTo<VariationStore>
129 varStore; /* Offset to item variation store table. */
130 LOffsetTo<DeltaSetIndexMap>
131 advMap; /* Offset to advance var-idx mapping. */
132 LOffsetTo<DeltaSetIndexMap>
133 lsbMap; /* Offset to lsb/tsb var-idx mapping. */
134 LOffsetTo<DeltaSetIndexMap>
135 rsbMap; /* Offset to rsb/bsb var-idx mapping. */
136
137 public:
138 DEFINE_SIZE_STATIC (20);
139};
140
141struct HVAR : HVARVVAR {
142 static const hb_tag_t tableTag = HB_OT_TAG_HVAR;
143};
144struct VVAR : HVARVVAR {
145 static const hb_tag_t tableTag = HB_OT_TAG_VVAR;
146
147 inline bool sanitize (hb_sanitize_context_t *c) const
148 {
149 TRACE_SANITIZE (this);
150 return_trace (static_cast<const HVARVVAR *> (this)->sanitize (c) &&
151 vorgMap.sanitize (c, this));
152 }
153
154 protected:
155 LOffsetTo<DeltaSetIndexMap>
156 vorgMap; /* Offset to vertical-origin var-idx mapping. */
157
158 public:
159 DEFINE_SIZE_STATIC (24);
160};
161
162} /* namespace OT */
163
164
165#endif /* HB_OT_VAR_HVAR_TABLE_HH */