1 /* otfopen.c -- OpenType font reader.
3 Copyright (C) 2003, 2004, 2005, 2006, 2008
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H15PRO167
7 This file is part of libotf.
9 Libotf is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 Libotf is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library, in a file named COPYING; if not,
21 write to the Free Software Foundation, Inc., 59 Temple Place, Suite
22 330, Boston, MA 02111-1307, USA. */
32 #include FT_TRUETYPE_TABLES_H
35 Table of contents (almost parallel to otf.h):
39 (1) Readers for OTF Layout tables and OTF itself
40 (1-1) Basic types and functions
44 (1-5) Structures common to GDEF, GSUB, and GPOS
46 (1-7) Structures for ScriptList, FeatureList, and LookupList
47 (1-8) Structures common to GSUB and GPOS
50 (1-11) Structure for OTF
52 (2) API for reading OTF
56 (2-4) OTF_check_table()
63 Example of typical usage of OTF_Stream.
67 OTF_StreamState state;
70 OPEN_STREAM (_FILE_NAME_, stream);
73 SETUP_STREAM (stream, fp, 0, 256, _NAME_);
74 offset = READ_OFFSET (stream);
75 nbytes = READ_ULONG (stream);
76 SETUP_STREAM (stream, fp, offset, nbytes, _NAME2_);
78 CLOSE_STREAM (stream);
92 typedef long OTF_StreamState;
95 make_stream (const char *name)
98 char *errfmt = "stream creation%s";
101 stream = calloc (1, sizeof (OTF_Stream));
103 OTF_ERROR (OTF_ERROR_MEMORY, "");
109 setup_stream (OTF_Stream *stream, FILE *fp, long offset, int nbytes)
111 char *errfmt = "stream setup for %s";
115 if (stream->allocated < nbytes)
117 unsigned char *buf = malloc (nbytes);
120 OTF_ERROR (OTF_ERROR_MEMORY, stream->name);
124 stream->allocated = nbytes;
126 stream->bufsize = nbytes;
127 if (fseek (fp, offset, SEEK_SET) < 0)
128 OTF_ERROR (OTF_ERROR_FILE, stream->name);
129 if (fread (stream->buf, 1, nbytes, fp) != nbytes)
130 OTF_ERROR (OTF_ERROR_FILE, stream->name);
135 make_stream_from_ft_face (FT_Face face, const char *name)
137 char *errfmt = "FT_Face stream creation for %s";
142 FT_ULong tag = FT_MAKE_TAG (name[0], name[1], name[2], name[3]);
144 if (FT_Load_Sfnt_Table (face, tag, 0, NULL, &nbytes))
146 buf = malloc (nbytes);
148 OTF_ERROR (OTF_ERROR_MEMORY, name);
149 if (FT_Load_Sfnt_Table (face, tag, 0, buf, &nbytes))
152 OTF_ERROR (OTF_ERROR_FT_FACE, name);
154 stream = make_stream (name);
159 stream->allocated = nbytes;
160 stream->bufsize = nbytes;
165 free_stream (OTF_Stream *stream)
172 #define SAVE_STREAM(stream, state) ((state) = (stream)->pos)
173 #define RESTORE_STREAM(stream, state) ((stream)->pos = (state))
174 #define SEEK_STREAM(stream, offset) ((stream)->pos = (offset))
176 #define STREAM_CHECK_SIZE(stream, size) \
177 if ((stream)->pos + (size) > (stream)->bufsize) \
179 char *errfmt = "buffer overrun in %s"; \
181 OTF_ERROR (OTF_ERROR_TABLE, (stream)->name); \
187 #define READ_USHORT(stream, var) \
189 STREAM_CHECK_SIZE ((stream), 2); \
190 (var) = (((stream)->buf[(stream)->pos] << 8) \
191 | (stream)->buf[(stream)->pos + 1]); \
192 (stream)->pos += 2; \
195 #define READ_SHORT(stream, var) \
197 STREAM_CHECK_SIZE ((stream), 2); \
198 (var) = (short) (((stream)->buf[(stream)->pos] << 8) \
199 | (stream)->buf[(stream)->pos + 1]); \
200 (stream)->pos += 2; \
203 #define READ_UINT24(stream, var) \
205 STREAM_CHECK_SIZE ((stream), 3); \
206 (var) = (((stream)->buf[(stream)->pos ] << 16) \
207 | ((stream)->buf[(stream)->pos + 1] << 8) \
208 | (stream)->buf[(stream)->pos + 2]); \
209 (stream)->pos += 3; \
212 #define READ_ULONG(stream, var) \
214 STREAM_CHECK_SIZE ((stream), 4); \
215 (var) = (((stream)->buf[(stream)->pos] << 24) \
216 | ((stream)->buf[(stream)->pos + 1] << 16) \
217 | ((stream)->buf[(stream)->pos + 2] << 8) \
218 | (stream)->buf[(stream)->pos + 3]); \
219 (stream)->pos += 4; \
222 #define READ_LONG(stream, var) \
224 STREAM_CHECK_SIZE ((stream), 4); \
225 (var) = (int) (((stream)->buf[(stream)->pos] << 24) \
226 | ((stream)->buf[(stream)->pos + 1] << 16) \
227 | ((stream)->buf[(stream)->pos + 2] << 8) \
228 | (stream)->buf[(stream)->pos + 3]); \
229 (stream)->pos += 4; \
233 #define READ_FIXED(stream, fixed) \
235 READ_USHORT ((stream), (fixed).high); \
236 READ_USHORT ((stream), (fixed).low); \
240 #define READ_BYTES(stream, p, nbytes) \
242 STREAM_CHECK_SIZE ((stream), (nbytes)); \
243 memcpy ((p), (stream)->buf + (stream)->pos, (nbytes)); \
244 (stream)->pos += (nbytes); \
248 #define READ_TAG READ_ULONG
249 #define READ_OFFSET READ_USHORT
250 #define READ_UINT16 READ_USHORT
251 #define READ_INT16 READ_SHORT
252 #define READ_GLYPHID READ_USHORT
255 /*** (1) Structures for OTF Layout tables and OTF itself */
257 /*** (1-1) Basic types and functions */
270 #define OTF_MEMORY_RECORD_SIZE 1024
272 struct OTF_MemoryRecord
275 void *memory[OTF_MEMORY_RECORD_SIZE];
276 struct OTF_MemoryRecord *next;
279 typedef struct OTF_MemoryRecord OTF_MemoryRecord;
289 struct _OTF_TableInfo;
290 typedef struct _OTF_TableInfo OTF_TableInfo;
292 struct _OTF_TableInfo
294 /* Points to one of OTF->head, OTF->name, etc. */
296 /* Function to read one of OTF tables. */
297 void *(*reader) (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag);
298 /* Stream given to <reader>. */
302 struct OTF_InternalData
304 /* Information about each OTF table. */
305 OTF_TableInfo table_info[OTF_TABLE_TYPE_MAX];
307 /* Stream used to read the header part of OTF. */
308 OTF_Stream *header_stream;
310 /* Records of allocated memories. */
311 OTF_MemoryRecord *memory_record;
315 static OTF_MemoryRecord *
316 allocate_memory_record (OTF *otf)
318 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
319 OTF_MemoryRecord *memrec = malloc (sizeof (OTF_MemoryRecord));
324 memrec->next = internal_data->memory_record;
325 internal_data->memory_record = memrec;
329 /* Memory allocation macros. */
331 #define OTF_MALLOC(p, size, arg) \
337 OTF_MemoryRecord *memrec \
338 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
339 (p) = malloc (sizeof (*(p)) * (size)); \
341 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
342 && ! (memrec = allocate_memory_record (otf)))) \
343 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
344 memrec->memory[memrec->used++] = (p); \
349 #define OTF_CALLOC(p, size, arg) \
355 OTF_MemoryRecord *memrec \
356 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
357 (p) = calloc ((size), sizeof (*(p))); \
359 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
360 && ! (memrec = allocate_memory_record (otf)))) \
361 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
362 memrec->memory[memrec->used++] = (p); \
367 /*** (1-2) "head" table */
370 read_head_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
372 OTF_Stream *stream = table->stream;
373 char *errfmt = "head%s";
377 OTF_CALLOC (head, 1, "");
378 READ_FIXED (stream, head->TableVersionNumber);
379 READ_FIXED (stream, head->fontRevision);
380 READ_ULONG (stream, head->checkSumAdjustment);
381 READ_ULONG (stream, head->magicNumber);
382 READ_USHORT (stream, head->flags);
383 READ_USHORT (stream, head->unitsPerEm);
385 *table->address = head;
390 /*** (1-3) "name" table */
393 read_name (OTF *otf, OTF_Stream *stream, OTF_NameRecord *rec)
395 char *errfmt = "nameID (%d)";
397 OTF_StreamState state;
402 if (rec->platformID == 0)
403 ucs = (rec->encodingID <= 3) ? 2 : 4;
404 else if (rec->platformID == 1 && rec->encodingID == 0)
406 else if (rec->platformID == 3)
407 ucs = (rec->encodingID == 1 ? 2
408 : rec->encodingID == 10 ? 4
411 OTF_MALLOC (rec->name, rec->length + 1, (void *) rec->nameID);
412 SAVE_STREAM (stream, state);
413 SEEK_STREAM (stream, stream->pos + rec->offset);
414 READ_BYTES (stream, rec->name, rec->length);
415 RESTORE_STREAM (stream, state);
416 rec->name[rec->length] = 0;
425 for (i = 0; i < rec->length / 2; i++)
427 if (rec->name[i * 2] > 0
428 || rec->name[i * 2 + 1] >= 128)
435 for (i = 0; i < rec->length / 2; i++)
436 rec->name[i] = rec->name[i * 2 + 1];
442 for (i = 0; i < rec->length / 4; i++)
444 if (rec->name[i * 4] > 0
445 || rec->name[i * 4 + 1] > 0
446 || rec->name[i * 4 + 2] > 0
447 || rec->name[i * 2 + 3] >= 128)
454 for (i = 0; i < rec->length / 4; i++)
455 rec->name[i] = rec->name[i * 4 + 3];
463 read_name_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
465 OTF_Stream *stream = table->stream;
466 char *errfmt = "name%s";
471 OTF_CALLOC (name, 1, "");
472 READ_USHORT (stream, name->format);
473 READ_USHORT (stream, name->count);
474 READ_USHORT (stream, name->stringOffset);
475 OTF_MALLOC (name->nameRecord, name->count, "");
476 for (i = 0; i < name->count; i++)
478 OTF_NameRecord *rec = name->nameRecord + i;
480 READ_USHORT (stream, rec->platformID);
481 READ_USHORT (stream, rec->encodingID);
482 READ_USHORT (stream, rec->languageID);
483 READ_USHORT (stream, rec->nameID);
484 READ_USHORT (stream, rec->length);
485 READ_USHORT (stream, rec->offset);
487 for (i = 0; i < name->count; i++)
489 OTF_NameRecord *rec = name->nameRecord + i;
490 int nameID = rec->nameID;
492 read_name (otf, stream, rec);
494 if (nameID >= OTF_max_nameID)
496 if (! name->name[nameID]
498 name->name[nameID] = (char *) rec->name;
501 *table->address = name;
506 /*** (1-4) "cmap" table */
508 static OTF_EncodingSubtable14 *
509 read_cmap_uvs_table (OTF *otf, OTF_Stream *stream, OTF_Offset offset)
511 OTF_EncodingSubtable14 *sub14;
512 char *errfmt = "cmap-uvs%s";
517 OTF_MALLOC (sub14, 1, " (EncodingSubtable14)");
518 READ_ULONG (stream, nRecords);
519 sub14->nRecords = nRecords;
520 OTF_MALLOC (sub14->Records, nRecords, "(EncodingSubtable14-Records)");
521 for (i = 0; i < sub14->nRecords; i++)
523 unsigned varSelector=0, defaultUVSOffset, nonDefaultUVSOffset;
525 READ_UINT24 (stream, varSelector);
526 sub14->Records[i].varSelector = varSelector;
527 READ_ULONG (stream, defaultUVSOffset);
528 sub14->Records[i].defaultUVSOffset = defaultUVSOffset;
529 READ_ULONG (stream, nonDefaultUVSOffset);
530 sub14->Records[i].nonDefaultUVSOffset = nonDefaultUVSOffset;
532 for (i = 0; i < sub14->nRecords; i++)
534 OTF_VariationSelectorRecord *record = &sub14->Records[i];
535 unsigned defaultUVSOffset = record->defaultUVSOffset;
536 unsigned nonDefaultUVSOffset = record->nonDefaultUVSOffset;
538 if (defaultUVSOffset)
540 unsigned numUnicodeValueRanges;
542 SEEK_STREAM (stream, offset+defaultUVSOffset);
543 READ_ULONG (stream, numUnicodeValueRanges);
544 record->numUnicodeValueRanges = numUnicodeValueRanges;
545 OTF_MALLOC (record->unicodeValueRanges,
546 numUnicodeValueRanges,
547 "(EncodingSubtable14-Records-unicodeValueRanges)");
548 for (j = 0; j < numUnicodeValueRanges; j++)
550 OTF_UnicodeValueRange *unicodeValueRange
551 = &record->unicodeValueRanges[j];
552 unsigned startUnicodeValue;
553 char additionalCount;
555 READ_UINT24 (stream, startUnicodeValue);
556 unicodeValueRange->startUnicodeValue=startUnicodeValue;
557 READ_BYTES (stream, &additionalCount, 1);
558 unicodeValueRange->additionalCount
559 = (unsigned short) additionalCount;
562 if (nonDefaultUVSOffset)
564 unsigned numUVSMappings;
566 SEEK_STREAM (stream, offset+nonDefaultUVSOffset);
567 READ_ULONG (stream, numUVSMappings);
568 record->numUVSMappings = numUVSMappings;
569 OTF_MALLOC (record->uvsMappings, numUVSMappings,
570 "(EncodingSubtable14-Records-uvsMappings)");
571 for (j = 0; j < numUVSMappings; j++)
573 OTF_UVSMapping *uvsMapping = &record->uvsMappings[j];
574 unsigned unicodeValue;
575 unsigned short glyphID;
577 READ_UINT24 (stream, unicodeValue);
578 uvsMapping->unicodeValue = unicodeValue;
579 READ_USHORT (stream, glyphID);
580 uvsMapping->glyphID = glyphID;
588 read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
590 OTF_Stream *stream = table->stream;
591 char *errfmt = "cmap%s";
594 int unicode_bmp_index = -1, unicode_full_index = -1;
597 OTF_CALLOC (cmap, 1, "");
598 READ_USHORT (stream, cmap->version);
599 READ_USHORT (stream, cmap->numTables);
600 OTF_MALLOC (cmap->EncodingRecord, cmap->numTables, "");
601 for (i = 0; i < cmap->numTables; i++)
603 unsigned platformID, encodingID;
605 READ_USHORT (stream, platformID);
606 cmap->EncodingRecord[i].platformID = platformID;
607 READ_USHORT (stream, encodingID);
608 cmap->EncodingRecord[i].encodingID = encodingID;
609 READ_ULONG (stream, cmap->EncodingRecord[i].offset);
613 unicode_bmp_index = i;
615 unicode_full_index = i;
617 else if (platformID == 3)
620 unicode_bmp_index = i;
621 else if (encodingID == 10)
622 unicode_full_index = i;
625 for (i = 0; i < cmap->numTables; i++)
629 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
630 READ_USHORT (stream, format);
631 cmap->EncodingRecord[i].subtable.format = format;
634 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
635 cmap->EncodingRecord[i].subtable.language = 0;
639 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
640 if (format == 8 || format == 10 || format == 12)
642 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
643 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
647 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
654 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
655 " (EncodingRecord)");
657 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
664 OTF_EncodingSubtable2 *sub2;
667 OTF_MALLOC (sub2, 1, " (EncodingSubtable2)");
668 cmap->EncodingRecord[i].subtable.f.f2 = sub2;
669 for (j = 0, max_key = 0; j < 256; j++)
671 READ_USHORT (stream, sub2->subHeaderKeys[j]);
672 if (max_key < sub2->subHeaderKeys[j])
673 max_key = sub2->subHeaderKeys[j];
676 sub2->subHeaderCount = max_key / 8;
677 OTF_MALLOC (sub2->subHeaders, max_key / 8, " (subHeaders)");
678 for (j = 0; j < sub2->subHeaderCount; j++)
680 READ_USHORT (stream, sub2->subHeaders[j].firstCode);
681 READ_USHORT (stream, sub2->subHeaders[j].entryCount);
682 READ_SHORT (stream, sub2->subHeaders[j].idDelta);
683 READ_USHORT (stream, sub2->subHeaders[j].idRangeOffset);
684 /* Make it offset from sub2->glyphIndexArray. */
685 sub2->subHeaders[j].idRangeOffset -= max_key - (j * 8 + 6);
687 sub2->glyphIndexCount = (cmap->EncodingRecord[i].subtable.length
689 OTF_MALLOC (sub2->glyphIndexArray, sub2->glyphIndexCount,
690 " (glyphIndexArray)");
691 READ_BYTES (stream, sub2->glyphIndexArray, sub2->glyphIndexCount);
697 OTF_EncodingSubtable4 *sub4;
702 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
703 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
704 READ_USHORT (stream, sub4->segCountX2);
705 segCount = sub4->segCountX2 / 2;
706 READ_USHORT (stream, sub4->searchRange);
707 READ_USHORT (stream, sub4->entrySelector);
708 READ_USHORT (stream, sub4->rangeShift);
709 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
710 for (j = 0; j < segCount; j++)
711 READ_USHORT (stream, sub4->segments[j].endCount);
712 READ_USHORT (stream, dummy);
713 for (j = 0; j < segCount; j++)
714 READ_USHORT (stream, sub4->segments[j].startCount);
715 for (j = 0; j < segCount; j++)
716 READ_SHORT (stream, sub4->segments[j].idDelta);
717 for (j = 0; j < segCount; j++)
720 unsigned rest = 2 * (segCount - j);
722 READ_USHORT (stream, off);
724 sub4->segments[j].idRangeOffset = 0xFFFF;
726 sub4->segments[j].idRangeOffset = (off - rest) / 2;
728 j = (cmap->EncodingRecord[i].subtable.length
729 - (14 + 2 * (segCount * 4 + 1)));
730 sub4->GlyphCount = j / 2;
731 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
732 for (j = 0; j < sub4->GlyphCount; j++)
733 READ_USHORT (stream, sub4->glyphIdArray[j]);
739 OTF_EncodingSubtable6 *sub6;
742 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
743 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
744 READ_USHORT (stream, sub6->firstCode);
745 READ_USHORT (stream, sub6->entryCount);
746 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
747 for (j = 0; j < sub6->entryCount; j++)
748 READ_USHORT (stream, sub6->glyphIdArray[j]);
754 OTF_EncodingSubtable8 *sub8;
757 OTF_MALLOC (sub8, 1, " (EncodingSubtable8)");
758 cmap->EncodingRecord[i].subtable.f.f8 = sub8;
759 for (j = 0; j < 8192; j++)
760 READ_BYTES (stream, sub8->is32, 8192);
761 READ_ULONG (stream, sub8->nGroups);
762 OTF_MALLOC (sub8->Groups, sub8->nGroups, " (Groups)");
763 for (j = 0; j < sub8->nGroups; j++)
765 READ_ULONG (stream, sub8->Groups[i].startCharCode);
766 READ_ULONG (stream, sub8->Groups[i].endCharCode);
767 READ_ULONG (stream, sub8->Groups[i].startGlyphID);
774 OTF_EncodingSubtable10 *sub10;
777 OTF_MALLOC (sub10, 1, " (EncodingSubtable10)");
778 cmap->EncodingRecord[i].subtable.f.f10 = sub10;
779 READ_ULONG (stream, sub10->startCharCode);
780 READ_ULONG (stream, sub10->numChars);
781 OTF_MALLOC (sub10->glyphs, sub10->numChars, " (GlyphCount)");
782 for (j = 0; j < sub10->numChars; j++)
783 READ_USHORT (stream, sub10->glyphs[j]);
789 OTF_EncodingSubtable12 *sub12;
792 OTF_MALLOC (sub12, 1, " (EncodingSubtable12)");
793 cmap->EncodingRecord[i].subtable.f.f12 = sub12;
794 READ_ULONG (stream, sub12->nGroups);
795 OTF_MALLOC (sub12->Groups, sub12->nGroups, " (Groups)");
796 for (j = 0; j < sub12->nGroups; j++)
798 READ_ULONG (stream, sub12->Groups[j].startCharCode);
799 READ_ULONG (stream, sub12->Groups[j].endCharCode);
800 READ_ULONG (stream, sub12->Groups[j].startGlyphID);
807 cmap->EncodingRecord[i].subtable.f.f14
808 = read_cmap_uvs_table (otf, stream,
809 cmap->EncodingRecord[i].offset);
814 OTF_ERROR (OTF_ERROR_TABLE, " (invalid Subtable format)");
818 if (unicode_bmp_index >= 0)
820 OTF_EncodingRecord *rec = cmap->EncodingRecord + unicode_bmp_index;
821 OTF_GlyphID glyph_id, max_glyph_id = 0;
823 OTF_CALLOC (cmap->unicode_table, 0x10000, "");
824 switch (rec->subtable.format)
828 OTF_EncodingSubtable4 *sub4 = rec->subtable.f.f4;
829 int segCount = sub4->segCountX2 / 2;
831 for (i = 0; i < segCount; i++)
833 OTF_cmapSegment *seg = sub4->segments + i;
836 if (seg->idRangeOffset == 0xFFFF)
837 for (c = seg->startCount; c <= seg->endCount; c++)
839 glyph_id = c + seg->idDelta;
840 cmap->unicode_table[c] = glyph_id;
841 if (glyph_id > max_glyph_id)
842 max_glyph_id = glyph_id;
845 for (c = seg->startCount; c <= seg->endCount && c != 0xFFFF;
848 glyph_id = sub4->glyphIdArray[seg->idRangeOffset
849 + (c - seg->startCount)];
850 cmap->unicode_table[c] = glyph_id;
851 if (glyph_id > max_glyph_id)
852 max_glyph_id = glyph_id;
858 OTF_CALLOC (cmap->decode_table, max_glyph_id + 1, "");
859 for (i = 0; i < 0x10000; i++)
860 if (cmap->unicode_table[i])
861 cmap->decode_table[cmap->unicode_table[i]] = i;
862 cmap->max_glyph_id = max_glyph_id;
865 *table->address = cmap;
870 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
872 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
873 Glyph-IDs there. If COUNT is negative, read the number of
874 Glyphs-IDs at first. MINUS if nozero is how few the actual
875 Glyph-IDs are in STREAM than COUNT. */
878 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
879 int minus, int count)
881 char *errfmt = "GlyphID List%s";
886 READ_UINT16 (stream, count);
889 OTF_MALLOC (*ids, count, "");
890 for (i = 0; i < count + minus; i++)
891 READ_GLYPHID (stream, (*ids)[i]);
896 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
898 char *errfmt = "RangeRecord%s";
903 READ_UINT16 (stream, count);
906 OTF_MALLOC (*record, count, "");
907 for (i = 0; i < count; i++)
909 READ_GLYPHID (stream, (*record)[i].Start);
910 READ_GLYPHID (stream, (*record)[i].End);
911 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
918 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
919 OTF_Coverage *coverage)
921 char *errfmt = "Coverage%s";
923 OTF_StreamState state;
926 READ_OFFSET (stream, coverage->offset);
927 SAVE_STREAM (stream, state);
928 SEEK_STREAM (stream, offset + coverage->offset);
929 READ_UINT16 (stream, coverage->CoverageFormat);
930 if (coverage->CoverageFormat == 1)
931 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
932 else if (coverage->CoverageFormat == 2)
933 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
935 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
938 coverage->Count = (unsigned) count;
939 RESTORE_STREAM (stream, state);
943 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
944 and store the Coverages there. If COUNT is negative, read the
945 number of Coverages at first. */
948 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
949 OTF_Coverage **coverage, int count)
951 char *errfmt = "Coverage List%s";
956 READ_UINT16 (stream, count);
959 OTF_MALLOC (*coverage, count, "");
960 for (i = 0; i < count; i++)
961 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
968 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
971 char *errfmt = "ClassDef%s";
974 SEEK_STREAM (stream, class->offset);
975 READ_UINT16 (stream, class->ClassFormat);
976 if (class->ClassFormat == 1)
978 READ_GLYPHID (stream, class->f.f1.StartGlyph);
979 class->f.f1.GlyphCount
981 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
982 if (! class->f.f1.GlyphCount)
983 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
985 else if (class->ClassFormat == 2)
987 class->f.f2.ClassRangeCount
988 = (read_range_records
989 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
990 if (! class->f.f2.ClassRangeCount)
991 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
994 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1000 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
1002 char *errfmt = "ClassDef%s";
1004 OTF_StreamState state;
1006 READ_OFFSET (stream, class->offset);
1007 if (! class->offset)
1009 SAVE_STREAM (stream, state);
1010 SEEK_STREAM (stream, offset + class->offset);
1011 READ_UINT16 (stream, class->ClassFormat);
1012 if (class->ClassFormat == 1)
1014 READ_GLYPHID (stream, class->f.f1.StartGlyph);
1015 class->f.f1.GlyphCount
1016 = read_glyph_ids (otf, stream,
1017 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
1019 if (! class->f.f1.GlyphCount)
1022 else if (class->ClassFormat == 2)
1024 class->f.f2.ClassRangeCount
1025 = read_range_records (otf, stream,
1026 (OTF_RangeRecord **)
1027 &class->f.f2.ClassRangeRecord);
1028 if (! class->f.f2.ClassRangeCount)
1032 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1034 RESTORE_STREAM (stream, state);
1040 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
1041 OTF_DeviceTable *table)
1043 char *errfmt = "Device Table%s";
1054 SEEK_STREAM (stream, offset + table->offset);
1055 READ_UINT16 (stream, table->StartSize);
1056 READ_UINT16 (stream, table->EndSize);
1057 READ_UINT16 (stream, table->DeltaFormat);
1058 num = table->EndSize - table->StartSize + 1;
1059 if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
1061 OTF_MALLOC (table->DeltaValue, num, "");
1063 if (table->DeltaFormat == 1)
1064 for (i = 0; i < num; i++)
1067 READ_UINT16 (stream, val);
1068 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
1069 table->DeltaValue[i] = intval.int2;
1071 else if (table->DeltaFormat == 2)
1072 for (i = 0; i < num; i++)
1075 READ_UINT16 (stream, val);
1076 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
1077 table->DeltaValue[i] = intval.int4;
1079 else /* (table->DeltaFormat == 3) */
1080 for (i = 0; i < num; i++)
1084 READ_UINT16 (stream, val);
1085 intval.int8 = val >> 8;
1086 table->DeltaValue[i] = intval.int8;
1090 intval.int8 = val >> 8;
1091 table->DeltaValue[i] = intval.int8;
1097 /* Invalid DeltaFormat but several fonts has such values (bug of
1098 fontforge?). So accept it with NULL delta values. */
1099 table->DeltaValue = NULL;
1105 /*** (1-6) "GDEF" table */
1108 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
1109 OTF_AttachList *list)
1111 char *errfmt = "AttachList%s";
1115 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1117 READ_UINT16 (stream, list->GlyphCount);
1118 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
1119 for (i = 0; i < list->GlyphCount; i++)
1120 READ_OFFSET (stream, list->AttachPoint[i].offset);
1121 for (i = 0; i < list->GlyphCount; i++)
1125 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
1126 READ_UINT16 (stream, count);
1127 list->AttachPoint[i].PointCount = count;
1128 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
1129 for (j = 0; j < count; j++)
1130 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
1136 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
1137 OTF_CaretValue *caret)
1139 char *errfmt = "CaretValue%s";
1142 SEEK_STREAM (stream, offset + caret->offset);
1143 READ_UINT16 (stream, caret->CaretValueFormat);
1144 if (caret->CaretValueFormat == 1)
1145 READ_INT16 (stream, caret->f.f1.Coordinate);
1146 else if (caret->CaretValueFormat == 2)
1147 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
1148 else if (caret->CaretValueFormat == 3)
1150 READ_INT16 (stream, caret->f.f3.Coordinate);
1151 if (read_device_table (otf, stream, offset + caret->offset,
1152 &caret->f.f3.DeviceTable) < 0)
1156 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1161 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
1162 OTF_LigCaretList *list)
1164 char *errfmt = "LigCaretList%s";
1168 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1170 READ_UINT16 (stream, list->LigGlyphCount);
1171 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
1172 for (i = 0; i < list->LigGlyphCount; i++)
1173 READ_OFFSET (stream, list->LigGlyph[i].offset);
1174 for (i = 0; i < list->LigGlyphCount; i++)
1178 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
1179 READ_UINT16 (stream, count);
1180 list->LigGlyph[i].CaretCount = count;
1181 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
1182 for (j = 0; j < count; j++)
1183 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
1184 for (j = 0; j < count; j++)
1185 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
1186 &list->LigGlyph[i].CaretValue[j]) < 0)
1193 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
1197 READ_FIXED (stream, header->Version);
1198 READ_OFFSET (stream, header->GlyphClassDef);
1199 READ_OFFSET (stream, header->AttachList);
1200 READ_OFFSET (stream, header->LigCaretList);
1201 READ_OFFSET (stream, header->MarkAttachClassDef);
1206 read_gdef_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
1208 OTF_Stream *stream = table->stream;
1209 char *errfmt = "GDEF%s";
1210 void *errret = NULL;
1213 OTF_CALLOC (gdef, 1, "");
1216 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
1217 if (gdef->header.GlyphClassDef)
1219 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
1220 read_class_def_without_offset (otf, stream,
1221 &gdef->glyph_class_def);
1223 if (gdef->header.AttachList)
1224 read_attach_list (otf, stream, gdef->header.AttachList,
1225 &gdef->attach_list);
1226 if (gdef->header.LigCaretList)
1227 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
1228 &gdef->lig_caret_list);
1229 if (gdef->header.MarkAttachClassDef)
1231 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
1232 read_class_def_without_offset (otf, stream,
1233 &gdef->mark_attach_class_def);
1237 *table->address = gdef;
1242 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
1245 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
1246 OTF_ScriptList *list)
1248 char *errfmt = "Script List%s";
1252 SEEK_STREAM (stream, offset);
1253 READ_USHORT (stream, list->ScriptCount);
1254 OTF_CALLOC (list->Script, list->ScriptCount, "");
1256 for (i = 0; i < list->ScriptCount; i++)
1258 READ_TAG (stream, list->Script[i].ScriptTag);
1259 READ_OFFSET (stream, list->Script[i].offset);
1261 for (i = 0; i < list->ScriptCount; i++)
1263 OTF_Script *script = list->Script + i;
1264 long script_offset = offset + script->offset;
1266 SEEK_STREAM (stream, script_offset);
1267 READ_OFFSET (stream, script->DefaultLangSysOffset);
1268 READ_USHORT (stream, script->LangSysCount);
1269 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
1270 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
1271 for (j = 0; j < script->LangSysCount; j++)
1273 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
1274 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
1277 if (script->DefaultLangSysOffset)
1279 OTF_LangSys *langsys = &script->DefaultLangSys;
1281 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
1282 READ_OFFSET (stream, langsys->LookupOrder);
1283 READ_USHORT (stream, langsys->ReqFeatureIndex);
1284 READ_USHORT (stream, langsys->FeatureCount);
1285 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1287 for (k = 0; k < langsys->FeatureCount; k++)
1288 READ_USHORT (stream, langsys->FeatureIndex[k]);
1291 for (j = 0; j < script->LangSysCount; j++)
1293 OTF_LangSys *langsys = script->LangSys + j;
1295 SEEK_STREAM (stream,
1296 script_offset + script->LangSysRecord[j].LangSys);
1297 READ_OFFSET (stream, langsys->LookupOrder);
1298 READ_USHORT (stream, langsys->ReqFeatureIndex);
1299 READ_USHORT (stream, langsys->FeatureCount);
1300 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1302 for (k = 0; k < langsys->FeatureCount; k++)
1303 READ_USHORT (stream, langsys->FeatureIndex[k]);
1311 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
1312 OTF_FeatureList *list)
1314 char *errfmt = "Feature List%s";
1318 SEEK_STREAM (stream, offset);
1319 READ_UINT16 (stream, list->FeatureCount);
1320 OTF_CALLOC (list->Feature, list->FeatureCount, "");
1321 for (i = 0; i < list->FeatureCount; i++)
1323 READ_TAG (stream, list->Feature[i].FeatureTag);
1324 READ_OFFSET (stream, list->Feature[i].offset);
1326 for (i = 0; i < list->FeatureCount; i++)
1328 OTF_Feature *feature = list->Feature + i;
1330 SEEK_STREAM (stream, offset + feature->offset);
1331 READ_OFFSET (stream, feature->FeatureParams);
1332 READ_UINT16 (stream, feature->LookupCount);
1333 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1334 " (LookupListIndex)");
1335 for (j = 0; j < feature->LookupCount; j++)
1336 READ_UINT16 (stream, feature->LookupListIndex[j]);
1342 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1343 long offset, unsigned type,
1344 OTF_LookupSubTableGSUB *subtable);
1345 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1346 long offset, unsigned type,
1347 OTF_LookupSubTableGPOS *subtable);
1350 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1351 OTF_LookupList *list, int gsubp)
1353 char *errfmt = "Lookup List%s";
1357 SEEK_STREAM (stream, offset);
1358 READ_UINT16 (stream, list->LookupCount);
1359 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1361 for (i = 0; i < list->LookupCount; i++)
1362 READ_OFFSET (stream, list->Lookup[i].offset);
1363 for (i = 0; i < list->LookupCount; i++)
1365 OTF_Lookup *lookup = list->Lookup + i;
1367 SEEK_STREAM (stream, offset + lookup->offset);
1368 READ_UINT16 (stream, lookup->LookupType);
1369 READ_UINT16 (stream, lookup->LookupFlag);
1370 READ_UINT16 (stream, lookup->SubTableCount);
1371 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1372 " (SubTableOffset)");
1374 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1377 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1379 for (j = 0; j < lookup->SubTableCount; j++)
1380 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1381 for (j = 0; j < lookup->SubTableCount; j++)
1384 = offset + lookup->offset + lookup->SubTableOffset[j];
1387 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1389 lookup->SubTable.gsub + j) < 0
1390 : read_lookup_subtable_gpos (otf, stream, this_offset,
1392 lookup->SubTable.gpos + j) < 0)
1401 /*** (1-8) Structures common to GSUB and GPOS */
1404 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1405 OTF_LookupRecord **record, int count)
1407 char *errfmt = "LookupRecord%s";
1408 unsigned errret = 0;
1412 READ_UINT16 (stream, count);
1414 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1415 OTF_MALLOC (*record, count, "");
1416 for (i = 0; i < count; i++)
1418 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1419 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1425 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1427 char *errfmt = "List of Rule%s";
1428 unsigned errret = 0;
1429 OTF_StreamState state;
1433 READ_UINT16 (stream, count);
1435 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1436 OTF_MALLOC (*rule, count, "");
1437 for (i = 0; i < count; i++)
1439 READ_OFFSET (stream, (*rule)[i].offset);
1440 if (! (*rule)[i].offset)
1441 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1443 SAVE_STREAM (stream, state);
1444 for (i = 0; i < count; i++)
1446 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1447 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1448 if ((*rule)[i].GlyphCount == 0)
1449 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1450 READ_UINT16 (stream, (*rule)[i].LookupCount);
1451 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1452 (*rule)[i].GlyphCount) < 0)
1454 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1455 (*rule)[i].LookupCount) == 0)
1458 RESTORE_STREAM (stream, state);
1464 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1467 char *errfmt = "List of RuleSet%s";
1468 unsigned errret = 0;
1469 OTF_StreamState state;
1473 READ_UINT16 (stream, count);
1475 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1476 OTF_MALLOC (*set, count, "");
1477 for (i = 0; i < count; i++)
1479 READ_OFFSET (stream, (*set)[i].offset);
1480 if (! (*set)[i].offset)
1481 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1483 SAVE_STREAM (stream, state);
1484 for (i = 0; i < count; i++)
1486 SEEK_STREAM (stream, offset + (*set)[i].offset);
1488 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1490 if (! (*set)[i].RuleCount)
1493 RESTORE_STREAM (stream, state);
1498 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1499 OTF_ClassRule **rule)
1501 char *errfmt = "ClassRule%s";
1502 unsigned errret = 0;
1503 OTF_StreamState state;
1507 READ_UINT16 (stream, count);
1509 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1510 OTF_MALLOC (*rule, count, "");
1511 for (i = 0; i < count; i++)
1513 READ_OFFSET (stream, (*rule)[i].offset);
1514 if (! (*rule)[i].offset)
1515 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1517 SAVE_STREAM (stream, state);
1518 for (i = 0; i < count; i++)
1520 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1521 READ_USHORT (stream, (*rule)[i].GlyphCount);
1522 if (! (*rule)[i].GlyphCount)
1523 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1524 READ_USHORT (stream, (*rule)[i].LookupCount);
1525 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1526 0, (*rule)[i].GlyphCount - 1) < 0)
1528 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1529 (*rule)[i].LookupCount) == 0)
1532 RESTORE_STREAM (stream, state);
1537 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1540 char *errfmt = "ClassSet%s";
1541 unsigned errret = 0;
1542 OTF_StreamState state;
1546 READ_UINT16 (stream, count);
1548 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1549 OTF_CALLOC (*set, count, "");
1550 for (i = 0; i < count; i++)
1551 /* Offset can be zero. */
1552 READ_OFFSET (stream, (*set)[i].offset);
1553 SAVE_STREAM (stream, state);
1554 for (i = 0; i < count; i++)
1555 if ((*set)[i].offset)
1557 SEEK_STREAM (stream, offset + (*set)[i].offset);
1558 (*set)[i].ClassRuleCnt
1559 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1560 &(*set)[i].ClassRule);
1561 if (! (*set)[i].ClassRuleCnt)
1564 RESTORE_STREAM (stream, state);
1569 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1570 OTF_ChainRule **rule)
1572 char *errfmt = "ChainRule%s";
1573 unsigned errret = 0;
1577 READ_UINT16 (stream, count);
1579 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1580 OTF_MALLOC (*rule, count, "");
1581 for (i = 0; i < count; i++)
1582 READ_OFFSET (stream, (*rule)[i].offset);
1583 for (i = 0; i < count; i++)
1585 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1586 (*rule)[i].BacktrackGlyphCount
1587 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1588 (*rule)[i].InputGlyphCount
1589 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1590 if (! (*rule)[i].InputGlyphCount)
1591 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1592 (*rule)[i].LookaheadGlyphCount
1593 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1594 (*rule)[i].LookupCount
1595 = read_lookup_record_list (otf, stream,
1596 &(*rule)[i].LookupRecord, -1);
1597 if (! (*rule)[i].LookupCount)
1605 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1606 OTF_ChainRuleSet **set)
1608 char *errfmt = "ChainRuleSet%s";
1609 unsigned errret = 0;
1610 OTF_StreamState state;
1614 READ_UINT16 (stream, count);
1616 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1617 OTF_MALLOC (*set, count, "");
1618 for (i = 0; i < count; i++)
1620 READ_OFFSET (stream, (*set)[i].offset);
1621 if (! (*set)[i].offset)
1622 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1624 SAVE_STREAM (stream, state);
1625 for (i = 0; i < count; i++)
1627 SEEK_STREAM (stream, offset + (*set)[i].offset);
1628 (*set)[i].ChainRuleCount
1629 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1630 &(*set)[i].ChainRule);
1631 if (! (*set)[i].ChainRuleCount)
1634 RESTORE_STREAM (stream, state);
1639 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1640 OTF_ChainClassRule **rule)
1642 char *errfmt = "ChainClassRule%s";
1643 unsigned errret = 0;
1647 READ_UINT16 (stream, count);
1649 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1650 OTF_MALLOC (*rule, count, "");
1651 for (i = 0; i < count; i++)
1653 READ_OFFSET (stream, (*rule)[i].offset);
1654 if (! (*rule)[i].offset)
1655 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1657 for (i = 0; i < count; i++)
1659 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1660 (*rule)[i].BacktrackGlyphCount
1661 = read_glyph_ids (otf, stream,
1662 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1663 (*rule)[i].InputGlyphCount
1664 = read_glyph_ids (otf, stream,
1665 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1666 if (! (*rule)[i].InputGlyphCount)
1667 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1668 (*rule)[i].LookaheadGlyphCount
1669 = read_glyph_ids (otf, stream,
1670 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1671 (*rule)[i].LookupCount
1672 = read_lookup_record_list (otf, stream,
1673 &(*rule)[i].LookupRecord, -1);
1674 if (! (*rule)[i].LookupCount)
1681 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1682 OTF_ChainClassSet **set)
1684 char *errfmt = "ChainClassSet%s";
1685 unsigned errret = 0;
1686 OTF_StreamState state;
1690 READ_UINT16 (stream, count);
1692 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1693 OTF_MALLOC (*set, count, "");
1694 for (i = 0; i < count; i++)
1695 /* Offset may be zero. */
1696 READ_OFFSET (stream, (*set)[i].offset);
1697 SAVE_STREAM (stream, state);
1698 for (i = 0; i < count; i++)
1699 if ((*set)[i].offset)
1701 SEEK_STREAM (stream, offset + (*set)[i].offset);
1702 (*set)[i].ChainClassRuleCnt
1703 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1704 &(*set)[i].ChainClassRule);
1705 if (! (*set)[i].ChainClassRuleCnt)
1708 RESTORE_STREAM (stream, state);
1713 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1714 OTF_Coverage *coverage,OTF_Context1 *context1)
1716 if (read_coverage (otf, stream, offset, coverage) < 0)
1718 context1->RuleSetCount
1719 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1720 if (! context1->RuleSetCount)
1726 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1727 OTF_Coverage *coverage,OTF_Context2 *context2)
1729 if (read_coverage (otf, stream, offset, coverage) < 0
1730 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1732 context2->ClassSetCnt
1733 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1734 if (! context2->ClassSetCnt)
1740 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1741 OTF_Coverage *coverage,OTF_Context3 *context3)
1743 char *errfmt = "Context1%s";
1746 READ_USHORT (stream, context3->GlyphCount);
1747 if (context3->GlyphCount < 0)
1748 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1749 READ_USHORT (stream, context3->LookupCount);
1750 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1751 context3->GlyphCount) < 0)
1753 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1754 context3->LookupCount) < 0)
1760 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1761 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1763 if (read_coverage (otf, stream, offset, coverage) < 0)
1765 chain_context1->ChainRuleSetCount
1766 = read_chain_rule_set_list (otf, stream, offset,
1767 &chain_context1->ChainRuleSet);
1768 if (! chain_context1->ChainRuleSetCount)
1774 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1775 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1777 if (read_coverage (otf, stream, offset, coverage) < 0
1778 || read_class_def (otf, stream, offset,
1779 &chain_context2->BacktrackClassDef) < 0
1780 || read_class_def (otf, stream, offset,
1781 &chain_context2->InputClassDef) < 0
1782 || read_class_def (otf, stream, offset,
1783 &chain_context2->LookaheadClassDef) < 0)
1785 chain_context2->ChainClassSetCnt
1786 = read_chain_class_set_list (otf, stream, offset,
1787 &chain_context2->ChainClassSet);
1788 if (! chain_context2->ChainClassSetCnt)
1794 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1795 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1799 count = read_coverage_list (otf, stream, offset,
1800 &chain_context3->Backtrack, -1);
1803 chain_context3->BacktrackGlyphCount = (unsigned) count;
1804 count = read_coverage_list (otf, stream, offset,
1805 &chain_context3->Input, -1);
1808 chain_context3->InputGlyphCount = (unsigned) count;
1809 *coverage = chain_context3->Input[0];
1810 count = read_coverage_list (otf, stream, offset,
1811 &chain_context3->LookAhead, -1);
1812 chain_context3->LookaheadGlyphCount = (unsigned) count;
1813 chain_context3->LookupCount
1814 = read_lookup_record_list (otf, stream,
1815 &chain_context3->LookupRecord, -1);
1820 read_gsub_gpos_table (OTF *otf, OTF_TableInfo *table, int gsubp,
1821 enum OTF_ReaderFlag flag)
1823 OTF_Stream *stream = table->stream;
1824 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1825 void *errret = NULL;
1826 OTF_GSUB_GPOS *gsub_gpos = *table->address;
1829 SEEK_STREAM (stream, 10);
1832 SEEK_STREAM (stream, 0);
1833 OTF_CALLOC (gsub_gpos, 1, "");
1834 READ_FIXED (stream, gsub_gpos->Version);
1835 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1836 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1837 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1838 *table->address = gsub_gpos;
1841 if (! gsub_gpos->ScriptList.Script
1842 && read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1843 &gsub_gpos->ScriptList) < 0)
1845 if (flag != OTF_READ_SCRIPTS)
1847 if (! gsub_gpos->FeatureList.Feature
1848 && read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1849 &gsub_gpos->FeatureList) < 0)
1851 if (flag != OTF_READ_FEATURES)
1853 if (! gsub_gpos->LookupList.Lookup
1854 && read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1855 &gsub_gpos->LookupList, gsubp) < 0)
1864 /* (1-9) "GSUB" table */
1867 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1869 char *errfmt = "Sequence%s";
1870 unsigned errret = 0;
1874 READ_UINT16 (stream, count);
1876 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1877 OTF_MALLOC (*seq, count, "");
1878 for (i = 0; i < count; i++)
1879 READ_OFFSET (stream, (*seq)[i].offset);
1880 for (i = 0; i < count; i++)
1882 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1883 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1884 &(*seq)[i].Substitute, 0, -1);
1885 if (! (*seq)[i].GlyphCount)
1892 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1893 OTF_Ligature **ligature)
1895 char *errfmt = "Ligature%s";
1900 READ_UINT16 (stream, count);
1903 OTF_MALLOC (*ligature, count, "");
1904 for (i = 0; i < count; i++)
1905 READ_OFFSET (stream, (*ligature)[i].offset);
1906 for (i = 0; i < count; i++)
1908 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1909 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1910 (*ligature)[i].CompCount
1911 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1912 if (! (*ligature)[i].CompCount)
1919 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1920 OTF_LigatureSet **ligset)
1922 char *errfmt = "LigatureSet%s";
1927 READ_UINT16 (stream, count);
1930 OTF_MALLOC (*ligset, count, "");
1931 for (i = 0; i < count; i++)
1932 READ_OFFSET (stream, (*ligset)[i].offset);
1933 for (i = 0; i < count; i++)
1937 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1938 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1939 &(*ligset)[i].Ligature);
1942 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1948 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1949 OTF_AlternateSet **altset)
1951 char *errfmt = "AlternateSet%s";
1956 READ_UINT16 (stream, count);
1958 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1959 OTF_MALLOC (*altset, count, "");
1960 for (i = 0; i < count; i++)
1961 READ_OFFSET (stream, (*altset)[i].offset);
1962 for (i = 0; i < count; i++)
1966 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1967 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1970 (*altset)[i].GlyphCount = (unsigned) alt_count;
1976 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1977 OTF_Coverage *coverage,
1978 OTF_GSUB_ReverseChain1 *reverse_chain)
1982 if (read_coverage (otf, stream, offset, coverage) < 0)
1984 count = read_coverage_list (otf, stream, offset,
1985 &reverse_chain->Backtrack, -1);
1988 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1989 count = read_coverage_list (otf, stream, offset,
1990 &reverse_chain->LookAhead, -1);
1993 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1994 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
1997 reverse_chain->GlyphCount = count;
2002 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
2003 unsigned type, OTF_LookupSubTableGSUB *subtable)
2008 SEEK_STREAM (stream, offset);
2009 READ_USHORT (stream, subtable->Format);
2010 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
2014 if (subtable->Format == 1)
2016 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2018 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
2020 else if (subtable->Format == 2)
2022 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2024 subtable->u.single2.GlyphCount
2025 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
2027 if (! subtable->u.single2.GlyphCount)
2031 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2035 if (subtable->Format == 1)
2037 read_coverage (otf, stream, offset, &subtable->Coverage);
2038 subtable->u.multiple1.SequenceCount
2039 = read_sequence (otf, stream, offset,
2040 &subtable->u.multiple1.Sequence);
2043 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2047 if (subtable->Format == 1)
2049 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2051 subtable->u.alternate1.AlternateSetCount
2052 = read_alternate_set_list (otf, stream, offset,
2053 &subtable->u.alternate1.AlternateSet);
2054 if (! subtable->u.alternate1.AlternateSetCount)
2058 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2062 if (subtable->Format == 1)
2064 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2066 subtable->u.ligature1.LigSetCount
2067 = read_ligature_set_list (otf, stream, offset,
2068 &subtable->u.ligature1.LigatureSet);
2069 if (! subtable->u.ligature1.LigSetCount)
2073 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2077 if (subtable->Format == 1)
2079 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2080 &subtable->u.context1) < 0)
2083 else if (subtable->Format == 2)
2085 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2086 &subtable->u.context2) < 0)
2089 else if (subtable->Format == 3)
2091 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2092 &subtable->u.context3) < 0)
2096 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2100 if (subtable->Format == 1)
2102 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2103 &subtable->u.chain_context1) < 0)
2106 else if (subtable->Format == 2)
2108 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2109 &subtable->u.chain_context2) < 0)
2112 else if (subtable->Format == 3)
2114 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2115 &subtable->u.chain_context3) < 0)
2119 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2123 if (subtable->Format == 1)
2127 OTF_LookupSubTableGSUB *ex_subtable;
2129 READ_USHORT (stream, ex_type);
2130 READ_ULONG (stream, ex_offset);
2131 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2132 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
2133 ex_type, ex_subtable) < 0)
2135 subtable->u.extension1.ExtensionLookupType = ex_type;
2136 subtable->u.extension1.ExtensionOffset = ex_offset;
2137 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2140 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2144 if (subtable->Format == 1)
2146 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
2147 &subtable->u.reverse_chain1) < 0)
2151 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2155 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2161 read_gsub_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2163 return read_gsub_gpos_table (otf, table, 1, flag);
2167 /* (1-10) "GPOS" table */
2170 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
2171 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
2174 OTF_StreamState state;
2177 memset (value_record, 0, sizeof (OTF_ValueRecord));
2180 for (i = 0, size = 0; i < 8; i++)
2184 if (bit & OTF_XPlacement)
2185 READ_INT16 (stream, value_record->XPlacement);
2186 if (bit & OTF_YPlacement)
2187 READ_INT16 (stream, value_record->YPlacement);
2188 if (bit & OTF_XAdvance)
2189 READ_INT16 (stream, value_record->XAdvance);
2190 if (bit & OTF_YAdvance)
2191 READ_INT16 (stream, value_record->YAdvance);
2192 if (bit & OTF_XPlaDevice)
2193 READ_OFFSET (stream, value_record->XPlaDevice.offset);
2194 if (bit & OTF_YPlaDevice)
2195 READ_OFFSET (stream, value_record->YPlaDevice.offset);
2196 if (bit & OTF_XAdvDevice)
2197 READ_OFFSET (stream, value_record->XAdvDevice.offset);
2198 if (bit & OTF_YAdvDevice)
2199 READ_OFFSET (stream, value_record->YAdvDevice.offset);
2200 SAVE_STREAM (stream, state);
2201 if (value_record->XPlaDevice.offset)
2203 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
2206 if (value_record->YPlaDevice.offset)
2208 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
2211 if (value_record->XAdvDevice.offset)
2213 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
2216 if (value_record->YAdvDevice.offset)
2218 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
2221 RESTORE_STREAM (stream, state);
2227 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
2229 char *errfmt = "Anchor%s";
2232 SEEK_STREAM (stream, offset + anchor->offset);
2233 READ_UINT16 (stream, anchor->AnchorFormat);
2234 READ_INT16 (stream, anchor->XCoordinate);
2235 READ_INT16 (stream, anchor->YCoordinate);
2236 if (anchor->AnchorFormat == 1)
2238 else if (anchor->AnchorFormat == 2)
2240 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
2242 else if (anchor->AnchorFormat == 3)
2244 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
2245 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
2246 if (anchor->f.f2.XDeviceTable.offset)
2248 if (read_device_table (otf, stream, offset + anchor->offset,
2249 &anchor->f.f2.XDeviceTable) < 0)
2252 if (anchor->f.f2.YDeviceTable.offset)
2254 if (read_device_table (otf, stream, offset + anchor->offset,
2255 &anchor->f.f2.YDeviceTable) < 0)
2260 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
2266 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
2267 OTF_MarkArray *array)
2269 char *errfmt = "MarkArray%s";
2271 OTF_StreamState state;
2274 READ_OFFSET (stream, array->offset);
2275 SAVE_STREAM (stream, state);
2276 SEEK_STREAM (stream, offset + array->offset);
2277 READ_UINT16 (stream, array->MarkCount);
2278 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
2279 for (i = 0; i < array->MarkCount; i++)
2281 READ_UINT16 (stream, array->MarkRecord[i].Class);
2282 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
2284 for (i = 0; i < array->MarkCount; i++)
2285 if (read_anchor (otf, stream, offset + array->offset,
2286 &array->MarkRecord[i].MarkAnchor) < 0)
2288 RESTORE_STREAM (stream, state);
2293 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
2294 unsigned ClassCount, OTF_AnchorArray *array)
2296 char *errfmt = "AnchorArray%s";
2298 OTF_StreamState state;
2301 READ_OFFSET (stream, array->offset);
2302 SAVE_STREAM (stream, state);
2303 SEEK_STREAM (stream, offset + array->offset);
2304 READ_UINT16 (stream, array->Count);
2305 OTF_MALLOC (array->AnchorRecord, array->Count, "");
2306 for (i = 0; i < array->Count; i++)
2308 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
2310 for (j = 0; j < ClassCount; j++)
2311 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
2313 for (i = 0; i < array->Count; i++)
2314 for (j = 0; j < ClassCount; j++)
2315 if (read_anchor (otf, stream, offset + array->offset,
2316 &array->AnchorRecord[i].Anchor[j]) < 0)
2318 RESTORE_STREAM (stream, state);
2322 static OTF_PairSet *
2323 read_pair_set_list (OTF *otf, OTF_Stream *stream, long offset, unsigned num,
2324 enum OTF_ValueFormat bit1, enum OTF_ValueFormat bit2)
2326 char *errfmt = "PairSet%s";
2327 void *errret = NULL;
2328 OTF_StreamState state;
2332 OTF_MALLOC (set, num, "");
2333 for (i = 0; i < num; i++)
2334 READ_OFFSET (stream, set[i].offset);
2335 SAVE_STREAM (stream, state);
2336 for (i = 0; i < num; i++)
2338 SEEK_STREAM (stream, offset + set[i].offset);
2339 READ_UINT16 (stream, set[i].PairValueCount);
2340 OTF_MALLOC (set[i].PairValueRecord, set[i].PairValueCount, "");
2341 for (j = 0; j < set[i].PairValueCount; j++)
2343 OTF_PairValueRecord *rec = set[i].PairValueRecord + j;
2345 READ_UINT16 (stream, rec->SecondGlyph);
2346 read_value_record (otf, stream, offset, bit1, &rec->Value1);
2347 read_value_record (otf, stream, offset, bit2, &rec->Value2);
2350 RESTORE_STREAM (stream, state);
2354 static OTF_Class1Record *
2355 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
2356 unsigned num1, enum OTF_ValueFormat bit1,
2357 unsigned num2, enum OTF_ValueFormat bit2)
2359 char *errfmt = "Class1Record%s";
2360 void *errret = NULL;
2361 OTF_Class1Record *rec;
2364 OTF_MALLOC (rec, num1, "");
2365 for (i = 0; i < num1; i++)
2367 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
2368 for (j = 0; j < num2; j++)
2370 if (read_value_record (otf, stream, offset,
2371 bit1, &rec[i].Class2Record[j].Value1) < 0
2372 || read_value_record (otf, stream, offset,
2373 bit2, &rec[i].Class2Record[j].Value2) < 0)
2381 read_entry_exit_list (OTF *otf, OTF_Stream *stream, long offset,
2382 OTF_EntryExitRecord **rec)
2384 char *errfmt = "EntryExitSet%s";
2388 OTF_StreamState state;
2390 READ_UINT16 (stream, count);
2392 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
2393 OTF_MALLOC (*rec, count, "");
2394 for (i = 0; i < count; i++)
2396 READ_OFFSET (stream, (*rec)[i].EntryAnchor.offset);
2397 READ_OFFSET (stream, (*rec)[i].ExitAnchor.offset);
2399 SAVE_STREAM (stream, state);
2400 for (i = 0; i < count; i++)
2402 if (read_anchor (otf, stream, offset, &(*rec)[i].EntryAnchor) < 0)
2404 if (read_anchor (otf, stream, offset, &(*rec)[i].ExitAnchor) < 0)
2407 RESTORE_STREAM (stream, state);
2412 read_ligature_attach (OTF *otf, OTF_Stream *stream, long offset,
2413 unsigned ClassCount, OTF_LigatureAttach *attach)
2415 char *errfmt = "LigatureAttach%s";
2419 SEEK_STREAM (stream, offset + attach->offset);
2420 READ_UINT16 (stream, attach->ComponentCount);
2421 OTF_MALLOC (attach->ComponentRecord, attach->ComponentCount, "");
2422 for (i = 0; i < attach->ComponentCount; i++)
2424 OTF_MALLOC (attach->ComponentRecord[i].LigatureAnchor, ClassCount,
2425 " (ComponentRecord)");
2426 for (j = 0; j < ClassCount; j++)
2427 READ_OFFSET (stream,
2428 attach->ComponentRecord[i].LigatureAnchor[j].offset);
2430 for (i = 0; i < attach->ComponentCount; i++)
2431 for (j = 0; j < ClassCount; j++)
2433 if (attach->ComponentRecord[i].LigatureAnchor[j].offset)
2435 if (read_anchor (otf, stream, offset + attach->offset,
2436 &attach->ComponentRecord[i].LigatureAnchor[j]) < 0)
2440 attach->ComponentRecord[i].LigatureAnchor[j].AnchorFormat = 0;
2446 read_ligature_array (OTF *otf, OTF_Stream *stream, long offset,
2447 unsigned class_count, OTF_LigatureArray *array)
2449 char *errfmt = "LigatureArray%s";
2451 OTF_StreamState state;
2454 READ_OFFSET (stream, array->offset);
2455 SAVE_STREAM (stream, state);
2456 SEEK_STREAM (stream, offset + array->offset);
2457 READ_UINT16 (stream, array->LigatureCount);
2458 OTF_MALLOC (array->LigatureAttach, array->LigatureCount, "");
2459 for (i = 0; i < array->LigatureCount; i++)
2460 READ_OFFSET (stream, array->LigatureAttach[i].offset);
2461 for (i = 0; i < array->LigatureCount; i++)
2462 read_ligature_attach (otf, stream, offset + array->offset,
2463 class_count, array->LigatureAttach + i);
2464 RESTORE_STREAM (stream, state);
2469 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
2470 long offset, unsigned type,
2471 OTF_LookupSubTableGPOS *subtable)
2476 SEEK_STREAM (stream, offset);
2477 READ_UINT16 (stream, subtable->Format);
2478 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2482 if (subtable->Format == 1)
2484 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2486 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2487 read_value_record (otf, stream, offset,
2488 subtable->u.single1.ValueFormat,
2489 &subtable->u.single1.Value);
2491 else if (subtable->Format == 2)
2493 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2496 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2498 READ_UINT16 (stream, single2->ValueFormat);
2499 READ_UINT16 (stream, single2->ValueCount);
2500 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2501 for (i = 0; i < single2->ValueCount; i++)
2502 read_value_record (otf, stream, offset, single2->ValueFormat,
2503 single2->Value + i);
2506 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2510 if (subtable->Format == 1)
2512 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2514 READ_UINT16 (stream, subtable->u.pair1.ValueFormat1);
2515 READ_UINT16 (stream, subtable->u.pair1.ValueFormat2);
2516 READ_UINT16 (stream, subtable->u.pair1.PairSetCount);
2517 subtable->u.pair1.PairSet
2518 = read_pair_set_list (otf, stream, offset,
2519 subtable->u.pair1.PairSetCount,
2520 subtable->u.pair1.ValueFormat1,
2521 subtable->u.pair1.ValueFormat2);
2522 if (! subtable->u.pair1.PairSet)
2525 else if (subtable->Format == 2)
2527 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2529 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2530 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2531 if (read_class_def (otf, stream, offset,
2532 &subtable->u.pair2.ClassDef1) < 0
2533 || read_class_def (otf, stream, offset,
2534 &subtable->u.pair2.ClassDef2) < 0)
2536 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2537 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2538 subtable->u.pair2.Class1Record
2539 = read_class1_record_list (otf, stream, offset,
2540 subtable->u.pair2.Class1Count,
2541 subtable->u.pair2.ValueFormat1,
2542 subtable->u.pair2.Class2Count,
2543 subtable->u.pair2.ValueFormat2);
2544 if (! subtable->u.pair2.Class1Record)
2548 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2552 if (subtable->Format == 1)
2554 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2556 subtable->u.cursive1.EntryExitCount
2557 = read_entry_exit_list (otf, stream, offset,
2558 &subtable->u.cursive1.EntryExitRecord);
2559 if (! subtable->u.cursive1.EntryExitCount)
2563 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2567 if (subtable->Format == 1)
2569 read_coverage (otf, stream, offset, &subtable->Coverage);
2570 read_coverage (otf, stream, offset,
2571 &subtable->u.mark_base1.BaseCoverage);
2572 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2573 read_mark_array (otf, stream, offset,
2574 &subtable->u.mark_base1.MarkArray);
2575 read_anchor_array (otf, stream, offset,
2576 subtable->u.mark_base1.ClassCount,
2577 &subtable->u.mark_base1.BaseArray);
2580 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2584 if (subtable->Format == 1)
2586 read_coverage (otf, stream, offset, &subtable->Coverage);
2587 read_coverage (otf, stream, offset,
2588 &subtable->u.mark_lig1.LigatureCoverage);
2589 READ_UINT16 (stream, subtable->u.mark_lig1.ClassCount);
2590 read_mark_array (otf, stream, offset,
2591 &subtable->u.mark_lig1.MarkArray);
2592 read_ligature_array (otf, stream, offset,
2593 subtable->u.mark_lig1.ClassCount,
2594 &subtable->u.mark_lig1.LigatureArray);
2599 if (subtable->Format == 1)
2601 read_coverage (otf, stream, offset, &subtable->Coverage);
2602 read_coverage (otf, stream, offset,
2603 &subtable->u.mark_mark1.Mark2Coverage);
2604 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2605 read_mark_array (otf, stream, offset,
2606 &subtable->u.mark_mark1.Mark1Array);
2607 read_anchor_array (otf, stream, offset,
2608 subtable->u.mark_mark1.ClassCount,
2609 &subtable->u.mark_mark1.Mark2Array);
2612 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2616 if (subtable->Format == 1)
2618 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2619 &subtable->u.context1) < 0)
2622 else if (subtable->Format == 2)
2624 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2625 &subtable->u.context2) < 0)
2628 else if (subtable->Format == 3)
2630 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2631 &subtable->u.context3) < 0)
2635 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2639 if (subtable->Format == 1)
2641 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2642 &subtable->u.chain_context1) < 0)
2645 else if (subtable->Format == 2)
2647 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2648 &subtable->u.chain_context2) < 0)
2651 else if (subtable->Format == 3)
2653 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2654 &subtable->u.chain_context3) < 0)
2658 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2662 if (subtable->Format == 1)
2666 OTF_LookupSubTableGPOS *ex_subtable;
2668 READ_USHORT (stream, ex_type);
2669 READ_ULONG (stream, ex_offset);
2670 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2671 if (read_lookup_subtable_gpos (otf, stream, offset + ex_offset,
2672 ex_type, ex_subtable) < 0)
2674 subtable->u.extension1.ExtensionLookupType = ex_type;
2675 subtable->u.extension1.ExtensionOffset = ex_offset;
2676 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2679 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2683 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2689 read_gpos_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2691 return read_gsub_gpos_table (otf, table, 0, flag);
2699 read_base_table (OTF_Stream *stream, long offset)
2703 OTF_MALLOC (base, 1);
2712 read_jstf_table (OTF_Stream *stream, long offset)
2716 OTF_MALLOC (jstf, 1);
2722 /*** (1-11) Structure for OTF */
2725 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2729 READ_FIXED (stream, table->sfnt_version);
2730 READ_USHORT (stream, table->numTables);
2731 READ_USHORT (stream, table->searchRange);
2732 READ_USHORT (stream, table->enterSelector);
2733 READ_USHORT (stream, table->rangeShift);
2738 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2743 READ_TAG (stream, tag);
2745 table->name[0] = tag >> 24;
2746 table->name[1] = (tag >> 16) & 0xFF;
2747 table->name[2] = (tag >> 8) & 0xFF;
2748 table->name[3] = tag & 0xFF;
2749 table->name[4] = '\0';
2750 READ_ULONG (stream, table->checkSum);
2751 READ_ULONG (stream, table->offset);
2752 READ_ULONG (stream, table->length);
2757 read_header_part (OTF *otf, FILE *fp, FT_Face face)
2759 char *errfmt = "otf header%s";
2762 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2764 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2765 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2766 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2767 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2768 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2769 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2770 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2771 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2772 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2773 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2774 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2775 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2779 OTF_Tag head_tag = OTF_tag ("head");
2780 OTF_Tag name_tag = OTF_tag ("name");
2781 OTF_Tag cmap_tag = OTF_tag ("cmap");
2782 OTF_Tag gdef_tag = OTF_tag ("GDEF");
2783 OTF_Tag gsub_tag = OTF_tag ("GSUB");
2784 OTF_Tag gpos_tag = OTF_tag ("GPOS");
2785 OTF_Stream *stream = make_stream ("Offset Table");
2789 internal_data->header_stream = stream;
2791 /* Size of Offset Table is 12 bytes. */
2792 if (setup_stream (stream, fp, 0, 12) < 0)
2794 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2797 /* Size of each Table Directory is 16 bytes. */
2798 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables) < 0)
2801 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables,
2803 for (i = 0; i < otf->offset_table.numTables; i++)
2805 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2806 OTF_TableInfo *table_info = NULL;
2810 if (tag == head_tag)
2811 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2812 else if (tag == name_tag)
2813 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2814 else if (tag == cmap_tag)
2815 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2816 else if (tag == gdef_tag)
2817 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2818 else if (tag == gsub_tag)
2819 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2820 else if (tag == gpos_tag)
2821 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2825 table_info->stream = make_stream (otf->table_dirs[i].name);
2826 if (setup_stream (table_info->stream, fp,
2827 otf->table_dirs[i].offset,
2828 otf->table_dirs[i].length) < 0)
2833 internal_data->header_stream = NULL;
2834 free_stream (stream);
2840 internal_data->header_stream = NULL;
2841 if ((stream = make_stream_from_ft_face (face, "head")))
2842 internal_data->table_info[OTF_TABLE_TYPE_HEAD].stream = stream;
2843 if ((stream = make_stream_from_ft_face (face, "name")))
2844 internal_data->table_info[OTF_TABLE_TYPE_NAME].stream = stream;
2845 if ((stream = make_stream_from_ft_face (face, "cmap")))
2846 internal_data->table_info[OTF_TABLE_TYPE_CMAP].stream = stream;
2847 if ((stream = make_stream_from_ft_face (face, "GDEF")))
2848 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream = stream;
2849 if ((stream = make_stream_from_ft_face (face, "GSUB")))
2850 internal_data->table_info[OTF_TABLE_TYPE_GSUB].stream = stream;
2851 if ((stream = make_stream_from_ft_face (face, "GPOS")))
2852 internal_data->table_info[OTF_TABLE_TYPE_GPOS].stream = stream;
2855 if (! internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream)
2856 /* We can simulate the GDEF table. */
2857 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream
2858 = make_stream ("GDEF");
2862 static OTF_TableInfo *
2863 get_table_info (OTF *otf, const char *name)
2865 char *errfmt = "OTF Table Read%s";
2866 OTF_TableInfo *errret = NULL;
2867 OTF_InternalData *internal_data = otf->internal_data;
2868 OTF_TableInfo *table_info;
2869 OTF_Tag tag = OTF_tag (name);
2872 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2874 if (tag == OTF_tag ("head"))
2875 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2876 else if (tag == OTF_tag ("name"))
2877 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2878 else if (tag == OTF_tag ("cmap"))
2879 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2880 else if (tag == OTF_tag ("GDEF"))
2881 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2882 else if (tag == OTF_tag ("GSUB"))
2883 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2884 else if (tag == OTF_tag ("GPOS"))
2885 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2887 OTF_ERROR (OTF_ERROR_TABLE, " (unsupported table name)");
2889 if (*table_info->address)
2892 if (! table_info->stream)
2893 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2894 if (! table_info->reader)
2895 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2901 /*** (2) API for reading OTF */
2903 /*** (2-1) OTF_open() */
2905 /* Note: We can't use memory allocation macros in the following
2906 functions because those macros return from the functions before
2907 freeing memory previously allocated. */
2910 OTF_open (const char *otf_name)
2913 char *errfmt = "opening otf (%s)";
2914 void *errret = NULL;
2916 OTF_InternalData *internal_data;
2917 int len = strlen (otf_name);
2918 const char *ext = otf_name + (len - 4);
2922 || (ext[1] != 'O' && ext[1] != 'T' && ext[1] != 'o' && ext[1] != 't')
2923 || (ext[2] != 'T' && ext[2] != 't')
2924 || (ext[3] != 'F' && ext[3] != 'f'))
2925 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2926 fp = fopen (otf_name, "r");
2928 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2929 otf = calloc (1, sizeof (OTF));
2931 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2932 otf->filename = strdup (otf_name);
2933 if (! otf->filename)
2937 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2940 internal_data = calloc (1, sizeof (OTF_InternalData));
2941 if (! internal_data)
2942 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2943 otf->internal_data = internal_data;
2944 if (! allocate_memory_record (otf))
2945 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2947 /* Here after, all pointers to allocated memory are recorded in
2948 otf->internal_data->memory_record except for what allocated by
2949 the functions allocate_memory_record and make_stream. */
2951 if (read_header_part (otf, fp, NULL) < 0)
2963 OTF_open_ft_face (FT_Face face)
2965 char *errfmt = "opening otf from Freetype (%s)";
2966 void *errret = NULL;
2968 OTF_InternalData *internal_data;
2970 if (! FT_IS_SFNT (face))
2971 OTF_ERROR (OTF_ERROR_FILE, (char *) face->family_name);
2972 otf = calloc (1, sizeof (OTF));
2974 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2975 otf->filename = NULL;
2977 internal_data = calloc (1, sizeof (OTF_InternalData));
2978 if (! internal_data)
2979 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2980 otf->internal_data = internal_data;
2981 if (! allocate_memory_record (otf))
2982 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2984 if (read_header_part (otf, NULL, face) < 0)
2993 /*** (2-2) OTF_close() */
2996 OTF_close (OTF *otf)
2998 OTF_InternalData *internal_data = otf->internal_data;
3003 OTF_MemoryRecord *memrec = internal_data->memory_record;
3005 if (internal_data->header_stream)
3006 free_stream (internal_data->header_stream);
3008 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
3009 if (internal_data->table_info[i].stream)
3010 free_stream (internal_data->table_info[i].stream);
3014 OTF_MemoryRecord *next = memrec->next;
3016 for (i = memrec->used - 1; i >= 0; i--)
3017 free (memrec->memory[i]);
3021 free (internal_data);
3024 free (otf->filename);
3028 /*** (2-3) OTF_get_table() */
3031 OTF_get_table (OTF *otf, const char *name)
3033 OTF_TableInfo *table_info = get_table_info (otf, name);
3038 if (! table_info->stream)
3039 /* Already fully loaded. */
3042 address = (*table_info->reader) (otf, table_info, OTF_READ_FULL);
3043 free_stream (table_info->stream);
3044 table_info->stream = NULL;
3047 table_info->reader = NULL;
3053 /*** (2-4) OTF_check_table() */
3056 OTF_check_table (OTF *otf, const char *name)
3058 return (get_table_info (otf, name) ? 0 : -1);
3061 /*** (2-5) OTF_get_scripts() */
3064 OTF_get_scripts (OTF *otf, int gsubp)
3066 OTF_TableInfo *table_info
3067 = (otf->internal_data->table_info
3068 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3071 if (! table_info->reader)
3073 if (! table_info->stream)
3074 /* Already fully loaded. */
3077 address = (*table_info->reader) (otf, table_info, OTF_READ_SCRIPTS);
3080 table_info->reader = NULL;
3086 /*** (2-6) OTF_get_features() */
3089 OTF_get_features (OTF *otf, int gsubp)
3091 OTF_TableInfo *table_info
3092 = (otf->internal_data->table_info
3093 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3096 if (! table_info->reader)
3098 if (! table_info->stream)
3100 if (*table_info->address)
3101 /* Already fully loaded. */
3106 address = (*table_info->reader) (otf, table_info, OTF_READ_FEATURES);
3109 table_info->reader = NULL;
3115 /*** (2-7) OTF_check_features */
3118 OTF_check_features (OTF *otf, int gsubp,
3119 OTF_Tag script, OTF_Tag language, const OTF_Tag *features,
3122 OTF_ScriptList *script_list;
3123 OTF_Script *Script = NULL;
3124 OTF_LangSys *LangSys = NULL;
3125 OTF_FeatureList *feature_list;
3128 if (OTF_get_features (otf, gsubp) < 0)
3130 for (i = 0; i < n_features; i++)
3132 OTF_Tag feature = features[i];
3136 if ((((unsigned) feature) & 0x80000000) == 0)
3143 script_list = &otf->gsub->ScriptList;
3144 feature_list = &otf->gsub->FeatureList;
3148 script_list = &otf->gpos->ScriptList;
3149 feature_list = &otf->gpos->FeatureList;
3151 for (i = 0; i < script_list->ScriptCount && ! Script; i++)
3152 if (script_list->Script[i].ScriptTag == script)
3153 Script = script_list->Script + i;
3158 for (i = 0; i < Script->LangSysCount && ! LangSys; i++)
3159 if (Script->LangSysRecord[i].LangSysTag == language)
3160 LangSys = Script->LangSys + i;
3163 LangSys = &Script->DefaultLangSys;
3164 for (j = 0; j < n_features; j++)
3166 OTF_Tag feature = features[j];
3171 if (((unsigned) feature) & 0x80000000)
3173 feature = (OTF_Tag) (((unsigned) feature) & 0x7FFFFFFF);
3176 for (i = 0; i < LangSys->FeatureCount; i++)
3177 if (feature_list->Feature[LangSys->FeatureIndex[i]].FeatureTag
3184 if (i == LangSys->FeatureCount)
3191 /*** (5) API miscellaneous ***/
3194 OTF_tag (const char *name)
3196 const unsigned char *p = (unsigned char *) name;
3200 return (OTF_Tag) ((p[0] << 24)
3204 : (p[2] << 8) | p[3]))));
3208 OTF_tag_name (OTF_Tag tag, char *name)
3210 name[0] = (char) (tag >> 24);
3211 name[1] = (char) ((tag >> 16) & 0xFF);
3212 name[2] = (char) ((tag >> 8) & 0xFF);
3213 name[3] = (char) (tag & 0xFF);