1 /* otfopen.c -- OpenType font reader.
3 Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009
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)
397 OTF_StreamState state;
402 sprintf (errfmt, "nameID (%d)%%s", rec->nameID);
403 if (rec->platformID == 0)
404 ucs = (rec->encodingID <= 3) ? 2 : 4;
405 else if (rec->platformID == 1 && rec->encodingID == 0)
407 else if (rec->platformID == 3)
408 ucs = (rec->encodingID == 1 ? 2
409 : rec->encodingID == 10 ? 4
412 OTF_MALLOC (rec->name, rec->length + 1, "");
413 SAVE_STREAM (stream, state);
414 SEEK_STREAM (stream, stream->pos + rec->offset);
415 READ_BYTES (stream, rec->name, rec->length);
416 RESTORE_STREAM (stream, state);
417 rec->name[rec->length] = 0;
426 for (i = 0; i < rec->length / 2; i++)
428 if (rec->name[i * 2] > 0
429 || rec->name[i * 2 + 1] >= 128)
436 for (i = 0; i < rec->length / 2; i++)
437 rec->name[i] = rec->name[i * 2 + 1];
443 for (i = 0; i < rec->length / 4; i++)
445 if (rec->name[i * 4] > 0
446 || rec->name[i * 4 + 1] > 0
447 || rec->name[i * 4 + 2] > 0
448 || rec->name[i * 2 + 3] >= 128)
455 for (i = 0; i < rec->length / 4; i++)
456 rec->name[i] = rec->name[i * 4 + 3];
464 read_name_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
466 OTF_Stream *stream = table->stream;
467 char *errfmt = "name%s";
472 OTF_CALLOC (name, 1, "");
473 READ_USHORT (stream, name->format);
474 READ_USHORT (stream, name->count);
475 READ_USHORT (stream, name->stringOffset);
476 OTF_MALLOC (name->nameRecord, name->count, "");
477 for (i = 0; i < name->count; i++)
479 OTF_NameRecord *rec = name->nameRecord + i;
481 READ_USHORT (stream, rec->platformID);
482 READ_USHORT (stream, rec->encodingID);
483 READ_USHORT (stream, rec->languageID);
484 READ_USHORT (stream, rec->nameID);
485 READ_USHORT (stream, rec->length);
486 READ_USHORT (stream, rec->offset);
488 for (i = 0; i < name->count; i++)
490 OTF_NameRecord *rec = name->nameRecord + i;
491 int nameID = rec->nameID;
493 read_name (otf, stream, rec);
495 if (nameID >= OTF_max_nameID)
497 if (! name->name[nameID]
499 name->name[nameID] = (char *) rec->name;
502 *table->address = name;
507 /*** (1-4) "cmap" table */
509 static OTF_EncodingSubtable14 *
510 read_cmap_uvs_table (OTF *otf, OTF_Stream *stream, OTF_Offset offset)
512 OTF_EncodingSubtable14 *sub14;
513 char *errfmt = "cmap-uvs%s";
518 OTF_MALLOC (sub14, 1, " (EncodingSubtable14)");
519 READ_ULONG (stream, nRecords);
520 sub14->nRecords = nRecords;
521 OTF_MALLOC (sub14->Records, nRecords, "(EncodingSubtable14-Records)");
522 for (i = 0; i < sub14->nRecords; i++)
524 unsigned varSelector=0, defaultUVSOffset, nonDefaultUVSOffset;
526 READ_UINT24 (stream, varSelector);
527 sub14->Records[i].varSelector = varSelector;
528 READ_ULONG (stream, defaultUVSOffset);
529 sub14->Records[i].defaultUVSOffset = defaultUVSOffset;
530 READ_ULONG (stream, nonDefaultUVSOffset);
531 sub14->Records[i].nonDefaultUVSOffset = nonDefaultUVSOffset;
533 for (i = 0; i < sub14->nRecords; i++)
535 OTF_VariationSelectorRecord *record = &sub14->Records[i];
536 unsigned defaultUVSOffset = record->defaultUVSOffset;
537 unsigned nonDefaultUVSOffset = record->nonDefaultUVSOffset;
539 if (defaultUVSOffset)
541 unsigned numUnicodeValueRanges;
543 SEEK_STREAM (stream, offset+defaultUVSOffset);
544 READ_ULONG (stream, numUnicodeValueRanges);
545 record->numUnicodeValueRanges = numUnicodeValueRanges;
546 OTF_MALLOC (record->unicodeValueRanges,
547 numUnicodeValueRanges,
548 "(EncodingSubtable14-Records-unicodeValueRanges)");
549 for (j = 0; j < numUnicodeValueRanges; j++)
551 OTF_UnicodeValueRange *unicodeValueRange
552 = &record->unicodeValueRanges[j];
553 unsigned startUnicodeValue;
554 char additionalCount;
556 READ_UINT24 (stream, startUnicodeValue);
557 unicodeValueRange->startUnicodeValue=startUnicodeValue;
558 READ_BYTES (stream, &additionalCount, 1);
559 unicodeValueRange->additionalCount
560 = (unsigned short) additionalCount;
563 if (nonDefaultUVSOffset)
565 unsigned numUVSMappings;
567 SEEK_STREAM (stream, offset+nonDefaultUVSOffset);
568 READ_ULONG (stream, numUVSMappings);
569 record->numUVSMappings = numUVSMappings;
570 OTF_MALLOC (record->uvsMappings, numUVSMappings,
571 "(EncodingSubtable14-Records-uvsMappings)");
572 for (j = 0; j < numUVSMappings; j++)
574 OTF_UVSMapping *uvsMapping = &record->uvsMappings[j];
575 unsigned unicodeValue;
576 unsigned short glyphID;
578 READ_UINT24 (stream, unicodeValue);
579 uvsMapping->unicodeValue = unicodeValue;
580 READ_USHORT (stream, glyphID);
581 uvsMapping->glyphID = glyphID;
589 read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
591 OTF_Stream *stream = table->stream;
592 char *errfmt = "cmap%s";
595 int unicode_bmp_index = -1, unicode_full_index = -1;
598 OTF_CALLOC (cmap, 1, "");
599 READ_USHORT (stream, cmap->version);
600 READ_USHORT (stream, cmap->numTables);
601 OTF_MALLOC (cmap->EncodingRecord, cmap->numTables, "");
602 for (i = 0; i < cmap->numTables; i++)
604 unsigned platformID, encodingID;
606 READ_USHORT (stream, platformID);
607 cmap->EncodingRecord[i].platformID = platformID;
608 READ_USHORT (stream, encodingID);
609 cmap->EncodingRecord[i].encodingID = encodingID;
610 READ_ULONG (stream, cmap->EncodingRecord[i].offset);
614 unicode_bmp_index = i;
616 unicode_full_index = i;
618 else if (platformID == 3)
621 unicode_bmp_index = i;
622 else if (encodingID == 10)
623 unicode_full_index = i;
626 for (i = 0; i < cmap->numTables; i++)
630 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
631 READ_USHORT (stream, format);
632 cmap->EncodingRecord[i].subtable.format = format;
635 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
636 cmap->EncodingRecord[i].subtable.language = 0;
640 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
641 if (format == 8 || format == 10 || format == 12)
643 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
644 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
648 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
655 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
656 " (EncodingRecord)");
658 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
665 OTF_EncodingSubtable2 *sub2;
668 OTF_MALLOC (sub2, 1, " (EncodingSubtable2)");
669 cmap->EncodingRecord[i].subtable.f.f2 = sub2;
670 for (j = 0, max_key = 0; j < 256; j++)
672 READ_USHORT (stream, sub2->subHeaderKeys[j]);
673 if (max_key < sub2->subHeaderKeys[j])
674 max_key = sub2->subHeaderKeys[j];
677 sub2->subHeaderCount = max_key / 8;
678 OTF_MALLOC (sub2->subHeaders, max_key / 8, " (subHeaders)");
679 for (j = 0; j < sub2->subHeaderCount; j++)
681 READ_USHORT (stream, sub2->subHeaders[j].firstCode);
682 READ_USHORT (stream, sub2->subHeaders[j].entryCount);
683 READ_SHORT (stream, sub2->subHeaders[j].idDelta);
684 READ_USHORT (stream, sub2->subHeaders[j].idRangeOffset);
685 /* Make it offset from sub2->glyphIndexArray. */
686 sub2->subHeaders[j].idRangeOffset -= max_key - (j * 8 + 6);
688 sub2->glyphIndexCount = (cmap->EncodingRecord[i].subtable.length
690 OTF_MALLOC (sub2->glyphIndexArray, sub2->glyphIndexCount,
691 " (glyphIndexArray)");
692 READ_BYTES (stream, sub2->glyphIndexArray, sub2->glyphIndexCount);
698 OTF_EncodingSubtable4 *sub4;
703 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
704 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
705 READ_USHORT (stream, sub4->segCountX2);
706 segCount = sub4->segCountX2 / 2;
707 READ_USHORT (stream, sub4->searchRange);
708 READ_USHORT (stream, sub4->entrySelector);
709 READ_USHORT (stream, sub4->rangeShift);
710 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
711 for (j = 0; j < segCount; j++)
712 READ_USHORT (stream, sub4->segments[j].endCount);
713 READ_USHORT (stream, dummy);
714 for (j = 0; j < segCount; j++)
715 READ_USHORT (stream, sub4->segments[j].startCount);
716 for (j = 0; j < segCount; j++)
717 READ_SHORT (stream, sub4->segments[j].idDelta);
718 for (j = 0; j < segCount; j++)
721 unsigned rest = 2 * (segCount - j);
723 READ_USHORT (stream, off);
725 sub4->segments[j].idRangeOffset = 0xFFFF;
727 sub4->segments[j].idRangeOffset = (off - rest) / 2;
729 j = (cmap->EncodingRecord[i].subtable.length
730 - (14 + 2 * (segCount * 4 + 1)));
731 sub4->GlyphCount = j / 2;
732 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
733 for (j = 0; j < sub4->GlyphCount; j++)
734 READ_USHORT (stream, sub4->glyphIdArray[j]);
740 OTF_EncodingSubtable6 *sub6;
743 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
744 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
745 READ_USHORT (stream, sub6->firstCode);
746 READ_USHORT (stream, sub6->entryCount);
747 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
748 for (j = 0; j < sub6->entryCount; j++)
749 READ_USHORT (stream, sub6->glyphIdArray[j]);
755 OTF_EncodingSubtable8 *sub8;
758 OTF_MALLOC (sub8, 1, " (EncodingSubtable8)");
759 cmap->EncodingRecord[i].subtable.f.f8 = sub8;
760 for (j = 0; j < 8192; j++)
761 READ_BYTES (stream, sub8->is32, 8192);
762 READ_ULONG (stream, sub8->nGroups);
763 OTF_MALLOC (sub8->Groups, sub8->nGroups, " (Groups)");
764 for (j = 0; j < sub8->nGroups; j++)
766 READ_ULONG (stream, sub8->Groups[i].startCharCode);
767 READ_ULONG (stream, sub8->Groups[i].endCharCode);
768 READ_ULONG (stream, sub8->Groups[i].startGlyphID);
775 OTF_EncodingSubtable10 *sub10;
778 OTF_MALLOC (sub10, 1, " (EncodingSubtable10)");
779 cmap->EncodingRecord[i].subtable.f.f10 = sub10;
780 READ_ULONG (stream, sub10->startCharCode);
781 READ_ULONG (stream, sub10->numChars);
782 OTF_MALLOC (sub10->glyphs, sub10->numChars, " (GlyphCount)");
783 for (j = 0; j < sub10->numChars; j++)
784 READ_USHORT (stream, sub10->glyphs[j]);
790 OTF_EncodingSubtable12 *sub12;
793 OTF_MALLOC (sub12, 1, " (EncodingSubtable12)");
794 cmap->EncodingRecord[i].subtable.f.f12 = sub12;
795 READ_ULONG (stream, sub12->nGroups);
796 OTF_MALLOC (sub12->Groups, sub12->nGroups, " (Groups)");
797 for (j = 0; j < sub12->nGroups; j++)
799 READ_ULONG (stream, sub12->Groups[j].startCharCode);
800 READ_ULONG (stream, sub12->Groups[j].endCharCode);
801 READ_ULONG (stream, sub12->Groups[j].startGlyphID);
808 cmap->EncodingRecord[i].subtable.f.f14
809 = read_cmap_uvs_table (otf, stream,
810 cmap->EncodingRecord[i].offset);
815 OTF_ERROR (OTF_ERROR_TABLE, " (invalid Subtable format)");
819 if (unicode_bmp_index >= 0)
821 OTF_EncodingRecord *rec = cmap->EncodingRecord + unicode_bmp_index;
822 OTF_GlyphID glyph_id, max_glyph_id = 0;
824 OTF_CALLOC (cmap->unicode_table, 0x10000, "");
825 switch (rec->subtable.format)
829 OTF_EncodingSubtable4 *sub4 = rec->subtable.f.f4;
830 int segCount = sub4->segCountX2 / 2;
832 for (i = 0; i < segCount; i++)
834 OTF_cmapSegment *seg = sub4->segments + i;
837 if (seg->idRangeOffset == 0xFFFF)
838 for (c = seg->startCount; c <= seg->endCount; c++)
840 glyph_id = c + seg->idDelta;
841 cmap->unicode_table[c] = glyph_id;
842 if (glyph_id > max_glyph_id)
843 max_glyph_id = glyph_id;
846 for (c = seg->startCount; c <= seg->endCount && c != 0xFFFF;
849 glyph_id = sub4->glyphIdArray[seg->idRangeOffset
850 + (c - seg->startCount)];
851 cmap->unicode_table[c] = glyph_id;
852 if (glyph_id > max_glyph_id)
853 max_glyph_id = glyph_id;
859 OTF_CALLOC (cmap->decode_table, max_glyph_id + 1, "");
860 for (i = 0; i < 0x10000; i++)
861 if (cmap->unicode_table[i])
862 cmap->decode_table[cmap->unicode_table[i]] = i;
863 cmap->max_glyph_id = max_glyph_id;
866 *table->address = cmap;
871 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
873 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
874 Glyph-IDs there. If COUNT is negative, read the number of
875 Glyphs-IDs at first. MINUS if nozero is how few the actual
876 Glyph-IDs are in STREAM than COUNT. */
879 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
880 int minus, int count)
882 char *errfmt = "GlyphID List%s";
887 READ_UINT16 (stream, count);
890 OTF_MALLOC (*ids, count, "");
891 for (i = 0; i < count + minus; i++)
892 READ_GLYPHID (stream, (*ids)[i]);
897 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
899 char *errfmt = "RangeRecord%s";
904 READ_UINT16 (stream, count);
907 OTF_MALLOC (*record, count, "");
908 for (i = 0; i < count; i++)
910 READ_GLYPHID (stream, (*record)[i].Start);
911 READ_GLYPHID (stream, (*record)[i].End);
912 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
919 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
920 OTF_Coverage *coverage)
922 char *errfmt = "Coverage%s";
924 OTF_StreamState state;
927 READ_OFFSET (stream, coverage->offset);
928 SAVE_STREAM (stream, state);
929 SEEK_STREAM (stream, offset + coverage->offset);
930 READ_UINT16 (stream, coverage->CoverageFormat);
931 if (coverage->CoverageFormat == 1)
932 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
933 else if (coverage->CoverageFormat == 2)
934 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
936 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
939 coverage->Count = (unsigned) count;
940 RESTORE_STREAM (stream, state);
944 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
945 and store the Coverages there. If COUNT is negative, read the
946 number of Coverages at first. */
949 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
950 OTF_Coverage **coverage, int count)
952 char *errfmt = "Coverage List%s";
957 READ_UINT16 (stream, count);
960 OTF_MALLOC (*coverage, count, "");
961 for (i = 0; i < count; i++)
962 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
969 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
972 char *errfmt = "ClassDef%s";
975 SEEK_STREAM (stream, class->offset);
976 READ_UINT16 (stream, class->ClassFormat);
977 if (class->ClassFormat == 1)
979 READ_GLYPHID (stream, class->f.f1.StartGlyph);
980 class->f.f1.GlyphCount
982 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
983 if (! class->f.f1.GlyphCount)
984 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
986 else if (class->ClassFormat == 2)
988 class->f.f2.ClassRangeCount
989 = (read_range_records
990 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
991 if (! class->f.f2.ClassRangeCount)
992 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
995 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1001 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
1003 char *errfmt = "ClassDef%s";
1005 OTF_StreamState state;
1007 READ_OFFSET (stream, class->offset);
1008 if (! class->offset)
1010 SAVE_STREAM (stream, state);
1011 SEEK_STREAM (stream, offset + class->offset);
1012 READ_UINT16 (stream, class->ClassFormat);
1013 if (class->ClassFormat == 1)
1015 READ_GLYPHID (stream, class->f.f1.StartGlyph);
1016 class->f.f1.GlyphCount
1017 = read_glyph_ids (otf, stream,
1018 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
1020 if (! class->f.f1.GlyphCount)
1023 else if (class->ClassFormat == 2)
1025 class->f.f2.ClassRangeCount
1026 = read_range_records (otf, stream,
1027 (OTF_RangeRecord **)
1028 &class->f.f2.ClassRangeRecord);
1029 if (! class->f.f2.ClassRangeCount)
1033 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1035 RESTORE_STREAM (stream, state);
1041 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
1042 OTF_DeviceTable *table)
1044 char *errfmt = "Device Table%s";
1055 SEEK_STREAM (stream, offset + table->offset);
1056 READ_UINT16 (stream, table->StartSize);
1057 READ_UINT16 (stream, table->EndSize);
1058 READ_UINT16 (stream, table->DeltaFormat);
1059 num = table->EndSize - table->StartSize + 1;
1060 if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
1062 OTF_MALLOC (table->DeltaValue, num, "");
1064 if (table->DeltaFormat == 1)
1065 for (i = 0; i < num; i++)
1068 READ_UINT16 (stream, val);
1069 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
1070 table->DeltaValue[i] = intval.int2;
1072 else if (table->DeltaFormat == 2)
1073 for (i = 0; i < num; i++)
1076 READ_UINT16 (stream, val);
1077 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
1078 table->DeltaValue[i] = intval.int4;
1080 else /* (table->DeltaFormat == 3) */
1081 for (i = 0; i < num; i++)
1085 READ_UINT16 (stream, val);
1086 intval.int8 = val >> 8;
1087 table->DeltaValue[i] = intval.int8;
1091 intval.int8 = val >> 8;
1092 table->DeltaValue[i] = intval.int8;
1098 /* Invalid DeltaFormat but several fonts has such values (bug of
1099 fontforge?). So accept it with NULL delta values. */
1100 table->DeltaValue = NULL;
1106 /*** (1-6) "GDEF" table */
1109 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
1110 OTF_AttachList *list)
1112 char *errfmt = "AttachList%s";
1116 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1118 READ_UINT16 (stream, list->GlyphCount);
1119 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
1120 for (i = 0; i < list->GlyphCount; i++)
1121 READ_OFFSET (stream, list->AttachPoint[i].offset);
1122 for (i = 0; i < list->GlyphCount; i++)
1126 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
1127 READ_UINT16 (stream, count);
1128 list->AttachPoint[i].PointCount = count;
1129 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
1130 for (j = 0; j < count; j++)
1131 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
1137 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
1138 OTF_CaretValue *caret)
1140 char *errfmt = "CaretValue%s";
1143 SEEK_STREAM (stream, offset + caret->offset);
1144 READ_UINT16 (stream, caret->CaretValueFormat);
1145 if (caret->CaretValueFormat == 1)
1146 READ_INT16 (stream, caret->f.f1.Coordinate);
1147 else if (caret->CaretValueFormat == 2)
1148 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
1149 else if (caret->CaretValueFormat == 3)
1151 READ_INT16 (stream, caret->f.f3.Coordinate);
1152 if (read_device_table (otf, stream, offset + caret->offset,
1153 &caret->f.f3.DeviceTable) < 0)
1157 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1162 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
1163 OTF_LigCaretList *list)
1165 char *errfmt = "LigCaretList%s";
1169 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1171 READ_UINT16 (stream, list->LigGlyphCount);
1172 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
1173 for (i = 0; i < list->LigGlyphCount; i++)
1174 READ_OFFSET (stream, list->LigGlyph[i].offset);
1175 for (i = 0; i < list->LigGlyphCount; i++)
1179 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
1180 READ_UINT16 (stream, count);
1181 list->LigGlyph[i].CaretCount = count;
1182 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
1183 for (j = 0; j < count; j++)
1184 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
1185 for (j = 0; j < count; j++)
1186 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
1187 &list->LigGlyph[i].CaretValue[j]) < 0)
1194 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
1198 READ_FIXED (stream, header->Version);
1199 READ_OFFSET (stream, header->GlyphClassDef);
1200 READ_OFFSET (stream, header->AttachList);
1201 READ_OFFSET (stream, header->LigCaretList);
1202 READ_OFFSET (stream, header->MarkAttachClassDef);
1207 read_gdef_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
1209 OTF_Stream *stream = table->stream;
1210 char *errfmt = "GDEF%s";
1211 void *errret = NULL;
1214 OTF_CALLOC (gdef, 1, "");
1217 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
1218 if (gdef->header.GlyphClassDef)
1220 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
1221 read_class_def_without_offset (otf, stream,
1222 &gdef->glyph_class_def);
1224 if (gdef->header.AttachList)
1225 read_attach_list (otf, stream, gdef->header.AttachList,
1226 &gdef->attach_list);
1227 if (gdef->header.LigCaretList)
1228 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
1229 &gdef->lig_caret_list);
1230 if (gdef->header.MarkAttachClassDef)
1232 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
1233 read_class_def_without_offset (otf, stream,
1234 &gdef->mark_attach_class_def);
1238 *table->address = gdef;
1243 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
1246 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
1247 OTF_ScriptList *list)
1249 char *errfmt = "Script List%s";
1253 SEEK_STREAM (stream, offset);
1254 READ_USHORT (stream, list->ScriptCount);
1255 OTF_CALLOC (list->Script, list->ScriptCount, "");
1257 for (i = 0; i < list->ScriptCount; i++)
1259 READ_TAG (stream, list->Script[i].ScriptTag);
1260 READ_OFFSET (stream, list->Script[i].offset);
1262 for (i = 0; i < list->ScriptCount; i++)
1264 OTF_Script *script = list->Script + i;
1265 long script_offset = offset + script->offset;
1267 SEEK_STREAM (stream, script_offset);
1268 READ_OFFSET (stream, script->DefaultLangSysOffset);
1269 READ_USHORT (stream, script->LangSysCount);
1270 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
1271 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
1272 for (j = 0; j < script->LangSysCount; j++)
1274 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
1275 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
1278 if (script->DefaultLangSysOffset)
1280 OTF_LangSys *langsys = &script->DefaultLangSys;
1282 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
1283 READ_OFFSET (stream, langsys->LookupOrder);
1284 READ_USHORT (stream, langsys->ReqFeatureIndex);
1285 READ_USHORT (stream, langsys->FeatureCount);
1286 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1288 for (k = 0; k < langsys->FeatureCount; k++)
1289 READ_USHORT (stream, langsys->FeatureIndex[k]);
1292 for (j = 0; j < script->LangSysCount; j++)
1294 OTF_LangSys *langsys = script->LangSys + j;
1296 SEEK_STREAM (stream,
1297 script_offset + script->LangSysRecord[j].LangSys);
1298 READ_OFFSET (stream, langsys->LookupOrder);
1299 READ_USHORT (stream, langsys->ReqFeatureIndex);
1300 READ_USHORT (stream, langsys->FeatureCount);
1301 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1303 for (k = 0; k < langsys->FeatureCount; k++)
1304 READ_USHORT (stream, langsys->FeatureIndex[k]);
1312 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
1313 OTF_FeatureList *list)
1315 char *errfmt = "Feature List%s";
1319 SEEK_STREAM (stream, offset);
1320 READ_UINT16 (stream, list->FeatureCount);
1321 OTF_CALLOC (list->Feature, list->FeatureCount, "");
1322 for (i = 0; i < list->FeatureCount; i++)
1324 READ_TAG (stream, list->Feature[i].FeatureTag);
1325 READ_OFFSET (stream, list->Feature[i].offset);
1327 for (i = 0; i < list->FeatureCount; i++)
1329 OTF_Feature *feature = list->Feature + i;
1331 SEEK_STREAM (stream, offset + feature->offset);
1332 READ_OFFSET (stream, feature->FeatureParams);
1333 READ_UINT16 (stream, feature->LookupCount);
1334 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1335 " (LookupListIndex)");
1336 for (j = 0; j < feature->LookupCount; j++)
1337 READ_UINT16 (stream, feature->LookupListIndex[j]);
1343 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1344 long offset, unsigned type,
1345 OTF_LookupSubTableGSUB *subtable);
1346 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1347 long offset, unsigned type,
1348 OTF_LookupSubTableGPOS *subtable);
1351 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1352 OTF_LookupList *list, int gsubp)
1354 char *errfmt = "Lookup List%s";
1358 SEEK_STREAM (stream, offset);
1359 READ_UINT16 (stream, list->LookupCount);
1360 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1362 for (i = 0; i < list->LookupCount; i++)
1363 READ_OFFSET (stream, list->Lookup[i].offset);
1364 for (i = 0; i < list->LookupCount; i++)
1366 OTF_Lookup *lookup = list->Lookup + i;
1368 SEEK_STREAM (stream, offset + lookup->offset);
1369 READ_UINT16 (stream, lookup->LookupType);
1370 READ_UINT16 (stream, lookup->LookupFlag);
1371 READ_UINT16 (stream, lookup->SubTableCount);
1372 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1373 " (SubTableOffset)");
1375 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1378 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1380 for (j = 0; j < lookup->SubTableCount; j++)
1381 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1382 for (j = 0; j < lookup->SubTableCount; j++)
1385 = offset + lookup->offset + lookup->SubTableOffset[j];
1388 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1390 lookup->SubTable.gsub + j) < 0
1391 : read_lookup_subtable_gpos (otf, stream, this_offset,
1393 lookup->SubTable.gpos + j) < 0)
1402 /*** (1-8) Structures common to GSUB and GPOS */
1405 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1406 OTF_LookupRecord **record, int count)
1408 char *errfmt = "LookupRecord%s";
1409 unsigned errret = 0;
1413 READ_UINT16 (stream, count);
1415 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1416 OTF_MALLOC (*record, count, "");
1417 for (i = 0; i < count; i++)
1419 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1420 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1426 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1428 char *errfmt = "List of Rule%s";
1429 unsigned errret = 0;
1430 OTF_StreamState state;
1434 READ_UINT16 (stream, count);
1436 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1437 OTF_MALLOC (*rule, count, "");
1438 for (i = 0; i < count; i++)
1440 READ_OFFSET (stream, (*rule)[i].offset);
1441 if (! (*rule)[i].offset)
1442 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1444 SAVE_STREAM (stream, state);
1445 for (i = 0; i < count; i++)
1447 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1448 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1449 if ((*rule)[i].GlyphCount == 0)
1450 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1451 READ_UINT16 (stream, (*rule)[i].LookupCount);
1452 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1453 (*rule)[i].GlyphCount) < 0)
1455 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1456 (*rule)[i].LookupCount) == 0)
1459 RESTORE_STREAM (stream, state);
1465 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1468 char *errfmt = "List of RuleSet%s";
1469 unsigned errret = 0;
1470 OTF_StreamState state;
1474 READ_UINT16 (stream, count);
1476 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1477 OTF_MALLOC (*set, count, "");
1478 for (i = 0; i < count; i++)
1480 READ_OFFSET (stream, (*set)[i].offset);
1481 if (! (*set)[i].offset)
1482 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1484 SAVE_STREAM (stream, state);
1485 for (i = 0; i < count; i++)
1487 SEEK_STREAM (stream, offset + (*set)[i].offset);
1489 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1491 if (! (*set)[i].RuleCount)
1494 RESTORE_STREAM (stream, state);
1499 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1500 OTF_ClassRule **rule)
1502 char *errfmt = "ClassRule%s";
1503 unsigned errret = 0;
1504 OTF_StreamState state;
1508 READ_UINT16 (stream, count);
1510 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1511 OTF_MALLOC (*rule, count, "");
1512 for (i = 0; i < count; i++)
1514 READ_OFFSET (stream, (*rule)[i].offset);
1515 if (! (*rule)[i].offset)
1516 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1518 SAVE_STREAM (stream, state);
1519 for (i = 0; i < count; i++)
1521 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1522 READ_USHORT (stream, (*rule)[i].GlyphCount);
1523 if (! (*rule)[i].GlyphCount)
1524 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1525 READ_USHORT (stream, (*rule)[i].LookupCount);
1526 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1527 0, (*rule)[i].GlyphCount - 1) < 0)
1529 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1530 (*rule)[i].LookupCount) == 0)
1533 RESTORE_STREAM (stream, state);
1538 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1541 char *errfmt = "ClassSet%s";
1542 unsigned errret = 0;
1543 OTF_StreamState state;
1547 READ_UINT16 (stream, count);
1549 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1550 OTF_CALLOC (*set, count, "");
1551 for (i = 0; i < count; i++)
1552 /* Offset can be zero. */
1553 READ_OFFSET (stream, (*set)[i].offset);
1554 SAVE_STREAM (stream, state);
1555 for (i = 0; i < count; i++)
1556 if ((*set)[i].offset)
1558 SEEK_STREAM (stream, offset + (*set)[i].offset);
1559 (*set)[i].ClassRuleCnt
1560 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1561 &(*set)[i].ClassRule);
1562 if (! (*set)[i].ClassRuleCnt)
1565 RESTORE_STREAM (stream, state);
1570 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1571 OTF_ChainRule **rule)
1573 char *errfmt = "ChainRule%s";
1574 unsigned errret = 0;
1578 READ_UINT16 (stream, count);
1580 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1581 OTF_MALLOC (*rule, count, "");
1582 for (i = 0; i < count; i++)
1583 READ_OFFSET (stream, (*rule)[i].offset);
1584 for (i = 0; i < count; i++)
1586 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1587 (*rule)[i].BacktrackGlyphCount
1588 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1589 (*rule)[i].InputGlyphCount
1590 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1591 if (! (*rule)[i].InputGlyphCount)
1592 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1593 (*rule)[i].LookaheadGlyphCount
1594 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1595 (*rule)[i].LookupCount
1596 = read_lookup_record_list (otf, stream,
1597 &(*rule)[i].LookupRecord, -1);
1598 if (! (*rule)[i].LookupCount)
1606 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1607 OTF_ChainRuleSet **set)
1609 char *errfmt = "ChainRuleSet%s";
1610 unsigned errret = 0;
1611 OTF_StreamState state;
1615 READ_UINT16 (stream, count);
1617 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1618 OTF_MALLOC (*set, count, "");
1619 for (i = 0; i < count; i++)
1621 READ_OFFSET (stream, (*set)[i].offset);
1622 if (! (*set)[i].offset)
1623 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1625 SAVE_STREAM (stream, state);
1626 for (i = 0; i < count; i++)
1628 SEEK_STREAM (stream, offset + (*set)[i].offset);
1629 (*set)[i].ChainRuleCount
1630 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1631 &(*set)[i].ChainRule);
1632 if (! (*set)[i].ChainRuleCount)
1635 RESTORE_STREAM (stream, state);
1640 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1641 OTF_ChainClassRule **rule)
1643 char *errfmt = "ChainClassRule%s";
1644 unsigned errret = 0;
1648 READ_UINT16 (stream, count);
1650 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1651 OTF_MALLOC (*rule, count, "");
1652 for (i = 0; i < count; i++)
1654 READ_OFFSET (stream, (*rule)[i].offset);
1655 if (! (*rule)[i].offset)
1656 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1658 for (i = 0; i < count; i++)
1660 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1661 (*rule)[i].BacktrackGlyphCount
1662 = read_glyph_ids (otf, stream,
1663 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1664 (*rule)[i].InputGlyphCount
1665 = read_glyph_ids (otf, stream,
1666 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1667 if (! (*rule)[i].InputGlyphCount)
1668 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1669 (*rule)[i].LookaheadGlyphCount
1670 = read_glyph_ids (otf, stream,
1671 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1672 (*rule)[i].LookupCount
1673 = read_lookup_record_list (otf, stream,
1674 &(*rule)[i].LookupRecord, -1);
1675 if (! (*rule)[i].LookupCount)
1682 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1683 OTF_ChainClassSet **set)
1685 char *errfmt = "ChainClassSet%s";
1686 unsigned errret = 0;
1687 OTF_StreamState state;
1691 READ_UINT16 (stream, count);
1693 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1694 OTF_MALLOC (*set, count, "");
1695 for (i = 0; i < count; i++)
1696 /* Offset may be zero. */
1697 READ_OFFSET (stream, (*set)[i].offset);
1698 SAVE_STREAM (stream, state);
1699 for (i = 0; i < count; i++)
1700 if ((*set)[i].offset)
1702 SEEK_STREAM (stream, offset + (*set)[i].offset);
1703 (*set)[i].ChainClassRuleCnt
1704 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1705 &(*set)[i].ChainClassRule);
1706 if (! (*set)[i].ChainClassRuleCnt)
1709 RESTORE_STREAM (stream, state);
1714 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1715 OTF_Coverage *coverage,OTF_Context1 *context1)
1717 if (read_coverage (otf, stream, offset, coverage) < 0)
1719 context1->RuleSetCount
1720 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1721 if (! context1->RuleSetCount)
1727 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1728 OTF_Coverage *coverage,OTF_Context2 *context2)
1730 if (read_coverage (otf, stream, offset, coverage) < 0
1731 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1733 context2->ClassSetCnt
1734 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1735 if (! context2->ClassSetCnt)
1741 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1742 OTF_Coverage *coverage,OTF_Context3 *context3)
1744 char *errfmt = "Context1%s";
1747 READ_USHORT (stream, context3->GlyphCount);
1748 if (context3->GlyphCount < 0)
1749 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1750 READ_USHORT (stream, context3->LookupCount);
1751 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1752 context3->GlyphCount) < 0)
1754 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1755 context3->LookupCount) < 0)
1761 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1762 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1764 if (read_coverage (otf, stream, offset, coverage) < 0)
1766 chain_context1->ChainRuleSetCount
1767 = read_chain_rule_set_list (otf, stream, offset,
1768 &chain_context1->ChainRuleSet);
1769 if (! chain_context1->ChainRuleSetCount)
1775 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1776 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1778 if (read_coverage (otf, stream, offset, coverage) < 0
1779 || read_class_def (otf, stream, offset,
1780 &chain_context2->BacktrackClassDef) < 0
1781 || read_class_def (otf, stream, offset,
1782 &chain_context2->InputClassDef) < 0
1783 || read_class_def (otf, stream, offset,
1784 &chain_context2->LookaheadClassDef) < 0)
1786 chain_context2->ChainClassSetCnt
1787 = read_chain_class_set_list (otf, stream, offset,
1788 &chain_context2->ChainClassSet);
1789 if (! chain_context2->ChainClassSetCnt)
1795 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1796 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1800 count = read_coverage_list (otf, stream, offset,
1801 &chain_context3->Backtrack, -1);
1804 chain_context3->BacktrackGlyphCount = (unsigned) count;
1805 count = read_coverage_list (otf, stream, offset,
1806 &chain_context3->Input, -1);
1809 chain_context3->InputGlyphCount = (unsigned) count;
1810 *coverage = chain_context3->Input[0];
1811 count = read_coverage_list (otf, stream, offset,
1812 &chain_context3->LookAhead, -1);
1813 chain_context3->LookaheadGlyphCount = (unsigned) count;
1814 chain_context3->LookupCount
1815 = read_lookup_record_list (otf, stream,
1816 &chain_context3->LookupRecord, -1);
1821 read_gsub_gpos_table (OTF *otf, OTF_TableInfo *table, int gsubp,
1822 enum OTF_ReaderFlag flag)
1824 OTF_Stream *stream = table->stream;
1825 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1826 void *errret = NULL;
1827 OTF_GSUB_GPOS *gsub_gpos = *table->address;
1830 SEEK_STREAM (stream, 10);
1833 SEEK_STREAM (stream, 0);
1834 OTF_CALLOC (gsub_gpos, 1, "");
1835 READ_FIXED (stream, gsub_gpos->Version);
1836 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1837 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1838 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1839 *table->address = gsub_gpos;
1842 if (! gsub_gpos->ScriptList.Script
1843 && read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1844 &gsub_gpos->ScriptList) < 0)
1846 if (flag != OTF_READ_SCRIPTS)
1848 if (! gsub_gpos->FeatureList.Feature
1849 && read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1850 &gsub_gpos->FeatureList) < 0)
1852 if (flag != OTF_READ_FEATURES)
1854 if (! gsub_gpos->LookupList.Lookup
1855 && read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1856 &gsub_gpos->LookupList, gsubp) < 0)
1865 /* (1-9) "GSUB" table */
1868 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1870 char *errfmt = "Sequence%s";
1871 unsigned errret = 0;
1875 READ_UINT16 (stream, count);
1877 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1878 OTF_MALLOC (*seq, count, "");
1879 for (i = 0; i < count; i++)
1880 READ_OFFSET (stream, (*seq)[i].offset);
1881 for (i = 0; i < count; i++)
1883 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1884 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1885 &(*seq)[i].Substitute, 0, -1);
1886 if (! (*seq)[i].GlyphCount)
1893 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1894 OTF_Ligature **ligature)
1896 char *errfmt = "Ligature%s";
1901 READ_UINT16 (stream, count);
1904 OTF_MALLOC (*ligature, count, "");
1905 for (i = 0; i < count; i++)
1906 READ_OFFSET (stream, (*ligature)[i].offset);
1907 for (i = 0; i < count; i++)
1909 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1910 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1911 (*ligature)[i].CompCount
1912 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1913 if (! (*ligature)[i].CompCount)
1920 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1921 OTF_LigatureSet **ligset)
1923 char *errfmt = "LigatureSet%s";
1928 READ_UINT16 (stream, count);
1931 OTF_MALLOC (*ligset, count, "");
1932 for (i = 0; i < count; i++)
1933 READ_OFFSET (stream, (*ligset)[i].offset);
1934 for (i = 0; i < count; i++)
1938 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1939 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1940 &(*ligset)[i].Ligature);
1943 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1949 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1950 OTF_AlternateSet **altset)
1952 char *errfmt = "AlternateSet%s";
1957 READ_UINT16 (stream, count);
1959 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1960 OTF_MALLOC (*altset, count, "");
1961 for (i = 0; i < count; i++)
1962 READ_OFFSET (stream, (*altset)[i].offset);
1963 for (i = 0; i < count; i++)
1967 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1968 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1971 (*altset)[i].GlyphCount = (unsigned) alt_count;
1977 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1978 OTF_Coverage *coverage,
1979 OTF_GSUB_ReverseChain1 *reverse_chain)
1983 if (read_coverage (otf, stream, offset, coverage) < 0)
1985 count = read_coverage_list (otf, stream, offset,
1986 &reverse_chain->Backtrack, -1);
1989 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1990 count = read_coverage_list (otf, stream, offset,
1991 &reverse_chain->LookAhead, -1);
1994 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1995 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
1998 reverse_chain->GlyphCount = count;
2003 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
2004 unsigned type, OTF_LookupSubTableGSUB *subtable)
2009 SEEK_STREAM (stream, offset);
2010 READ_USHORT (stream, subtable->Format);
2011 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
2015 if (subtable->Format == 1)
2017 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2019 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
2021 else if (subtable->Format == 2)
2023 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2025 subtable->u.single2.GlyphCount
2026 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
2028 if (! subtable->u.single2.GlyphCount)
2032 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2036 if (subtable->Format == 1)
2038 read_coverage (otf, stream, offset, &subtable->Coverage);
2039 subtable->u.multiple1.SequenceCount
2040 = read_sequence (otf, stream, offset,
2041 &subtable->u.multiple1.Sequence);
2044 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2048 if (subtable->Format == 1)
2050 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2052 subtable->u.alternate1.AlternateSetCount
2053 = read_alternate_set_list (otf, stream, offset,
2054 &subtable->u.alternate1.AlternateSet);
2055 if (! subtable->u.alternate1.AlternateSetCount)
2059 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2063 if (subtable->Format == 1)
2065 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2067 subtable->u.ligature1.LigSetCount
2068 = read_ligature_set_list (otf, stream, offset,
2069 &subtable->u.ligature1.LigatureSet);
2070 if (! subtable->u.ligature1.LigSetCount)
2074 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2078 if (subtable->Format == 1)
2080 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2081 &subtable->u.context1) < 0)
2084 else if (subtable->Format == 2)
2086 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2087 &subtable->u.context2) < 0)
2090 else if (subtable->Format == 3)
2092 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2093 &subtable->u.context3) < 0)
2097 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2101 if (subtable->Format == 1)
2103 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2104 &subtable->u.chain_context1) < 0)
2107 else if (subtable->Format == 2)
2109 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2110 &subtable->u.chain_context2) < 0)
2113 else if (subtable->Format == 3)
2115 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2116 &subtable->u.chain_context3) < 0)
2120 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2124 if (subtable->Format == 1)
2128 OTF_LookupSubTableGSUB *ex_subtable;
2130 READ_USHORT (stream, ex_type);
2131 READ_ULONG (stream, ex_offset);
2132 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2133 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
2134 ex_type, ex_subtable) < 0)
2136 subtable->u.extension1.ExtensionLookupType = ex_type;
2137 subtable->u.extension1.ExtensionOffset = ex_offset;
2138 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2141 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2145 if (subtable->Format == 1)
2147 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
2148 &subtable->u.reverse_chain1) < 0)
2152 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2156 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2162 read_gsub_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2164 return read_gsub_gpos_table (otf, table, 1, flag);
2168 /* (1-10) "GPOS" table */
2171 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
2172 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
2175 OTF_StreamState state;
2178 memset (value_record, 0, sizeof (OTF_ValueRecord));
2181 for (i = 0, size = 0; i < 8; i++)
2185 if (bit & OTF_XPlacement)
2186 READ_INT16 (stream, value_record->XPlacement);
2187 if (bit & OTF_YPlacement)
2188 READ_INT16 (stream, value_record->YPlacement);
2189 if (bit & OTF_XAdvance)
2190 READ_INT16 (stream, value_record->XAdvance);
2191 if (bit & OTF_YAdvance)
2192 READ_INT16 (stream, value_record->YAdvance);
2193 if (bit & OTF_XPlaDevice)
2194 READ_OFFSET (stream, value_record->XPlaDevice.offset);
2195 if (bit & OTF_YPlaDevice)
2196 READ_OFFSET (stream, value_record->YPlaDevice.offset);
2197 if (bit & OTF_XAdvDevice)
2198 READ_OFFSET (stream, value_record->XAdvDevice.offset);
2199 if (bit & OTF_YAdvDevice)
2200 READ_OFFSET (stream, value_record->YAdvDevice.offset);
2201 SAVE_STREAM (stream, state);
2202 if (value_record->XPlaDevice.offset)
2204 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
2207 if (value_record->YPlaDevice.offset)
2209 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
2212 if (value_record->XAdvDevice.offset)
2214 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
2217 if (value_record->YAdvDevice.offset)
2219 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
2222 RESTORE_STREAM (stream, state);
2228 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
2230 char *errfmt = "Anchor%s";
2233 SEEK_STREAM (stream, offset + anchor->offset);
2234 READ_UINT16 (stream, anchor->AnchorFormat);
2235 READ_INT16 (stream, anchor->XCoordinate);
2236 READ_INT16 (stream, anchor->YCoordinate);
2237 if (anchor->AnchorFormat == 1)
2239 else if (anchor->AnchorFormat == 2)
2241 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
2243 else if (anchor->AnchorFormat == 3)
2245 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
2246 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
2247 if (anchor->f.f2.XDeviceTable.offset)
2249 if (read_device_table (otf, stream, offset + anchor->offset,
2250 &anchor->f.f2.XDeviceTable) < 0)
2253 if (anchor->f.f2.YDeviceTable.offset)
2255 if (read_device_table (otf, stream, offset + anchor->offset,
2256 &anchor->f.f2.YDeviceTable) < 0)
2261 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
2267 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
2268 OTF_MarkArray *array)
2270 char *errfmt = "MarkArray%s";
2272 OTF_StreamState state;
2275 READ_OFFSET (stream, array->offset);
2276 SAVE_STREAM (stream, state);
2277 SEEK_STREAM (stream, offset + array->offset);
2278 READ_UINT16 (stream, array->MarkCount);
2279 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
2280 for (i = 0; i < array->MarkCount; i++)
2282 READ_UINT16 (stream, array->MarkRecord[i].Class);
2283 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
2285 for (i = 0; i < array->MarkCount; i++)
2286 if (read_anchor (otf, stream, offset + array->offset,
2287 &array->MarkRecord[i].MarkAnchor) < 0)
2289 RESTORE_STREAM (stream, state);
2294 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
2295 unsigned ClassCount, OTF_AnchorArray *array)
2297 char *errfmt = "AnchorArray%s";
2299 OTF_StreamState state;
2302 READ_OFFSET (stream, array->offset);
2303 SAVE_STREAM (stream, state);
2304 SEEK_STREAM (stream, offset + array->offset);
2305 READ_UINT16 (stream, array->Count);
2306 OTF_MALLOC (array->AnchorRecord, array->Count, "");
2307 for (i = 0; i < array->Count; i++)
2309 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
2311 for (j = 0; j < ClassCount; j++)
2312 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
2314 for (i = 0; i < array->Count; i++)
2315 for (j = 0; j < ClassCount; j++)
2316 if (read_anchor (otf, stream, offset + array->offset,
2317 &array->AnchorRecord[i].Anchor[j]) < 0)
2319 RESTORE_STREAM (stream, state);
2323 static OTF_PairSet *
2324 read_pair_set_list (OTF *otf, OTF_Stream *stream, long offset, unsigned num,
2325 enum OTF_ValueFormat bit1, enum OTF_ValueFormat bit2)
2327 char *errfmt = "PairSet%s";
2328 void *errret = NULL;
2329 OTF_StreamState state;
2333 OTF_MALLOC (set, num, "");
2334 for (i = 0; i < num; i++)
2335 READ_OFFSET (stream, set[i].offset);
2336 SAVE_STREAM (stream, state);
2337 for (i = 0; i < num; i++)
2339 SEEK_STREAM (stream, offset + set[i].offset);
2340 READ_UINT16 (stream, set[i].PairValueCount);
2341 OTF_MALLOC (set[i].PairValueRecord, set[i].PairValueCount, "");
2342 for (j = 0; j < set[i].PairValueCount; j++)
2344 OTF_PairValueRecord *rec = set[i].PairValueRecord + j;
2346 READ_UINT16 (stream, rec->SecondGlyph);
2347 read_value_record (otf, stream, offset, bit1, &rec->Value1);
2348 read_value_record (otf, stream, offset, bit2, &rec->Value2);
2351 RESTORE_STREAM (stream, state);
2355 static OTF_Class1Record *
2356 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
2357 unsigned num1, enum OTF_ValueFormat bit1,
2358 unsigned num2, enum OTF_ValueFormat bit2)
2360 char *errfmt = "Class1Record%s";
2361 void *errret = NULL;
2362 OTF_Class1Record *rec;
2365 OTF_MALLOC (rec, num1, "");
2366 for (i = 0; i < num1; i++)
2368 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
2369 for (j = 0; j < num2; j++)
2371 if (read_value_record (otf, stream, offset,
2372 bit1, &rec[i].Class2Record[j].Value1) < 0
2373 || read_value_record (otf, stream, offset,
2374 bit2, &rec[i].Class2Record[j].Value2) < 0)
2382 read_entry_exit_list (OTF *otf, OTF_Stream *stream, long offset,
2383 OTF_EntryExitRecord **rec)
2385 char *errfmt = "EntryExitSet%s";
2389 OTF_StreamState state;
2391 READ_UINT16 (stream, count);
2393 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
2394 OTF_MALLOC (*rec, count, "");
2395 for (i = 0; i < count; i++)
2397 READ_OFFSET (stream, (*rec)[i].EntryAnchor.offset);
2398 READ_OFFSET (stream, (*rec)[i].ExitAnchor.offset);
2400 SAVE_STREAM (stream, state);
2401 for (i = 0; i < count; i++)
2403 if (read_anchor (otf, stream, offset, &(*rec)[i].EntryAnchor) < 0)
2405 if (read_anchor (otf, stream, offset, &(*rec)[i].ExitAnchor) < 0)
2408 RESTORE_STREAM (stream, state);
2413 read_ligature_attach (OTF *otf, OTF_Stream *stream, long offset,
2414 unsigned ClassCount, OTF_LigatureAttach *attach)
2416 char *errfmt = "LigatureAttach%s";
2420 SEEK_STREAM (stream, offset + attach->offset);
2421 READ_UINT16 (stream, attach->ComponentCount);
2422 OTF_MALLOC (attach->ComponentRecord, attach->ComponentCount, "");
2423 for (i = 0; i < attach->ComponentCount; i++)
2425 OTF_MALLOC (attach->ComponentRecord[i].LigatureAnchor, ClassCount,
2426 " (ComponentRecord)");
2427 for (j = 0; j < ClassCount; j++)
2428 READ_OFFSET (stream,
2429 attach->ComponentRecord[i].LigatureAnchor[j].offset);
2431 for (i = 0; i < attach->ComponentCount; i++)
2432 for (j = 0; j < ClassCount; j++)
2434 if (attach->ComponentRecord[i].LigatureAnchor[j].offset)
2436 if (read_anchor (otf, stream, offset + attach->offset,
2437 &attach->ComponentRecord[i].LigatureAnchor[j]) < 0)
2441 attach->ComponentRecord[i].LigatureAnchor[j].AnchorFormat = 0;
2447 read_ligature_array (OTF *otf, OTF_Stream *stream, long offset,
2448 unsigned class_count, OTF_LigatureArray *array)
2450 char *errfmt = "LigatureArray%s";
2452 OTF_StreamState state;
2455 READ_OFFSET (stream, array->offset);
2456 SAVE_STREAM (stream, state);
2457 SEEK_STREAM (stream, offset + array->offset);
2458 READ_UINT16 (stream, array->LigatureCount);
2459 OTF_MALLOC (array->LigatureAttach, array->LigatureCount, "");
2460 for (i = 0; i < array->LigatureCount; i++)
2461 READ_OFFSET (stream, array->LigatureAttach[i].offset);
2462 for (i = 0; i < array->LigatureCount; i++)
2463 read_ligature_attach (otf, stream, offset + array->offset,
2464 class_count, array->LigatureAttach + i);
2465 RESTORE_STREAM (stream, state);
2470 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
2471 long offset, unsigned type,
2472 OTF_LookupSubTableGPOS *subtable)
2477 SEEK_STREAM (stream, offset);
2478 READ_UINT16 (stream, subtable->Format);
2479 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2483 if (subtable->Format == 1)
2485 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2487 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2488 read_value_record (otf, stream, offset,
2489 subtable->u.single1.ValueFormat,
2490 &subtable->u.single1.Value);
2492 else if (subtable->Format == 2)
2494 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2497 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2499 READ_UINT16 (stream, single2->ValueFormat);
2500 READ_UINT16 (stream, single2->ValueCount);
2501 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2502 for (i = 0; i < single2->ValueCount; i++)
2503 read_value_record (otf, stream, offset, single2->ValueFormat,
2504 single2->Value + i);
2507 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2511 if (subtable->Format == 1)
2513 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2515 READ_UINT16 (stream, subtable->u.pair1.ValueFormat1);
2516 READ_UINT16 (stream, subtable->u.pair1.ValueFormat2);
2517 READ_UINT16 (stream, subtable->u.pair1.PairSetCount);
2518 subtable->u.pair1.PairSet
2519 = read_pair_set_list (otf, stream, offset,
2520 subtable->u.pair1.PairSetCount,
2521 subtable->u.pair1.ValueFormat1,
2522 subtable->u.pair1.ValueFormat2);
2523 if (! subtable->u.pair1.PairSet)
2526 else if (subtable->Format == 2)
2528 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2530 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2531 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2532 if (read_class_def (otf, stream, offset,
2533 &subtable->u.pair2.ClassDef1) < 0
2534 || read_class_def (otf, stream, offset,
2535 &subtable->u.pair2.ClassDef2) < 0)
2537 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2538 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2539 subtable->u.pair2.Class1Record
2540 = read_class1_record_list (otf, stream, offset,
2541 subtable->u.pair2.Class1Count,
2542 subtable->u.pair2.ValueFormat1,
2543 subtable->u.pair2.Class2Count,
2544 subtable->u.pair2.ValueFormat2);
2545 if (! subtable->u.pair2.Class1Record)
2549 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2553 if (subtable->Format == 1)
2555 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2557 subtable->u.cursive1.EntryExitCount
2558 = read_entry_exit_list (otf, stream, offset,
2559 &subtable->u.cursive1.EntryExitRecord);
2560 if (! subtable->u.cursive1.EntryExitCount)
2564 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2568 if (subtable->Format == 1)
2570 read_coverage (otf, stream, offset, &subtable->Coverage);
2571 read_coverage (otf, stream, offset,
2572 &subtable->u.mark_base1.BaseCoverage);
2573 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2574 read_mark_array (otf, stream, offset,
2575 &subtable->u.mark_base1.MarkArray);
2576 read_anchor_array (otf, stream, offset,
2577 subtable->u.mark_base1.ClassCount,
2578 &subtable->u.mark_base1.BaseArray);
2581 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2585 if (subtable->Format == 1)
2587 read_coverage (otf, stream, offset, &subtable->Coverage);
2588 read_coverage (otf, stream, offset,
2589 &subtable->u.mark_lig1.LigatureCoverage);
2590 READ_UINT16 (stream, subtable->u.mark_lig1.ClassCount);
2591 read_mark_array (otf, stream, offset,
2592 &subtable->u.mark_lig1.MarkArray);
2593 read_ligature_array (otf, stream, offset,
2594 subtable->u.mark_lig1.ClassCount,
2595 &subtable->u.mark_lig1.LigatureArray);
2600 if (subtable->Format == 1)
2602 read_coverage (otf, stream, offset, &subtable->Coverage);
2603 read_coverage (otf, stream, offset,
2604 &subtable->u.mark_mark1.Mark2Coverage);
2605 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2606 read_mark_array (otf, stream, offset,
2607 &subtable->u.mark_mark1.Mark1Array);
2608 read_anchor_array (otf, stream, offset,
2609 subtable->u.mark_mark1.ClassCount,
2610 &subtable->u.mark_mark1.Mark2Array);
2613 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2617 if (subtable->Format == 1)
2619 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2620 &subtable->u.context1) < 0)
2623 else if (subtable->Format == 2)
2625 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2626 &subtable->u.context2) < 0)
2629 else if (subtable->Format == 3)
2631 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2632 &subtable->u.context3) < 0)
2636 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2640 if (subtable->Format == 1)
2642 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2643 &subtable->u.chain_context1) < 0)
2646 else if (subtable->Format == 2)
2648 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2649 &subtable->u.chain_context2) < 0)
2652 else if (subtable->Format == 3)
2654 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2655 &subtable->u.chain_context3) < 0)
2659 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2663 if (subtable->Format == 1)
2667 OTF_LookupSubTableGPOS *ex_subtable;
2669 READ_USHORT (stream, ex_type);
2670 READ_ULONG (stream, ex_offset);
2671 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2672 if (read_lookup_subtable_gpos (otf, stream, offset + ex_offset,
2673 ex_type, ex_subtable) < 0)
2675 subtable->u.extension1.ExtensionLookupType = ex_type;
2676 subtable->u.extension1.ExtensionOffset = ex_offset;
2677 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2680 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2684 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2690 read_gpos_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2692 return read_gsub_gpos_table (otf, table, 0, flag);
2700 read_base_table (OTF_Stream *stream, long offset)
2704 OTF_MALLOC (base, 1);
2713 read_jstf_table (OTF_Stream *stream, long offset)
2717 OTF_MALLOC (jstf, 1);
2723 /*** (1-11) Structure for OTF */
2726 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2730 READ_FIXED (stream, table->sfnt_version);
2731 READ_USHORT (stream, table->numTables);
2732 READ_USHORT (stream, table->searchRange);
2733 READ_USHORT (stream, table->enterSelector);
2734 READ_USHORT (stream, table->rangeShift);
2739 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2744 READ_TAG (stream, tag);
2746 table->name[0] = tag >> 24;
2747 table->name[1] = (tag >> 16) & 0xFF;
2748 table->name[2] = (tag >> 8) & 0xFF;
2749 table->name[3] = tag & 0xFF;
2750 table->name[4] = '\0';
2751 READ_ULONG (stream, table->checkSum);
2752 READ_ULONG (stream, table->offset);
2753 READ_ULONG (stream, table->length);
2758 read_header_part (OTF *otf, FILE *fp, FT_Face face)
2760 char *errfmt = "otf header%s";
2763 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2765 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2766 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2767 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2768 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2769 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2770 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2771 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2772 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2773 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2774 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2775 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2776 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2780 OTF_Tag head_tag = OTF_tag ("head");
2781 OTF_Tag name_tag = OTF_tag ("name");
2782 OTF_Tag cmap_tag = OTF_tag ("cmap");
2783 OTF_Tag gdef_tag = OTF_tag ("GDEF");
2784 OTF_Tag gsub_tag = OTF_tag ("GSUB");
2785 OTF_Tag gpos_tag = OTF_tag ("GPOS");
2786 OTF_Stream *stream = make_stream ("Offset Table");
2790 internal_data->header_stream = stream;
2792 /* Size of Offset Table is 12 bytes. */
2793 if (setup_stream (stream, fp, 0, 12) < 0)
2795 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2798 /* Size of each Table Directory is 16 bytes. */
2799 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables) < 0)
2802 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables,
2804 for (i = 0; i < otf->offset_table.numTables; i++)
2806 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2807 OTF_TableInfo *table_info = NULL;
2811 if (tag == head_tag)
2812 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2813 else if (tag == name_tag)
2814 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2815 else if (tag == cmap_tag)
2816 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2817 else if (tag == gdef_tag)
2818 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2819 else if (tag == gsub_tag)
2820 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2821 else if (tag == gpos_tag)
2822 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2826 table_info->stream = make_stream (otf->table_dirs[i].name);
2827 if (setup_stream (table_info->stream, fp,
2828 otf->table_dirs[i].offset,
2829 otf->table_dirs[i].length) < 0)
2834 internal_data->header_stream = NULL;
2835 free_stream (stream);
2841 internal_data->header_stream = NULL;
2842 if ((stream = make_stream_from_ft_face (face, "head")))
2843 internal_data->table_info[OTF_TABLE_TYPE_HEAD].stream = stream;
2844 if ((stream = make_stream_from_ft_face (face, "name")))
2845 internal_data->table_info[OTF_TABLE_TYPE_NAME].stream = stream;
2846 if ((stream = make_stream_from_ft_face (face, "cmap")))
2847 internal_data->table_info[OTF_TABLE_TYPE_CMAP].stream = stream;
2848 if ((stream = make_stream_from_ft_face (face, "GDEF")))
2849 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream = stream;
2850 if ((stream = make_stream_from_ft_face (face, "GSUB")))
2851 internal_data->table_info[OTF_TABLE_TYPE_GSUB].stream = stream;
2852 if ((stream = make_stream_from_ft_face (face, "GPOS")))
2853 internal_data->table_info[OTF_TABLE_TYPE_GPOS].stream = stream;
2856 if (! internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream)
2857 /* We can simulate the GDEF table. */
2858 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream
2859 = make_stream ("GDEF");
2863 static OTF_TableInfo *
2864 get_table_info (OTF *otf, const char *name)
2866 char *errfmt = "OTF Table Read%s";
2867 OTF_TableInfo *errret = NULL;
2868 OTF_InternalData *internal_data = otf->internal_data;
2869 OTF_TableInfo *table_info;
2870 OTF_Tag tag = OTF_tag (name);
2873 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2875 if (tag == OTF_tag ("head"))
2876 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2877 else if (tag == OTF_tag ("name"))
2878 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2879 else if (tag == OTF_tag ("cmap"))
2880 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2881 else if (tag == OTF_tag ("GDEF"))
2882 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2883 else if (tag == OTF_tag ("GSUB"))
2884 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2885 else if (tag == OTF_tag ("GPOS"))
2886 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2888 OTF_ERROR (OTF_ERROR_TABLE, " (unsupported table name)");
2890 if (*table_info->address)
2893 if (! table_info->stream)
2894 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2895 if (! table_info->reader)
2896 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2902 /*** (2) API for reading OTF */
2904 /*** (2-1) OTF_open() */
2906 /* Note: We can't use memory allocation macros in the following
2907 functions because those macros return from the functions before
2908 freeing memory previously allocated. */
2911 OTF_open (const char *otf_name)
2914 char *errfmt = "opening otf (%s)";
2915 void *errret = NULL;
2917 OTF_InternalData *internal_data;
2918 int len = strlen (otf_name);
2919 const char *ext = otf_name + (len - 4);
2923 || (ext[1] != 'O' && ext[1] != 'T' && ext[1] != 'o' && ext[1] != 't')
2924 || (ext[2] != 'T' && ext[2] != 't')
2925 || (ext[3] != 'F' && ext[3] != 'f'))
2926 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2927 fp = fopen (otf_name, "r");
2929 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2930 otf = calloc (1, sizeof (OTF));
2932 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2933 otf->filename = strdup (otf_name);
2934 if (! otf->filename)
2938 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2941 internal_data = calloc (1, sizeof (OTF_InternalData));
2942 if (! internal_data)
2943 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2944 otf->internal_data = internal_data;
2945 if (! allocate_memory_record (otf))
2946 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2948 /* Here after, all pointers to allocated memory are recorded in
2949 otf->internal_data->memory_record except for what allocated by
2950 the functions allocate_memory_record and make_stream. */
2952 if (read_header_part (otf, fp, NULL) < 0)
2964 OTF_open_ft_face (FT_Face face)
2966 char *errfmt = "opening otf from Freetype (%s)";
2967 void *errret = NULL;
2969 OTF_InternalData *internal_data;
2971 if (! FT_IS_SFNT (face))
2972 OTF_ERROR (OTF_ERROR_FILE, (char *) face->family_name);
2973 otf = calloc (1, sizeof (OTF));
2975 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2976 otf->filename = NULL;
2978 internal_data = calloc (1, sizeof (OTF_InternalData));
2979 if (! internal_data)
2980 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2981 otf->internal_data = internal_data;
2982 if (! allocate_memory_record (otf))
2983 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2985 if (read_header_part (otf, NULL, face) < 0)
2994 /*** (2-2) OTF_close() */
2997 OTF_close (OTF *otf)
2999 OTF_InternalData *internal_data = otf->internal_data;
3004 OTF_MemoryRecord *memrec = internal_data->memory_record;
3006 if (internal_data->header_stream)
3007 free_stream (internal_data->header_stream);
3009 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
3010 if (internal_data->table_info[i].stream)
3011 free_stream (internal_data->table_info[i].stream);
3015 OTF_MemoryRecord *next = memrec->next;
3017 for (i = memrec->used - 1; i >= 0; i--)
3018 free (memrec->memory[i]);
3022 free (internal_data);
3025 free (otf->filename);
3029 /*** (2-3) OTF_get_table() */
3032 OTF_get_table (OTF *otf, const char *name)
3034 OTF_TableInfo *table_info = get_table_info (otf, name);
3039 if (! table_info->stream)
3040 /* Already fully loaded. */
3043 address = (*table_info->reader) (otf, table_info, OTF_READ_FULL);
3044 free_stream (table_info->stream);
3045 table_info->stream = NULL;
3048 table_info->reader = NULL;
3054 /*** (2-4) OTF_check_table() */
3057 OTF_check_table (OTF *otf, const char *name)
3059 return (get_table_info (otf, name) ? 0 : -1);
3062 /*** (2-5) OTF_get_scripts() */
3065 OTF_get_scripts (OTF *otf, int gsubp)
3067 OTF_TableInfo *table_info
3068 = (otf->internal_data->table_info
3069 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3072 if (! table_info->reader)
3074 if (! table_info->stream)
3075 /* Already fully loaded. */
3078 address = (*table_info->reader) (otf, table_info, OTF_READ_SCRIPTS);
3081 table_info->reader = NULL;
3087 /*** (2-6) OTF_get_features() */
3090 OTF_get_features (OTF *otf, int gsubp)
3092 OTF_TableInfo *table_info
3093 = (otf->internal_data->table_info
3094 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3097 if (! table_info->reader)
3099 if (! table_info->stream)
3101 if (*table_info->address)
3102 /* Already fully loaded. */
3107 address = (*table_info->reader) (otf, table_info, OTF_READ_FEATURES);
3110 table_info->reader = NULL;
3116 /*** (2-7) OTF_check_features */
3119 OTF_check_features (OTF *otf, int gsubp,
3120 OTF_Tag script, OTF_Tag language, const OTF_Tag *features,
3123 OTF_ScriptList *script_list;
3124 OTF_Script *Script = NULL;
3125 OTF_LangSys *LangSys = NULL;
3126 OTF_FeatureList *feature_list;
3129 if (OTF_get_features (otf, gsubp) < 0)
3131 for (i = 0; i < n_features; i++)
3133 OTF_Tag feature = features[i];
3137 if ((((unsigned) feature) & 0x80000000) == 0)
3144 script_list = &otf->gsub->ScriptList;
3145 feature_list = &otf->gsub->FeatureList;
3149 script_list = &otf->gpos->ScriptList;
3150 feature_list = &otf->gpos->FeatureList;
3152 for (i = 0; i < script_list->ScriptCount && ! Script; i++)
3153 if (script_list->Script[i].ScriptTag == script)
3154 Script = script_list->Script + i;
3159 for (i = 0; i < Script->LangSysCount && ! LangSys; i++)
3160 if (Script->LangSysRecord[i].LangSysTag == language)
3161 LangSys = Script->LangSys + i;
3164 LangSys = &Script->DefaultLangSys;
3165 for (j = 0; j < n_features; j++)
3167 OTF_Tag feature = features[j];
3172 if (((unsigned) feature) & 0x80000000)
3174 feature = (OTF_Tag) (((unsigned) feature) & 0x7FFFFFFF);
3177 for (i = 0; i < LangSys->FeatureCount; i++)
3178 if (feature_list->Feature[LangSys->FeatureIndex[i]].FeatureTag
3185 if (i == LangSys->FeatureCount)
3192 /*** (5) API miscellaneous ***/
3195 OTF_tag (const char *name)
3197 const unsigned char *p = (unsigned char *) name;
3201 return (OTF_Tag) ((p[0] << 24)
3205 : (p[2] << 8) | p[3]))));
3209 OTF_tag_name (OTF_Tag tag, char *name)
3211 name[0] = (char) (tag >> 24);
3212 name[1] = (char) ((tag >> 16) & 0xFF);
3213 name[2] = (char) ((tag >> 8) & 0xFF);
3214 name[3] = (char) (tag & 0xFF);