1 /* otfopen.c -- OpenType font reader.
3 Copyright (C) 2003, 2004, 2005, 2006, 2008
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H15PRO167
7 This file is part of libotf.
9 Libotf is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 Libotf is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library, in a file named COPYING; if not,
21 write to the Free Software Foundation, Inc., 59 Temple Place, Suite
22 330, Boston, MA 02111-1307, USA. */
32 #include FT_TRUETYPE_TABLES_H
35 Table of contents (almost parallel to otf.h):
39 (1) Readers for OTF Layout tables and OTF itself
40 (1-1) Basic types and functions
44 (1-5) Structures common to GDEF, GSUB, and GPOS
46 (1-7) Structures for ScriptList, FeatureList, and LookupList
47 (1-8) Structures common to GSUB and GPOS
50 (1-11) Structure for OTF
52 (2) API for reading OTF
56 (2-4) OTF_check_table()
63 Example of typical usage of OTF_Stream.
67 OTF_StreamState state;
70 OPEN_STREAM (_FILE_NAME_, stream);
73 SETUP_STREAM (stream, fp, 0, 256, _NAME_);
74 offset = READ_OFFSET (stream);
75 nbytes = READ_ULONG (stream);
76 SETUP_STREAM (stream, fp, offset, nbytes, _NAME2_);
78 CLOSE_STREAM (stream);
92 typedef long OTF_StreamState;
95 make_stream (const char *name)
98 char *errfmt = "stream creation%s";
101 stream = calloc (1, sizeof (OTF_Stream));
103 OTF_ERROR (OTF_ERROR_MEMORY, "");
109 setup_stream (OTF_Stream *stream, FILE *fp, long offset, int nbytes)
111 char *errfmt = "stream setup for %s";
115 if (stream->allocated < nbytes)
117 unsigned char *buf = malloc (nbytes);
120 OTF_ERROR (OTF_ERROR_MEMORY, stream->name);
124 stream->allocated = nbytes;
126 stream->bufsize = nbytes;
127 if (fseek (fp, offset, SEEK_SET) < 0)
128 OTF_ERROR (OTF_ERROR_FILE, stream->name);
129 if (fread (stream->buf, 1, nbytes, fp) != nbytes)
130 OTF_ERROR (OTF_ERROR_FILE, stream->name);
135 make_stream_from_ft_face (FT_Face face, const char *name)
137 char *errfmt = "FT_Face stream creation for %s";
142 FT_ULong tag = FT_MAKE_TAG (name[0], name[1], name[2], name[3]);
144 if (FT_Load_Sfnt_Table (face, tag, 0, NULL, &nbytes))
146 buf = malloc (nbytes);
148 OTF_ERROR (OTF_ERROR_MEMORY, name);
149 if (FT_Load_Sfnt_Table (face, tag, 0, buf, &nbytes))
152 OTF_ERROR (OTF_ERROR_FT_FACE, name);
154 stream = make_stream (name);
159 stream->allocated = nbytes;
160 stream->bufsize = nbytes;
165 free_stream (OTF_Stream *stream)
171 #define SAVE_STREAM(stream, state) ((state) = (stream)->pos)
172 #define RESTORE_STREAM(stream, state) ((stream)->pos = (state))
173 #define SEEK_STREAM(stream, offset) ((stream)->pos = (offset))
175 #define STREAM_CHECK_SIZE(stream, size) \
176 if ((stream)->pos + (size) > (stream)->bufsize) \
178 char *errfmt = "buffer overrun in %s"; \
180 OTF_ERROR (OTF_ERROR_TABLE, (stream)->name); \
186 #define READ_USHORT(stream, var) \
188 STREAM_CHECK_SIZE ((stream), 2); \
189 (var) = (((stream)->buf[(stream)->pos] << 8) \
190 | (stream)->buf[(stream)->pos + 1]); \
191 (stream)->pos += 2; \
194 #define READ_SHORT(stream, var) \
196 STREAM_CHECK_SIZE ((stream), 2); \
197 (var) = (short) (((stream)->buf[(stream)->pos] << 8) \
198 | (stream)->buf[(stream)->pos + 1]); \
199 (stream)->pos += 2; \
202 #define READ_UINT24(stream, var) \
204 STREAM_CHECK_SIZE ((stream), 3); \
205 (var) = (((stream)->buf[(stream)->pos ] << 16) \
206 | ((stream)->buf[(stream)->pos + 1] << 8) \
207 | (stream)->buf[(stream)->pos + 2]); \
208 (stream)->pos += 3; \
211 #define READ_ULONG(stream, var) \
213 STREAM_CHECK_SIZE ((stream), 4); \
214 (var) = (((stream)->buf[(stream)->pos] << 24) \
215 | ((stream)->buf[(stream)->pos + 1] << 16) \
216 | ((stream)->buf[(stream)->pos + 2] << 8) \
217 | (stream)->buf[(stream)->pos + 3]); \
218 (stream)->pos += 4; \
221 #define READ_LONG(stream, var) \
223 STREAM_CHECK_SIZE ((stream), 4); \
224 (var) = (int) (((stream)->buf[(stream)->pos] << 24) \
225 | ((stream)->buf[(stream)->pos + 1] << 16) \
226 | ((stream)->buf[(stream)->pos + 2] << 8) \
227 | (stream)->buf[(stream)->pos + 3]); \
228 (stream)->pos += 4; \
232 #define READ_FIXED(stream, fixed) \
234 READ_USHORT ((stream), (fixed).high); \
235 READ_USHORT ((stream), (fixed).low); \
239 #define READ_BYTES(stream, p, nbytes) \
241 STREAM_CHECK_SIZE ((stream), (nbytes)); \
242 memcpy ((p), (stream)->buf + (stream)->pos, (nbytes)); \
243 (stream)->pos += (nbytes); \
247 #define READ_TAG READ_ULONG
248 #define READ_OFFSET READ_USHORT
249 #define READ_UINT16 READ_USHORT
250 #define READ_INT16 READ_SHORT
251 #define READ_GLYPHID READ_USHORT
254 /*** (1) Structures for OTF Layout tables and OTF itself */
256 /*** (1-1) Basic types and functions */
269 #define OTF_MEMORY_RECORD_SIZE 1024
271 struct OTF_MemoryRecord
274 void *memory[OTF_MEMORY_RECORD_SIZE];
275 struct OTF_MemoryRecord *next;
278 typedef struct OTF_MemoryRecord OTF_MemoryRecord;
288 struct _OTF_TableInfo;
289 typedef struct _OTF_TableInfo OTF_TableInfo;
291 struct _OTF_TableInfo
293 /* Points to one of OTF->head, OTF->name, etc. */
295 /* Function to read one of OTF tables. */
296 void *(*reader) (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag);
297 /* Stream given to <reader>. */
301 struct OTF_InternalData
303 /* Information about each OTF table. */
304 OTF_TableInfo table_info[OTF_TABLE_TYPE_MAX];
306 /* Stream used to read the header part of OTF. */
307 OTF_Stream *header_stream;
309 /* Records of allocated memories. */
310 OTF_MemoryRecord *memory_record;
314 static OTF_MemoryRecord *
315 allocate_memory_record (OTF *otf)
317 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
318 OTF_MemoryRecord *memrec = malloc (sizeof (OTF_MemoryRecord));
323 memrec->next = internal_data->memory_record;
324 internal_data->memory_record = memrec;
328 /* Memory allocation macros. */
330 #define OTF_MALLOC(p, size, arg) \
336 OTF_MemoryRecord *memrec \
337 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
338 (p) = malloc (sizeof (*(p)) * (size)); \
340 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
341 && ! (memrec = allocate_memory_record (otf)))) \
342 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
343 memrec->memory[memrec->used++] = (p); \
348 #define OTF_CALLOC(p, size, arg) \
354 OTF_MemoryRecord *memrec \
355 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
356 (p) = calloc ((size), sizeof (*(p))); \
358 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
359 && ! (memrec = allocate_memory_record (otf)))) \
360 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
361 memrec->memory[memrec->used++] = (p); \
366 /*** (1-2) "head" table */
369 read_head_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
371 OTF_Stream *stream = table->stream;
372 char *errfmt = "head%s";
376 OTF_CALLOC (head, 1, "");
377 READ_FIXED (stream, head->TableVersionNumber);
378 READ_FIXED (stream, head->fontRevision);
379 READ_ULONG (stream, head->checkSumAdjustment);
380 READ_ULONG (stream, head->magicNumber);
381 READ_USHORT (stream, head->flags);
382 READ_USHORT (stream, head->unitsPerEm);
384 *table->address = head;
389 /*** (1-3) "name" table */
392 read_name (OTF *otf, OTF_Stream *stream, OTF_NameRecord *rec)
394 char *errfmt = "nameID (%d)";
396 OTF_StreamState state;
401 if (rec->platformID == 0)
402 ucs = (rec->encodingID <= 3) ? 2 : 4;
403 else if (rec->platformID == 1 && rec->encodingID == 0)
405 else if (rec->platformID == 3)
406 ucs = (rec->encodingID == 1 ? 2
407 : rec->encodingID == 10 ? 4
410 OTF_MALLOC (rec->name, rec->length + 1, (void *) rec->nameID);
411 SAVE_STREAM (stream, state);
412 SEEK_STREAM (stream, stream->pos + rec->offset);
413 READ_BYTES (stream, rec->name, rec->length);
414 RESTORE_STREAM (stream, state);
415 rec->name[rec->length] = 0;
424 for (i = 0; i < rec->length / 2; i++)
426 if (rec->name[i * 2] > 0
427 || rec->name[i * 2 + 1] >= 128)
434 for (i = 0; i < rec->length / 2; i++)
435 rec->name[i] = rec->name[i * 2 + 1];
441 for (i = 0; i < rec->length / 4; i++)
443 if (rec->name[i * 4] > 0
444 || rec->name[i * 4 + 1] > 0
445 || rec->name[i * 4 + 2] > 0
446 || rec->name[i * 2 + 3] >= 128)
453 for (i = 0; i < rec->length / 4; i++)
454 rec->name[i] = rec->name[i * 4 + 3];
462 read_name_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
464 OTF_Stream *stream = table->stream;
465 char *errfmt = "name%s";
470 OTF_CALLOC (name, 1, "");
471 READ_USHORT (stream, name->format);
472 READ_USHORT (stream, name->count);
473 READ_USHORT (stream, name->stringOffset);
474 OTF_MALLOC (name->nameRecord, name->count, "");
475 for (i = 0; i < name->count; i++)
477 OTF_NameRecord *rec = name->nameRecord + i;
479 READ_USHORT (stream, rec->platformID);
480 READ_USHORT (stream, rec->encodingID);
481 READ_USHORT (stream, rec->languageID);
482 READ_USHORT (stream, rec->nameID);
483 READ_USHORT (stream, rec->length);
484 READ_USHORT (stream, rec->offset);
486 for (i = 0; i < name->count; i++)
488 OTF_NameRecord *rec = name->nameRecord + i;
489 int nameID = rec->nameID;
491 read_name (otf, stream, rec);
493 if (nameID >= OTF_max_nameID)
495 if (! name->name[nameID]
497 name->name[nameID] = (char *) rec->name;
500 *table->address = name;
505 /*** (1-4) "cmap" table */
507 static OTF_EncodingSubtable14 *
508 read_cmap_uvs_table (OTF *otf, OTF_Stream *stream, OTF_Offset offset)
510 OTF_EncodingSubtable14 *sub14;
511 char *errfmt = "cmap-uvs%s";
516 OTF_MALLOC (sub14, 1, " (EncodingSubtable14)");
517 READ_ULONG (stream, nRecords);
518 sub14->nRecords = nRecords;
519 OTF_MALLOC (sub14->Records, nRecords, "(EncodingSubtable14-Records)");
520 for (i = 0; i < sub14->nRecords; i++)
522 unsigned varSelector=0, defaultUVSOffset, nonDefaultUVSOffset;
524 READ_UINT24 (stream, varSelector);
525 sub14->Records[i].varSelector = varSelector;
526 READ_ULONG (stream, defaultUVSOffset);
527 sub14->Records[i].defaultUVSOffset = defaultUVSOffset;
528 READ_ULONG (stream, nonDefaultUVSOffset);
529 sub14->Records[i].nonDefaultUVSOffset = nonDefaultUVSOffset;
531 for (i = 0; i < sub14->nRecords; i++)
533 OTF_VariationSelectorRecord *record = &sub14->Records[i];
534 unsigned defaultUVSOffset = record->defaultUVSOffset;
535 unsigned nonDefaultUVSOffset = record->nonDefaultUVSOffset;
537 if (defaultUVSOffset)
539 unsigned numUnicodeValueRanges;
541 SEEK_STREAM (stream, offset+defaultUVSOffset);
542 READ_ULONG (stream, numUnicodeValueRanges);
543 record->numUnicodeValueRanges = numUnicodeValueRanges;
544 OTF_MALLOC (record->unicodeValueRanges,
545 numUnicodeValueRanges,
546 "(EncodingSubtable14-Records-unicodeValueRanges)");
547 for (j = 0; j < numUnicodeValueRanges; j++)
549 OTF_UnicodeValueRange *unicodeValueRange
550 = &record->unicodeValueRanges[j];
551 unsigned startUnicodeValue;
552 char additionalCount;
554 READ_UINT24 (stream, startUnicodeValue);
555 unicodeValueRange->startUnicodeValue=startUnicodeValue;
556 READ_BYTES (stream, &additionalCount, 1);
557 unicodeValueRange->additionalCount
558 = (unsigned short) additionalCount;
561 if (nonDefaultUVSOffset)
563 unsigned numUVSMappings;
565 SEEK_STREAM (stream, offset+nonDefaultUVSOffset);
566 READ_ULONG (stream, numUVSMappings);
567 record->numUVSMappings = numUVSMappings;
568 OTF_MALLOC (record->uvsMappings, numUVSMappings,
569 "(EncodingSubtable14-Records-uvsMappings)");
570 for (j = 0; j < numUVSMappings; j++)
572 OTF_UVSMapping *uvsMapping = &record->uvsMappings[j];
573 unsigned unicodeValue;
574 unsigned short glyphID;
576 READ_UINT24 (stream, unicodeValue);
577 uvsMapping->unicodeValue = unicodeValue;
578 READ_USHORT (stream, glyphID);
579 uvsMapping->glyphID = glyphID;
587 read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
589 OTF_Stream *stream = table->stream;
590 char *errfmt = "cmap%s";
593 int unicode_bmp_index = -1, unicode_full_index = -1;
596 OTF_CALLOC (cmap, 1, "");
597 READ_USHORT (stream, cmap->version);
598 READ_USHORT (stream, cmap->numTables);
599 OTF_MALLOC (cmap->EncodingRecord, cmap->numTables, "");
600 for (i = 0; i < cmap->numTables; i++)
602 unsigned platformID, encodingID;
604 READ_USHORT (stream, platformID);
605 cmap->EncodingRecord[i].platformID = platformID;
606 READ_USHORT (stream, encodingID);
607 cmap->EncodingRecord[i].encodingID = encodingID;
608 READ_ULONG (stream, cmap->EncodingRecord[i].offset);
612 unicode_bmp_index = i;
614 unicode_full_index = i;
616 else if (platformID == 3)
619 unicode_bmp_index = i;
620 else if (encodingID == 10)
621 unicode_full_index = i;
624 for (i = 0; i < cmap->numTables; i++)
628 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
629 READ_USHORT (stream, format);
630 cmap->EncodingRecord[i].subtable.format = format;
633 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
634 cmap->EncodingRecord[i].subtable.language = 0;
638 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
639 if (format == 8 || format == 10 || format == 12)
641 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
642 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
646 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
653 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
654 " (EncodingRecord)");
656 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
663 OTF_EncodingSubtable2 *sub2;
666 OTF_MALLOC (sub2, 1, " (EncodingSubtable2)");
667 cmap->EncodingRecord[i].subtable.f.f2 = sub2;
668 for (j = 0, max_key = 0; j < 256; j++)
670 READ_USHORT (stream, sub2->subHeaderKeys[j]);
671 if (max_key < sub2->subHeaderKeys[j])
672 max_key = sub2->subHeaderKeys[j];
675 sub2->subHeaderCount = max_key / 8;
676 OTF_MALLOC (sub2->subHeaders, max_key / 8, " (subHeaders)");
677 for (j = 0; j < sub2->subHeaderCount; j++)
679 READ_USHORT (stream, sub2->subHeaders[j].firstCode);
680 READ_USHORT (stream, sub2->subHeaders[j].entryCount);
681 READ_SHORT (stream, sub2->subHeaders[j].idDelta);
682 READ_USHORT (stream, sub2->subHeaders[j].idRangeOffset);
683 /* Make it offset from sub2->glyphIndexArray. */
684 sub2->subHeaders[j].idRangeOffset -= max_key - (j * 8 + 6);
686 sub2->glyphIndexCount = (cmap->EncodingRecord[i].subtable.length
688 OTF_MALLOC (sub2->glyphIndexArray, sub2->glyphIndexCount,
689 " (glyphIndexArray)");
690 READ_BYTES (stream, sub2->glyphIndexArray, sub2->glyphIndexCount);
696 OTF_EncodingSubtable4 *sub4;
701 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
702 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
703 READ_USHORT (stream, sub4->segCountX2);
704 segCount = sub4->segCountX2 / 2;
705 READ_USHORT (stream, sub4->searchRange);
706 READ_USHORT (stream, sub4->entrySelector);
707 READ_USHORT (stream, sub4->rangeShift);
708 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
709 for (j = 0; j < segCount; j++)
710 READ_USHORT (stream, sub4->segments[j].endCount);
711 READ_USHORT (stream, dummy);
712 for (j = 0; j < segCount; j++)
713 READ_USHORT (stream, sub4->segments[j].startCount);
714 for (j = 0; j < segCount; j++)
715 READ_SHORT (stream, sub4->segments[j].idDelta);
716 for (j = 0; j < segCount; j++)
719 unsigned rest = 2 * (segCount - j);
721 READ_USHORT (stream, off);
723 sub4->segments[j].idRangeOffset = 0xFFFF;
725 sub4->segments[j].idRangeOffset = (off - rest) / 2;
727 j = (cmap->EncodingRecord[i].subtable.length
728 - (14 + 2 * (segCount * 4 + 1)));
729 sub4->GlyphCount = j / 2;
730 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
731 for (j = 0; j < sub4->GlyphCount; j++)
732 READ_USHORT (stream, sub4->glyphIdArray[j]);
738 OTF_EncodingSubtable6 *sub6;
741 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
742 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
743 READ_USHORT (stream, sub6->firstCode);
744 READ_USHORT (stream, sub6->entryCount);
745 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
746 for (j = 0; j < sub6->entryCount; j++)
747 READ_USHORT (stream, sub6->glyphIdArray[j]);
753 OTF_EncodingSubtable8 *sub8;
756 OTF_MALLOC (sub8, 1, " (EncodingSubtable8)");
757 cmap->EncodingRecord[i].subtable.f.f8 = sub8;
758 for (j = 0; j < 8192; j++)
759 READ_BYTES (stream, sub8->is32, 8192);
760 READ_ULONG (stream, sub8->nGroups);
761 OTF_MALLOC (sub8->Groups, sub8->nGroups, " (Groups)");
762 for (j = 0; j < sub8->nGroups; j++)
764 READ_ULONG (stream, sub8->Groups[i].startCharCode);
765 READ_ULONG (stream, sub8->Groups[i].endCharCode);
766 READ_ULONG (stream, sub8->Groups[i].startGlyphID);
773 OTF_EncodingSubtable10 *sub10;
776 OTF_MALLOC (sub10, 1, " (EncodingSubtable10)");
777 cmap->EncodingRecord[i].subtable.f.f10 = sub10;
778 READ_ULONG (stream, sub10->startCharCode);
779 READ_ULONG (stream, sub10->numChars);
780 OTF_MALLOC (sub10->glyphs, sub10->numChars, " (GlyphCount)");
781 for (j = 0; j < sub10->numChars; j++)
782 READ_USHORT (stream, sub10->glyphs[j]);
788 OTF_EncodingSubtable12 *sub12;
791 OTF_MALLOC (sub12, 1, " (EncodingSubtable12)");
792 cmap->EncodingRecord[i].subtable.f.f12 = sub12;
793 READ_ULONG (stream, sub12->nGroups);
794 OTF_MALLOC (sub12->Groups, sub12->nGroups, " (Groups)");
795 for (j = 0; j < sub12->nGroups; j++)
797 READ_ULONG (stream, sub12->Groups[j].startCharCode);
798 READ_ULONG (stream, sub12->Groups[j].endCharCode);
799 READ_ULONG (stream, sub12->Groups[j].startGlyphID);
806 cmap->EncodingRecord[i].subtable.f.f14
807 = read_cmap_uvs_table (otf, stream,
808 cmap->EncodingRecord[i].offset);
813 OTF_ERROR (OTF_ERROR_TABLE, " (invalid Subtable format)");
817 if (unicode_bmp_index >= 0)
819 OTF_EncodingRecord *rec = cmap->EncodingRecord + unicode_bmp_index;
820 OTF_GlyphID glyph_id, max_glyph_id = 0;
822 OTF_CALLOC (cmap->unicode_table, 0x10000, "");
823 switch (rec->subtable.format)
827 OTF_EncodingSubtable4 *sub4 = rec->subtable.f.f4;
828 int segCount = sub4->segCountX2 / 2;
830 for (i = 0; i < segCount; i++)
832 OTF_cmapSegment *seg = sub4->segments + i;
835 if (seg->idRangeOffset == 0xFFFF)
836 for (c = seg->startCount; c <= seg->endCount; c++)
838 glyph_id = c + seg->idDelta;
839 cmap->unicode_table[c] = glyph_id;
840 if (glyph_id > max_glyph_id)
841 max_glyph_id = glyph_id;
844 for (c = seg->startCount; c <= seg->endCount && c != 0xFFFF;
847 glyph_id = sub4->glyphIdArray[seg->idRangeOffset
848 + (c - seg->startCount)];
849 cmap->unicode_table[c] = glyph_id;
850 if (glyph_id > max_glyph_id)
851 max_glyph_id = glyph_id;
857 OTF_CALLOC (cmap->decode_table, max_glyph_id + 1, "");
858 for (i = 0; i < 0x10000; i++)
859 if (cmap->unicode_table[i])
860 cmap->decode_table[cmap->unicode_table[i]] = i;
861 cmap->max_glyph_id = max_glyph_id;
864 *table->address = cmap;
869 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
871 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
872 Glyph-IDs there. If COUNT is negative, read the number of
873 Glyphs-IDs at first. MINUS if nozero is how few the actual
874 Glyph-IDs are in STREAM than COUNT. */
877 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
878 int minus, int count)
880 char *errfmt = "GlyphID List%s";
885 READ_UINT16 (stream, count);
888 OTF_MALLOC (*ids, count, "");
889 for (i = 0; i < count + minus; i++)
890 READ_GLYPHID (stream, (*ids)[i]);
895 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
897 char *errfmt = "RangeRecord%s";
902 READ_UINT16 (stream, count);
905 OTF_MALLOC (*record, count, "");
906 for (i = 0; i < count; i++)
908 READ_GLYPHID (stream, (*record)[i].Start);
909 READ_GLYPHID (stream, (*record)[i].End);
910 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
917 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
918 OTF_Coverage *coverage)
920 char *errfmt = "Coverage%s";
922 OTF_StreamState state;
925 READ_OFFSET (stream, coverage->offset);
926 SAVE_STREAM (stream, state);
927 SEEK_STREAM (stream, offset + coverage->offset);
928 READ_UINT16 (stream, coverage->CoverageFormat);
929 if (coverage->CoverageFormat == 1)
930 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
931 else if (coverage->CoverageFormat == 2)
932 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
934 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
937 coverage->Count = (unsigned) count;
938 RESTORE_STREAM (stream, state);
942 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
943 and store the Coverages there. If COUNT is negative, read the
944 number of Coverages at first. */
947 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
948 OTF_Coverage **coverage, int count)
950 char *errfmt = "Coverage List%s";
955 READ_UINT16 (stream, count);
958 OTF_MALLOC (*coverage, count, "");
959 for (i = 0; i < count; i++)
960 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
967 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
970 char *errfmt = "ClassDef%s";
973 SEEK_STREAM (stream, class->offset);
974 READ_UINT16 (stream, class->ClassFormat);
975 if (class->ClassFormat == 1)
977 READ_GLYPHID (stream, class->f.f1.StartGlyph);
978 class->f.f1.GlyphCount
980 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
981 if (! class->f.f1.GlyphCount)
982 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
984 else if (class->ClassFormat == 2)
986 class->f.f2.ClassRangeCount
987 = (read_range_records
988 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
989 if (! class->f.f2.ClassRangeCount)
990 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
993 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
999 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
1001 char *errfmt = "ClassDef%s";
1003 OTF_StreamState state;
1005 READ_OFFSET (stream, class->offset);
1006 if (! class->offset)
1008 SAVE_STREAM (stream, state);
1009 SEEK_STREAM (stream, offset + class->offset);
1010 READ_UINT16 (stream, class->ClassFormat);
1011 if (class->ClassFormat == 1)
1013 READ_GLYPHID (stream, class->f.f1.StartGlyph);
1014 class->f.f1.GlyphCount
1015 = read_glyph_ids (otf, stream,
1016 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
1018 if (! class->f.f1.GlyphCount)
1021 else if (class->ClassFormat == 2)
1023 class->f.f2.ClassRangeCount
1024 = read_range_records (otf, stream,
1025 (OTF_RangeRecord **)
1026 &class->f.f2.ClassRangeRecord);
1027 if (! class->f.f2.ClassRangeCount)
1031 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1033 RESTORE_STREAM (stream, state);
1039 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
1040 OTF_DeviceTable *table)
1042 char *errfmt = "Device Table%s";
1053 SEEK_STREAM (stream, offset + table->offset);
1054 READ_UINT16 (stream, table->StartSize);
1055 READ_UINT16 (stream, table->EndSize);
1056 READ_UINT16 (stream, table->DeltaFormat);
1057 num = table->EndSize - table->StartSize + 1;
1058 if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
1060 OTF_MALLOC (table->DeltaValue, num, "");
1062 if (table->DeltaFormat == 1)
1063 for (i = 0; i < num; i++)
1066 READ_UINT16 (stream, val);
1067 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
1068 table->DeltaValue[i] = intval.int2;
1070 else if (table->DeltaFormat == 2)
1071 for (i = 0; i < num; i++)
1074 READ_UINT16 (stream, val);
1075 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
1076 table->DeltaValue[i] = intval.int4;
1078 else /* (table->DeltaFormat == 3) */
1079 for (i = 0; i < num; i++)
1083 READ_UINT16 (stream, val);
1084 intval.int8 = val >> 8;
1085 table->DeltaValue[i] = intval.int8;
1089 intval.int8 = val >> 8;
1090 table->DeltaValue[i] = intval.int8;
1096 /* Invalid DeltaFormat but several fonts has such values (bug of
1097 fontforge?). So accept it with NULL delta values. */
1098 table->DeltaValue = NULL;
1104 /*** (1-6) "GDEF" table */
1107 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
1108 OTF_AttachList *list)
1110 char *errfmt = "AttachList%s";
1114 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1116 READ_UINT16 (stream, list->GlyphCount);
1117 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
1118 for (i = 0; i < list->GlyphCount; i++)
1119 READ_OFFSET (stream, list->AttachPoint[i].offset);
1120 for (i = 0; i < list->GlyphCount; i++)
1124 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
1125 READ_UINT16 (stream, count);
1126 list->AttachPoint[i].PointCount = count;
1127 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
1128 for (j = 0; j < count; j++)
1129 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
1135 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
1136 OTF_CaretValue *caret)
1138 char *errfmt = "CaretValue%s";
1141 SEEK_STREAM (stream, offset + caret->offset);
1142 READ_UINT16 (stream, caret->CaretValueFormat);
1143 if (caret->CaretValueFormat == 1)
1144 READ_INT16 (stream, caret->f.f1.Coordinate);
1145 else if (caret->CaretValueFormat == 2)
1146 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
1147 else if (caret->CaretValueFormat == 3)
1149 READ_INT16 (stream, caret->f.f3.Coordinate);
1150 if (read_device_table (otf, stream, offset + caret->offset,
1151 &caret->f.f3.DeviceTable) < 0)
1155 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1160 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
1161 OTF_LigCaretList *list)
1163 char *errfmt = "LigCaretList%s";
1167 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1169 READ_UINT16 (stream, list->LigGlyphCount);
1170 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
1171 for (i = 0; i < list->LigGlyphCount; i++)
1172 READ_OFFSET (stream, list->LigGlyph[i].offset);
1173 for (i = 0; i < list->LigGlyphCount; i++)
1177 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
1178 READ_UINT16 (stream, count);
1179 list->LigGlyph[i].CaretCount = count;
1180 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
1181 for (j = 0; j < count; j++)
1182 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
1183 for (j = 0; j < count; j++)
1184 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
1185 &list->LigGlyph[i].CaretValue[j]) < 0)
1192 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
1196 READ_FIXED (stream, header->Version);
1197 READ_OFFSET (stream, header->GlyphClassDef);
1198 READ_OFFSET (stream, header->AttachList);
1199 READ_OFFSET (stream, header->LigCaretList);
1200 READ_OFFSET (stream, header->MarkAttachClassDef);
1205 read_gdef_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
1207 OTF_Stream *stream = table->stream;
1208 char *errfmt = "GDEF%s";
1209 void *errret = NULL;
1212 OTF_CALLOC (gdef, 1, "");
1213 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
1214 if (gdef->header.GlyphClassDef)
1216 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
1217 read_class_def_without_offset (otf, stream, &gdef->glyph_class_def);
1219 if (gdef->header.AttachList)
1220 read_attach_list (otf, stream, gdef->header.AttachList,
1221 &gdef->attach_list);
1222 if (gdef->header.LigCaretList)
1223 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
1224 &gdef->lig_caret_list);
1225 if (gdef->header.MarkAttachClassDef)
1227 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
1228 read_class_def_without_offset (otf, stream, &gdef->mark_attach_class_def);
1231 *table->address = gdef;
1236 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
1239 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
1240 OTF_ScriptList *list)
1242 char *errfmt = "Script List%s";
1246 SEEK_STREAM (stream, offset);
1247 READ_USHORT (stream, list->ScriptCount);
1248 OTF_CALLOC (list->Script, list->ScriptCount, "");
1250 for (i = 0; i < list->ScriptCount; i++)
1252 READ_TAG (stream, list->Script[i].ScriptTag);
1253 READ_OFFSET (stream, list->Script[i].offset);
1255 for (i = 0; i < list->ScriptCount; i++)
1257 OTF_Script *script = list->Script + i;
1258 long script_offset = offset + script->offset;
1260 SEEK_STREAM (stream, script_offset);
1261 READ_OFFSET (stream, script->DefaultLangSysOffset);
1262 READ_USHORT (stream, script->LangSysCount);
1263 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
1264 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
1265 for (j = 0; j < script->LangSysCount; j++)
1267 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
1268 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
1271 if (script->DefaultLangSysOffset)
1273 OTF_LangSys *langsys = &script->DefaultLangSys;
1275 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
1276 READ_OFFSET (stream, langsys->LookupOrder);
1277 READ_USHORT (stream, langsys->ReqFeatureIndex);
1278 READ_USHORT (stream, langsys->FeatureCount);
1279 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1281 for (k = 0; k < langsys->FeatureCount; k++)
1282 READ_USHORT (stream, langsys->FeatureIndex[k]);
1285 for (j = 0; j < script->LangSysCount; j++)
1287 OTF_LangSys *langsys = script->LangSys + j;
1289 SEEK_STREAM (stream,
1290 script_offset + script->LangSysRecord[j].LangSys);
1291 READ_OFFSET (stream, langsys->LookupOrder);
1292 READ_USHORT (stream, langsys->ReqFeatureIndex);
1293 READ_USHORT (stream, langsys->FeatureCount);
1294 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1296 for (k = 0; k < langsys->FeatureCount; k++)
1297 READ_USHORT (stream, langsys->FeatureIndex[k]);
1305 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
1306 OTF_FeatureList *list)
1308 char *errfmt = "Feature List%s";
1312 SEEK_STREAM (stream, offset);
1313 READ_UINT16 (stream, list->FeatureCount);
1314 OTF_CALLOC (list->Feature, list->FeatureCount, "");
1315 for (i = 0; i < list->FeatureCount; i++)
1317 READ_TAG (stream, list->Feature[i].FeatureTag);
1318 READ_OFFSET (stream, list->Feature[i].offset);
1320 for (i = 0; i < list->FeatureCount; i++)
1322 OTF_Feature *feature = list->Feature + i;
1324 SEEK_STREAM (stream, offset + feature->offset);
1325 READ_OFFSET (stream, feature->FeatureParams);
1326 READ_UINT16 (stream, feature->LookupCount);
1327 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1328 " (LookupListIndex)");
1329 for (j = 0; j < feature->LookupCount; j++)
1330 READ_UINT16 (stream, feature->LookupListIndex[j]);
1336 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1337 long offset, unsigned type,
1338 OTF_LookupSubTableGSUB *subtable);
1339 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1340 long offset, unsigned type,
1341 OTF_LookupSubTableGPOS *subtable);
1344 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1345 OTF_LookupList *list, int gsubp)
1347 char *errfmt = "Lookup List%s";
1351 SEEK_STREAM (stream, offset);
1352 READ_UINT16 (stream, list->LookupCount);
1353 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1355 for (i = 0; i < list->LookupCount; i++)
1356 READ_OFFSET (stream, list->Lookup[i].offset);
1357 for (i = 0; i < list->LookupCount; i++)
1359 OTF_Lookup *lookup = list->Lookup + i;
1361 SEEK_STREAM (stream, offset + lookup->offset);
1362 READ_UINT16 (stream, lookup->LookupType);
1363 READ_UINT16 (stream, lookup->LookupFlag);
1364 READ_UINT16 (stream, lookup->SubTableCount);
1365 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1366 " (SubTableOffset)");
1368 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1371 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1373 for (j = 0; j < lookup->SubTableCount; j++)
1374 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1375 for (j = 0; j < lookup->SubTableCount; j++)
1378 = offset + lookup->offset + lookup->SubTableOffset[j];
1381 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1383 lookup->SubTable.gsub + j) < 0
1384 : read_lookup_subtable_gpos (otf, stream, this_offset,
1386 lookup->SubTable.gpos + j) < 0)
1395 /*** (1-8) Structures common to GSUB and GPOS */
1398 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1399 OTF_LookupRecord **record, int count)
1401 char *errfmt = "LookupRecord%s";
1402 unsigned errret = 0;
1406 READ_UINT16 (stream, count);
1408 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1409 OTF_MALLOC (*record, count, "");
1410 for (i = 0; i < count; i++)
1412 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1413 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1419 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1421 char *errfmt = "List of Rule%s";
1422 unsigned errret = 0;
1423 OTF_StreamState state;
1427 READ_UINT16 (stream, count);
1429 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1430 OTF_MALLOC (*rule, count, "");
1431 for (i = 0; i < count; i++)
1433 READ_OFFSET (stream, (*rule)[i].offset);
1434 if (! (*rule)[i].offset)
1435 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1437 SAVE_STREAM (stream, state);
1438 for (i = 0; i < count; i++)
1440 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1441 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1442 if ((*rule)[i].GlyphCount == 0)
1443 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1444 READ_UINT16 (stream, (*rule)[i].LookupCount);
1445 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1446 (*rule)[i].GlyphCount) < 0)
1448 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1449 (*rule)[i].LookupCount) == 0)
1452 RESTORE_STREAM (stream, state);
1458 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1461 char *errfmt = "List of RuleSet%s";
1462 unsigned errret = 0;
1463 OTF_StreamState state;
1467 READ_UINT16 (stream, count);
1469 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1470 OTF_MALLOC (*set, count, "");
1471 for (i = 0; i < count; i++)
1473 READ_OFFSET (stream, (*set)[i].offset);
1474 if (! (*set)[i].offset)
1475 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1477 SAVE_STREAM (stream, state);
1478 for (i = 0; i < count; i++)
1480 SEEK_STREAM (stream, offset + (*set)[i].offset);
1482 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1484 if (! (*set)[i].RuleCount)
1487 RESTORE_STREAM (stream, state);
1492 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1493 OTF_ClassRule **rule)
1495 char *errfmt = "ClassRule%s";
1496 unsigned errret = 0;
1497 OTF_StreamState state;
1501 READ_UINT16 (stream, count);
1503 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1504 OTF_MALLOC (*rule, count, "");
1505 for (i = 0; i < count; i++)
1507 READ_OFFSET (stream, (*rule)[i].offset);
1508 if (! (*rule)[i].offset)
1509 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1511 SAVE_STREAM (stream, state);
1512 for (i = 0; i < count; i++)
1514 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1515 READ_USHORT (stream, (*rule)[i].GlyphCount);
1516 if (! (*rule)[i].GlyphCount)
1517 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1518 READ_USHORT (stream, (*rule)[i].LookupCount);
1519 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1520 0, (*rule)[i].GlyphCount - 1) < 0)
1522 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1523 (*rule)[i].LookupCount) == 0)
1526 RESTORE_STREAM (stream, state);
1531 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1534 char *errfmt = "ClassSet%s";
1535 unsigned errret = 0;
1536 OTF_StreamState state;
1540 READ_UINT16 (stream, count);
1542 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1543 OTF_CALLOC (*set, count, "");
1544 for (i = 0; i < count; i++)
1545 /* Offset can be zero. */
1546 READ_OFFSET (stream, (*set)[i].offset);
1547 SAVE_STREAM (stream, state);
1548 for (i = 0; i < count; i++)
1549 if ((*set)[i].offset)
1551 SEEK_STREAM (stream, offset + (*set)[i].offset);
1552 (*set)[i].ClassRuleCnt
1553 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1554 &(*set)[i].ClassRule);
1555 if (! (*set)[i].ClassRuleCnt)
1558 RESTORE_STREAM (stream, state);
1563 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1564 OTF_ChainRule **rule)
1566 char *errfmt = "ChainRule%s";
1567 unsigned errret = 0;
1571 READ_UINT16 (stream, count);
1573 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1574 OTF_MALLOC (*rule, count, "");
1575 for (i = 0; i < count; i++)
1576 READ_OFFSET (stream, (*rule)[i].offset);
1577 for (i = 0; i < count; i++)
1579 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1580 (*rule)[i].BacktrackGlyphCount
1581 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1582 (*rule)[i].InputGlyphCount
1583 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1584 if (! (*rule)[i].InputGlyphCount)
1585 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1586 (*rule)[i].LookaheadGlyphCount
1587 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1588 (*rule)[i].LookupCount
1589 = read_lookup_record_list (otf, stream,
1590 &(*rule)[i].LookupRecord, -1);
1591 if (! (*rule)[i].LookupCount)
1599 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1600 OTF_ChainRuleSet **set)
1602 char *errfmt = "ChainRuleSet%s";
1603 unsigned errret = 0;
1604 OTF_StreamState state;
1608 READ_UINT16 (stream, count);
1610 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1611 OTF_MALLOC (*set, count, "");
1612 for (i = 0; i < count; i++)
1614 READ_OFFSET (stream, (*set)[i].offset);
1615 if (! (*set)[i].offset)
1616 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1618 SAVE_STREAM (stream, state);
1619 for (i = 0; i < count; i++)
1621 SEEK_STREAM (stream, offset + (*set)[i].offset);
1622 (*set)[i].ChainRuleCount
1623 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1624 &(*set)[i].ChainRule);
1625 if (! (*set)[i].ChainRuleCount)
1628 RESTORE_STREAM (stream, state);
1633 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1634 OTF_ChainClassRule **rule)
1636 char *errfmt = "ChainClassRule%s";
1637 unsigned errret = 0;
1641 READ_UINT16 (stream, count);
1643 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1644 OTF_MALLOC (*rule, count, "");
1645 for (i = 0; i < count; i++)
1647 READ_OFFSET (stream, (*rule)[i].offset);
1648 if (! (*rule)[i].offset)
1649 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1651 for (i = 0; i < count; i++)
1653 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1654 (*rule)[i].BacktrackGlyphCount
1655 = read_glyph_ids (otf, stream,
1656 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1657 (*rule)[i].InputGlyphCount
1658 = read_glyph_ids (otf, stream,
1659 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1660 if (! (*rule)[i].InputGlyphCount)
1661 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1662 (*rule)[i].LookaheadGlyphCount
1663 = read_glyph_ids (otf, stream,
1664 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1665 (*rule)[i].LookupCount
1666 = read_lookup_record_list (otf, stream,
1667 &(*rule)[i].LookupRecord, -1);
1668 if (! (*rule)[i].LookupCount)
1675 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1676 OTF_ChainClassSet **set)
1678 char *errfmt = "ChainClassSet%s";
1679 unsigned errret = 0;
1680 OTF_StreamState state;
1684 READ_UINT16 (stream, count);
1686 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1687 OTF_MALLOC (*set, count, "");
1688 for (i = 0; i < count; i++)
1689 /* Offset may be zero. */
1690 READ_OFFSET (stream, (*set)[i].offset);
1691 SAVE_STREAM (stream, state);
1692 for (i = 0; i < count; i++)
1693 if ((*set)[i].offset)
1695 SEEK_STREAM (stream, offset + (*set)[i].offset);
1696 (*set)[i].ChainClassRuleCnt
1697 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1698 &(*set)[i].ChainClassRule);
1699 if (! (*set)[i].ChainClassRuleCnt)
1702 RESTORE_STREAM (stream, state);
1707 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1708 OTF_Coverage *coverage,OTF_Context1 *context1)
1710 if (read_coverage (otf, stream, offset, coverage) < 0)
1712 context1->RuleSetCount
1713 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1714 if (! context1->RuleSetCount)
1720 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1721 OTF_Coverage *coverage,OTF_Context2 *context2)
1723 if (read_coverage (otf, stream, offset, coverage) < 0
1724 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1726 context2->ClassSetCnt
1727 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1728 if (! context2->ClassSetCnt)
1734 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1735 OTF_Coverage *coverage,OTF_Context3 *context3)
1737 char *errfmt = "Context1%s";
1740 READ_USHORT (stream, context3->GlyphCount);
1741 if (context3->GlyphCount < 0)
1742 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1743 READ_USHORT (stream, context3->LookupCount);
1744 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1745 context3->GlyphCount) < 0)
1747 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1748 context3->LookupCount) < 0)
1754 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1755 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1757 if (read_coverage (otf, stream, offset, coverage) < 0)
1759 chain_context1->ChainRuleSetCount
1760 = read_chain_rule_set_list (otf, stream, offset,
1761 &chain_context1->ChainRuleSet);
1762 if (! chain_context1->ChainRuleSetCount)
1768 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1769 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1771 if (read_coverage (otf, stream, offset, coverage) < 0
1772 || read_class_def (otf, stream, offset,
1773 &chain_context2->BacktrackClassDef) < 0
1774 || read_class_def (otf, stream, offset,
1775 &chain_context2->InputClassDef) < 0
1776 || read_class_def (otf, stream, offset,
1777 &chain_context2->LookaheadClassDef) < 0)
1779 chain_context2->ChainClassSetCnt
1780 = read_chain_class_set_list (otf, stream, offset,
1781 &chain_context2->ChainClassSet);
1782 if (! chain_context2->ChainClassSetCnt)
1788 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1789 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1793 count = read_coverage_list (otf, stream, offset,
1794 &chain_context3->Backtrack, -1);
1797 chain_context3->BacktrackGlyphCount = (unsigned) count;
1798 count = read_coverage_list (otf, stream, offset,
1799 &chain_context3->Input, -1);
1802 chain_context3->InputGlyphCount = (unsigned) count;
1803 *coverage = chain_context3->Input[0];
1804 count = read_coverage_list (otf, stream, offset,
1805 &chain_context3->LookAhead, -1);
1806 chain_context3->LookaheadGlyphCount = (unsigned) count;
1807 chain_context3->LookupCount
1808 = read_lookup_record_list (otf, stream,
1809 &chain_context3->LookupRecord, -1);
1814 read_gsub_gpos_table (OTF *otf, OTF_TableInfo *table, int gsubp,
1815 enum OTF_ReaderFlag flag)
1817 OTF_Stream *stream = table->stream;
1818 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1819 void *errret = NULL;
1820 OTF_GSUB_GPOS *gsub_gpos = *table->address;
1823 SEEK_STREAM (stream, 10);
1826 SEEK_STREAM (stream, 0);
1827 OTF_CALLOC (gsub_gpos, 1, "");
1828 READ_FIXED (stream, gsub_gpos->Version);
1829 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1830 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1831 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1832 *table->address = gsub_gpos;
1835 if (! gsub_gpos->ScriptList.Script
1836 && read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1837 &gsub_gpos->ScriptList) < 0)
1839 if (flag != OTF_READ_SCRIPTS)
1841 if (! gsub_gpos->FeatureList.Feature
1842 && read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1843 &gsub_gpos->FeatureList) < 0)
1845 if (flag != OTF_READ_FEATURES)
1847 if (! gsub_gpos->LookupList.Lookup
1848 && read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1849 &gsub_gpos->LookupList, gsubp) < 0)
1858 /* (1-9) "GSUB" table */
1861 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1863 char *errfmt = "Sequence%s";
1864 unsigned errret = 0;
1868 READ_UINT16 (stream, count);
1870 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1871 OTF_MALLOC (*seq, count, "");
1872 for (i = 0; i < count; i++)
1873 READ_OFFSET (stream, (*seq)[i].offset);
1874 for (i = 0; i < count; i++)
1876 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1877 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1878 &(*seq)[i].Substitute, 0, -1);
1879 if (! (*seq)[i].GlyphCount)
1886 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1887 OTF_Ligature **ligature)
1889 char *errfmt = "Ligature%s";
1894 READ_UINT16 (stream, count);
1897 OTF_MALLOC (*ligature, count, "");
1898 for (i = 0; i < count; i++)
1899 READ_OFFSET (stream, (*ligature)[i].offset);
1900 for (i = 0; i < count; i++)
1902 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1903 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1904 (*ligature)[i].CompCount
1905 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1906 if (! (*ligature)[i].CompCount)
1913 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1914 OTF_LigatureSet **ligset)
1916 char *errfmt = "LigatureSet%s";
1921 READ_UINT16 (stream, count);
1924 OTF_MALLOC (*ligset, count, "");
1925 for (i = 0; i < count; i++)
1926 READ_OFFSET (stream, (*ligset)[i].offset);
1927 for (i = 0; i < count; i++)
1931 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1932 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1933 &(*ligset)[i].Ligature);
1936 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1942 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1943 OTF_AlternateSet **altset)
1945 char *errfmt = "AlternateSet%s";
1950 READ_UINT16 (stream, count);
1952 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1953 OTF_MALLOC (*altset, count, "");
1954 for (i = 0; i < count; i++)
1955 READ_OFFSET (stream, (*altset)[i].offset);
1956 for (i = 0; i < count; i++)
1960 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1961 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1964 (*altset)[i].GlyphCount = (unsigned) alt_count;
1970 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1971 OTF_Coverage *coverage,
1972 OTF_GSUB_ReverseChain1 *reverse_chain)
1976 if (read_coverage (otf, stream, offset, coverage) < 0)
1978 count = read_coverage_list (otf, stream, offset,
1979 &reverse_chain->Backtrack, -1);
1982 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1983 count = read_coverage_list (otf, stream, offset,
1984 &reverse_chain->LookAhead, -1);
1987 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1988 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
1991 reverse_chain->GlyphCount = count;
1996 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
1997 unsigned type, OTF_LookupSubTableGSUB *subtable)
2002 SEEK_STREAM (stream, offset);
2003 READ_USHORT (stream, subtable->Format);
2004 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
2008 if (subtable->Format == 1)
2010 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2012 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
2014 else if (subtable->Format == 2)
2016 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2018 subtable->u.single2.GlyphCount
2019 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
2021 if (! subtable->u.single2.GlyphCount)
2025 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2029 if (subtable->Format == 1)
2031 read_coverage (otf, stream, offset, &subtable->Coverage);
2032 subtable->u.multiple1.SequenceCount
2033 = read_sequence (otf, stream, offset,
2034 &subtable->u.multiple1.Sequence);
2037 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2041 if (subtable->Format == 1)
2043 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2045 subtable->u.alternate1.AlternateSetCount
2046 = read_alternate_set_list (otf, stream, offset,
2047 &subtable->u.alternate1.AlternateSet);
2048 if (! subtable->u.alternate1.AlternateSetCount)
2052 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2056 if (subtable->Format == 1)
2058 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2060 subtable->u.ligature1.LigSetCount
2061 = read_ligature_set_list (otf, stream, offset,
2062 &subtable->u.ligature1.LigatureSet);
2063 if (! subtable->u.ligature1.LigSetCount)
2067 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2071 if (subtable->Format == 1)
2073 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2074 &subtable->u.context1) < 0)
2077 else if (subtable->Format == 2)
2079 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2080 &subtable->u.context2) < 0)
2083 else if (subtable->Format == 3)
2085 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2086 &subtable->u.context3) < 0)
2090 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2094 if (subtable->Format == 1)
2096 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2097 &subtable->u.chain_context1) < 0)
2100 else if (subtable->Format == 2)
2102 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2103 &subtable->u.chain_context2) < 0)
2106 else if (subtable->Format == 3)
2108 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2109 &subtable->u.chain_context3) < 0)
2113 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2117 if (subtable->Format == 1)
2121 OTF_LookupSubTableGSUB *ex_subtable;
2123 READ_USHORT (stream, ex_type);
2124 READ_ULONG (stream, ex_offset);
2125 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2126 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
2127 ex_type, ex_subtable) < 0)
2129 subtable->u.extension1.ExtensionLookupType = ex_type;
2130 subtable->u.extension1.ExtensionOffset = ex_offset;
2131 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2134 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2138 if (subtable->Format == 1)
2140 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
2141 &subtable->u.reverse_chain1) < 0)
2145 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2149 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2155 read_gsub_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2157 return read_gsub_gpos_table (otf, table, 1, flag);
2161 /* (1-10) "GPOS" table */
2164 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
2165 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
2168 OTF_StreamState state;
2171 memset (value_record, 0, sizeof (OTF_ValueRecord));
2174 for (i = 0, size = 0; i < 8; i++)
2178 if (bit & OTF_XPlacement)
2179 READ_INT16 (stream, value_record->XPlacement);
2180 if (bit & OTF_YPlacement)
2181 READ_INT16 (stream, value_record->YPlacement);
2182 if (bit & OTF_XAdvance)
2183 READ_INT16 (stream, value_record->XAdvance);
2184 if (bit & OTF_YAdvance)
2185 READ_INT16 (stream, value_record->YAdvance);
2186 if (bit & OTF_XPlaDevice)
2187 READ_OFFSET (stream, value_record->XPlaDevice.offset);
2188 if (bit & OTF_YPlaDevice)
2189 READ_OFFSET (stream, value_record->YPlaDevice.offset);
2190 if (bit & OTF_XAdvDevice)
2191 READ_OFFSET (stream, value_record->XAdvDevice.offset);
2192 if (bit & OTF_YAdvDevice)
2193 READ_OFFSET (stream, value_record->YAdvDevice.offset);
2194 SAVE_STREAM (stream, state);
2195 if (value_record->XPlaDevice.offset)
2197 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
2200 if (value_record->YPlaDevice.offset)
2202 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
2205 if (value_record->XAdvDevice.offset)
2207 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
2210 if (value_record->YAdvDevice.offset)
2212 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
2215 RESTORE_STREAM (stream, state);
2221 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
2223 char *errfmt = "Anchor%s";
2226 SEEK_STREAM (stream, offset + anchor->offset);
2227 READ_UINT16 (stream, anchor->AnchorFormat);
2228 READ_INT16 (stream, anchor->XCoordinate);
2229 READ_INT16 (stream, anchor->YCoordinate);
2230 if (anchor->AnchorFormat == 1)
2232 else if (anchor->AnchorFormat == 2)
2234 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
2236 else if (anchor->AnchorFormat == 3)
2238 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
2239 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
2240 if (anchor->f.f2.XDeviceTable.offset)
2242 if (read_device_table (otf, stream, offset + anchor->offset,
2243 &anchor->f.f2.XDeviceTable) < 0)
2246 if (anchor->f.f2.YDeviceTable.offset)
2248 if (read_device_table (otf, stream, offset + anchor->offset,
2249 &anchor->f.f2.YDeviceTable) < 0)
2254 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
2260 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
2261 OTF_MarkArray *array)
2263 char *errfmt = "MarkArray%s";
2265 OTF_StreamState state;
2268 READ_OFFSET (stream, array->offset);
2269 SAVE_STREAM (stream, state);
2270 SEEK_STREAM (stream, offset + array->offset);
2271 READ_UINT16 (stream, array->MarkCount);
2272 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
2273 for (i = 0; i < array->MarkCount; i++)
2275 READ_UINT16 (stream, array->MarkRecord[i].Class);
2276 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
2278 for (i = 0; i < array->MarkCount; i++)
2279 if (read_anchor (otf, stream, offset + array->offset,
2280 &array->MarkRecord[i].MarkAnchor) < 0)
2282 RESTORE_STREAM (stream, state);
2287 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
2288 unsigned ClassCount, OTF_AnchorArray *array)
2290 char *errfmt = "AnchorArray%s";
2292 OTF_StreamState state;
2295 READ_OFFSET (stream, array->offset);
2296 SAVE_STREAM (stream, state);
2297 SEEK_STREAM (stream, offset + array->offset);
2298 READ_UINT16 (stream, array->Count);
2299 OTF_MALLOC (array->AnchorRecord, array->Count, "");
2300 for (i = 0; i < array->Count; i++)
2302 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
2304 for (j = 0; j < ClassCount; j++)
2305 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
2307 for (i = 0; i < array->Count; i++)
2308 for (j = 0; j < ClassCount; j++)
2309 if (read_anchor (otf, stream, offset + array->offset,
2310 &array->AnchorRecord[i].Anchor[j]) < 0)
2312 RESTORE_STREAM (stream, state);
2316 static OTF_PairSet *
2317 read_pair_set_list (OTF *otf, OTF_Stream *stream, long offset, unsigned num,
2318 enum OTF_ValueFormat bit1, enum OTF_ValueFormat bit2)
2320 char *errfmt = "PairSet%s";
2321 void *errret = NULL;
2322 OTF_StreamState state;
2326 OTF_MALLOC (set, num, "");
2327 for (i = 0; i < num; i++)
2328 READ_OFFSET (stream, set[i].offset);
2329 SAVE_STREAM (stream, state);
2330 for (i = 0; i < num; i++)
2332 SEEK_STREAM (stream, offset + set[i].offset);
2333 READ_UINT16 (stream, set[i].PairValueCount);
2334 OTF_MALLOC (set[i].PairValueRecord, set[i].PairValueCount, "");
2335 for (j = 0; j < set[i].PairValueCount; j++)
2337 OTF_PairValueRecord *rec = set[i].PairValueRecord + j;
2339 READ_UINT16 (stream, rec->SecondGlyph);
2340 read_value_record (otf, stream, offset, bit1, &rec->Value1);
2341 read_value_record (otf, stream, offset, bit2, &rec->Value2);
2344 RESTORE_STREAM (stream, state);
2348 static OTF_Class1Record *
2349 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
2350 unsigned num1, enum OTF_ValueFormat bit1,
2351 unsigned num2, enum OTF_ValueFormat bit2)
2353 char *errfmt = "Class1Record%s";
2354 void *errret = NULL;
2355 OTF_Class1Record *rec;
2358 OTF_MALLOC (rec, num1, "");
2359 for (i = 0; i < num1; i++)
2361 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
2362 for (j = 0; j < num2; j++)
2364 if (read_value_record (otf, stream, offset,
2365 bit1, &rec[i].Class2Record[j].Value1) < 0
2366 || read_value_record (otf, stream, offset,
2367 bit2, &rec[i].Class2Record[j].Value2) < 0)
2375 read_entry_exit_list (OTF *otf, OTF_Stream *stream, long offset,
2376 OTF_EntryExitRecord **rec)
2378 char *errfmt = "EntryExitSet%s";
2382 OTF_StreamState state;
2384 READ_UINT16 (stream, count);
2386 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
2387 OTF_MALLOC (*rec, count, "");
2388 for (i = 0; i < count; i++)
2390 READ_OFFSET (stream, (*rec)[i].EntryAnchor.offset);
2391 READ_OFFSET (stream, (*rec)[i].ExitAnchor.offset);
2393 SAVE_STREAM (stream, state);
2394 for (i = 0; i < count; i++)
2396 if (read_anchor (otf, stream, offset, &(*rec)[i].EntryAnchor) < 0)
2398 if (read_anchor (otf, stream, offset, &(*rec)[i].ExitAnchor) < 0)
2401 RESTORE_STREAM (stream, state);
2406 read_ligature_attach (OTF *otf, OTF_Stream *stream, long offset,
2407 unsigned ClassCount, OTF_LigatureAttach *attach)
2409 char *errfmt = "LigatureAttach%s";
2413 SEEK_STREAM (stream, offset + attach->offset);
2414 READ_UINT16 (stream, attach->ComponentCount);
2415 OTF_MALLOC (attach->ComponentRecord, attach->ComponentCount, "");
2416 for (i = 0; i < attach->ComponentCount; i++)
2418 OTF_MALLOC (attach->ComponentRecord[i].LigatureAnchor, ClassCount,
2419 " (ComponentRecord)");
2420 for (j = 0; j < ClassCount; j++)
2421 READ_OFFSET (stream,
2422 attach->ComponentRecord[i].LigatureAnchor[j].offset);
2424 for (i = 0; i < attach->ComponentCount; i++)
2425 for (j = 0; j < ClassCount; j++)
2427 if (attach->ComponentRecord[i].LigatureAnchor[j].offset)
2429 if (read_anchor (otf, stream, offset + attach->offset,
2430 &attach->ComponentRecord[i].LigatureAnchor[j]) < 0)
2434 attach->ComponentRecord[i].LigatureAnchor[j].AnchorFormat = 0;
2440 read_ligature_array (OTF *otf, OTF_Stream *stream, long offset,
2441 unsigned class_count, OTF_LigatureArray *array)
2443 char *errfmt = "LigatureArray%s";
2445 OTF_StreamState state;
2448 READ_OFFSET (stream, array->offset);
2449 SAVE_STREAM (stream, state);
2450 SEEK_STREAM (stream, offset + array->offset);
2451 READ_UINT16 (stream, array->LigatureCount);
2452 OTF_MALLOC (array->LigatureAttach, array->LigatureCount, "");
2453 for (i = 0; i < array->LigatureCount; i++)
2454 READ_OFFSET (stream, array->LigatureAttach[i].offset);
2455 for (i = 0; i < array->LigatureCount; i++)
2456 read_ligature_attach (otf, stream, offset + array->offset,
2457 class_count, array->LigatureAttach + i);
2458 RESTORE_STREAM (stream, state);
2463 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
2464 long offset, unsigned type,
2465 OTF_LookupSubTableGPOS *subtable)
2470 SEEK_STREAM (stream, offset);
2471 READ_UINT16 (stream, subtable->Format);
2472 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2476 if (subtable->Format == 1)
2478 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2480 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2481 read_value_record (otf, stream, offset,
2482 subtable->u.single1.ValueFormat,
2483 &subtable->u.single1.Value);
2485 else if (subtable->Format == 2)
2487 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2490 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2492 READ_UINT16 (stream, single2->ValueFormat);
2493 READ_UINT16 (stream, single2->ValueCount);
2494 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2495 for (i = 0; i < single2->ValueCount; i++)
2496 read_value_record (otf, stream, offset, single2->ValueFormat,
2497 single2->Value + i);
2500 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2504 if (subtable->Format == 1)
2506 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2508 READ_UINT16 (stream, subtable->u.pair1.ValueFormat1);
2509 READ_UINT16 (stream, subtable->u.pair1.ValueFormat2);
2510 READ_UINT16 (stream, subtable->u.pair1.PairSetCount);
2511 subtable->u.pair1.PairSet
2512 = read_pair_set_list (otf, stream, offset,
2513 subtable->u.pair1.PairSetCount,
2514 subtable->u.pair1.ValueFormat1,
2515 subtable->u.pair1.ValueFormat2);
2516 if (! subtable->u.pair1.PairSet)
2519 else if (subtable->Format == 2)
2521 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2523 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2524 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2525 if (read_class_def (otf, stream, offset,
2526 &subtable->u.pair2.ClassDef1) < 0
2527 || read_class_def (otf, stream, offset,
2528 &subtable->u.pair2.ClassDef2) < 0)
2530 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2531 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2532 subtable->u.pair2.Class1Record
2533 = read_class1_record_list (otf, stream, offset,
2534 subtable->u.pair2.Class1Count,
2535 subtable->u.pair2.ValueFormat1,
2536 subtable->u.pair2.Class2Count,
2537 subtable->u.pair2.ValueFormat2);
2538 if (! subtable->u.pair2.Class1Record)
2542 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2546 if (subtable->Format == 1)
2548 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2550 subtable->u.cursive1.EntryExitCount
2551 = read_entry_exit_list (otf, stream, offset,
2552 &subtable->u.cursive1.EntryExitRecord);
2553 if (! subtable->u.cursive1.EntryExitCount)
2557 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2561 if (subtable->Format == 1)
2563 read_coverage (otf, stream, offset, &subtable->Coverage);
2564 read_coverage (otf, stream, offset,
2565 &subtable->u.mark_base1.BaseCoverage);
2566 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2567 read_mark_array (otf, stream, offset,
2568 &subtable->u.mark_base1.MarkArray);
2569 read_anchor_array (otf, stream, offset,
2570 subtable->u.mark_base1.ClassCount,
2571 &subtable->u.mark_base1.BaseArray);
2574 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2578 if (subtable->Format == 1)
2580 read_coverage (otf, stream, offset, &subtable->Coverage);
2581 read_coverage (otf, stream, offset,
2582 &subtable->u.mark_lig1.LigatureCoverage);
2583 READ_UINT16 (stream, subtable->u.mark_lig1.ClassCount);
2584 read_mark_array (otf, stream, offset,
2585 &subtable->u.mark_lig1.MarkArray);
2586 read_ligature_array (otf, stream, offset,
2587 subtable->u.mark_lig1.ClassCount,
2588 &subtable->u.mark_lig1.LigatureArray);
2593 if (subtable->Format == 1)
2595 read_coverage (otf, stream, offset, &subtable->Coverage);
2596 read_coverage (otf, stream, offset,
2597 &subtable->u.mark_mark1.Mark2Coverage);
2598 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2599 read_mark_array (otf, stream, offset,
2600 &subtable->u.mark_mark1.Mark1Array);
2601 read_anchor_array (otf, stream, offset,
2602 subtable->u.mark_mark1.ClassCount,
2603 &subtable->u.mark_mark1.Mark2Array);
2606 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2610 if (subtable->Format == 1)
2612 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2613 &subtable->u.context1) < 0)
2616 else if (subtable->Format == 2)
2618 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2619 &subtable->u.context2) < 0)
2622 else if (subtable->Format == 3)
2624 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2625 &subtable->u.context3) < 0)
2629 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2633 if (subtable->Format == 1)
2635 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2636 &subtable->u.chain_context1) < 0)
2639 else if (subtable->Format == 2)
2641 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2642 &subtable->u.chain_context2) < 0)
2645 else if (subtable->Format == 3)
2647 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2648 &subtable->u.chain_context3) < 0)
2652 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2656 if (subtable->Format == 1)
2660 OTF_LookupSubTableGPOS *ex_subtable;
2662 READ_USHORT (stream, ex_type);
2663 READ_ULONG (stream, ex_offset);
2664 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2665 if (read_lookup_subtable_gpos (otf, stream, offset + ex_offset,
2666 ex_type, ex_subtable) < 0)
2668 subtable->u.extension1.ExtensionLookupType = ex_type;
2669 subtable->u.extension1.ExtensionOffset = ex_offset;
2670 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2673 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2677 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2683 read_gpos_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2685 return read_gsub_gpos_table (otf, table, 0, flag);
2693 read_base_table (OTF_Stream *stream, long offset)
2697 OTF_MALLOC (base, 1);
2706 read_jstf_table (OTF_Stream *stream, long offset)
2710 OTF_MALLOC (jstf, 1);
2716 /*** (1-11) Structure for OTF */
2719 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2723 READ_FIXED (stream, table->sfnt_version);
2724 READ_USHORT (stream, table->numTables);
2725 READ_USHORT (stream, table->searchRange);
2726 READ_USHORT (stream, table->enterSelector);
2727 READ_USHORT (stream, table->rangeShift);
2732 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2737 READ_TAG (stream, tag);
2739 table->name[0] = tag >> 24;
2740 table->name[1] = (tag >> 16) & 0xFF;
2741 table->name[2] = (tag >> 8) & 0xFF;
2742 table->name[3] = tag & 0xFF;
2743 table->name[4] = '\0';
2744 READ_ULONG (stream, table->checkSum);
2745 READ_ULONG (stream, table->offset);
2746 READ_ULONG (stream, table->length);
2751 read_header_part (OTF *otf, FILE *fp, FT_Face face)
2753 char *errfmt = "otf header%s";
2756 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2758 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2759 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2760 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2761 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2762 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2763 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2764 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2765 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2766 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2767 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2768 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2769 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2773 OTF_Tag head_tag = OTF_tag ("head");
2774 OTF_Tag name_tag = OTF_tag ("name");
2775 OTF_Tag cmap_tag = OTF_tag ("cmap");
2776 OTF_Tag gdef_tag = OTF_tag ("GDEF");
2777 OTF_Tag gsub_tag = OTF_tag ("GSUB");
2778 OTF_Tag gpos_tag = OTF_tag ("GPOS");
2779 OTF_Stream *stream = make_stream ("Offset Table");
2783 internal_data->header_stream = stream;
2785 /* Size of Offset Table is 12 bytes. */
2786 if (setup_stream (stream, fp, 0, 12) < 0)
2788 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2791 /* Size of each Table Directory is 16 bytes. */
2792 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables) < 0)
2795 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables,
2797 for (i = 0; i < otf->offset_table.numTables; i++)
2799 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2800 OTF_TableInfo *table_info = NULL;
2804 if (tag == head_tag)
2805 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2806 else if (tag == name_tag)
2807 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2808 else if (tag == cmap_tag)
2809 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2810 else if (tag == gdef_tag)
2811 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2812 else if (tag == gsub_tag)
2813 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2814 else if (tag == gpos_tag)
2815 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2819 table_info->stream = make_stream (otf->table_dirs[i].name);
2820 if (setup_stream (table_info->stream, fp,
2821 otf->table_dirs[i].offset,
2822 otf->table_dirs[i].length) < 0)
2827 internal_data->header_stream = NULL;
2828 free_stream (stream);
2834 internal_data->header_stream = NULL;
2835 if ((stream = make_stream_from_ft_face (face, "head")))
2836 internal_data->table_info[OTF_TABLE_TYPE_HEAD].stream = stream;
2837 if ((stream = make_stream_from_ft_face (face, "name")))
2838 internal_data->table_info[OTF_TABLE_TYPE_NAME].stream = stream;
2839 if ((stream = make_stream_from_ft_face (face, "cmap")))
2840 internal_data->table_info[OTF_TABLE_TYPE_CMAP].stream = stream;
2841 if ((stream = make_stream_from_ft_face (face, "GDEF")))
2842 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream = stream;
2843 if ((stream = make_stream_from_ft_face (face, "GSUB")))
2844 internal_data->table_info[OTF_TABLE_TYPE_GSUB].stream = stream;
2845 if ((stream = make_stream_from_ft_face (face, "GPOS")))
2846 internal_data->table_info[OTF_TABLE_TYPE_GPOS].stream = stream;
2852 static OTF_TableInfo *
2853 get_table_info (OTF *otf, const char *name)
2855 char *errfmt = "OTF Table Read%s";
2856 OTF_TableInfo *errret = NULL;
2857 OTF_InternalData *internal_data = otf->internal_data;
2858 OTF_TableInfo *table_info;
2859 OTF_Tag tag = OTF_tag (name);
2862 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2864 if (tag == OTF_tag ("head"))
2865 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2866 else if (tag == OTF_tag ("name"))
2867 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2868 else if (tag == OTF_tag ("cmap"))
2869 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2870 else if (tag == OTF_tag ("GDEF"))
2871 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2872 else if (tag == OTF_tag ("GSUB"))
2873 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2874 else if (tag == OTF_tag ("GPOS"))
2875 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2877 OTF_ERROR (OTF_ERROR_TABLE, " (unsupported table name)");
2879 if (*table_info->address)
2882 if (! table_info->stream)
2883 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2884 if (! table_info->reader)
2885 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2891 /*** (2) API for reading OTF */
2893 /*** (2-1) OTF_open() */
2895 /* Note: We can't use memory allocation macros in the following
2896 functions because those macros return from the functions before
2897 freeing memory previously allocated. */
2900 OTF_open (const char *otf_name)
2903 char *errfmt = "opening otf (%s)";
2904 void *errret = NULL;
2906 OTF_InternalData *internal_data;
2907 int len = strlen (otf_name);
2908 const char *ext = otf_name + (len - 4);
2912 || (ext[1] != 'O' && ext[1] != 'T' && ext[1] != 'o' && ext[1] != 't')
2913 || (ext[2] != 'T' && ext[2] != 't')
2914 || (ext[3] != 'F' && ext[3] != 'f'))
2915 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2916 fp = fopen (otf_name, "r");
2918 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2919 otf = calloc (1, sizeof (OTF));
2921 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2922 otf->filename = strdup (otf_name);
2923 if (! otf->filename)
2927 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2930 internal_data = calloc (1, sizeof (OTF_InternalData));
2931 if (! internal_data)
2932 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2933 otf->internal_data = internal_data;
2934 if (! allocate_memory_record (otf))
2935 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2937 /* Here after, all pointers to allocated memory are recorded in
2938 otf->internal_data->memory_record except for what allocated by
2939 the functions allocate_memory_record and make_stream. */
2941 if (read_header_part (otf, fp, NULL) < 0)
2953 OTF_open_ft_face (FT_Face face)
2955 char *errfmt = "opening otf from Freetype (%s)";
2956 void *errret = NULL;
2958 OTF_InternalData *internal_data;
2960 if (! FT_IS_SFNT (face))
2961 OTF_ERROR (OTF_ERROR_FILE, (char *) face->family_name);
2962 otf = calloc (1, sizeof (OTF));
2964 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2965 otf->filename = NULL;
2967 internal_data = calloc (1, sizeof (OTF_InternalData));
2968 if (! internal_data)
2969 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2970 otf->internal_data = internal_data;
2971 if (! allocate_memory_record (otf))
2972 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2974 if (read_header_part (otf, NULL, face) < 0)
2983 /*** (2-2) OTF_close() */
2986 OTF_close (OTF *otf)
2988 OTF_InternalData *internal_data = otf->internal_data;
2993 OTF_MemoryRecord *memrec = internal_data->memory_record;
2995 if (internal_data->header_stream)
2996 free_stream (internal_data->header_stream);
2998 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
2999 if (internal_data->table_info[i].stream)
3000 free_stream (internal_data->table_info[i].stream);
3004 OTF_MemoryRecord *next = memrec->next;
3006 for (i = memrec->used - 1; i >= 0; i--)
3007 free (memrec->memory[i]);
3011 free (internal_data);
3014 free (otf->filename);
3018 /*** (2-3) OTF_get_table() */
3021 OTF_get_table (OTF *otf, const char *name)
3023 OTF_TableInfo *table_info = get_table_info (otf, name);
3028 if (! table_info->stream)
3029 /* Already fully loaded. */
3032 address = (*table_info->reader) (otf, table_info, OTF_READ_FULL);
3033 free_stream (table_info->stream);
3034 table_info->stream = NULL;
3037 table_info->reader = NULL;
3043 /*** (2-4) OTF_check_table() */
3046 OTF_check_table (OTF *otf, const char *name)
3048 return (get_table_info (otf, name) ? 0 : -1);
3051 /*** (2-5) OTF_get_scripts() */
3054 OTF_get_scripts (OTF *otf, int gsubp)
3056 OTF_TableInfo *table_info
3057 = (otf->internal_data->table_info
3058 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3061 if (! table_info->reader)
3063 if (! table_info->stream)
3064 /* Already fully loaded. */
3067 address = (*table_info->reader) (otf, table_info, OTF_READ_SCRIPTS);
3070 table_info->reader = NULL;
3076 /*** (2-6) OTF_get_features() */
3079 OTF_get_features (OTF *otf, int gsubp)
3081 OTF_TableInfo *table_info
3082 = (otf->internal_data->table_info
3083 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3086 if (! table_info->reader)
3088 if (! table_info->stream)
3090 if (*table_info->address)
3091 /* Already fully loaded. */
3096 address = (*table_info->reader) (otf, table_info, OTF_READ_FEATURES);
3099 table_info->reader = NULL;
3105 /*** (2-7) OTF_check_features */
3108 OTF_check_features (OTF *otf, int gsubp,
3109 OTF_Tag script, OTF_Tag language, const OTF_Tag *features,
3112 OTF_ScriptList *script_list;
3113 OTF_Script *Script = NULL;
3114 OTF_LangSys *LangSys = NULL;
3115 OTF_FeatureList *feature_list;
3118 if (OTF_get_features (otf, gsubp) < 0)
3120 for (i = 0; i < n_features; i++)
3122 OTF_Tag feature = features[i];
3126 if ((((unsigned) feature) & 0x80000000) == 0)
3133 script_list = &otf->gsub->ScriptList;
3134 feature_list = &otf->gsub->FeatureList;
3138 script_list = &otf->gpos->ScriptList;
3139 feature_list = &otf->gpos->FeatureList;
3141 for (i = 0; i < script_list->ScriptCount && ! Script; i++)
3142 if (script_list->Script[i].ScriptTag == script)
3143 Script = script_list->Script + i;
3148 for (i = 0; i < Script->LangSysCount && ! LangSys; i++)
3149 if (Script->LangSysRecord[i].LangSysTag == language)
3150 LangSys = Script->LangSys + i;
3153 LangSys = &Script->DefaultLangSys;
3154 for (j = 0; j < n_features; j++)
3156 OTF_Tag feature = features[j];
3161 if (((unsigned) feature) & 0x80000000)
3163 feature = (OTF_Tag) (((unsigned) feature) & 0x7FFFFFFF);
3166 for (i = 0; i < LangSys->FeatureCount; i++)
3167 if (feature_list->Feature[LangSys->FeatureIndex[i]].FeatureTag
3174 if (i == LangSys->FeatureCount)
3181 /*** (5) API miscellaneous ***/
3184 OTF_tag (const char *name)
3186 const unsigned char *p = (unsigned char *) name;
3190 return (OTF_Tag) ((p[0] << 24)
3194 : (p[2] << 8) | p[3]))));
3198 OTF_tag_name (OTF_Tag tag, char *name)
3200 name[0] = (char) (tag >> 24);
3201 name[1] = (char) ((tag >> 16) & 0xFF);
3202 name[2] = (char) ((tag >> 8) & 0xFF);
3203 name[3] = (char) (tag & 0xFF);