11
11
#include " absl/flags/parse.h"
12
12
#include " absl/status/statusor.h"
13
13
#include " absl/strings/str_cat.h"
14
+ #include " common/axis_range.h"
14
15
#include " common/font_data.h"
15
16
#include " hb.h"
16
17
#include " ift/encoder/encoder.h"
@@ -123,7 +124,7 @@ int write_output(const Encoder& encoder, const FontData& base_font) {
123
124
}
124
125
125
126
template <typename T>
126
- flat_hash_set<uint32_t > values (T proto_set) {
127
+ flat_hash_set<uint32_t > values (const T& proto_set) {
127
128
flat_hash_set<uint32_t > result;
128
129
for (uint32_t v : proto_set.values ()) {
129
130
result.insert (v);
@@ -132,14 +133,23 @@ flat_hash_set<uint32_t> values(T proto_set) {
132
133
}
133
134
134
135
template <typename T>
135
- btree_set<hb_tag_t > tag_values (T proto_set) {
136
+ btree_set<hb_tag_t > tag_values (const T& proto_set) {
136
137
btree_set<hb_tag_t > result;
137
138
for (const auto & tag : proto_set.values ()) {
138
139
result.insert (FontHelper::ToTag (tag));
139
140
}
140
141
return result;
141
142
}
142
143
144
+ StatusOr<Encoder::design_space_t > to_design_space (const DesignSpace& proto) {
145
+ Encoder::design_space_t result;
146
+ for (const auto & [tag_str, range_proto] : proto.ranges ()) {
147
+ auto range = TRY (common::AxisRange::Range (range_proto.start (), range_proto.end ()));
148
+ result[FontHelper::ToTag (tag_str)] = range;
149
+ }
150
+ return result;
151
+ }
152
+
143
153
Status ConfigureEncoder (EncoderConfig config, Encoder& encoder) {
144
154
// First configure the glyph keyed segments, including features deps
145
155
for (const auto & [id, gids] : config.glyph_segments ()) {
@@ -162,17 +172,21 @@ Status ConfigureEncoder(EncoderConfig config, Encoder& encoder) {
162
172
auto init_codepoints = values (config.initial_codepoints ());
163
173
auto init_features = tag_values (config.initial_features ());
164
174
auto init_segments = values (config.initial_glyph_patches ());
165
- // TODO(garretrieger): support init design space too
175
+ auto init_design_space = TRY ( to_design_space (config. initial_design_space ()));
166
176
167
177
if ((!init_codepoints.empty () || !init_features.empty ()) &&
168
178
init_segments.empty ()) {
169
179
Encoder::SubsetDefinition base_subset;
170
180
base_subset.codepoints = init_codepoints;
171
181
base_subset.feature_tags = init_features;
182
+ base_subset.design_space = init_design_space;
172
183
TRYV (encoder.SetBaseSubsetFromDef (base_subset));
173
- } else if (init_codepoints.empty () && init_features.empty () &&
184
+ } else if (init_codepoints.empty () && init_features.empty () && init_design_space. empty () &&
174
185
!init_segments.empty ()) {
175
186
TRYV (encoder.SetBaseSubsetFromSegments (init_segments));
187
+ } else if (init_codepoints.empty () && init_features.empty () && !init_design_space.empty () &&
188
+ !init_segments.empty ()) {
189
+ TRYV (encoder.SetBaseSubsetFromSegments (init_segments, init_design_space));
176
190
} else {
177
191
return absl::UnimplementedError (
178
192
" Setting base subset from both codepoints and glyph patches is not yet "
@@ -188,7 +202,10 @@ Status ConfigureEncoder(EncoderConfig config, Encoder& encoder) {
188
202
encoder.AddFeatureGroupSegment (tag_values (features));
189
203
}
190
204
191
- // TODO(garretrieger): support design space.
205
+ for (const auto & design_space_proto : config.non_glyph_design_space_segmentation ()) {
206
+ auto design_space = TRY (to_design_space (design_space_proto));
207
+ encoder.AddDesignSpaceSegment (design_space);
208
+ }
192
209
193
210
for (const auto & segments : config.glyph_patch_groupings ()) {
194
211
TRYV (encoder.AddNonGlyphSegmentFromGlyphSegments (values (segments)));
0 commit comments