1 /*
2 * Copyright 2011 Google Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "sfntly/table/truetype/glyph_table.h"
18
19 #include <stdlib.h>
20
21 #include "sfntly/port/exception_type.h"
22
23 namespace sfntly {
24 /******************************************************************************
25 * Constants
26 ******************************************************************************/
27 const int32_t GlyphTable::SimpleGlyph::kFLAG_ONCURVE = 1;
28 const int32_t GlyphTable::SimpleGlyph::kFLAG_XSHORT = 1 << 1;
29 const int32_t GlyphTable::SimpleGlyph::kFLAG_YSHORT = 1 << 2;
30 const int32_t GlyphTable::SimpleGlyph::kFLAG_REPEAT = 1 << 3;
31 const int32_t GlyphTable::SimpleGlyph::kFLAG_XREPEATSIGN = 1 << 4;
32 const int32_t GlyphTable::SimpleGlyph::kFLAG_YREPEATSIGN = 1 << 5;
33
34 const int32_t GlyphTable::CompositeGlyph::kFLAG_ARG_1_AND_2_ARE_WORDS = 1 << 0;
35 const int32_t GlyphTable::CompositeGlyph::kFLAG_ARGS_ARE_XY_VALUES = 1 << 1;
36 const int32_t GlyphTable::CompositeGlyph::kFLAG_ROUND_XY_TO_GRID = 1 << 2;
37 const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_SCALE = 1 << 3;
38 const int32_t GlyphTable::CompositeGlyph::kFLAG_RESERVED = 1 << 4;
39 const int32_t GlyphTable::CompositeGlyph::kFLAG_MORE_COMPONENTS = 1 << 5;
40 const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6;
41 const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_TWO_BY_TWO = 1 << 7;
42 const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_INSTRUCTIONS = 1 << 8;
43 const int32_t GlyphTable::CompositeGlyph::kFLAG_USE_MY_METRICS = 1 << 9;
44 const int32_t GlyphTable::CompositeGlyph::kFLAG_OVERLAP_COMPOUND = 1 << 10;
45 const int32_t GlyphTable::CompositeGlyph::kFLAG_SCALED_COMPONENT_OFFSET = 1 << 11;
46 const int32_t GlyphTable::CompositeGlyph::kFLAG_UNSCALED_COMPONENT_OFFSET = 1 << 12;
47
48 /******************************************************************************
49 * GlyphTable class
50 ******************************************************************************/
~GlyphTable()51 GlyphTable::~GlyphTable() {
52 }
53
GetGlyph(int32_t offset,int32_t length)54 GlyphTable::Glyph* GlyphTable::GetGlyph(int32_t offset, int32_t length) {
55 return GlyphTable::Glyph::GetGlyph(this, this->data_, offset, length);
56 }
57
GlyphTable(Header * header,ReadableFontData * data)58 GlyphTable::GlyphTable(Header* header, ReadableFontData* data)
59 : SubTableContainerTable(header, data) {
60 }
61
62 /******************************************************************************
63 * GlyphTable::Builder class
64 ******************************************************************************/
Builder(Header * header,ReadableFontData * data)65 GlyphTable::Builder::Builder(Header* header, ReadableFontData* data)
66 : SubTableContainerTable::Builder(header, data) {
67 }
68
~Builder()69 GlyphTable::Builder::~Builder() {
70 }
71
SetLoca(const std::vector<int32_t> & loca)72 void GlyphTable::Builder::SetLoca(const std::vector<int32_t>& loca) {
73 loca_ = loca;
74 set_model_changed(false);
75 glyph_builders_.clear();
76 }
77
GenerateLocaList(std::vector<int32_t> * locas)78 void GlyphTable::Builder::GenerateLocaList(std::vector<int32_t>* locas) {
79 assert(locas);
80 GlyphBuilderList* glyph_builders = GetGlyphBuilders();
81 locas->push_back(0);
82 if (glyph_builders->size() == 0) {
83 locas->push_back(0);
84 } else {
85 int32_t total = 0;
86 for (GlyphBuilderList::iterator b = glyph_builders->begin(),
87 b_end = glyph_builders->end();
88 b != b_end; ++b) {
89 int32_t size = (*b)->SubDataSizeToSerialize();
90 locas->push_back(total + size);
91 total += size;
92 }
93 }
94 }
95
96 CALLER_ATTACH GlyphTable::Builder*
CreateBuilder(Header * header,WritableFontData * data)97 GlyphTable::Builder::CreateBuilder(Header* header, WritableFontData* data) {
98 Ptr<GlyphTable::Builder> builder;
99 builder = new GlyphTable::Builder(header, data);
100 return builder.Detach();
101 }
102
GlyphBuilders()103 GlyphTable::GlyphBuilderList* GlyphTable::Builder::GlyphBuilders() {
104 return GetGlyphBuilders();
105 }
106
SetGlyphBuilders(GlyphBuilderList * glyph_builders)107 void GlyphTable::Builder::SetGlyphBuilders(GlyphBuilderList* glyph_builders) {
108 glyph_builders_ = *glyph_builders;
109 set_model_changed();
110 }
111
112 CALLER_ATTACH GlyphTable::Glyph::Builder*
GlyphBuilder(ReadableFontData * data)113 GlyphTable::Builder::GlyphBuilder(ReadableFontData* data) {
114 return Glyph::Builder::GetBuilder(this, data);
115 }
116
117 CALLER_ATTACH FontDataTable*
SubBuildTable(ReadableFontData * data)118 GlyphTable::Builder::SubBuildTable(ReadableFontData* data) {
119 FontDataTablePtr table = new GlyphTable(header(), data);
120 return table.Detach();
121 }
122
SubDataSet()123 void GlyphTable::Builder::SubDataSet() {
124 glyph_builders_.clear();
125 set_model_changed(false);
126 }
127
SubDataSizeToSerialize()128 int32_t GlyphTable::Builder::SubDataSizeToSerialize() {
129 if (glyph_builders_.empty())
130 return 0;
131
132 bool variable = false;
133 int32_t size = 0;
134
135 // Calculate size of each table.
136 for (GlyphBuilderList::iterator b = glyph_builders_.begin(),
137 end = glyph_builders_.end(); b != end; ++b) {
138 int32_t glyph_size = (*b)->SubDataSizeToSerialize();
139 size += abs(glyph_size);
140 variable |= glyph_size <= 0;
141 }
142 return variable ? -size : size;
143 }
144
SubReadyToSerialize()145 bool GlyphTable::Builder::SubReadyToSerialize() {
146 return !glyph_builders_.empty();
147 }
148
SubSerialize(WritableFontData * new_data)149 int32_t GlyphTable::Builder::SubSerialize(WritableFontData* new_data) {
150 int32_t size = 0;
151 for (GlyphBuilderList::iterator b = glyph_builders_.begin(),
152 end = glyph_builders_.end(); b != end; ++b) {
153 FontDataPtr data;
154 data.Attach(new_data->Slice(size));
155 size += (*b)->SubSerialize(down_cast<WritableFontData*>(data.p_));
156 }
157 return size;
158 }
159
Initialize(ReadableFontData * data,const std::vector<int32_t> & loca)160 void GlyphTable::Builder::Initialize(ReadableFontData* data,
161 const std::vector<int32_t>& loca) {
162 if (data != NULL) {
163 if (loca_.empty()) {
164 return;
165 }
166 int32_t loca_value;
167 int32_t last_loca_value = loca[0];
168 for (size_t i = 1; i < loca.size(); ++i) {
169 loca_value = loca[i];
170 GlyphBuilderPtr builder;
171 builder.Attach(
172 Glyph::Builder::GetBuilder(this,
173 data,
174 last_loca_value /*offset*/,
175 loca_value - last_loca_value /*length*/));
176 glyph_builders_.push_back(builder);
177 last_loca_value = loca_value;
178 }
179 }
180 }
181
GetGlyphBuilders()182 GlyphTable::GlyphBuilderList* GlyphTable::Builder::GetGlyphBuilders() {
183 if (glyph_builders_.empty()) {
184 if (InternalReadData() && loca_.empty()) {
185 #if !defined (SFNTLY_NO_EXCEPTION)
186 throw IllegalStateException(
187 "Loca values not set - unable to parse glyph data.");
188 #endif
189 return NULL;
190 }
191 Initialize(InternalReadData(), loca_);
192 set_model_changed();
193 }
194 return &glyph_builders_;
195 }
196
Revert()197 void GlyphTable::Builder::Revert() {
198 glyph_builders_.clear();
199 set_model_changed(false);
200 }
201
202 /******************************************************************************
203 * GlyphTable::Glyph class
204 ******************************************************************************/
~Glyph()205 GlyphTable::Glyph::~Glyph() {}
206
207 CALLER_ATTACH GlyphTable::Glyph*
GetGlyph(GlyphTable * table,ReadableFontData * data,int32_t offset,int32_t length)208 GlyphTable::Glyph::GetGlyph(GlyphTable* table,
209 ReadableFontData* data,
210 int32_t offset,
211 int32_t length) {
212 UNREFERENCED_PARAMETER(table);
213 int32_t type = GlyphType(data, offset, length);
214 GlyphPtr glyph;
215
216 ReadableFontDataPtr sliced_data;
217 sliced_data.Attach(down_cast<ReadableFontData*>(data->Slice(offset, length)));
218 if (sliced_data) {
219 if (type == GlyphType::kSimple)
220 glyph = new SimpleGlyph(sliced_data);
221 else
222 glyph = new CompositeGlyph(sliced_data);
223 }
224 return glyph.Detach();
225 }
226
Padding()227 int32_t GlyphTable::Glyph::Padding() {
228 Initialize();
229 return SubTable::Padding();
230 }
231
GlyphType()232 int32_t GlyphTable::Glyph::GlyphType() {
233 return glyph_type_;
234 }
235
NumberOfContours()236 int32_t GlyphTable::Glyph::NumberOfContours() {
237 return number_of_contours_;
238 }
239
XMin()240 int32_t GlyphTable::Glyph::XMin() {
241 return data_->ReadShort(Offset::kXMin);
242 }
243
XMax()244 int32_t GlyphTable::Glyph::XMax() {
245 return data_->ReadShort(Offset::kXMax);
246 }
247
YMin()248 int32_t GlyphTable::Glyph::YMin() {
249 return data_->ReadShort(Offset::kYMin);
250 }
251
YMax()252 int32_t GlyphTable::Glyph::YMax() {
253 return data_->ReadShort(Offset::kYMax);
254 }
255
Glyph(ReadableFontData * data,int32_t glyph_type)256 GlyphTable::Glyph::Glyph(ReadableFontData* data, int32_t glyph_type)
257 : SubTable(data),
258 glyph_type_(glyph_type) {
259 if (data_->Length() == 0) {
260 number_of_contours_ = 0;
261 } else {
262 // -1 if composite
263 number_of_contours_ = data_->ReadShort(Offset::kNumberOfContours);
264 }
265 }
266
GlyphType(ReadableFontData * data,int32_t offset,int32_t length)267 int32_t GlyphTable::Glyph::GlyphType(ReadableFontData* data,
268 int32_t offset,
269 int32_t length) {
270 if (length == 0) {
271 return GlyphType::kSimple;
272 }
273 int32_t number_of_contours = data->ReadShort(offset);
274 if (number_of_contours >= 0) {
275 return GlyphType::kSimple;
276 }
277 return GlyphType::kComposite;
278 }
279
280 /******************************************************************************
281 * GlyphTable::Glyph::Builder class
282 ******************************************************************************/
~Builder()283 GlyphTable::Glyph::Builder::~Builder() {
284 }
285
Builder(WritableFontData * data)286 GlyphTable::Glyph::Builder::Builder(WritableFontData* data)
287 : SubTable::Builder(data) {
288 }
289
Builder(ReadableFontData * data)290 GlyphTable::Glyph::Builder::Builder(ReadableFontData* data)
291 : SubTable::Builder(data) {
292 }
293
294 CALLER_ATTACH GlyphTable::Glyph::Builder*
GetBuilder(GlyphTable::Builder * table_builder,ReadableFontData * data)295 GlyphTable::Glyph::Builder::GetBuilder(
296 GlyphTable::Builder* table_builder,
297 ReadableFontData* data) {
298 return GetBuilder(table_builder, data, 0, data->Length());
299 }
300
301 CALLER_ATTACH GlyphTable::Glyph::Builder*
GetBuilder(GlyphTable::Builder * table_builder,ReadableFontData * data,int32_t offset,int32_t length)302 GlyphTable::Glyph::Builder::GetBuilder(
303 GlyphTable::Builder* table_builder,
304 ReadableFontData* data,
305 int32_t offset,
306 int32_t length) {
307 UNREFERENCED_PARAMETER(table_builder);
308 int32_t type = Glyph::GlyphType(data, offset, length);
309 GlyphBuilderPtr builder;
310 ReadableFontDataPtr sliced_data;
311 sliced_data.Attach(down_cast<ReadableFontData*>(data->Slice(offset, length)));
312 if (type == GlyphType::kSimple) {
313 builder = new SimpleGlyph::SimpleGlyphBuilder(sliced_data);
314 } else {
315 builder = new CompositeGlyph::CompositeGlyphBuilder(sliced_data);
316 }
317 return builder.Detach();
318 }
319
SubDataSet()320 void GlyphTable::Glyph::Builder::SubDataSet() {
321 // NOP
322 }
323
SubDataSizeToSerialize()324 int32_t GlyphTable::Glyph::Builder::SubDataSizeToSerialize() {
325 return InternalReadData()->Length();
326 }
327
SubReadyToSerialize()328 bool GlyphTable::Glyph::Builder::SubReadyToSerialize() {
329 return true;
330 }
331
SubSerialize(WritableFontData * new_data)332 int32_t GlyphTable::Glyph::Builder::SubSerialize(WritableFontData* new_data) {
333 return InternalReadData()->CopyTo(new_data);
334 }
335
336 /******************************************************************************
337 * GlyphTable::SimpleGlyph
338 ******************************************************************************/
SimpleGlyph(ReadableFontData * data)339 GlyphTable::SimpleGlyph::SimpleGlyph(ReadableFontData* data)
340 : GlyphTable::Glyph(data, GlyphType::kSimple), initialized_(false) {
341 }
342
~SimpleGlyph()343 GlyphTable::SimpleGlyph::~SimpleGlyph() {
344 }
345
InstructionSize()346 int32_t GlyphTable::SimpleGlyph::InstructionSize() {
347 Initialize();
348 return instruction_size_;
349 }
350
Instructions()351 CALLER_ATTACH ReadableFontData* GlyphTable::SimpleGlyph::Instructions() {
352 Initialize();
353 return down_cast<ReadableFontData*>(
354 data_->Slice(instructions_offset_, InstructionSize()));
355 }
356
Initialize()357 void GlyphTable::SimpleGlyph::Initialize() {
358 AutoLock lock(initialization_lock_);
359 if (initialized_) {
360 return;
361 }
362
363 if (ReadFontData()->Length() == 0) {
364 instruction_size_ = 0;
365 number_of_points_ = 0;
366 instructions_offset_ = 0;
367 flags_offset_ = 0;
368 x_coordinates_offset_ = 0;
369 y_coordinates_offset_ = 0;
370 return;
371 }
372
373 instruction_size_ = data_->ReadUShort(Offset::kSimpleEndPtsOfCountours +
374 NumberOfContours() * DataSize::kUSHORT);
375 instructions_offset_ = Offset::kSimpleEndPtsOfCountours +
376 (NumberOfContours() + 1) * DataSize::kUSHORT;
377 flags_offset_ = instructions_offset_ + instruction_size_ * DataSize::kBYTE;
378 number_of_points_ = ContourEndPoint(NumberOfContours() - 1) + 1;
379 x_coordinates_.resize(number_of_points_);
380 y_coordinates_.resize(number_of_points_);
381 on_curve_.resize(number_of_points_);
382 ParseData(false);
383 x_coordinates_offset_ = flags_offset_ + flag_byte_count_ * DataSize::kBYTE;
384 y_coordinates_offset_ = x_coordinates_offset_ + x_byte_count_ *
385 DataSize::kBYTE;
386 contour_index_.resize(NumberOfContours() + 1);
387 contour_index_[0] = 0;
388 for (uint32_t contour = 0; contour < contour_index_.size() - 1; ++contour) {
389 contour_index_[contour + 1] = ContourEndPoint(contour) + 1;
390 }
391 ParseData(true);
392 int32_t non_padded_data_length =
393 5 * DataSize::kSHORT +
394 (NumberOfContours() * DataSize::kUSHORT) +
395 DataSize::kUSHORT +
396 (instruction_size_ * DataSize::kBYTE) +
397 (flag_byte_count_ * DataSize::kBYTE) +
398 (x_byte_count_ * DataSize::kBYTE) +
399 (y_byte_count_ * DataSize::kBYTE);
400 set_padding(DataLength() - non_padded_data_length);
401 initialized_ = true;
402 }
403
ParseData(bool fill_arrays)404 void GlyphTable::SimpleGlyph::ParseData(bool fill_arrays) {
405 int32_t flag = 0;
406 int32_t flag_repeat = 0;
407 int32_t flag_index = 0;
408 int32_t x_byte_index = 0;
409 int32_t y_byte_index = 0;
410
411 for (int32_t point_index = 0; point_index < number_of_points_;
412 ++point_index) {
413 // get the flag for the current point
414 if (flag_repeat == 0) {
415 flag = FlagAsInt(flag_index++);
416 if ((flag & kFLAG_REPEAT) == kFLAG_REPEAT) {
417 flag_repeat = FlagAsInt(flag_index++);
418 }
419 } else {
420 flag_repeat--;
421 }
422
423 // on the curve?
424 if (fill_arrays) {
425 on_curve_[point_index] = ((flag & kFLAG_ONCURVE) == kFLAG_ONCURVE);
426 }
427 // get the x coordinate
428 if ((flag & kFLAG_XSHORT) == kFLAG_XSHORT) {
429 // single byte x coord value
430 if (fill_arrays) {
431 x_coordinates_[point_index] =
432 data_->ReadUByte(x_coordinates_offset_ + x_byte_index);
433 x_coordinates_[point_index] *=
434 ((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN) ? 1 : -1;
435 }
436 x_byte_index++;
437 } else {
438 // double byte coord value
439 if (!((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN)) {
440 if (fill_arrays) {
441 x_coordinates_[point_index] =
442 data_->ReadShort(x_coordinates_offset_ + x_byte_index);
443 }
444 x_byte_index += 2;
445 }
446 }
447 if (fill_arrays && point_index > 0) {
448 x_coordinates_[point_index] += x_coordinates_[point_index - 1];
449 }
450
451 // get the y coordinate
452 if ((flag & kFLAG_YSHORT) == kFLAG_YSHORT) {
453 if (fill_arrays) {
454 y_coordinates_[point_index] =
455 data_->ReadUByte(y_coordinates_offset_ + y_byte_index);
456 y_coordinates_[point_index] *=
457 ((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN) ? 1 : -1;
458 }
459 y_byte_index++;
460 } else {
461 if (!((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN)) {
462 if (fill_arrays) {
463 y_coordinates_[point_index] =
464 data_->ReadShort(y_coordinates_offset_ + y_byte_index);
465 }
466 y_byte_index += 2;
467 }
468 }
469 if (fill_arrays && point_index > 0) {
470 y_coordinates_[point_index] += y_coordinates_[point_index - 1];
471 }
472 }
473 flag_byte_count_ = flag_index;
474 x_byte_count_ = x_byte_index;
475 y_byte_count_ = y_byte_index;
476 }
477
FlagAsInt(int32_t index)478 int32_t GlyphTable::SimpleGlyph::FlagAsInt(int32_t index) {
479 return data_->ReadUByte(flags_offset_ + index * DataSize::kBYTE);
480 }
481
ContourEndPoint(int32_t contour)482 int32_t GlyphTable::SimpleGlyph::ContourEndPoint(int32_t contour) {
483 return data_->ReadUShort(contour * DataSize::kUSHORT +
484 Offset::kSimpleEndPtsOfCountours);
485 }
486
487 /******************************************************************************
488 * GlyphTable::SimpleGlyph::Builder
489 ******************************************************************************/
~SimpleGlyphBuilder()490 GlyphTable::SimpleGlyph::SimpleGlyphBuilder::~SimpleGlyphBuilder() {
491 }
492
SimpleGlyphBuilder(WritableFontData * data)493 GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder(
494 WritableFontData* data)
495 : Glyph::Builder(data) {
496 }
497
SimpleGlyphBuilder(ReadableFontData * data)498 GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder(
499 ReadableFontData* data)
500 : Glyph::Builder(data) {
501 }
502
503 CALLER_ATTACH FontDataTable*
SubBuildTable(ReadableFontData * data)504 GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SubBuildTable(
505 ReadableFontData* data) {
506 FontDataTablePtr table = new SimpleGlyph(data);
507 return table.Detach();
508 }
509
510 /******************************************************************************
511 * GlyphTable::CompositeGlyph
512 ******************************************************************************/
CompositeGlyph(ReadableFontData * data)513 GlyphTable::CompositeGlyph::CompositeGlyph(ReadableFontData* data)
514 : GlyphTable::Glyph(data, GlyphType::kComposite),
515 instruction_size_(0),
516 instructions_offset_(0),
517 initialized_(false) {
518 Initialize();
519 }
520
~CompositeGlyph()521 GlyphTable::CompositeGlyph::~CompositeGlyph() {
522 }
523
Flags(int32_t contour)524 int32_t GlyphTable::CompositeGlyph::Flags(int32_t contour) {
525 if (contour < 0 || static_cast<size_t>(contour) >= contour_index_.size())
526 return ReadableFontData::kInvalidUnsigned;
527 return data_->ReadUShort(contour_index_[contour]);
528 }
529
NumGlyphs()530 int32_t GlyphTable::CompositeGlyph::NumGlyphs() {
531 return contour_index_.size();
532 }
533
GlyphIndex(int32_t contour)534 int32_t GlyphTable::CompositeGlyph::GlyphIndex(int32_t contour) {
535 if (contour < 0 || static_cast<size_t>(contour) >= contour_index_.size())
536 return ReadableFontData::kInvalidUnsigned;
537 return data_->ReadUShort(DataSize::kUSHORT + contour_index_[contour]);
538 }
539
InstructionSize()540 int32_t GlyphTable::CompositeGlyph::InstructionSize() {
541 return instruction_size_;
542 }
543
Instructions()544 CALLER_ATTACH ReadableFontData* GlyphTable::CompositeGlyph::Instructions() {
545 return down_cast<ReadableFontData*>(
546 data_->Slice(instructions_offset_, InstructionSize()));
547 }
548
Initialize()549 void GlyphTable::CompositeGlyph::Initialize() {
550 AutoLock lock(initialization_lock_);
551 if (initialized_) {
552 return;
553 }
554
555 int32_t index = 5 * DataSize::kUSHORT;
556 int32_t flags = kFLAG_MORE_COMPONENTS;
557
558 while ((flags & kFLAG_MORE_COMPONENTS) == kFLAG_MORE_COMPONENTS) {
559 contour_index_.push_back(index);
560 flags = data_->ReadUShort(index);
561 if (flags == ReadableFontData::kInvalidUnsigned)
562 break;
563
564 index += 2 * DataSize::kUSHORT; // flags and glyphIndex
565 if ((flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == kFLAG_ARG_1_AND_2_ARE_WORDS) {
566 index += 2 * DataSize::kSHORT;
567 } else {
568 index += 2 * DataSize::kBYTE;
569 }
570 if ((flags & kFLAG_WE_HAVE_A_SCALE) == kFLAG_WE_HAVE_A_SCALE) {
571 index += DataSize::kF2DOT14;
572 } else if ((flags & kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) ==
573 kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) {
574 index += 2 * DataSize::kF2DOT14;
575 } else if ((flags & kFLAG_WE_HAVE_A_TWO_BY_TWO) ==
576 kFLAG_WE_HAVE_A_TWO_BY_TWO) {
577 index += 4 * DataSize::kF2DOT14;
578 }
579 int32_t non_padded_data_length = index;
580 if ((flags & kFLAG_WE_HAVE_INSTRUCTIONS) == kFLAG_WE_HAVE_INSTRUCTIONS) {
581 instruction_size_ = data_->ReadUShort(index);
582 index += DataSize::kUSHORT;
583 instructions_offset_ = index;
584 non_padded_data_length = index + (instruction_size_ * DataSize::kBYTE);
585 }
586 set_padding(DataLength() - non_padded_data_length);
587 }
588
589 initialized_ = true;
590 }
591
592 /******************************************************************************
593 * GlyphTable::CompositeGlyph::Builder
594 ******************************************************************************/
~CompositeGlyphBuilder()595 GlyphTable::CompositeGlyph::CompositeGlyphBuilder::~CompositeGlyphBuilder() {
596 }
597
CompositeGlyphBuilder(WritableFontData * data)598 GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder(
599 WritableFontData* data)
600 : Glyph::Builder(data) {
601 }
602
CompositeGlyphBuilder(ReadableFontData * data)603 GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder(
604 ReadableFontData* data)
605 : Glyph::Builder(data) {
606 }
607
608 CALLER_ATTACH FontDataTable*
SubBuildTable(ReadableFontData * data)609 GlyphTable::CompositeGlyph::CompositeGlyphBuilder::SubBuildTable(
610 ReadableFontData* data) {
611 FontDataTablePtr table = new CompositeGlyph(data);
612 return table.Detach();
613 }
614
615 } // namespace sfntly
616