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 cmap->table_index = unicode_full_index;
628 for (i = 0; i < cmap->numTables; i++)
632 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
633 READ_USHORT (stream, format);
634 cmap->EncodingRecord[i].subtable.format = format;
637 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
638 cmap->EncodingRecord[i].subtable.language = 0;
642 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
643 if (format == 8 || format == 10 || format == 12)
645 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
646 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
650 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
657 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
658 " (EncodingRecord)");
660 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
667 OTF_EncodingSubtable2 *sub2;
670 OTF_MALLOC (sub2, 1, " (EncodingSubtable2)");
671 cmap->EncodingRecord[i].subtable.f.f2 = sub2;
672 for (j = 0, max_key = 0; j < 256; j++)
674 READ_USHORT (stream, sub2->subHeaderKeys[j]);
675 if (max_key < sub2->subHeaderKeys[j])
676 max_key = sub2->subHeaderKeys[j];
679 sub2->subHeaderCount = max_key / 8;
680 OTF_MALLOC (sub2->subHeaders, max_key / 8, " (subHeaders)");
681 for (j = 0; j < sub2->subHeaderCount; j++)
683 READ_USHORT (stream, sub2->subHeaders[j].firstCode);
684 READ_USHORT (stream, sub2->subHeaders[j].entryCount);
685 READ_SHORT (stream, sub2->subHeaders[j].idDelta);
686 READ_USHORT (stream, sub2->subHeaders[j].idRangeOffset);
687 /* Make it offset from sub2->glyphIndexArray. */
688 sub2->subHeaders[j].idRangeOffset -= max_key - (j * 8 + 6);
690 sub2->glyphIndexCount = (cmap->EncodingRecord[i].subtable.length
692 OTF_MALLOC (sub2->glyphIndexArray, sub2->glyphIndexCount,
693 " (glyphIndexArray)");
694 READ_BYTES (stream, sub2->glyphIndexArray, sub2->glyphIndexCount);
700 OTF_EncodingSubtable4 *sub4;
705 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
706 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
707 READ_USHORT (stream, sub4->segCountX2);
708 segCount = sub4->segCountX2 / 2;
709 READ_USHORT (stream, sub4->searchRange);
710 READ_USHORT (stream, sub4->entrySelector);
711 READ_USHORT (stream, sub4->rangeShift);
712 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
713 for (j = 0; j < segCount; j++)
714 READ_USHORT (stream, sub4->segments[j].endCount);
715 READ_USHORT (stream, dummy);
716 for (j = 0; j < segCount; j++)
717 READ_USHORT (stream, sub4->segments[j].startCount);
718 for (j = 0; j < segCount; j++)
719 READ_SHORT (stream, sub4->segments[j].idDelta);
720 for (j = 0; j < segCount; j++)
723 unsigned rest = 2 * (segCount - j);
725 READ_USHORT (stream, off);
727 sub4->segments[j].idRangeOffset = 0xFFFF;
729 sub4->segments[j].idRangeOffset = (off - rest) / 2;
731 j = (cmap->EncodingRecord[i].subtable.length
732 - (14 + 2 * (segCount * 4 + 1)));
733 sub4->GlyphCount = j / 2;
734 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
735 for (j = 0; j < sub4->GlyphCount; j++)
736 READ_USHORT (stream, sub4->glyphIdArray[j]);
742 OTF_EncodingSubtable6 *sub6;
745 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
746 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
747 READ_USHORT (stream, sub6->firstCode);
748 READ_USHORT (stream, sub6->entryCount);
749 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
750 for (j = 0; j < sub6->entryCount; j++)
751 READ_USHORT (stream, sub6->glyphIdArray[j]);
757 OTF_EncodingSubtable8 *sub8;
760 OTF_MALLOC (sub8, 1, " (EncodingSubtable8)");
761 cmap->EncodingRecord[i].subtable.f.f8 = sub8;
762 for (j = 0; j < 8192; j++)
763 READ_BYTES (stream, sub8->is32, 8192);
764 READ_ULONG (stream, sub8->nGroups);
765 OTF_MALLOC (sub8->Groups, sub8->nGroups, " (Groups)");
766 for (j = 0; j < sub8->nGroups; j++)
768 READ_ULONG (stream, sub8->Groups[i].startCharCode);
769 READ_ULONG (stream, sub8->Groups[i].endCharCode);
770 READ_ULONG (stream, sub8->Groups[i].startGlyphID);
777 OTF_EncodingSubtable10 *sub10;
780 OTF_MALLOC (sub10, 1, " (EncodingSubtable10)");
781 cmap->EncodingRecord[i].subtable.f.f10 = sub10;
782 READ_ULONG (stream, sub10->startCharCode);
783 READ_ULONG (stream, sub10->numChars);
784 OTF_MALLOC (sub10->glyphs, sub10->numChars, " (GlyphCount)");
785 for (j = 0; j < sub10->numChars; j++)
786 READ_USHORT (stream, sub10->glyphs[j]);
792 OTF_EncodingSubtable12 *sub12;
795 OTF_MALLOC (sub12, 1, " (EncodingSubtable12)");
796 cmap->EncodingRecord[i].subtable.f.f12 = sub12;
797 READ_ULONG (stream, sub12->nGroups);
798 OTF_MALLOC (sub12->Groups, sub12->nGroups, " (Groups)");
799 for (j = 0; j < sub12->nGroups; j++)
801 READ_ULONG (stream, sub12->Groups[j].startCharCode);
802 READ_ULONG (stream, sub12->Groups[j].endCharCode);
803 READ_ULONG (stream, sub12->Groups[j].startGlyphID);
810 cmap->EncodingRecord[i].subtable.f.f14
811 = read_cmap_uvs_table (otf, stream,
812 cmap->EncodingRecord[i].offset);
817 OTF_ERROR (OTF_ERROR_TABLE, " (invalid Subtable format)");
821 if (unicode_bmp_index >= 0)
823 OTF_EncodingRecord *rec = cmap->EncodingRecord + unicode_bmp_index;
824 OTF_GlyphID glyph_id, max_glyph_id = 0;
826 OTF_CALLOC (cmap->unicode_table, 0x10000, "");
827 switch (rec->subtable.format)
831 OTF_EncodingSubtable4 *sub4 = rec->subtable.f.f4;
832 int segCount = sub4->segCountX2 / 2;
834 for (i = 0; i < segCount; i++)
836 OTF_cmapSegment *seg = sub4->segments + i;
839 if (seg->idRangeOffset == 0xFFFF)
840 for (c = seg->startCount; c <= seg->endCount; c++)
842 glyph_id = c + seg->idDelta;
843 cmap->unicode_table[c] = glyph_id;
844 if (glyph_id > max_glyph_id)
845 max_glyph_id = glyph_id;
848 for (c = seg->startCount; c <= seg->endCount && c != 0xFFFF;
851 glyph_id = sub4->glyphIdArray[seg->idRangeOffset
852 + (c - seg->startCount)];
853 cmap->unicode_table[c] = glyph_id;
854 if (glyph_id > max_glyph_id)
855 max_glyph_id = glyph_id;
861 OTF_CALLOC (cmap->decode_table, max_glyph_id + 1, "");
862 for (i = 0; i < 0x10000; i++)
863 if (cmap->unicode_table[i])
864 cmap->decode_table[cmap->unicode_table[i]] = i;
865 cmap->max_glyph_id = max_glyph_id;
868 *table->address = cmap;
873 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
875 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
876 Glyph-IDs there. If COUNT is negative, read the number of
877 Glyphs-IDs at first. MINUS if nozero is how few the actual
878 Glyph-IDs are in STREAM than COUNT. */
881 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
882 int minus, int count)
884 char *errfmt = "GlyphID List%s";
889 READ_UINT16 (stream, count);
892 OTF_MALLOC (*ids, count, "");
893 for (i = 0; i < count + minus; i++)
894 READ_GLYPHID (stream, (*ids)[i]);
899 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
901 char *errfmt = "RangeRecord%s";
906 READ_UINT16 (stream, count);
909 OTF_MALLOC (*record, count, "");
910 for (i = 0; i < count; i++)
912 READ_GLYPHID (stream, (*record)[i].Start);
913 READ_GLYPHID (stream, (*record)[i].End);
914 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
921 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
922 OTF_Coverage *coverage)
924 char *errfmt = "Coverage%s";
926 OTF_StreamState state;
929 READ_OFFSET (stream, coverage->offset);
930 SAVE_STREAM (stream, state);
931 SEEK_STREAM (stream, offset + coverage->offset);
932 READ_UINT16 (stream, coverage->CoverageFormat);
933 if (coverage->CoverageFormat == 1)
934 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
935 else if (coverage->CoverageFormat == 2)
936 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
938 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
941 coverage->Count = (unsigned) count;
942 RESTORE_STREAM (stream, state);
946 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
947 and store the Coverages there. If COUNT is negative, read the
948 number of Coverages at first. */
951 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
952 OTF_Coverage **coverage, int count)
954 char *errfmt = "Coverage List%s";
959 READ_UINT16 (stream, count);
962 OTF_MALLOC (*coverage, count, "");
963 for (i = 0; i < count; i++)
964 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
971 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
974 char *errfmt = "ClassDef%s";
977 SEEK_STREAM (stream, class->offset);
978 READ_UINT16 (stream, class->ClassFormat);
979 if (class->ClassFormat == 1)
981 READ_GLYPHID (stream, class->f.f1.StartGlyph);
982 class->f.f1.GlyphCount
984 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
985 if (! class->f.f1.GlyphCount)
986 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
988 else if (class->ClassFormat == 2)
990 class->f.f2.ClassRangeCount
991 = (read_range_records
992 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
993 if (! class->f.f2.ClassRangeCount)
994 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
997 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1003 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
1005 char *errfmt = "ClassDef%s";
1007 OTF_StreamState state;
1009 READ_OFFSET (stream, class->offset);
1010 if (! class->offset)
1012 SAVE_STREAM (stream, state);
1013 SEEK_STREAM (stream, offset + class->offset);
1014 READ_UINT16 (stream, class->ClassFormat);
1015 if (class->ClassFormat == 1)
1017 READ_GLYPHID (stream, class->f.f1.StartGlyph);
1018 class->f.f1.GlyphCount
1019 = read_glyph_ids (otf, stream,
1020 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
1022 if (! class->f.f1.GlyphCount)
1025 else if (class->ClassFormat == 2)
1027 class->f.f2.ClassRangeCount
1028 = read_range_records (otf, stream,
1029 (OTF_RangeRecord **)
1030 &class->f.f2.ClassRangeRecord);
1031 if (! class->f.f2.ClassRangeCount)
1035 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1037 RESTORE_STREAM (stream, state);
1043 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
1044 OTF_DeviceTable *table)
1046 char *errfmt = "Device Table%s";
1057 SEEK_STREAM (stream, offset + table->offset);
1058 READ_UINT16 (stream, table->StartSize);
1059 READ_UINT16 (stream, table->EndSize);
1060 READ_UINT16 (stream, table->DeltaFormat);
1061 num = table->EndSize - table->StartSize + 1;
1062 if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
1064 OTF_MALLOC (table->DeltaValue, num, "");
1066 if (table->DeltaFormat == 1)
1067 for (i = 0; i < num; i++)
1070 READ_UINT16 (stream, val);
1071 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
1072 table->DeltaValue[i] = intval.int2;
1074 else if (table->DeltaFormat == 2)
1075 for (i = 0; i < num; i++)
1078 READ_UINT16 (stream, val);
1079 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
1080 table->DeltaValue[i] = intval.int4;
1082 else /* (table->DeltaFormat == 3) */
1083 for (i = 0; i < num; i++)
1087 READ_UINT16 (stream, val);
1088 intval.int8 = val >> 8;
1089 table->DeltaValue[i] = intval.int8;
1093 intval.int8 = val >> 8;
1094 table->DeltaValue[i] = intval.int8;
1100 /* Invalid DeltaFormat but several fonts has such values (bug of
1101 fontforge?). So accept it with NULL delta values. */
1102 table->DeltaValue = NULL;
1108 /*** (1-6) "GDEF" table */
1111 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
1112 OTF_AttachList *list)
1114 char *errfmt = "AttachList%s";
1118 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1120 READ_UINT16 (stream, list->GlyphCount);
1121 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
1122 for (i = 0; i < list->GlyphCount; i++)
1123 READ_OFFSET (stream, list->AttachPoint[i].offset);
1124 for (i = 0; i < list->GlyphCount; i++)
1128 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
1129 READ_UINT16 (stream, count);
1130 list->AttachPoint[i].PointCount = count;
1131 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
1132 for (j = 0; j < count; j++)
1133 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
1139 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
1140 OTF_CaretValue *caret)
1142 char *errfmt = "CaretValue%s";
1145 SEEK_STREAM (stream, offset + caret->offset);
1146 READ_UINT16 (stream, caret->CaretValueFormat);
1147 if (caret->CaretValueFormat == 1)
1148 READ_INT16 (stream, caret->f.f1.Coordinate);
1149 else if (caret->CaretValueFormat == 2)
1150 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
1151 else if (caret->CaretValueFormat == 3)
1153 READ_INT16 (stream, caret->f.f3.Coordinate);
1154 if (read_device_table (otf, stream, offset + caret->offset,
1155 &caret->f.f3.DeviceTable) < 0)
1159 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1164 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
1165 OTF_LigCaretList *list)
1167 char *errfmt = "LigCaretList%s";
1171 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1173 READ_UINT16 (stream, list->LigGlyphCount);
1174 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
1175 for (i = 0; i < list->LigGlyphCount; i++)
1176 READ_OFFSET (stream, list->LigGlyph[i].offset);
1177 for (i = 0; i < list->LigGlyphCount; i++)
1181 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
1182 READ_UINT16 (stream, count);
1183 list->LigGlyph[i].CaretCount = count;
1184 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
1185 for (j = 0; j < count; j++)
1186 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
1187 for (j = 0; j < count; j++)
1188 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
1189 &list->LigGlyph[i].CaretValue[j]) < 0)
1196 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
1200 READ_FIXED (stream, header->Version);
1201 READ_OFFSET (stream, header->GlyphClassDef);
1202 READ_OFFSET (stream, header->AttachList);
1203 READ_OFFSET (stream, header->LigCaretList);
1204 READ_OFFSET (stream, header->MarkAttachClassDef);
1209 read_gdef_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
1211 OTF_Stream *stream = table->stream;
1212 char *errfmt = "GDEF%s";
1213 void *errret = NULL;
1216 OTF_CALLOC (gdef, 1, "");
1219 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
1220 if (gdef->header.GlyphClassDef)
1222 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
1223 read_class_def_without_offset (otf, stream,
1224 &gdef->glyph_class_def);
1226 if (gdef->header.AttachList)
1227 read_attach_list (otf, stream, gdef->header.AttachList,
1228 &gdef->attach_list);
1229 if (gdef->header.LigCaretList)
1230 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
1231 &gdef->lig_caret_list);
1232 if (gdef->header.MarkAttachClassDef)
1234 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
1235 read_class_def_without_offset (otf, stream,
1236 &gdef->mark_attach_class_def);
1240 *table->address = gdef;
1245 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
1248 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
1249 OTF_ScriptList *list)
1251 char *errfmt = "Script List%s";
1255 SEEK_STREAM (stream, offset);
1256 READ_USHORT (stream, list->ScriptCount);
1257 OTF_CALLOC (list->Script, list->ScriptCount, "");
1259 for (i = 0; i < list->ScriptCount; i++)
1261 READ_TAG (stream, list->Script[i].ScriptTag);
1262 READ_OFFSET (stream, list->Script[i].offset);
1264 for (i = 0; i < list->ScriptCount; i++)
1266 OTF_Script *script = list->Script + i;
1267 long script_offset = offset + script->offset;
1269 SEEK_STREAM (stream, script_offset);
1270 READ_OFFSET (stream, script->DefaultLangSysOffset);
1271 READ_USHORT (stream, script->LangSysCount);
1272 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
1273 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
1274 for (j = 0; j < script->LangSysCount; j++)
1276 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
1277 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
1280 if (script->DefaultLangSysOffset)
1282 OTF_LangSys *langsys = &script->DefaultLangSys;
1284 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
1285 READ_OFFSET (stream, langsys->LookupOrder);
1286 READ_USHORT (stream, langsys->ReqFeatureIndex);
1287 READ_USHORT (stream, langsys->FeatureCount);
1288 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1290 for (k = 0; k < langsys->FeatureCount; k++)
1291 READ_USHORT (stream, langsys->FeatureIndex[k]);
1294 for (j = 0; j < script->LangSysCount; j++)
1296 OTF_LangSys *langsys = script->LangSys + j;
1298 SEEK_STREAM (stream,
1299 script_offset + script->LangSysRecord[j].LangSys);
1300 READ_OFFSET (stream, langsys->LookupOrder);
1301 READ_USHORT (stream, langsys->ReqFeatureIndex);
1302 READ_USHORT (stream, langsys->FeatureCount);
1303 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1305 for (k = 0; k < langsys->FeatureCount; k++)
1306 READ_USHORT (stream, langsys->FeatureIndex[k]);
1314 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
1315 OTF_FeatureList *list)
1317 char *errfmt = "Feature List%s";
1321 SEEK_STREAM (stream, offset);
1322 READ_UINT16 (stream, list->FeatureCount);
1323 OTF_CALLOC (list->Feature, list->FeatureCount, "");
1324 for (i = 0; i < list->FeatureCount; i++)
1326 READ_TAG (stream, list->Feature[i].FeatureTag);
1327 READ_OFFSET (stream, list->Feature[i].offset);
1329 for (i = 0; i < list->FeatureCount; i++)
1331 OTF_Feature *feature = list->Feature + i;
1333 SEEK_STREAM (stream, offset + feature->offset);
1334 READ_OFFSET (stream, feature->FeatureParams);
1335 READ_UINT16 (stream, feature->LookupCount);
1336 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1337 " (LookupListIndex)");
1338 for (j = 0; j < feature->LookupCount; j++)
1339 READ_UINT16 (stream, feature->LookupListIndex[j]);
1345 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1346 long offset, unsigned type,
1347 OTF_LookupSubTableGSUB *subtable);
1348 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1349 long offset, unsigned type,
1350 OTF_LookupSubTableGPOS *subtable);
1353 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1354 OTF_LookupList *list, int gsubp)
1356 char *errfmt = "Lookup List%s";
1360 SEEK_STREAM (stream, offset);
1361 READ_UINT16 (stream, list->LookupCount);
1362 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1364 for (i = 0; i < list->LookupCount; i++)
1365 READ_OFFSET (stream, list->Lookup[i].offset);
1366 for (i = 0; i < list->LookupCount; i++)
1368 OTF_Lookup *lookup = list->Lookup + i;
1370 SEEK_STREAM (stream, offset + lookup->offset);
1371 READ_UINT16 (stream, lookup->LookupType);
1372 READ_UINT16 (stream, lookup->LookupFlag);
1373 READ_UINT16 (stream, lookup->SubTableCount);
1374 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1375 " (SubTableOffset)");
1377 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1380 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1382 for (j = 0; j < lookup->SubTableCount; j++)
1383 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1384 for (j = 0; j < lookup->SubTableCount; j++)
1387 = offset + lookup->offset + lookup->SubTableOffset[j];
1390 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1392 lookup->SubTable.gsub + j) < 0
1393 : read_lookup_subtable_gpos (otf, stream, this_offset,
1395 lookup->SubTable.gpos + j) < 0)
1404 /*** (1-8) Structures common to GSUB and GPOS */
1407 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1408 OTF_LookupRecord **record, int count)
1410 char *errfmt = "LookupRecord%s";
1411 unsigned errret = 0;
1415 READ_UINT16 (stream, count);
1417 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1418 OTF_MALLOC (*record, count, "");
1419 for (i = 0; i < count; i++)
1421 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1422 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1428 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1430 char *errfmt = "List of Rule%s";
1431 unsigned errret = 0;
1432 OTF_StreamState state;
1436 READ_UINT16 (stream, count);
1438 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1439 OTF_MALLOC (*rule, count, "");
1440 for (i = 0; i < count; i++)
1442 READ_OFFSET (stream, (*rule)[i].offset);
1443 if (! (*rule)[i].offset)
1444 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1446 SAVE_STREAM (stream, state);
1447 for (i = 0; i < count; i++)
1449 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1450 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1451 if ((*rule)[i].GlyphCount == 0)
1452 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1453 READ_UINT16 (stream, (*rule)[i].LookupCount);
1454 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1455 (*rule)[i].GlyphCount) < 0)
1457 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1458 (*rule)[i].LookupCount) == 0)
1461 RESTORE_STREAM (stream, state);
1467 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1470 char *errfmt = "List of RuleSet%s";
1471 unsigned errret = 0;
1472 OTF_StreamState state;
1476 READ_UINT16 (stream, count);
1478 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1479 OTF_MALLOC (*set, count, "");
1480 for (i = 0; i < count; i++)
1482 READ_OFFSET (stream, (*set)[i].offset);
1483 if (! (*set)[i].offset)
1484 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1486 SAVE_STREAM (stream, state);
1487 for (i = 0; i < count; i++)
1489 SEEK_STREAM (stream, offset + (*set)[i].offset);
1491 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1493 if (! (*set)[i].RuleCount)
1496 RESTORE_STREAM (stream, state);
1501 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1502 OTF_ClassRule **rule)
1504 char *errfmt = "ClassRule%s";
1505 unsigned errret = 0;
1506 OTF_StreamState state;
1510 READ_UINT16 (stream, count);
1512 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1513 OTF_MALLOC (*rule, count, "");
1514 for (i = 0; i < count; i++)
1516 READ_OFFSET (stream, (*rule)[i].offset);
1517 if (! (*rule)[i].offset)
1518 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1520 SAVE_STREAM (stream, state);
1521 for (i = 0; i < count; i++)
1523 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1524 READ_USHORT (stream, (*rule)[i].GlyphCount);
1525 if (! (*rule)[i].GlyphCount)
1526 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1527 READ_USHORT (stream, (*rule)[i].LookupCount);
1528 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1529 0, (*rule)[i].GlyphCount - 1) < 0)
1531 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1532 (*rule)[i].LookupCount) == 0)
1535 RESTORE_STREAM (stream, state);
1540 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1543 char *errfmt = "ClassSet%s";
1544 unsigned errret = 0;
1545 OTF_StreamState state;
1549 READ_UINT16 (stream, count);
1551 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1552 OTF_CALLOC (*set, count, "");
1553 for (i = 0; i < count; i++)
1554 /* Offset can be zero. */
1555 READ_OFFSET (stream, (*set)[i].offset);
1556 SAVE_STREAM (stream, state);
1557 for (i = 0; i < count; i++)
1558 if ((*set)[i].offset)
1560 SEEK_STREAM (stream, offset + (*set)[i].offset);
1561 (*set)[i].ClassRuleCnt
1562 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1563 &(*set)[i].ClassRule);
1564 if (! (*set)[i].ClassRuleCnt)
1567 RESTORE_STREAM (stream, state);
1572 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1573 OTF_ChainRule **rule)
1575 char *errfmt = "ChainRule%s";
1576 unsigned errret = 0;
1580 READ_UINT16 (stream, count);
1582 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1583 OTF_MALLOC (*rule, count, "");
1584 for (i = 0; i < count; i++)
1585 READ_OFFSET (stream, (*rule)[i].offset);
1586 for (i = 0; i < count; i++)
1588 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1589 (*rule)[i].BacktrackGlyphCount
1590 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1591 (*rule)[i].InputGlyphCount
1592 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1593 if (! (*rule)[i].InputGlyphCount)
1594 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1595 (*rule)[i].LookaheadGlyphCount
1596 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1597 (*rule)[i].LookupCount
1598 = read_lookup_record_list (otf, stream,
1599 &(*rule)[i].LookupRecord, -1);
1600 if (! (*rule)[i].LookupCount)
1608 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1609 OTF_ChainRuleSet **set)
1611 char *errfmt = "ChainRuleSet%s";
1612 unsigned errret = 0;
1613 OTF_StreamState state;
1617 READ_UINT16 (stream, count);
1619 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1620 OTF_MALLOC (*set, count, "");
1621 for (i = 0; i < count; i++)
1623 READ_OFFSET (stream, (*set)[i].offset);
1624 if (! (*set)[i].offset)
1625 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1627 SAVE_STREAM (stream, state);
1628 for (i = 0; i < count; i++)
1630 SEEK_STREAM (stream, offset + (*set)[i].offset);
1631 (*set)[i].ChainRuleCount
1632 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1633 &(*set)[i].ChainRule);
1634 if (! (*set)[i].ChainRuleCount)
1637 RESTORE_STREAM (stream, state);
1642 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1643 OTF_ChainClassRule **rule)
1645 char *errfmt = "ChainClassRule%s";
1646 unsigned errret = 0;
1650 READ_UINT16 (stream, count);
1652 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1653 OTF_MALLOC (*rule, count, "");
1654 for (i = 0; i < count; i++)
1656 READ_OFFSET (stream, (*rule)[i].offset);
1657 if (! (*rule)[i].offset)
1658 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1660 for (i = 0; i < count; i++)
1662 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1663 (*rule)[i].BacktrackGlyphCount
1664 = read_glyph_ids (otf, stream,
1665 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1666 (*rule)[i].InputGlyphCount
1667 = read_glyph_ids (otf, stream,
1668 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1669 if (! (*rule)[i].InputGlyphCount)
1670 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1671 (*rule)[i].LookaheadGlyphCount
1672 = read_glyph_ids (otf, stream,
1673 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1674 (*rule)[i].LookupCount
1675 = read_lookup_record_list (otf, stream,
1676 &(*rule)[i].LookupRecord, -1);
1677 if (! (*rule)[i].LookupCount)
1684 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1685 OTF_ChainClassSet **set)
1687 char *errfmt = "ChainClassSet%s";
1688 unsigned errret = 0;
1689 OTF_StreamState state;
1693 READ_UINT16 (stream, count);
1695 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1696 OTF_MALLOC (*set, count, "");
1697 for (i = 0; i < count; i++)
1698 /* Offset may be zero. */
1699 READ_OFFSET (stream, (*set)[i].offset);
1700 SAVE_STREAM (stream, state);
1701 for (i = 0; i < count; i++)
1702 if ((*set)[i].offset)
1704 SEEK_STREAM (stream, offset + (*set)[i].offset);
1705 (*set)[i].ChainClassRuleCnt
1706 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1707 &(*set)[i].ChainClassRule);
1708 if (! (*set)[i].ChainClassRuleCnt)
1711 RESTORE_STREAM (stream, state);
1716 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1717 OTF_Coverage *coverage,OTF_Context1 *context1)
1719 if (read_coverage (otf, stream, offset, coverage) < 0)
1721 context1->RuleSetCount
1722 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1723 if (! context1->RuleSetCount)
1729 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1730 OTF_Coverage *coverage,OTF_Context2 *context2)
1732 if (read_coverage (otf, stream, offset, coverage) < 0
1733 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1735 context2->ClassSetCnt
1736 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1737 if (! context2->ClassSetCnt)
1743 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1744 OTF_Coverage *coverage,OTF_Context3 *context3)
1746 char *errfmt = "Context1%s";
1749 READ_USHORT (stream, context3->GlyphCount);
1750 if (context3->GlyphCount < 0)
1751 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1752 READ_USHORT (stream, context3->LookupCount);
1753 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1754 context3->GlyphCount) < 0)
1756 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1757 context3->LookupCount) < 0)
1763 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1764 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1766 if (read_coverage (otf, stream, offset, coverage) < 0)
1768 chain_context1->ChainRuleSetCount
1769 = read_chain_rule_set_list (otf, stream, offset,
1770 &chain_context1->ChainRuleSet);
1771 if (! chain_context1->ChainRuleSetCount)
1777 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1778 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1780 if (read_coverage (otf, stream, offset, coverage) < 0
1781 || read_class_def (otf, stream, offset,
1782 &chain_context2->BacktrackClassDef) < 0
1783 || read_class_def (otf, stream, offset,
1784 &chain_context2->InputClassDef) < 0
1785 || read_class_def (otf, stream, offset,
1786 &chain_context2->LookaheadClassDef) < 0)
1788 chain_context2->ChainClassSetCnt
1789 = read_chain_class_set_list (otf, stream, offset,
1790 &chain_context2->ChainClassSet);
1791 if (! chain_context2->ChainClassSetCnt)
1797 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1798 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1802 count = read_coverage_list (otf, stream, offset,
1803 &chain_context3->Backtrack, -1);
1806 chain_context3->BacktrackGlyphCount = (unsigned) count;
1807 count = read_coverage_list (otf, stream, offset,
1808 &chain_context3->Input, -1);
1811 chain_context3->InputGlyphCount = (unsigned) count;
1812 *coverage = chain_context3->Input[0];
1813 count = read_coverage_list (otf, stream, offset,
1814 &chain_context3->LookAhead, -1);
1815 chain_context3->LookaheadGlyphCount = (unsigned) count;
1816 chain_context3->LookupCount
1817 = read_lookup_record_list (otf, stream,
1818 &chain_context3->LookupRecord, -1);
1823 read_gsub_gpos_table (OTF *otf, OTF_TableInfo *table, int gsubp,
1824 enum OTF_ReaderFlag flag)
1826 OTF_Stream *stream = table->stream;
1827 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1828 void *errret = NULL;
1829 OTF_GSUB_GPOS *gsub_gpos = *table->address;
1832 SEEK_STREAM (stream, 10);
1835 SEEK_STREAM (stream, 0);
1836 OTF_CALLOC (gsub_gpos, 1, "");
1837 READ_FIXED (stream, gsub_gpos->Version);
1838 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1839 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1840 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1841 *table->address = gsub_gpos;
1844 if (! gsub_gpos->ScriptList.Script
1845 && read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1846 &gsub_gpos->ScriptList) < 0)
1848 if (flag != OTF_READ_SCRIPTS)
1850 if (! gsub_gpos->FeatureList.Feature
1851 && read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1852 &gsub_gpos->FeatureList) < 0)
1854 if (flag != OTF_READ_FEATURES)
1856 if (! gsub_gpos->LookupList.Lookup
1857 && read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1858 &gsub_gpos->LookupList, gsubp) < 0)
1867 /* (1-9) "GSUB" table */
1870 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1872 char *errfmt = "Sequence%s";
1873 unsigned errret = 0;
1877 READ_UINT16 (stream, count);
1879 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1880 OTF_MALLOC (*seq, count, "");
1881 for (i = 0; i < count; i++)
1882 READ_OFFSET (stream, (*seq)[i].offset);
1883 for (i = 0; i < count; i++)
1885 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1886 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1887 &(*seq)[i].Substitute, 0, -1);
1888 if (! (*seq)[i].GlyphCount)
1895 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1896 OTF_Ligature **ligature)
1898 char *errfmt = "Ligature%s";
1903 READ_UINT16 (stream, count);
1906 OTF_MALLOC (*ligature, count, "");
1907 for (i = 0; i < count; i++)
1908 READ_OFFSET (stream, (*ligature)[i].offset);
1909 for (i = 0; i < count; i++)
1911 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1912 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1913 (*ligature)[i].CompCount
1914 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1915 if (! (*ligature)[i].CompCount)
1922 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1923 OTF_LigatureSet **ligset)
1925 char *errfmt = "LigatureSet%s";
1930 READ_UINT16 (stream, count);
1933 OTF_MALLOC (*ligset, count, "");
1934 for (i = 0; i < count; i++)
1935 READ_OFFSET (stream, (*ligset)[i].offset);
1936 for (i = 0; i < count; i++)
1940 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1941 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1942 &(*ligset)[i].Ligature);
1945 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1951 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1952 OTF_AlternateSet **altset)
1954 char *errfmt = "AlternateSet%s";
1959 READ_UINT16 (stream, count);
1961 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1962 OTF_MALLOC (*altset, count, "");
1963 for (i = 0; i < count; i++)
1964 READ_OFFSET (stream, (*altset)[i].offset);
1965 for (i = 0; i < count; i++)
1969 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1970 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1973 (*altset)[i].GlyphCount = (unsigned) alt_count;
1979 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1980 OTF_Coverage *coverage,
1981 OTF_GSUB_ReverseChain1 *reverse_chain)
1985 if (read_coverage (otf, stream, offset, coverage) < 0)
1987 count = read_coverage_list (otf, stream, offset,
1988 &reverse_chain->Backtrack, -1);
1991 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1992 count = read_coverage_list (otf, stream, offset,
1993 &reverse_chain->LookAhead, -1);
1996 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1997 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
2000 reverse_chain->GlyphCount = count;
2005 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
2006 unsigned type, OTF_LookupSubTableGSUB *subtable)
2011 SEEK_STREAM (stream, offset);
2012 READ_USHORT (stream, subtable->Format);
2013 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
2017 if (subtable->Format == 1)
2019 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2021 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
2023 else if (subtable->Format == 2)
2025 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2027 subtable->u.single2.GlyphCount
2028 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
2030 if (! subtable->u.single2.GlyphCount)
2034 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2038 if (subtable->Format == 1)
2040 read_coverage (otf, stream, offset, &subtable->Coverage);
2041 subtable->u.multiple1.SequenceCount
2042 = read_sequence (otf, stream, offset,
2043 &subtable->u.multiple1.Sequence);
2046 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2050 if (subtable->Format == 1)
2052 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2054 subtable->u.alternate1.AlternateSetCount
2055 = read_alternate_set_list (otf, stream, offset,
2056 &subtable->u.alternate1.AlternateSet);
2057 if (! subtable->u.alternate1.AlternateSetCount)
2061 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2065 if (subtable->Format == 1)
2067 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2069 subtable->u.ligature1.LigSetCount
2070 = read_ligature_set_list (otf, stream, offset,
2071 &subtable->u.ligature1.LigatureSet);
2072 if (! subtable->u.ligature1.LigSetCount)
2076 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2080 if (subtable->Format == 1)
2082 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2083 &subtable->u.context1) < 0)
2086 else if (subtable->Format == 2)
2088 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2089 &subtable->u.context2) < 0)
2092 else if (subtable->Format == 3)
2094 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2095 &subtable->u.context3) < 0)
2099 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2103 if (subtable->Format == 1)
2105 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2106 &subtable->u.chain_context1) < 0)
2109 else if (subtable->Format == 2)
2111 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2112 &subtable->u.chain_context2) < 0)
2115 else if (subtable->Format == 3)
2117 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2118 &subtable->u.chain_context3) < 0)
2122 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2126 if (subtable->Format == 1)
2130 OTF_LookupSubTableGSUB *ex_subtable;
2132 READ_USHORT (stream, ex_type);
2133 READ_ULONG (stream, ex_offset);
2134 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2135 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
2136 ex_type, ex_subtable) < 0)
2138 subtable->u.extension1.ExtensionLookupType = ex_type;
2139 subtable->u.extension1.ExtensionOffset = ex_offset;
2140 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2143 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2147 if (subtable->Format == 1)
2149 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
2150 &subtable->u.reverse_chain1) < 0)
2154 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2158 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2164 read_gsub_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2166 return read_gsub_gpos_table (otf, table, 1, flag);
2170 /* (1-10) "GPOS" table */
2173 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
2174 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
2177 OTF_StreamState state;
2180 memset (value_record, 0, sizeof (OTF_ValueRecord));
2183 for (i = 0, size = 0; i < 8; i++)
2187 if (bit & OTF_XPlacement)
2188 READ_INT16 (stream, value_record->XPlacement);
2189 if (bit & OTF_YPlacement)
2190 READ_INT16 (stream, value_record->YPlacement);
2191 if (bit & OTF_XAdvance)
2192 READ_INT16 (stream, value_record->XAdvance);
2193 if (bit & OTF_YAdvance)
2194 READ_INT16 (stream, value_record->YAdvance);
2195 if (bit & OTF_XPlaDevice)
2196 READ_OFFSET (stream, value_record->XPlaDevice.offset);
2197 if (bit & OTF_YPlaDevice)
2198 READ_OFFSET (stream, value_record->YPlaDevice.offset);
2199 if (bit & OTF_XAdvDevice)
2200 READ_OFFSET (stream, value_record->XAdvDevice.offset);
2201 if (bit & OTF_YAdvDevice)
2202 READ_OFFSET (stream, value_record->YAdvDevice.offset);
2203 SAVE_STREAM (stream, state);
2204 if (value_record->XPlaDevice.offset)
2206 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
2209 if (value_record->YPlaDevice.offset)
2211 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
2214 if (value_record->XAdvDevice.offset)
2216 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
2219 if (value_record->YAdvDevice.offset)
2221 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
2224 RESTORE_STREAM (stream, state);
2230 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
2232 char *errfmt = "Anchor%s";
2235 SEEK_STREAM (stream, offset + anchor->offset);
2236 READ_UINT16 (stream, anchor->AnchorFormat);
2237 READ_INT16 (stream, anchor->XCoordinate);
2238 READ_INT16 (stream, anchor->YCoordinate);
2239 if (anchor->AnchorFormat == 1)
2241 else if (anchor->AnchorFormat == 2)
2243 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
2245 else if (anchor->AnchorFormat == 3)
2247 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
2248 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
2249 if (anchor->f.f2.XDeviceTable.offset)
2251 if (read_device_table (otf, stream, offset + anchor->offset,
2252 &anchor->f.f2.XDeviceTable) < 0)
2255 if (anchor->f.f2.YDeviceTable.offset)
2257 if (read_device_table (otf, stream, offset + anchor->offset,
2258 &anchor->f.f2.YDeviceTable) < 0)
2263 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
2269 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
2270 OTF_MarkArray *array)
2272 char *errfmt = "MarkArray%s";
2274 OTF_StreamState state;
2277 READ_OFFSET (stream, array->offset);
2278 SAVE_STREAM (stream, state);
2279 SEEK_STREAM (stream, offset + array->offset);
2280 READ_UINT16 (stream, array->MarkCount);
2281 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
2282 for (i = 0; i < array->MarkCount; i++)
2284 READ_UINT16 (stream, array->MarkRecord[i].Class);
2285 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
2287 for (i = 0; i < array->MarkCount; i++)
2288 if (read_anchor (otf, stream, offset + array->offset,
2289 &array->MarkRecord[i].MarkAnchor) < 0)
2291 RESTORE_STREAM (stream, state);
2296 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
2297 unsigned ClassCount, OTF_AnchorArray *array)
2299 char *errfmt = "AnchorArray%s";
2301 OTF_StreamState state;
2304 READ_OFFSET (stream, array->offset);
2305 SAVE_STREAM (stream, state);
2306 SEEK_STREAM (stream, offset + array->offset);
2307 READ_UINT16 (stream, array->Count);
2308 OTF_MALLOC (array->AnchorRecord, array->Count, "");
2309 for (i = 0; i < array->Count; i++)
2311 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
2313 for (j = 0; j < ClassCount; j++)
2314 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
2316 for (i = 0; i < array->Count; i++)
2317 for (j = 0; j < ClassCount; j++)
2318 if (read_anchor (otf, stream, offset + array->offset,
2319 &array->AnchorRecord[i].Anchor[j]) < 0)
2321 RESTORE_STREAM (stream, state);
2325 static OTF_PairSet *
2326 read_pair_set_list (OTF *otf, OTF_Stream *stream, long offset, unsigned num,
2327 enum OTF_ValueFormat bit1, enum OTF_ValueFormat bit2)
2329 char *errfmt = "PairSet%s";
2330 void *errret = NULL;
2331 OTF_StreamState state;
2335 OTF_MALLOC (set, num, "");
2336 for (i = 0; i < num; i++)
2337 READ_OFFSET (stream, set[i].offset);
2338 SAVE_STREAM (stream, state);
2339 for (i = 0; i < num; i++)
2341 SEEK_STREAM (stream, offset + set[i].offset);
2342 READ_UINT16 (stream, set[i].PairValueCount);
2343 OTF_MALLOC (set[i].PairValueRecord, set[i].PairValueCount, "");
2344 for (j = 0; j < set[i].PairValueCount; j++)
2346 OTF_PairValueRecord *rec = set[i].PairValueRecord + j;
2348 READ_UINT16 (stream, rec->SecondGlyph);
2349 read_value_record (otf, stream, offset, bit1, &rec->Value1);
2350 read_value_record (otf, stream, offset, bit2, &rec->Value2);
2353 RESTORE_STREAM (stream, state);
2357 static OTF_Class1Record *
2358 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
2359 unsigned num1, enum OTF_ValueFormat bit1,
2360 unsigned num2, enum OTF_ValueFormat bit2)
2362 char *errfmt = "Class1Record%s";
2363 void *errret = NULL;
2364 OTF_Class1Record *rec;
2367 OTF_MALLOC (rec, num1, "");
2368 for (i = 0; i < num1; i++)
2370 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
2371 for (j = 0; j < num2; j++)
2373 if (read_value_record (otf, stream, offset,
2374 bit1, &rec[i].Class2Record[j].Value1) < 0
2375 || read_value_record (otf, stream, offset,
2376 bit2, &rec[i].Class2Record[j].Value2) < 0)
2384 read_entry_exit_list (OTF *otf, OTF_Stream *stream, long offset,
2385 OTF_EntryExitRecord **rec)
2387 char *errfmt = "EntryExitSet%s";
2391 OTF_StreamState state;
2393 READ_UINT16 (stream, count);
2395 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
2396 OTF_MALLOC (*rec, count, "");
2397 for (i = 0; i < count; i++)
2399 READ_OFFSET (stream, (*rec)[i].EntryAnchor.offset);
2400 READ_OFFSET (stream, (*rec)[i].ExitAnchor.offset);
2402 SAVE_STREAM (stream, state);
2403 for (i = 0; i < count; i++)
2405 if (read_anchor (otf, stream, offset, &(*rec)[i].EntryAnchor) < 0)
2407 if (read_anchor (otf, stream, offset, &(*rec)[i].ExitAnchor) < 0)
2410 RESTORE_STREAM (stream, state);
2415 read_ligature_attach (OTF *otf, OTF_Stream *stream, long offset,
2416 unsigned ClassCount, OTF_LigatureAttach *attach)
2418 char *errfmt = "LigatureAttach%s";
2422 SEEK_STREAM (stream, offset + attach->offset);
2423 READ_UINT16 (stream, attach->ComponentCount);
2424 OTF_MALLOC (attach->ComponentRecord, attach->ComponentCount, "");
2425 for (i = 0; i < attach->ComponentCount; i++)
2427 OTF_MALLOC (attach->ComponentRecord[i].LigatureAnchor, ClassCount,
2428 " (ComponentRecord)");
2429 for (j = 0; j < ClassCount; j++)
2430 READ_OFFSET (stream,
2431 attach->ComponentRecord[i].LigatureAnchor[j].offset);
2433 for (i = 0; i < attach->ComponentCount; i++)
2434 for (j = 0; j < ClassCount; j++)
2436 if (attach->ComponentRecord[i].LigatureAnchor[j].offset)
2438 if (read_anchor (otf, stream, offset + attach->offset,
2439 &attach->ComponentRecord[i].LigatureAnchor[j]) < 0)
2443 attach->ComponentRecord[i].LigatureAnchor[j].AnchorFormat = 0;
2449 read_ligature_array (OTF *otf, OTF_Stream *stream, long offset,
2450 unsigned class_count, OTF_LigatureArray *array)
2452 char *errfmt = "LigatureArray%s";
2454 OTF_StreamState state;
2457 READ_OFFSET (stream, array->offset);
2458 SAVE_STREAM (stream, state);
2459 SEEK_STREAM (stream, offset + array->offset);
2460 READ_UINT16 (stream, array->LigatureCount);
2461 OTF_MALLOC (array->LigatureAttach, array->LigatureCount, "");
2462 for (i = 0; i < array->LigatureCount; i++)
2463 READ_OFFSET (stream, array->LigatureAttach[i].offset);
2464 for (i = 0; i < array->LigatureCount; i++)
2465 read_ligature_attach (otf, stream, offset + array->offset,
2466 class_count, array->LigatureAttach + i);
2467 RESTORE_STREAM (stream, state);
2472 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
2473 long offset, unsigned type,
2474 OTF_LookupSubTableGPOS *subtable)
2479 SEEK_STREAM (stream, offset);
2480 READ_UINT16 (stream, subtable->Format);
2481 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2485 if (subtable->Format == 1)
2487 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2489 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2490 read_value_record (otf, stream, offset,
2491 subtable->u.single1.ValueFormat,
2492 &subtable->u.single1.Value);
2494 else if (subtable->Format == 2)
2496 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2499 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2501 READ_UINT16 (stream, single2->ValueFormat);
2502 READ_UINT16 (stream, single2->ValueCount);
2503 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2504 for (i = 0; i < single2->ValueCount; i++)
2505 read_value_record (otf, stream, offset, single2->ValueFormat,
2506 single2->Value + i);
2509 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2513 if (subtable->Format == 1)
2515 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2517 READ_UINT16 (stream, subtable->u.pair1.ValueFormat1);
2518 READ_UINT16 (stream, subtable->u.pair1.ValueFormat2);
2519 READ_UINT16 (stream, subtable->u.pair1.PairSetCount);
2520 subtable->u.pair1.PairSet
2521 = read_pair_set_list (otf, stream, offset,
2522 subtable->u.pair1.PairSetCount,
2523 subtable->u.pair1.ValueFormat1,
2524 subtable->u.pair1.ValueFormat2);
2525 if (! subtable->u.pair1.PairSet)
2528 else if (subtable->Format == 2)
2530 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2532 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2533 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2534 if (read_class_def (otf, stream, offset,
2535 &subtable->u.pair2.ClassDef1) < 0
2536 || read_class_def (otf, stream, offset,
2537 &subtable->u.pair2.ClassDef2) < 0)
2539 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2540 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2541 subtable->u.pair2.Class1Record
2542 = read_class1_record_list (otf, stream, offset,
2543 subtable->u.pair2.Class1Count,
2544 subtable->u.pair2.ValueFormat1,
2545 subtable->u.pair2.Class2Count,
2546 subtable->u.pair2.ValueFormat2);
2547 if (! subtable->u.pair2.Class1Record)
2551 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2555 if (subtable->Format == 1)
2557 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2559 subtable->u.cursive1.EntryExitCount
2560 = read_entry_exit_list (otf, stream, offset,
2561 &subtable->u.cursive1.EntryExitRecord);
2562 if (! subtable->u.cursive1.EntryExitCount)
2566 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2570 if (subtable->Format == 1)
2572 read_coverage (otf, stream, offset, &subtable->Coverage);
2573 read_coverage (otf, stream, offset,
2574 &subtable->u.mark_base1.BaseCoverage);
2575 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2576 read_mark_array (otf, stream, offset,
2577 &subtable->u.mark_base1.MarkArray);
2578 read_anchor_array (otf, stream, offset,
2579 subtable->u.mark_base1.ClassCount,
2580 &subtable->u.mark_base1.BaseArray);
2583 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2587 if (subtable->Format == 1)
2589 read_coverage (otf, stream, offset, &subtable->Coverage);
2590 read_coverage (otf, stream, offset,
2591 &subtable->u.mark_lig1.LigatureCoverage);
2592 READ_UINT16 (stream, subtable->u.mark_lig1.ClassCount);
2593 read_mark_array (otf, stream, offset,
2594 &subtable->u.mark_lig1.MarkArray);
2595 read_ligature_array (otf, stream, offset,
2596 subtable->u.mark_lig1.ClassCount,
2597 &subtable->u.mark_lig1.LigatureArray);
2602 if (subtable->Format == 1)
2604 read_coverage (otf, stream, offset, &subtable->Coverage);
2605 read_coverage (otf, stream, offset,
2606 &subtable->u.mark_mark1.Mark2Coverage);
2607 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2608 read_mark_array (otf, stream, offset,
2609 &subtable->u.mark_mark1.Mark1Array);
2610 read_anchor_array (otf, stream, offset,
2611 subtable->u.mark_mark1.ClassCount,
2612 &subtable->u.mark_mark1.Mark2Array);
2615 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2619 if (subtable->Format == 1)
2621 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2622 &subtable->u.context1) < 0)
2625 else if (subtable->Format == 2)
2627 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2628 &subtable->u.context2) < 0)
2631 else if (subtable->Format == 3)
2633 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2634 &subtable->u.context3) < 0)
2638 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2642 if (subtable->Format == 1)
2644 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2645 &subtable->u.chain_context1) < 0)
2648 else if (subtable->Format == 2)
2650 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2651 &subtable->u.chain_context2) < 0)
2654 else if (subtable->Format == 3)
2656 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2657 &subtable->u.chain_context3) < 0)
2661 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2665 if (subtable->Format == 1)
2669 OTF_LookupSubTableGPOS *ex_subtable;
2671 READ_USHORT (stream, ex_type);
2672 READ_ULONG (stream, ex_offset);
2673 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2674 if (read_lookup_subtable_gpos (otf, stream, offset + ex_offset,
2675 ex_type, ex_subtable) < 0)
2677 subtable->u.extension1.ExtensionLookupType = ex_type;
2678 subtable->u.extension1.ExtensionOffset = ex_offset;
2679 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2682 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2686 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2692 read_gpos_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2694 return read_gsub_gpos_table (otf, table, 0, flag);
2702 read_base_table (OTF_Stream *stream, long offset)
2706 OTF_MALLOC (base, 1);
2715 read_jstf_table (OTF_Stream *stream, long offset)
2719 OTF_MALLOC (jstf, 1);
2725 /*** (1-11) Structure for OTF */
2728 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2732 READ_FIXED (stream, table->sfnt_version);
2733 READ_USHORT (stream, table->numTables);
2734 READ_USHORT (stream, table->searchRange);
2735 READ_USHORT (stream, table->enterSelector);
2736 READ_USHORT (stream, table->rangeShift);
2741 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2746 READ_TAG (stream, tag);
2748 table->name[0] = tag >> 24;
2749 table->name[1] = (tag >> 16) & 0xFF;
2750 table->name[2] = (tag >> 8) & 0xFF;
2751 table->name[3] = tag & 0xFF;
2752 table->name[4] = '\0';
2753 READ_ULONG (stream, table->checkSum);
2754 READ_ULONG (stream, table->offset);
2755 READ_ULONG (stream, table->length);
2760 read_header_part (OTF *otf, FILE *fp, FT_Face face)
2762 char *errfmt = "otf header%s";
2765 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2767 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2768 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2769 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2770 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2771 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2772 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2773 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2774 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2775 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2776 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2777 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2778 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2782 OTF_Tag head_tag = OTF_tag ("head");
2783 OTF_Tag name_tag = OTF_tag ("name");
2784 OTF_Tag cmap_tag = OTF_tag ("cmap");
2785 OTF_Tag gdef_tag = OTF_tag ("GDEF");
2786 OTF_Tag gsub_tag = OTF_tag ("GSUB");
2787 OTF_Tag gpos_tag = OTF_tag ("GPOS");
2788 OTF_Stream *stream = make_stream ("Offset Table");
2792 internal_data->header_stream = stream;
2794 /* Size of Offset Table is 12 bytes. */
2795 if (setup_stream (stream, fp, 0, 12) < 0)
2797 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2800 /* Size of each Table Directory is 16 bytes. */
2801 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables) < 0)
2804 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables,
2806 for (i = 0; i < otf->offset_table.numTables; i++)
2808 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2809 OTF_TableInfo *table_info = NULL;
2813 if (tag == head_tag)
2814 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2815 else if (tag == name_tag)
2816 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2817 else if (tag == cmap_tag)
2818 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2819 else if (tag == gdef_tag)
2820 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2821 else if (tag == gsub_tag)
2822 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2823 else if (tag == gpos_tag)
2824 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2828 table_info->stream = make_stream (otf->table_dirs[i].name);
2829 if (setup_stream (table_info->stream, fp,
2830 otf->table_dirs[i].offset,
2831 otf->table_dirs[i].length) < 0)
2836 internal_data->header_stream = NULL;
2837 free_stream (stream);
2843 internal_data->header_stream = NULL;
2844 if ((stream = make_stream_from_ft_face (face, "head")))
2845 internal_data->table_info[OTF_TABLE_TYPE_HEAD].stream = stream;
2846 if ((stream = make_stream_from_ft_face (face, "name")))
2847 internal_data->table_info[OTF_TABLE_TYPE_NAME].stream = stream;
2848 if ((stream = make_stream_from_ft_face (face, "cmap")))
2849 internal_data->table_info[OTF_TABLE_TYPE_CMAP].stream = stream;
2850 if ((stream = make_stream_from_ft_face (face, "GDEF")))
2851 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream = stream;
2852 if ((stream = make_stream_from_ft_face (face, "GSUB")))
2853 internal_data->table_info[OTF_TABLE_TYPE_GSUB].stream = stream;
2854 if ((stream = make_stream_from_ft_face (face, "GPOS")))
2855 internal_data->table_info[OTF_TABLE_TYPE_GPOS].stream = stream;
2858 if (! internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream)
2859 /* We can simulate the GDEF table. */
2860 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream
2861 = make_stream ("GDEF");
2865 static OTF_TableInfo *
2866 get_table_info (OTF *otf, const char *name)
2868 char *errfmt = "OTF Table Read%s";
2869 OTF_TableInfo *errret = NULL;
2870 OTF_InternalData *internal_data = otf->internal_data;
2871 OTF_TableInfo *table_info;
2872 OTF_Tag tag = OTF_tag (name);
2875 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2877 if (tag == OTF_tag ("head"))
2878 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2879 else if (tag == OTF_tag ("name"))
2880 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2881 else if (tag == OTF_tag ("cmap"))
2882 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2883 else if (tag == OTF_tag ("GDEF"))
2884 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2885 else if (tag == OTF_tag ("GSUB"))
2886 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2887 else if (tag == OTF_tag ("GPOS"))
2888 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2890 OTF_ERROR (OTF_ERROR_TABLE, " (unsupported table name)");
2892 if (*table_info->address)
2895 if (! table_info->stream)
2896 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2897 if (! table_info->reader)
2898 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2904 /*** (2) API for reading OTF */
2906 /*** (2-1) OTF_open() */
2908 /* Note: We can't use memory allocation macros in the following
2909 functions because those macros return from the functions before
2910 freeing memory previously allocated. */
2913 OTF_open (const char *otf_name)
2916 char *errfmt = "opening otf (%s)";
2917 void *errret = NULL;
2919 OTF_InternalData *internal_data;
2920 int len = strlen (otf_name);
2921 const char *ext = otf_name + (len - 4);
2925 || (ext[1] != 'O' && ext[1] != 'T' && ext[1] != 'o' && ext[1] != 't')
2926 || (ext[2] != 'T' && ext[2] != 't')
2927 || (ext[3] != 'F' && ext[3] != 'f'))
2928 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2929 fp = fopen (otf_name, "r");
2931 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2932 otf = calloc (1, sizeof (OTF));
2934 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2935 otf->filename = strdup (otf_name);
2936 if (! otf->filename)
2940 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2943 internal_data = calloc (1, sizeof (OTF_InternalData));
2944 if (! internal_data)
2945 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2946 otf->internal_data = internal_data;
2947 if (! allocate_memory_record (otf))
2948 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2950 /* Here after, all pointers to allocated memory are recorded in
2951 otf->internal_data->memory_record except for what allocated by
2952 the functions allocate_memory_record and make_stream. */
2954 if (read_header_part (otf, fp, NULL) < 0)
2966 OTF_open_ft_face (FT_Face face)
2968 char *errfmt = "opening otf from Freetype (%s)";
2969 void *errret = NULL;
2971 OTF_InternalData *internal_data;
2973 if (! FT_IS_SFNT (face))
2974 OTF_ERROR (OTF_ERROR_FILE, (char *) face->family_name);
2975 otf = calloc (1, sizeof (OTF));
2977 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2978 otf->filename = NULL;
2980 internal_data = calloc (1, sizeof (OTF_InternalData));
2981 if (! internal_data)
2982 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2983 otf->internal_data = internal_data;
2984 if (! allocate_memory_record (otf))
2985 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2987 if (read_header_part (otf, NULL, face) < 0)
2996 /*** (2-2) OTF_close() */
2999 OTF_close (OTF *otf)
3001 OTF_InternalData *internal_data = otf->internal_data;
3006 OTF_MemoryRecord *memrec = internal_data->memory_record;
3008 if (internal_data->header_stream)
3009 free_stream (internal_data->header_stream);
3011 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
3012 if (internal_data->table_info[i].stream)
3013 free_stream (internal_data->table_info[i].stream);
3017 OTF_MemoryRecord *next = memrec->next;
3019 for (i = memrec->used - 1; i >= 0; i--)
3020 free (memrec->memory[i]);
3024 free (internal_data);
3027 free (otf->filename);
3031 /*** (2-3) OTF_get_table() */
3034 OTF_get_table (OTF *otf, const char *name)
3036 OTF_TableInfo *table_info = get_table_info (otf, name);
3041 if (! table_info->stream)
3042 /* Already fully loaded. */
3045 address = (*table_info->reader) (otf, table_info, OTF_READ_FULL);
3046 free_stream (table_info->stream);
3047 table_info->stream = NULL;
3050 table_info->reader = NULL;
3056 /*** (2-4) OTF_check_table() */
3059 OTF_check_table (OTF *otf, const char *name)
3061 return (get_table_info (otf, name) ? 0 : -1);
3064 /*** (2-5) OTF_get_scripts() */
3067 OTF_get_scripts (OTF *otf, int gsubp)
3069 OTF_TableInfo *table_info
3070 = (otf->internal_data->table_info
3071 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3074 if (! table_info->reader)
3076 if (! table_info->stream)
3077 /* Already fully loaded. */
3080 address = (*table_info->reader) (otf, table_info, OTF_READ_SCRIPTS);
3083 table_info->reader = NULL;
3089 /*** (2-6) OTF_get_features() */
3092 OTF_get_features (OTF *otf, int gsubp)
3094 OTF_TableInfo *table_info
3095 = (otf->internal_data->table_info
3096 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3099 if (! table_info->reader)
3101 if (! table_info->stream)
3103 if (*table_info->address)
3104 /* Already fully loaded. */
3109 address = (*table_info->reader) (otf, table_info, OTF_READ_FEATURES);
3112 table_info->reader = NULL;
3118 /*** (2-7) OTF_check_features */
3121 OTF_check_features (OTF *otf, int gsubp,
3122 OTF_Tag script, OTF_Tag language, const OTF_Tag *features,
3125 OTF_ScriptList *script_list;
3126 OTF_Script *Script = NULL;
3127 OTF_LangSys *LangSys = NULL;
3128 OTF_FeatureList *feature_list;
3131 if (OTF_get_features (otf, gsubp) < 0)
3133 for (i = 0; i < n_features; i++)
3135 OTF_Tag feature = features[i];
3139 if ((((unsigned) feature) & 0x80000000) == 0)
3146 script_list = &otf->gsub->ScriptList;
3147 feature_list = &otf->gsub->FeatureList;
3151 script_list = &otf->gpos->ScriptList;
3152 feature_list = &otf->gpos->FeatureList;
3154 for (i = 0; i < script_list->ScriptCount && ! Script; i++)
3155 if (script_list->Script[i].ScriptTag == script)
3156 Script = script_list->Script + i;
3161 for (i = 0; i < Script->LangSysCount && ! LangSys; i++)
3162 if (Script->LangSysRecord[i].LangSysTag == language)
3163 LangSys = Script->LangSys + i;
3166 LangSys = &Script->DefaultLangSys;
3167 for (j = 0; j < n_features; j++)
3169 OTF_Tag feature = features[j];
3174 if (((unsigned) feature) & 0x80000000)
3176 feature = (OTF_Tag) (((unsigned) feature) & 0x7FFFFFFF);
3179 for (i = 0; i < LangSys->FeatureCount; i++)
3180 if (feature_list->Feature[LangSys->FeatureIndex[i]].FeatureTag
3187 if (i == LangSys->FeatureCount)
3194 /*** (5) API miscellaneous ***/
3197 OTF_tag (const char *name)
3199 const unsigned char *p = (unsigned char *) name;
3203 return (OTF_Tag) ((p[0] << 24)
3207 : (p[2] << 8) | p[3]))));
3211 OTF_tag_name (OTF_Tag tag, char *name)
3213 name[0] = (char) (tag >> 24);
3214 name[1] = (char) ((tag >> 16) & 0xFF);
3215 name[2] = (char) ((tag >> 8) & 0xFF);
3216 name[3] = (char) (tag & 0xFF);