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;
523 READ_UINT24 (stream, varSelector);
524 sub14->Records[i].varSelector=varSelector;
525 READ_ULONG (stream, defaultUVSOffset);
526 sub14->Records[i].defaultUVSOffset=defaultUVSOffset;
527 READ_ULONG (stream, nonDefaultUVSOffset);
528 sub14->Records[i].nonDefaultUVSOffset=nonDefaultUVSOffset;
530 for (i = 0; i < sub14->nRecords; i++)
532 OTF_VariationSelectorRecord *record=&sub14->Records[i];
533 unsigned defaultUVSOffset = record->defaultUVSOffset;
534 unsigned nonDefaultUVSOffset = record->nonDefaultUVSOffset;
535 if (defaultUVSOffset)
537 unsigned numUnicodeValueRanges;
538 SEEK_STREAM (stream, offset+defaultUVSOffset);
539 READ_ULONG (stream, numUnicodeValueRanges);
540 record->numUnicodeValueRanges = numUnicodeValueRanges;
541 OTF_MALLOC (record->unicodeValueRanges,
542 numUnicodeValueRanges,
543 "(EncodingSubtable14-Records-unicodeValueRanges)");
544 for (j = 0; j < numUnicodeValueRanges; j++)
546 OTF_UnicodeValueRange *unicodeValueRange
547 = &record->unicodeValueRanges[j];
548 unsigned startUnicodeValue;
549 char additionalCount;
550 READ_UINT24 (stream, startUnicodeValue);
551 unicodeValueRange->startUnicodeValue=startUnicodeValue;
552 READ_BYTES (stream, &additionalCount, 1);
553 unicodeValueRange->additionalCount = (unsigned short) additionalCount;
556 if (nonDefaultUVSOffset)
558 unsigned numUVSMappings;
559 SEEK_STREAM (stream, offset+nonDefaultUVSOffset);
560 READ_ULONG (stream, numUVSMappings);
561 record->numUVSMappings = numUVSMappings;
562 OTF_MALLOC (record->uvsMappings, numUVSMappings,
563 "(EncodingSubtable14-Records-uvsMappings)");
564 for (j = 0; j < numUVSMappings; j++)
566 OTF_UVSMapping *uvsMapping = &record->uvsMappings[j];
567 unsigned unicodeValue;
568 unsigned short glyphID;
569 READ_UINT24 (stream, unicodeValue);
570 uvsMapping->unicodeValue = unicodeValue;
571 READ_USHORT (stream, glyphID);
572 uvsMapping->glyphID = glyphID;
580 read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
582 OTF_Stream *stream = table->stream;
583 char *errfmt = "cmap%s";
586 int unicode_bmp_index = -1, unicode_full_index = -1;
589 OTF_CALLOC (cmap, 1, "");
590 READ_USHORT (stream, cmap->version);
591 READ_USHORT (stream, cmap->numTables);
592 OTF_MALLOC (cmap->EncodingRecord, cmap->numTables, "");
593 for (i = 0; i < cmap->numTables; i++)
595 unsigned platformID, encodingID;
597 READ_USHORT (stream, platformID);
598 cmap->EncodingRecord[i].platformID = platformID;
599 READ_USHORT (stream, encodingID);
600 cmap->EncodingRecord[i].encodingID = encodingID;
601 READ_ULONG (stream, cmap->EncodingRecord[i].offset);
605 unicode_bmp_index = i;
607 unicode_full_index = i;
609 else if (platformID == 3)
612 unicode_bmp_index = i;
613 else if (encodingID == 10)
614 unicode_full_index = i;
617 for (i = 0; i < cmap->numTables; i++)
621 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
622 READ_USHORT (stream, format);
623 cmap->EncodingRecord[i].subtable.format = format;
626 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
627 cmap->EncodingRecord[i].subtable.language = 0;
631 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
632 if (format == 8 || format == 10 || format == 12)
634 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
635 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
639 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
646 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
647 " (EncodingRecord)");
649 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
656 OTF_EncodingSubtable2 *sub2;
659 OTF_MALLOC (sub2, 1, " (EncodingSubtable2)");
660 cmap->EncodingRecord[i].subtable.f.f2 = sub2;
661 for (j = 0, max_key = 0; j < 256; j++)
663 READ_USHORT (stream, sub2->subHeaderKeys[j]);
664 if (max_key < sub2->subHeaderKeys[j])
665 max_key = sub2->subHeaderKeys[j];
668 sub2->subHeaderCount = max_key / 8;
669 OTF_MALLOC (sub2->subHeaders, max_key / 8, " (subHeaders)");
670 for (j = 0; j < sub2->subHeaderCount; j++)
672 READ_USHORT (stream, sub2->subHeaders[j].firstCode);
673 READ_USHORT (stream, sub2->subHeaders[j].entryCount);
674 READ_SHORT (stream, sub2->subHeaders[j].idDelta);
675 READ_USHORT (stream, sub2->subHeaders[j].idRangeOffset);
676 /* Make it offset from sub2->glyphIndexArray. */
677 sub2->subHeaders[j].idRangeOffset -= max_key - (j * 8 + 6);
679 sub2->glyphIndexCount = (cmap->EncodingRecord[i].subtable.length
681 OTF_MALLOC (sub2->glyphIndexArray, sub2->glyphIndexCount,
682 " (glyphIndexArray)");
683 READ_BYTES (stream, sub2->glyphIndexArray, sub2->glyphIndexCount);
689 OTF_EncodingSubtable4 *sub4;
694 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
695 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
696 READ_USHORT (stream, sub4->segCountX2);
697 segCount = sub4->segCountX2 / 2;
698 READ_USHORT (stream, sub4->searchRange);
699 READ_USHORT (stream, sub4->entrySelector);
700 READ_USHORT (stream, sub4->rangeShift);
701 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
702 for (j = 0; j < segCount; j++)
703 READ_USHORT (stream, sub4->segments[j].endCount);
704 READ_USHORT (stream, dummy);
705 for (j = 0; j < segCount; j++)
706 READ_USHORT (stream, sub4->segments[j].startCount);
707 for (j = 0; j < segCount; j++)
708 READ_SHORT (stream, sub4->segments[j].idDelta);
709 for (j = 0; j < segCount; j++)
712 unsigned rest = 2 * (segCount - j);
714 READ_USHORT (stream, off);
716 sub4->segments[j].idRangeOffset = 0xFFFF;
718 sub4->segments[j].idRangeOffset = (off - rest) / 2;
720 j = (cmap->EncodingRecord[i].subtable.length
721 - (14 + 2 * (segCount * 4 + 1)));
722 sub4->GlyphCount = j / 2;
723 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
724 for (j = 0; j < sub4->GlyphCount; j++)
725 READ_USHORT (stream, sub4->glyphIdArray[j]);
731 OTF_EncodingSubtable6 *sub6;
734 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
735 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
736 READ_USHORT (stream, sub6->firstCode);
737 READ_USHORT (stream, sub6->entryCount);
738 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
739 for (j = 0; j < sub6->entryCount; j++)
740 READ_USHORT (stream, sub6->glyphIdArray[j]);
746 OTF_EncodingSubtable8 *sub8;
749 OTF_MALLOC (sub8, 1, " (EncodingSubtable8)");
750 cmap->EncodingRecord[i].subtable.f.f8 = sub8;
751 for (j = 0; j < 8192; j++)
752 READ_BYTES (stream, sub8->is32, 8192);
753 READ_ULONG (stream, sub8->nGroups);
754 OTF_MALLOC (sub8->Groups, sub8->nGroups, " (Groups)");
755 for (j = 0; j < sub8->nGroups; j++)
757 READ_ULONG (stream, sub8->Groups[i].startCharCode);
758 READ_ULONG (stream, sub8->Groups[i].endCharCode);
759 READ_ULONG (stream, sub8->Groups[i].startGlyphID);
766 OTF_EncodingSubtable10 *sub10;
769 OTF_MALLOC (sub10, 1, " (EncodingSubtable10)");
770 cmap->EncodingRecord[i].subtable.f.f10 = sub10;
771 READ_ULONG (stream, sub10->startCharCode);
772 READ_ULONG (stream, sub10->numChars);
773 OTF_MALLOC (sub10->glyphs, sub10->numChars, " (GlyphCount)");
774 for (j = 0; j < sub10->numChars; j++)
775 READ_USHORT (stream, sub10->glyphs[j]);
781 OTF_EncodingSubtable12 *sub12;
784 OTF_MALLOC (sub12, 1, " (EncodingSubtable12)");
785 cmap->EncodingRecord[i].subtable.f.f12 = sub12;
786 READ_ULONG (stream, sub12->nGroups);
787 OTF_MALLOC (sub12->Groups, sub12->nGroups, " (Groups)");
788 for (j = 0; j < sub12->nGroups; j++)
790 READ_ULONG (stream, sub12->Groups[j].startCharCode);
791 READ_ULONG (stream, sub12->Groups[j].endCharCode);
792 READ_ULONG (stream, sub12->Groups[j].startGlyphID);
799 cmap->EncodingRecord[i].subtable.f.f14
800 = read_cmap_uvs_table (otf, stream,
801 cmap->EncodingRecord[i].offset);
806 OTF_ERROR (OTF_ERROR_TABLE, " (invalid Subtable format)");
810 if (unicode_bmp_index >= 0)
812 OTF_EncodingRecord *rec = cmap->EncodingRecord + unicode_bmp_index;
813 OTF_GlyphID glyph_id, max_glyph_id = 0;
815 OTF_CALLOC (cmap->unicode_table, 0x10000, "");
816 switch (rec->subtable.format)
820 OTF_EncodingSubtable4 *sub4 = rec->subtable.f.f4;
821 int segCount = sub4->segCountX2 / 2;
823 for (i = 0; i < segCount; i++)
825 OTF_cmapSegment *seg = sub4->segments + i;
828 if (seg->idRangeOffset == 0xFFFF)
829 for (c = seg->startCount; c <= seg->endCount; c++)
831 glyph_id = c + seg->idDelta;
832 cmap->unicode_table[c] = glyph_id;
833 if (glyph_id > max_glyph_id)
834 max_glyph_id = glyph_id;
837 for (c = seg->startCount; c <= seg->endCount && c != 0xFFFF;
840 glyph_id = sub4->glyphIdArray[seg->idRangeOffset
841 + (c - seg->startCount)];
842 cmap->unicode_table[c] = glyph_id;
843 if (glyph_id > max_glyph_id)
844 max_glyph_id = glyph_id;
850 OTF_CALLOC (cmap->decode_table, max_glyph_id + 1, "");
851 for (i = 0; i < 0x10000; i++)
852 if (cmap->unicode_table[i])
853 cmap->decode_table[cmap->unicode_table[i]] = i;
854 cmap->max_glyph_id = max_glyph_id;
857 *table->address = cmap;
862 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
864 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
865 Glyph-IDs there. If COUNT is negative, read the number of
866 Glyphs-IDs at first. MINUS if nozero is how few the actual
867 Glyph-IDs are in STREAM than COUNT. */
870 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
871 int minus, int count)
873 char *errfmt = "GlyphID List%s";
878 READ_UINT16 (stream, count);
881 OTF_MALLOC (*ids, count, "");
882 for (i = 0; i < count + minus; i++)
883 READ_GLYPHID (stream, (*ids)[i]);
888 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
890 char *errfmt = "RangeRecord%s";
895 READ_UINT16 (stream, count);
898 OTF_MALLOC (*record, count, "");
899 for (i = 0; i < count; i++)
901 READ_GLYPHID (stream, (*record)[i].Start);
902 READ_GLYPHID (stream, (*record)[i].End);
903 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
910 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
911 OTF_Coverage *coverage)
913 char *errfmt = "Coverage%s";
915 OTF_StreamState state;
918 READ_OFFSET (stream, coverage->offset);
919 SAVE_STREAM (stream, state);
920 SEEK_STREAM (stream, offset + coverage->offset);
921 READ_UINT16 (stream, coverage->CoverageFormat);
922 if (coverage->CoverageFormat == 1)
923 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
924 else if (coverage->CoverageFormat == 2)
925 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
927 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
930 coverage->Count = (unsigned) count;
931 RESTORE_STREAM (stream, state);
935 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
936 and store the Coverages there. If COUNT is negative, read the
937 number of Coverages at first. */
940 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
941 OTF_Coverage **coverage, int count)
943 char *errfmt = "Coverage List%s";
948 READ_UINT16 (stream, count);
951 OTF_MALLOC (*coverage, count, "");
952 for (i = 0; i < count; i++)
953 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
960 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
963 char *errfmt = "ClassDef%s";
966 SEEK_STREAM (stream, class->offset);
967 READ_UINT16 (stream, class->ClassFormat);
968 if (class->ClassFormat == 1)
970 READ_GLYPHID (stream, class->f.f1.StartGlyph);
971 class->f.f1.GlyphCount
973 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
974 if (! class->f.f1.GlyphCount)
975 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
977 else if (class->ClassFormat == 2)
979 class->f.f2.ClassRangeCount
980 = (read_range_records
981 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
982 if (! class->f.f2.ClassRangeCount)
983 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
986 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
992 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
994 char *errfmt = "ClassDef%s";
996 OTF_StreamState state;
998 READ_OFFSET (stream, class->offset);
1001 SAVE_STREAM (stream, state);
1002 SEEK_STREAM (stream, offset + class->offset);
1003 READ_UINT16 (stream, class->ClassFormat);
1004 if (class->ClassFormat == 1)
1006 READ_GLYPHID (stream, class->f.f1.StartGlyph);
1007 class->f.f1.GlyphCount
1008 = read_glyph_ids (otf, stream,
1009 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
1011 if (! class->f.f1.GlyphCount)
1014 else if (class->ClassFormat == 2)
1016 class->f.f2.ClassRangeCount
1017 = read_range_records (otf, stream,
1018 (OTF_RangeRecord **)
1019 &class->f.f2.ClassRangeRecord);
1020 if (! class->f.f2.ClassRangeCount)
1024 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1026 RESTORE_STREAM (stream, state);
1032 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
1033 OTF_DeviceTable *table)
1035 char *errfmt = "Device Table%s";
1046 SEEK_STREAM (stream, offset + table->offset);
1047 READ_UINT16 (stream, table->StartSize);
1048 READ_UINT16 (stream, table->EndSize);
1049 READ_UINT16 (stream, table->DeltaFormat);
1050 num = table->EndSize - table->StartSize + 1;
1051 if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
1053 OTF_MALLOC (table->DeltaValue, num, "");
1055 if (table->DeltaFormat == 1)
1056 for (i = 0; i < num; i++)
1059 READ_UINT16 (stream, val);
1060 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
1061 table->DeltaValue[i] = intval.int2;
1063 else if (table->DeltaFormat == 2)
1064 for (i = 0; i < num; i++)
1067 READ_UINT16 (stream, val);
1068 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
1069 table->DeltaValue[i] = intval.int4;
1071 else /* (table->DeltaFormat == 3) */
1072 for (i = 0; i < num; i++)
1076 READ_UINT16 (stream, val);
1077 intval.int8 = val >> 8;
1078 table->DeltaValue[i] = intval.int8;
1082 intval.int8 = val >> 8;
1083 table->DeltaValue[i] = intval.int8;
1089 /* Invalid DeltaFormat but several fonts has such values (bug of
1090 fontforge?). So accept it with NULL delta values. */
1091 table->DeltaValue = NULL;
1097 /*** (1-6) "GDEF" table */
1100 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
1101 OTF_AttachList *list)
1103 char *errfmt = "AttachList%s";
1107 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1109 READ_UINT16 (stream, list->GlyphCount);
1110 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
1111 for (i = 0; i < list->GlyphCount; i++)
1112 READ_OFFSET (stream, list->AttachPoint[i].offset);
1113 for (i = 0; i < list->GlyphCount; i++)
1117 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
1118 READ_UINT16 (stream, count);
1119 list->AttachPoint[i].PointCount = count;
1120 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
1121 for (j = 0; j < count; j++)
1122 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
1128 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
1129 OTF_CaretValue *caret)
1131 char *errfmt = "CaretValue%s";
1134 SEEK_STREAM (stream, offset + caret->offset);
1135 READ_UINT16 (stream, caret->CaretValueFormat);
1136 if (caret->CaretValueFormat == 1)
1137 READ_INT16 (stream, caret->f.f1.Coordinate);
1138 else if (caret->CaretValueFormat == 2)
1139 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
1140 else if (caret->CaretValueFormat == 3)
1142 READ_INT16 (stream, caret->f.f3.Coordinate);
1143 if (read_device_table (otf, stream, offset + caret->offset,
1144 &caret->f.f3.DeviceTable) < 0)
1148 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
1153 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
1154 OTF_LigCaretList *list)
1156 char *errfmt = "LigCaretList%s";
1160 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
1162 READ_UINT16 (stream, list->LigGlyphCount);
1163 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
1164 for (i = 0; i < list->LigGlyphCount; i++)
1165 READ_OFFSET (stream, list->LigGlyph[i].offset);
1166 for (i = 0; i < list->LigGlyphCount; i++)
1170 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
1171 READ_UINT16 (stream, count);
1172 list->LigGlyph[i].CaretCount = count;
1173 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
1174 for (j = 0; j < count; j++)
1175 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
1176 for (j = 0; j < count; j++)
1177 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
1178 &list->LigGlyph[i].CaretValue[j]) < 0)
1185 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
1189 READ_FIXED (stream, header->Version);
1190 READ_OFFSET (stream, header->GlyphClassDef);
1191 READ_OFFSET (stream, header->AttachList);
1192 READ_OFFSET (stream, header->LigCaretList);
1193 READ_OFFSET (stream, header->MarkAttachClassDef);
1198 read_gdef_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
1200 OTF_Stream *stream = table->stream;
1201 char *errfmt = "GDEF%s";
1202 void *errret = NULL;
1205 OTF_CALLOC (gdef, 1, "");
1206 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
1207 if (gdef->header.GlyphClassDef)
1209 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
1210 read_class_def_without_offset (otf, stream, &gdef->glyph_class_def);
1212 if (gdef->header.AttachList)
1213 read_attach_list (otf, stream, gdef->header.AttachList,
1214 &gdef->attach_list);
1215 if (gdef->header.LigCaretList)
1216 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
1217 &gdef->lig_caret_list);
1218 if (gdef->header.MarkAttachClassDef)
1220 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
1221 read_class_def_without_offset (otf, stream, &gdef->mark_attach_class_def);
1224 *table->address = gdef;
1229 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
1232 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
1233 OTF_ScriptList *list)
1235 char *errfmt = "Script List%s";
1239 SEEK_STREAM (stream, offset);
1240 READ_USHORT (stream, list->ScriptCount);
1241 OTF_CALLOC (list->Script, list->ScriptCount, "");
1243 for (i = 0; i < list->ScriptCount; i++)
1245 READ_TAG (stream, list->Script[i].ScriptTag);
1246 READ_OFFSET (stream, list->Script[i].offset);
1248 for (i = 0; i < list->ScriptCount; i++)
1250 OTF_Script *script = list->Script + i;
1251 long script_offset = offset + script->offset;
1253 SEEK_STREAM (stream, script_offset);
1254 READ_OFFSET (stream, script->DefaultLangSysOffset);
1255 READ_USHORT (stream, script->LangSysCount);
1256 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
1257 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
1258 for (j = 0; j < script->LangSysCount; j++)
1260 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
1261 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
1264 if (script->DefaultLangSysOffset)
1266 OTF_LangSys *langsys = &script->DefaultLangSys;
1268 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
1269 READ_OFFSET (stream, langsys->LookupOrder);
1270 READ_USHORT (stream, langsys->ReqFeatureIndex);
1271 READ_USHORT (stream, langsys->FeatureCount);
1272 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1274 for (k = 0; k < langsys->FeatureCount; k++)
1275 READ_USHORT (stream, langsys->FeatureIndex[k]);
1278 for (j = 0; j < script->LangSysCount; j++)
1280 OTF_LangSys *langsys = script->LangSys + j;
1282 SEEK_STREAM (stream,
1283 script_offset + script->LangSysRecord[j].LangSys);
1284 READ_OFFSET (stream, langsys->LookupOrder);
1285 READ_USHORT (stream, langsys->ReqFeatureIndex);
1286 READ_USHORT (stream, langsys->FeatureCount);
1287 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
1289 for (k = 0; k < langsys->FeatureCount; k++)
1290 READ_USHORT (stream, langsys->FeatureIndex[k]);
1298 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
1299 OTF_FeatureList *list)
1301 char *errfmt = "Feature List%s";
1305 SEEK_STREAM (stream, offset);
1306 READ_UINT16 (stream, list->FeatureCount);
1307 OTF_CALLOC (list->Feature, list->FeatureCount, "");
1308 for (i = 0; i < list->FeatureCount; i++)
1310 READ_TAG (stream, list->Feature[i].FeatureTag);
1311 READ_OFFSET (stream, list->Feature[i].offset);
1313 for (i = 0; i < list->FeatureCount; i++)
1315 OTF_Feature *feature = list->Feature + i;
1317 SEEK_STREAM (stream, offset + feature->offset);
1318 READ_OFFSET (stream, feature->FeatureParams);
1319 READ_UINT16 (stream, feature->LookupCount);
1320 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1321 " (LookupListIndex)");
1322 for (j = 0; j < feature->LookupCount; j++)
1323 READ_UINT16 (stream, feature->LookupListIndex[j]);
1329 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1330 long offset, unsigned type,
1331 OTF_LookupSubTableGSUB *subtable);
1332 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1333 long offset, unsigned type,
1334 OTF_LookupSubTableGPOS *subtable);
1337 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1338 OTF_LookupList *list, int gsubp)
1340 char *errfmt = "Lookup List%s";
1344 SEEK_STREAM (stream, offset);
1345 READ_UINT16 (stream, list->LookupCount);
1346 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1348 for (i = 0; i < list->LookupCount; i++)
1349 READ_OFFSET (stream, list->Lookup[i].offset);
1350 for (i = 0; i < list->LookupCount; i++)
1352 OTF_Lookup *lookup = list->Lookup + i;
1354 SEEK_STREAM (stream, offset + lookup->offset);
1355 READ_UINT16 (stream, lookup->LookupType);
1356 READ_UINT16 (stream, lookup->LookupFlag);
1357 READ_UINT16 (stream, lookup->SubTableCount);
1358 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1359 " (SubTableOffset)");
1361 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1364 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1366 for (j = 0; j < lookup->SubTableCount; j++)
1367 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1368 for (j = 0; j < lookup->SubTableCount; j++)
1371 = offset + lookup->offset + lookup->SubTableOffset[j];
1374 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1376 lookup->SubTable.gsub + j) < 0
1377 : read_lookup_subtable_gpos (otf, stream, this_offset,
1379 lookup->SubTable.gpos + j) < 0)
1388 /*** (1-8) Structures common to GSUB and GPOS */
1391 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1392 OTF_LookupRecord **record, int count)
1394 char *errfmt = "LookupRecord%s";
1395 unsigned errret = 0;
1399 READ_UINT16 (stream, count);
1401 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1402 OTF_MALLOC (*record, count, "");
1403 for (i = 0; i < count; i++)
1405 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1406 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1412 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1414 char *errfmt = "List of Rule%s";
1415 unsigned errret = 0;
1416 OTF_StreamState state;
1420 READ_UINT16 (stream, count);
1422 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1423 OTF_MALLOC (*rule, count, "");
1424 for (i = 0; i < count; i++)
1426 READ_OFFSET (stream, (*rule)[i].offset);
1427 if (! (*rule)[i].offset)
1428 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1430 SAVE_STREAM (stream, state);
1431 for (i = 0; i < count; i++)
1433 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1434 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1435 if ((*rule)[i].GlyphCount == 0)
1436 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1437 READ_UINT16 (stream, (*rule)[i].LookupCount);
1438 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1439 (*rule)[i].GlyphCount) < 0)
1441 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1442 (*rule)[i].LookupCount) == 0)
1445 RESTORE_STREAM (stream, state);
1451 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1454 char *errfmt = "List of RuleSet%s";
1455 unsigned errret = 0;
1456 OTF_StreamState state;
1460 READ_UINT16 (stream, count);
1462 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1463 OTF_MALLOC (*set, count, "");
1464 for (i = 0; i < count; i++)
1466 READ_OFFSET (stream, (*set)[i].offset);
1467 if (! (*set)[i].offset)
1468 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1470 SAVE_STREAM (stream, state);
1471 for (i = 0; i < count; i++)
1473 SEEK_STREAM (stream, offset + (*set)[i].offset);
1475 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1477 if (! (*set)[i].RuleCount)
1480 RESTORE_STREAM (stream, state);
1485 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1486 OTF_ClassRule **rule)
1488 char *errfmt = "ClassRule%s";
1489 unsigned errret = 0;
1490 OTF_StreamState state;
1494 READ_UINT16 (stream, count);
1496 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1497 OTF_MALLOC (*rule, count, "");
1498 for (i = 0; i < count; i++)
1500 READ_OFFSET (stream, (*rule)[i].offset);
1501 if (! (*rule)[i].offset)
1502 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1504 SAVE_STREAM (stream, state);
1505 for (i = 0; i < count; i++)
1507 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1508 READ_USHORT (stream, (*rule)[i].GlyphCount);
1509 if (! (*rule)[i].GlyphCount)
1510 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1511 READ_USHORT (stream, (*rule)[i].LookupCount);
1512 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1513 0, (*rule)[i].GlyphCount - 1) < 0)
1515 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1516 (*rule)[i].LookupCount) == 0)
1519 RESTORE_STREAM (stream, state);
1524 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1527 char *errfmt = "ClassSet%s";
1528 unsigned errret = 0;
1529 OTF_StreamState state;
1533 READ_UINT16 (stream, count);
1535 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1536 OTF_CALLOC (*set, count, "");
1537 for (i = 0; i < count; i++)
1538 /* Offset can be zero. */
1539 READ_OFFSET (stream, (*set)[i].offset);
1540 SAVE_STREAM (stream, state);
1541 for (i = 0; i < count; i++)
1542 if ((*set)[i].offset)
1544 SEEK_STREAM (stream, offset + (*set)[i].offset);
1545 (*set)[i].ClassRuleCnt
1546 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1547 &(*set)[i].ClassRule);
1548 if (! (*set)[i].ClassRuleCnt)
1551 RESTORE_STREAM (stream, state);
1556 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1557 OTF_ChainRule **rule)
1559 char *errfmt = "ChainRule%s";
1560 unsigned errret = 0;
1564 READ_UINT16 (stream, count);
1566 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1567 OTF_MALLOC (*rule, count, "");
1568 for (i = 0; i < count; i++)
1569 READ_OFFSET (stream, (*rule)[i].offset);
1570 for (i = 0; i < count; i++)
1572 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1573 (*rule)[i].BacktrackGlyphCount
1574 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1575 (*rule)[i].InputGlyphCount
1576 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1577 if (! (*rule)[i].InputGlyphCount)
1578 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1579 (*rule)[i].LookaheadGlyphCount
1580 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1581 (*rule)[i].LookupCount
1582 = read_lookup_record_list (otf, stream,
1583 &(*rule)[i].LookupRecord, -1);
1584 if (! (*rule)[i].LookupCount)
1592 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1593 OTF_ChainRuleSet **set)
1595 char *errfmt = "ChainRuleSet%s";
1596 unsigned errret = 0;
1597 OTF_StreamState state;
1601 READ_UINT16 (stream, count);
1603 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1604 OTF_MALLOC (*set, count, "");
1605 for (i = 0; i < count; i++)
1607 READ_OFFSET (stream, (*set)[i].offset);
1608 if (! (*set)[i].offset)
1609 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1611 SAVE_STREAM (stream, state);
1612 for (i = 0; i < count; i++)
1614 SEEK_STREAM (stream, offset + (*set)[i].offset);
1615 (*set)[i].ChainRuleCount
1616 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1617 &(*set)[i].ChainRule);
1618 if (! (*set)[i].ChainRuleCount)
1621 RESTORE_STREAM (stream, state);
1626 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1627 OTF_ChainClassRule **rule)
1629 char *errfmt = "ChainClassRule%s";
1630 unsigned errret = 0;
1634 READ_UINT16 (stream, count);
1636 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1637 OTF_MALLOC (*rule, count, "");
1638 for (i = 0; i < count; i++)
1640 READ_OFFSET (stream, (*rule)[i].offset);
1641 if (! (*rule)[i].offset)
1642 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1644 for (i = 0; i < count; i++)
1646 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1647 (*rule)[i].BacktrackGlyphCount
1648 = read_glyph_ids (otf, stream,
1649 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1650 (*rule)[i].InputGlyphCount
1651 = read_glyph_ids (otf, stream,
1652 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1653 if (! (*rule)[i].InputGlyphCount)
1654 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1655 (*rule)[i].LookaheadGlyphCount
1656 = read_glyph_ids (otf, stream,
1657 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1658 (*rule)[i].LookupCount
1659 = read_lookup_record_list (otf, stream,
1660 &(*rule)[i].LookupRecord, -1);
1661 if (! (*rule)[i].LookupCount)
1668 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1669 OTF_ChainClassSet **set)
1671 char *errfmt = "ChainClassSet%s";
1672 unsigned errret = 0;
1673 OTF_StreamState state;
1677 READ_UINT16 (stream, count);
1679 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1680 OTF_MALLOC (*set, count, "");
1681 for (i = 0; i < count; i++)
1682 /* Offset may be zero. */
1683 READ_OFFSET (stream, (*set)[i].offset);
1684 SAVE_STREAM (stream, state);
1685 for (i = 0; i < count; i++)
1686 if ((*set)[i].offset)
1688 SEEK_STREAM (stream, offset + (*set)[i].offset);
1689 (*set)[i].ChainClassRuleCnt
1690 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1691 &(*set)[i].ChainClassRule);
1692 if (! (*set)[i].ChainClassRuleCnt)
1695 RESTORE_STREAM (stream, state);
1700 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1701 OTF_Coverage *coverage,OTF_Context1 *context1)
1703 if (read_coverage (otf, stream, offset, coverage) < 0)
1705 context1->RuleSetCount
1706 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1707 if (! context1->RuleSetCount)
1713 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1714 OTF_Coverage *coverage,OTF_Context2 *context2)
1716 if (read_coverage (otf, stream, offset, coverage) < 0
1717 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1719 context2->ClassSetCnt
1720 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1721 if (! context2->ClassSetCnt)
1727 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1728 OTF_Coverage *coverage,OTF_Context3 *context3)
1730 char *errfmt = "Context1%s";
1733 READ_USHORT (stream, context3->GlyphCount);
1734 if (context3->GlyphCount < 0)
1735 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1736 READ_USHORT (stream, context3->LookupCount);
1737 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1738 context3->GlyphCount) < 0)
1740 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1741 context3->LookupCount) < 0)
1747 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1748 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1750 if (read_coverage (otf, stream, offset, coverage) < 0)
1752 chain_context1->ChainRuleSetCount
1753 = read_chain_rule_set_list (otf, stream, offset,
1754 &chain_context1->ChainRuleSet);
1755 if (! chain_context1->ChainRuleSetCount)
1761 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1762 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1764 if (read_coverage (otf, stream, offset, coverage) < 0
1765 || read_class_def (otf, stream, offset,
1766 &chain_context2->BacktrackClassDef) < 0
1767 || read_class_def (otf, stream, offset,
1768 &chain_context2->InputClassDef) < 0
1769 || read_class_def (otf, stream, offset,
1770 &chain_context2->LookaheadClassDef) < 0)
1772 chain_context2->ChainClassSetCnt
1773 = read_chain_class_set_list (otf, stream, offset,
1774 &chain_context2->ChainClassSet);
1775 if (! chain_context2->ChainClassSetCnt)
1781 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1782 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1786 count = read_coverage_list (otf, stream, offset,
1787 &chain_context3->Backtrack, -1);
1790 chain_context3->BacktrackGlyphCount = (unsigned) count;
1791 count = read_coverage_list (otf, stream, offset,
1792 &chain_context3->Input, -1);
1795 chain_context3->InputGlyphCount = (unsigned) count;
1796 *coverage = chain_context3->Input[0];
1797 count = read_coverage_list (otf, stream, offset,
1798 &chain_context3->LookAhead, -1);
1799 chain_context3->LookaheadGlyphCount = (unsigned) count;
1800 chain_context3->LookupCount
1801 = read_lookup_record_list (otf, stream,
1802 &chain_context3->LookupRecord, -1);
1807 read_gsub_gpos_table (OTF *otf, OTF_TableInfo *table, int gsubp,
1808 enum OTF_ReaderFlag flag)
1810 OTF_Stream *stream = table->stream;
1811 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1812 void *errret = NULL;
1813 OTF_GSUB_GPOS *gsub_gpos = *table->address;
1816 SEEK_STREAM (stream, 10);
1819 SEEK_STREAM (stream, 0);
1820 OTF_CALLOC (gsub_gpos, 1, "");
1821 READ_FIXED (stream, gsub_gpos->Version);
1822 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1823 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1824 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1825 *table->address = gsub_gpos;
1828 if (! gsub_gpos->ScriptList.Script
1829 && read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1830 &gsub_gpos->ScriptList) < 0)
1832 if (flag != OTF_READ_SCRIPTS)
1834 if (! gsub_gpos->FeatureList.Feature
1835 && read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1836 &gsub_gpos->FeatureList) < 0)
1838 if (flag != OTF_READ_FEATURES)
1840 if (! gsub_gpos->LookupList.Lookup
1841 && read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1842 &gsub_gpos->LookupList, gsubp) < 0)
1851 /* (1-9) "GSUB" table */
1854 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1856 char *errfmt = "Sequence%s";
1857 unsigned errret = 0;
1861 READ_UINT16 (stream, count);
1863 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1864 OTF_MALLOC (*seq, count, "");
1865 for (i = 0; i < count; i++)
1866 READ_OFFSET (stream, (*seq)[i].offset);
1867 for (i = 0; i < count; i++)
1869 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1870 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1871 &(*seq)[i].Substitute, 0, -1);
1872 if (! (*seq)[i].GlyphCount)
1879 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1880 OTF_Ligature **ligature)
1882 char *errfmt = "Ligature%s";
1887 READ_UINT16 (stream, count);
1890 OTF_MALLOC (*ligature, count, "");
1891 for (i = 0; i < count; i++)
1892 READ_OFFSET (stream, (*ligature)[i].offset);
1893 for (i = 0; i < count; i++)
1895 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1896 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1897 (*ligature)[i].CompCount
1898 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1899 if (! (*ligature)[i].CompCount)
1906 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1907 OTF_LigatureSet **ligset)
1909 char *errfmt = "LigatureSet%s";
1914 READ_UINT16 (stream, count);
1917 OTF_MALLOC (*ligset, count, "");
1918 for (i = 0; i < count; i++)
1919 READ_OFFSET (stream, (*ligset)[i].offset);
1920 for (i = 0; i < count; i++)
1924 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1925 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1926 &(*ligset)[i].Ligature);
1929 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1935 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1936 OTF_AlternateSet **altset)
1938 char *errfmt = "AlternateSet%s";
1943 READ_UINT16 (stream, count);
1945 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1946 OTF_MALLOC (*altset, count, "");
1947 for (i = 0; i < count; i++)
1948 READ_OFFSET (stream, (*altset)[i].offset);
1949 for (i = 0; i < count; i++)
1953 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1954 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1957 (*altset)[i].GlyphCount = (unsigned) alt_count;
1963 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1964 OTF_Coverage *coverage,
1965 OTF_GSUB_ReverseChain1 *reverse_chain)
1969 if (read_coverage (otf, stream, offset, coverage) < 0)
1971 count = read_coverage_list (otf, stream, offset,
1972 &reverse_chain->Backtrack, -1);
1975 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1976 count = read_coverage_list (otf, stream, offset,
1977 &reverse_chain->LookAhead, -1);
1980 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1981 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
1984 reverse_chain->GlyphCount = count;
1989 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
1990 unsigned type, OTF_LookupSubTableGSUB *subtable)
1995 SEEK_STREAM (stream, offset);
1996 READ_USHORT (stream, subtable->Format);
1997 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
2001 if (subtable->Format == 1)
2003 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2005 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
2007 else if (subtable->Format == 2)
2009 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2011 subtable->u.single2.GlyphCount
2012 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
2014 if (! subtable->u.single2.GlyphCount)
2018 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2022 if (subtable->Format == 1)
2024 read_coverage (otf, stream, offset, &subtable->Coverage);
2025 subtable->u.multiple1.SequenceCount
2026 = read_sequence (otf, stream, offset,
2027 &subtable->u.multiple1.Sequence);
2030 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2034 if (subtable->Format == 1)
2036 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2038 subtable->u.alternate1.AlternateSetCount
2039 = read_alternate_set_list (otf, stream, offset,
2040 &subtable->u.alternate1.AlternateSet);
2041 if (! subtable->u.alternate1.AlternateSetCount)
2045 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2049 if (subtable->Format == 1)
2051 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2053 subtable->u.ligature1.LigSetCount
2054 = read_ligature_set_list (otf, stream, offset,
2055 &subtable->u.ligature1.LigatureSet);
2056 if (! subtable->u.ligature1.LigSetCount)
2060 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2064 if (subtable->Format == 1)
2066 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2067 &subtable->u.context1) < 0)
2070 else if (subtable->Format == 2)
2072 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2073 &subtable->u.context2) < 0)
2076 else if (subtable->Format == 3)
2078 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2079 &subtable->u.context3) < 0)
2083 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2087 if (subtable->Format == 1)
2089 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2090 &subtable->u.chain_context1) < 0)
2093 else if (subtable->Format == 2)
2095 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2096 &subtable->u.chain_context2) < 0)
2099 else if (subtable->Format == 3)
2101 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2102 &subtable->u.chain_context3) < 0)
2106 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2110 if (subtable->Format == 1)
2114 OTF_LookupSubTableGSUB *ex_subtable;
2116 READ_USHORT (stream, ex_type);
2117 READ_ULONG (stream, ex_offset);
2118 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2119 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
2120 ex_type, ex_subtable) < 0)
2122 subtable->u.extension1.ExtensionLookupType = ex_type;
2123 subtable->u.extension1.ExtensionOffset = ex_offset;
2124 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2127 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2131 if (subtable->Format == 1)
2133 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
2134 &subtable->u.reverse_chain1) < 0)
2138 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2142 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2148 read_gsub_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2150 return read_gsub_gpos_table (otf, table, 1, flag);
2154 /* (1-10) "GPOS" table */
2157 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
2158 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
2161 OTF_StreamState state;
2164 memset (value_record, 0, sizeof (OTF_ValueRecord));
2167 for (i = 0, size = 0; i < 8; i++)
2171 if (bit & OTF_XPlacement)
2172 READ_INT16 (stream, value_record->XPlacement);
2173 if (bit & OTF_YPlacement)
2174 READ_INT16 (stream, value_record->YPlacement);
2175 if (bit & OTF_XAdvance)
2176 READ_INT16 (stream, value_record->XAdvance);
2177 if (bit & OTF_YAdvance)
2178 READ_INT16 (stream, value_record->YAdvance);
2179 if (bit & OTF_XPlaDevice)
2180 READ_OFFSET (stream, value_record->XPlaDevice.offset);
2181 if (bit & OTF_YPlaDevice)
2182 READ_OFFSET (stream, value_record->YPlaDevice.offset);
2183 if (bit & OTF_XAdvDevice)
2184 READ_OFFSET (stream, value_record->XAdvDevice.offset);
2185 if (bit & OTF_YAdvDevice)
2186 READ_OFFSET (stream, value_record->YAdvDevice.offset);
2187 SAVE_STREAM (stream, state);
2188 if (value_record->XPlaDevice.offset)
2190 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
2193 if (value_record->YPlaDevice.offset)
2195 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
2198 if (value_record->XAdvDevice.offset)
2200 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
2203 if (value_record->YAdvDevice.offset)
2205 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
2208 RESTORE_STREAM (stream, state);
2214 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
2216 char *errfmt = "Anchor%s";
2219 SEEK_STREAM (stream, offset + anchor->offset);
2220 READ_UINT16 (stream, anchor->AnchorFormat);
2221 READ_INT16 (stream, anchor->XCoordinate);
2222 READ_INT16 (stream, anchor->YCoordinate);
2223 if (anchor->AnchorFormat == 1)
2225 else if (anchor->AnchorFormat == 2)
2227 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
2229 else if (anchor->AnchorFormat == 3)
2231 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
2232 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
2233 if (anchor->f.f2.XDeviceTable.offset)
2235 if (read_device_table (otf, stream, offset + anchor->offset,
2236 &anchor->f.f2.XDeviceTable) < 0)
2239 if (anchor->f.f2.YDeviceTable.offset)
2241 if (read_device_table (otf, stream, offset + anchor->offset,
2242 &anchor->f.f2.YDeviceTable) < 0)
2247 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
2253 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
2254 OTF_MarkArray *array)
2256 char *errfmt = "MarkArray%s";
2258 OTF_StreamState state;
2261 READ_OFFSET (stream, array->offset);
2262 SAVE_STREAM (stream, state);
2263 SEEK_STREAM (stream, offset + array->offset);
2264 READ_UINT16 (stream, array->MarkCount);
2265 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
2266 for (i = 0; i < array->MarkCount; i++)
2268 READ_UINT16 (stream, array->MarkRecord[i].Class);
2269 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
2271 for (i = 0; i < array->MarkCount; i++)
2272 if (read_anchor (otf, stream, offset + array->offset,
2273 &array->MarkRecord[i].MarkAnchor) < 0)
2275 RESTORE_STREAM (stream, state);
2280 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
2281 unsigned ClassCount, OTF_AnchorArray *array)
2283 char *errfmt = "AnchorArray%s";
2285 OTF_StreamState state;
2288 READ_OFFSET (stream, array->offset);
2289 SAVE_STREAM (stream, state);
2290 SEEK_STREAM (stream, offset + array->offset);
2291 READ_UINT16 (stream, array->Count);
2292 OTF_MALLOC (array->AnchorRecord, array->Count, "");
2293 for (i = 0; i < array->Count; i++)
2295 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
2297 for (j = 0; j < ClassCount; j++)
2298 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
2300 for (i = 0; i < array->Count; i++)
2301 for (j = 0; j < ClassCount; j++)
2302 if (read_anchor (otf, stream, offset + array->offset,
2303 &array->AnchorRecord[i].Anchor[j]) < 0)
2305 RESTORE_STREAM (stream, state);
2309 static OTF_PairSet *
2310 read_pair_set_list (OTF *otf, OTF_Stream *stream, long offset, unsigned num,
2311 enum OTF_ValueFormat bit1, enum OTF_ValueFormat bit2)
2313 char *errfmt = "PairSet%s";
2314 void *errret = NULL;
2315 OTF_StreamState state;
2319 OTF_MALLOC (set, num, "");
2320 for (i = 0; i < num; i++)
2321 READ_OFFSET (stream, set[i].offset);
2322 SAVE_STREAM (stream, state);
2323 for (i = 0; i < num; i++)
2325 SEEK_STREAM (stream, offset + set[i].offset);
2326 READ_UINT16 (stream, set[i].PairValueCount);
2327 OTF_MALLOC (set[i].PairValueRecord, set[i].PairValueCount, "");
2328 for (j = 0; j < set[i].PairValueCount; j++)
2330 OTF_PairValueRecord *rec = set[i].PairValueRecord + j;
2332 READ_UINT16 (stream, rec->SecondGlyph);
2333 read_value_record (otf, stream, offset, bit1, &rec->Value1);
2334 read_value_record (otf, stream, offset, bit2, &rec->Value2);
2337 RESTORE_STREAM (stream, state);
2341 static OTF_Class1Record *
2342 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
2343 unsigned num1, enum OTF_ValueFormat bit1,
2344 unsigned num2, enum OTF_ValueFormat bit2)
2346 char *errfmt = "Class1Record%s";
2347 void *errret = NULL;
2348 OTF_Class1Record *rec;
2351 OTF_MALLOC (rec, num1, "");
2352 for (i = 0; i < num1; i++)
2354 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
2355 for (j = 0; j < num2; j++)
2357 if (read_value_record (otf, stream, offset,
2358 bit1, &rec[i].Class2Record[j].Value1) < 0
2359 || read_value_record (otf, stream, offset,
2360 bit2, &rec[i].Class2Record[j].Value2) < 0)
2368 read_entry_exit_list (OTF *otf, OTF_Stream *stream, long offset,
2369 OTF_EntryExitRecord **rec)
2371 char *errfmt = "EntryExitSet%s";
2375 OTF_StreamState state;
2377 READ_UINT16 (stream, count);
2379 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
2380 OTF_MALLOC (*rec, count, "");
2381 for (i = 0; i < count; i++)
2383 READ_OFFSET (stream, (*rec)[i].EntryAnchor.offset);
2384 READ_OFFSET (stream, (*rec)[i].ExitAnchor.offset);
2386 SAVE_STREAM (stream, state);
2387 for (i = 0; i < count; i++)
2389 if (read_anchor (otf, stream, offset, &(*rec)[i].EntryAnchor) < 0)
2391 if (read_anchor (otf, stream, offset, &(*rec)[i].ExitAnchor) < 0)
2394 RESTORE_STREAM (stream, state);
2399 read_ligature_attach (OTF *otf, OTF_Stream *stream, long offset,
2400 unsigned ClassCount, OTF_LigatureAttach *attach)
2402 char *errfmt = "LigatureAttach%s";
2406 SEEK_STREAM (stream, offset + attach->offset);
2407 READ_UINT16 (stream, attach->ComponentCount);
2408 OTF_MALLOC (attach->ComponentRecord, attach->ComponentCount, "");
2409 for (i = 0; i < attach->ComponentCount; i++)
2411 OTF_MALLOC (attach->ComponentRecord[i].LigatureAnchor, ClassCount,
2412 " (ComponentRecord)");
2413 for (j = 0; j < ClassCount; j++)
2414 READ_OFFSET (stream,
2415 attach->ComponentRecord[i].LigatureAnchor[j].offset);
2417 for (i = 0; i < attach->ComponentCount; i++)
2418 for (j = 0; j < ClassCount; j++)
2420 if (attach->ComponentRecord[i].LigatureAnchor[j].offset)
2422 if (read_anchor (otf, stream, offset + attach->offset,
2423 &attach->ComponentRecord[i].LigatureAnchor[j]) < 0)
2427 attach->ComponentRecord[i].LigatureAnchor[j].AnchorFormat = 0;
2433 read_ligature_array (OTF *otf, OTF_Stream *stream, long offset,
2434 unsigned class_count, OTF_LigatureArray *array)
2436 char *errfmt = "LigatureArray%s";
2438 OTF_StreamState state;
2441 READ_OFFSET (stream, array->offset);
2442 SAVE_STREAM (stream, state);
2443 SEEK_STREAM (stream, offset + array->offset);
2444 READ_UINT16 (stream, array->LigatureCount);
2445 OTF_MALLOC (array->LigatureAttach, array->LigatureCount, "");
2446 for (i = 0; i < array->LigatureCount; i++)
2447 READ_OFFSET (stream, array->LigatureAttach[i].offset);
2448 for (i = 0; i < array->LigatureCount; i++)
2449 read_ligature_attach (otf, stream, offset + array->offset,
2450 class_count, array->LigatureAttach + i);
2451 RESTORE_STREAM (stream, state);
2456 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
2457 long offset, unsigned type,
2458 OTF_LookupSubTableGPOS *subtable)
2463 SEEK_STREAM (stream, offset);
2464 READ_UINT16 (stream, subtable->Format);
2465 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2469 if (subtable->Format == 1)
2471 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2473 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2474 read_value_record (otf, stream, offset,
2475 subtable->u.single1.ValueFormat,
2476 &subtable->u.single1.Value);
2478 else if (subtable->Format == 2)
2480 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2483 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2485 READ_UINT16 (stream, single2->ValueFormat);
2486 READ_UINT16 (stream, single2->ValueCount);
2487 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2488 for (i = 0; i < single2->ValueCount; i++)
2489 read_value_record (otf, stream, offset, single2->ValueFormat,
2490 single2->Value + i);
2493 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2497 if (subtable->Format == 1)
2499 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2501 READ_UINT16 (stream, subtable->u.pair1.ValueFormat1);
2502 READ_UINT16 (stream, subtable->u.pair1.ValueFormat2);
2503 READ_UINT16 (stream, subtable->u.pair1.PairSetCount);
2504 subtable->u.pair1.PairSet
2505 = read_pair_set_list (otf, stream, offset,
2506 subtable->u.pair1.PairSetCount,
2507 subtable->u.pair1.ValueFormat1,
2508 subtable->u.pair1.ValueFormat2);
2509 if (! subtable->u.pair1.PairSet)
2512 else if (subtable->Format == 2)
2514 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2516 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2517 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2518 if (read_class_def (otf, stream, offset,
2519 &subtable->u.pair2.ClassDef1) < 0
2520 || read_class_def (otf, stream, offset,
2521 &subtable->u.pair2.ClassDef2) < 0)
2523 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2524 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2525 subtable->u.pair2.Class1Record
2526 = read_class1_record_list (otf, stream, offset,
2527 subtable->u.pair2.Class1Count,
2528 subtable->u.pair2.ValueFormat1,
2529 subtable->u.pair2.Class2Count,
2530 subtable->u.pair2.ValueFormat2);
2531 if (! subtable->u.pair2.Class1Record)
2535 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2539 if (subtable->Format == 1)
2541 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
2543 subtable->u.cursive1.EntryExitCount
2544 = read_entry_exit_list (otf, stream, offset,
2545 &subtable->u.cursive1.EntryExitRecord);
2546 if (! subtable->u.cursive1.EntryExitCount)
2550 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2554 if (subtable->Format == 1)
2556 read_coverage (otf, stream, offset, &subtable->Coverage);
2557 read_coverage (otf, stream, offset,
2558 &subtable->u.mark_base1.BaseCoverage);
2559 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2560 read_mark_array (otf, stream, offset,
2561 &subtable->u.mark_base1.MarkArray);
2562 read_anchor_array (otf, stream, offset,
2563 subtable->u.mark_base1.ClassCount,
2564 &subtable->u.mark_base1.BaseArray);
2567 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2571 if (subtable->Format == 1)
2573 read_coverage (otf, stream, offset, &subtable->Coverage);
2574 read_coverage (otf, stream, offset,
2575 &subtable->u.mark_lig1.LigatureCoverage);
2576 READ_UINT16 (stream, subtable->u.mark_lig1.ClassCount);
2577 read_mark_array (otf, stream, offset,
2578 &subtable->u.mark_lig1.MarkArray);
2579 read_ligature_array (otf, stream, offset,
2580 subtable->u.mark_lig1.ClassCount,
2581 &subtable->u.mark_lig1.LigatureArray);
2586 if (subtable->Format == 1)
2588 read_coverage (otf, stream, offset, &subtable->Coverage);
2589 read_coverage (otf, stream, offset,
2590 &subtable->u.mark_mark1.Mark2Coverage);
2591 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2592 read_mark_array (otf, stream, offset,
2593 &subtable->u.mark_mark1.Mark1Array);
2594 read_anchor_array (otf, stream, offset,
2595 subtable->u.mark_mark1.ClassCount,
2596 &subtable->u.mark_mark1.Mark2Array);
2599 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2603 if (subtable->Format == 1)
2605 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2606 &subtable->u.context1) < 0)
2609 else if (subtable->Format == 2)
2611 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2612 &subtable->u.context2) < 0)
2615 else if (subtable->Format == 3)
2617 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2618 &subtable->u.context3) < 0)
2622 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2626 if (subtable->Format == 1)
2628 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2629 &subtable->u.chain_context1) < 0)
2632 else if (subtable->Format == 2)
2634 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2635 &subtable->u.chain_context2) < 0)
2638 else if (subtable->Format == 3)
2640 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2641 &subtable->u.chain_context3) < 0)
2645 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2649 if (subtable->Format == 1)
2653 OTF_LookupSubTableGPOS *ex_subtable;
2655 READ_USHORT (stream, ex_type);
2656 READ_ULONG (stream, ex_offset);
2657 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
2658 if (read_lookup_subtable_gpos (otf, stream, offset + ex_offset,
2659 ex_type, ex_subtable) < 0)
2661 subtable->u.extension1.ExtensionLookupType = ex_type;
2662 subtable->u.extension1.ExtensionOffset = ex_offset;
2663 subtable->u.extension1.ExtensionSubtable = ex_subtable;
2666 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2670 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2676 read_gpos_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
2678 return read_gsub_gpos_table (otf, table, 0, flag);
2686 read_base_table (OTF_Stream *stream, long offset)
2690 OTF_MALLOC (base, 1);
2699 read_jstf_table (OTF_Stream *stream, long offset)
2703 OTF_MALLOC (jstf, 1);
2709 /*** (1-11) Structure for OTF */
2712 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2716 READ_FIXED (stream, table->sfnt_version);
2717 READ_USHORT (stream, table->numTables);
2718 READ_USHORT (stream, table->searchRange);
2719 READ_USHORT (stream, table->enterSelector);
2720 READ_USHORT (stream, table->rangeShift);
2725 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2730 READ_TAG (stream, tag);
2732 table->name[0] = tag >> 24;
2733 table->name[1] = (tag >> 16) & 0xFF;
2734 table->name[2] = (tag >> 8) & 0xFF;
2735 table->name[3] = tag & 0xFF;
2736 table->name[4] = '\0';
2737 READ_ULONG (stream, table->checkSum);
2738 READ_ULONG (stream, table->offset);
2739 READ_ULONG (stream, table->length);
2744 read_header_part (OTF *otf, FILE *fp, FT_Face face)
2746 char *errfmt = "otf header%s";
2749 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2751 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2752 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2753 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2754 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2755 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2756 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2757 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2758 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2759 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2760 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2761 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2762 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2766 OTF_Tag head_tag = OTF_tag ("head");
2767 OTF_Tag name_tag = OTF_tag ("name");
2768 OTF_Tag cmap_tag = OTF_tag ("cmap");
2769 OTF_Tag gdef_tag = OTF_tag ("GDEF");
2770 OTF_Tag gsub_tag = OTF_tag ("GSUB");
2771 OTF_Tag gpos_tag = OTF_tag ("GPOS");
2772 OTF_Stream *stream = make_stream ("Offset Table");
2776 internal_data->header_stream = stream;
2778 /* Size of Offset Table is 12 bytes. */
2779 if (setup_stream (stream, fp, 0, 12) < 0)
2781 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2784 /* Size of each Table Directory is 16 bytes. */
2785 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables) < 0)
2788 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables,
2790 for (i = 0; i < otf->offset_table.numTables; i++)
2792 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2793 OTF_TableInfo *table_info = NULL;
2797 if (tag == head_tag)
2798 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2799 else if (tag == name_tag)
2800 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2801 else if (tag == cmap_tag)
2802 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2803 else if (tag == gdef_tag)
2804 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2805 else if (tag == gsub_tag)
2806 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2807 else if (tag == gpos_tag)
2808 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2812 table_info->stream = make_stream (otf->table_dirs[i].name);
2813 if (setup_stream (table_info->stream, fp,
2814 otf->table_dirs[i].offset,
2815 otf->table_dirs[i].length) < 0)
2820 internal_data->header_stream = NULL;
2821 free_stream (stream);
2827 internal_data->header_stream = NULL;
2828 if ((stream = make_stream_from_ft_face (face, "head")))
2829 internal_data->table_info[OTF_TABLE_TYPE_HEAD].stream = stream;
2830 if ((stream = make_stream_from_ft_face (face, "name")))
2831 internal_data->table_info[OTF_TABLE_TYPE_NAME].stream = stream;
2832 if ((stream = make_stream_from_ft_face (face, "cmap")))
2833 internal_data->table_info[OTF_TABLE_TYPE_CMAP].stream = stream;
2834 if ((stream = make_stream_from_ft_face (face, "GDEF")))
2835 internal_data->table_info[OTF_TABLE_TYPE_GDEF].stream = stream;
2836 if ((stream = make_stream_from_ft_face (face, "GSUB")))
2837 internal_data->table_info[OTF_TABLE_TYPE_GSUB].stream = stream;
2838 if ((stream = make_stream_from_ft_face (face, "GPOS")))
2839 internal_data->table_info[OTF_TABLE_TYPE_GPOS].stream = stream;
2845 static OTF_TableInfo *
2846 get_table_info (OTF *otf, const char *name)
2848 char *errfmt = "OTF Table Read%s";
2849 OTF_TableInfo *errret = NULL;
2850 OTF_InternalData *internal_data = otf->internal_data;
2851 OTF_TableInfo *table_info;
2852 OTF_Tag tag = OTF_tag (name);
2855 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2857 if (tag == OTF_tag ("head"))
2858 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2859 else if (tag == OTF_tag ("name"))
2860 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2861 else if (tag == OTF_tag ("cmap"))
2862 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2863 else if (tag == OTF_tag ("GDEF"))
2864 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2865 else if (tag == OTF_tag ("GSUB"))
2866 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2867 else if (tag == OTF_tag ("GPOS"))
2868 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2870 OTF_ERROR (OTF_ERROR_TABLE, " (unsupported table name)");
2872 if (*table_info->address)
2875 if (! table_info->stream)
2876 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2877 if (! table_info->reader)
2878 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2884 /*** (2) API for reading OTF */
2886 /*** (2-1) OTF_open() */
2888 /* Note: We can't use memory allocation macros in the following
2889 functions because those macros return from the functions before
2890 freeing memory previously allocated. */
2893 OTF_open (const char *otf_name)
2896 char *errfmt = "opening otf (%s)";
2897 void *errret = NULL;
2899 OTF_InternalData *internal_data;
2900 int len = strlen (otf_name);
2901 const char *ext = otf_name + (len - 4);
2905 || (ext[1] != 'O' && ext[1] != 'T' && ext[1] != 'o' && ext[1] != 't')
2906 || (ext[2] != 'T' && ext[2] != 't')
2907 || (ext[3] != 'F' && ext[3] != 'f'))
2908 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2909 fp = fopen (otf_name, "r");
2911 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2912 otf = calloc (1, sizeof (OTF));
2914 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2915 otf->filename = strdup (otf_name);
2916 if (! otf->filename)
2920 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2923 internal_data = calloc (1, sizeof (OTF_InternalData));
2924 if (! internal_data)
2925 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2926 otf->internal_data = internal_data;
2927 if (! allocate_memory_record (otf))
2928 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2930 /* Here after, all pointers to allocated memory are recorded in
2931 otf->internal_data->memory_record except for what allocated by
2932 the functions allocate_memory_record and make_stream. */
2934 if (read_header_part (otf, fp, NULL) < 0)
2946 OTF_open_ft_face (FT_Face face)
2948 char *errfmt = "opening otf from Freetype (%s)";
2949 void *errret = NULL;
2951 OTF_InternalData *internal_data;
2953 if (! FT_IS_SFNT (face))
2954 OTF_ERROR (OTF_ERROR_FILE, (char *) face->family_name);
2955 otf = calloc (1, sizeof (OTF));
2957 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2958 otf->filename = NULL;
2960 internal_data = calloc (1, sizeof (OTF_InternalData));
2961 if (! internal_data)
2962 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2963 otf->internal_data = internal_data;
2964 if (! allocate_memory_record (otf))
2965 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2967 if (read_header_part (otf, NULL, face) < 0)
2976 /*** (2-2) OTF_close() */
2979 OTF_close (OTF *otf)
2981 OTF_InternalData *internal_data = otf->internal_data;
2986 OTF_MemoryRecord *memrec = internal_data->memory_record;
2988 if (internal_data->header_stream)
2989 free_stream (internal_data->header_stream);
2991 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
2992 if (internal_data->table_info[i].stream)
2993 free_stream (internal_data->table_info[i].stream);
2997 OTF_MemoryRecord *next = memrec->next;
2999 for (i = memrec->used - 1; i >= 0; i--)
3000 free (memrec->memory[i]);
3004 free (internal_data);
3007 free (otf->filename);
3011 /*** (2-3) OTF_get_table() */
3014 OTF_get_table (OTF *otf, const char *name)
3016 OTF_TableInfo *table_info = get_table_info (otf, name);
3021 if (! table_info->stream)
3022 /* Already fully loaded. */
3025 address = (*table_info->reader) (otf, table_info, OTF_READ_FULL);
3026 free_stream (table_info->stream);
3027 table_info->stream = NULL;
3030 table_info->reader = NULL;
3036 /*** (2-4) OTF_check_table() */
3039 OTF_check_table (OTF *otf, const char *name)
3041 return (get_table_info (otf, name) ? 0 : -1);
3044 /*** (2-5) OTF_get_scripts() */
3047 OTF_get_scripts (OTF *otf, int gsubp)
3049 OTF_TableInfo *table_info
3050 = (otf->internal_data->table_info
3051 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3054 if (! table_info->reader)
3056 if (! table_info->stream)
3057 /* Already fully loaded. */
3060 address = (*table_info->reader) (otf, table_info, OTF_READ_SCRIPTS);
3063 table_info->reader = NULL;
3069 /*** (2-6) OTF_get_features() */
3072 OTF_get_features (OTF *otf, int gsubp)
3074 OTF_TableInfo *table_info
3075 = (otf->internal_data->table_info
3076 + (gsubp ? OTF_TABLE_TYPE_GSUB : OTF_TABLE_TYPE_GPOS));
3079 if (! table_info->reader)
3081 if (! table_info->stream)
3083 if (*table_info->address)
3084 /* Already fully loaded. */
3089 address = (*table_info->reader) (otf, table_info, OTF_READ_FEATURES);
3092 table_info->reader = NULL;
3098 /*** (2-7) OTF_check_features */
3101 OTF_check_features (OTF *otf, int gsubp,
3102 OTF_Tag script, OTF_Tag language, const OTF_Tag *features,
3105 OTF_ScriptList *script_list;
3106 OTF_Script *Script = NULL;
3107 OTF_LangSys *LangSys = NULL;
3108 OTF_FeatureList *feature_list;
3111 if (OTF_get_features (otf, gsubp) < 0)
3113 for (i = 0; i < n_features; i++)
3115 OTF_Tag feature = features[i];
3119 if ((((unsigned) feature) & 0x80000000) == 0)
3126 script_list = &otf->gsub->ScriptList;
3127 feature_list = &otf->gsub->FeatureList;
3131 script_list = &otf->gpos->ScriptList;
3132 feature_list = &otf->gpos->FeatureList;
3134 for (i = 0; i < script_list->ScriptCount && ! Script; i++)
3135 if (script_list->Script[i].ScriptTag == script)
3136 Script = script_list->Script + i;
3141 for (i = 0; i < Script->LangSysCount && ! LangSys; i++)
3142 if (Script->LangSysRecord[i].LangSysTag == language)
3143 LangSys = Script->LangSys + i;
3146 LangSys = &Script->DefaultLangSys;
3147 for (j = 0; j < n_features; j++)
3149 OTF_Tag feature = features[j];
3154 if (((unsigned) feature) & 0x80000000)
3156 feature = (OTF_Tag) (((unsigned) feature) & 0x7FFFFFFF);
3159 for (i = 0; i < LangSys->FeatureCount; i++)
3160 if (feature_list->Feature[LangSys->FeatureIndex[i]].FeatureTag
3167 if (i == LangSys->FeatureCount)
3174 /*** (5) API miscellaneous ***/
3177 OTF_tag (const char *name)
3179 const unsigned char *p = (unsigned char *) name;
3183 return (OTF_Tag) ((p[0] << 24)
3187 : (p[2] << 8) | p[3]))));
3191 OTF_tag_name (OTF_Tag tag, char *name)
3193 name[0] = (char) (tag >> 24);
3194 name[1] = (char) ((tag >> 16) & 0xFF);
3195 name[2] = (char) ((tag >> 8) & 0xFF);
3196 name[3] = (char) (tag & 0xFF);