1 /* otfopen.c -- OpenType font reader.
4 by AIST (National Institute of Advanced Industrial Science and Technology)
5 Registration Number H15PRO???
7 This file is part of the OTF library.
9 The OTF library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 The OTF library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with the OTF library; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
32 Table of contents (almost parallel to otf.h):
36 (1) Readers for OTF Layout tables and OTF itself
37 (1-1) Basic types and functions
41 (1-5) Structures common to GDEF, GSUB, and GPOS
43 (1-7) Structures for ScriptList, FeatureList, and LookupList
44 (1-8) Structures common to GSUB and GPOS
47 (1-11) Structure for OTF
49 (2) API for reading OTF
53 (2-4) OTF_check_table()
60 Example of typical usage of OTF_Stream.
64 OTF_StreamState state;
67 OPEN_STREAM (_FILE_NAME_, stream);
70 SETUP_STREAM (stream, fp, 0, 256, _NAME_);
71 offset = READ_OFFSET (stream);
72 nbytes = READ_ULONG (stream);
73 SETUP_STREAM (stream, fp, offset, nbytes, _NAME2_);
75 CLOSE_STREAM (stream);
90 typedef long OTF_StreamState;
96 char *errfmt = "stream creation%s";
99 stream = calloc (1, sizeof (OTF_Stream));
101 OTF_ERROR (OTF_ERROR_MEMORY, "");
106 setup_stream (OTF_Stream *stream, FILE *fp, long offset, int nbytes,
109 char *errfmt = "stream setup for %s";
114 if (stream->allocated < nbytes)
116 unsigned char *buf = malloc (nbytes);
119 OTF_ERROR (OTF_ERROR_MEMORY, stream->name);
123 stream->allocated = nbytes;
125 stream->bufsize = nbytes;
126 if (fseek (fp, offset, SEEK_SET) < 0)
127 OTF_ERROR (OTF_ERROR_FILE, stream->name);
128 if (fread (stream->buf, 1, nbytes, fp) != nbytes)
129 OTF_ERROR (OTF_ERROR_FILE, stream->name);
135 free_stream (OTF_Stream *stream)
141 #define SAVE_STREAM(stream, state) ((state) = (stream)->pos)
142 #define RESTORE_STREAM(stream, state) ((stream)->pos = (state))
143 #define SEEK_STREAM(stream, offset) ((stream)->pos = (offset))
145 #define STREAM_CHECK_SIZE(stream, size) \
146 if ((stream)->pos + (size) > (stream)->bufsize) \
148 char *errfmt = "buffer overrun in %s"; \
150 OTF_ERROR (OTF_ERROR_TABLE, (stream)->name); \
156 #define READ_USHORT(stream, var) \
158 STREAM_CHECK_SIZE ((stream), 2); \
159 (var) = (((stream)->buf[(stream)->pos] << 8) \
160 | (stream)->buf[(stream)->pos + 1]); \
161 (stream)->pos += 2; \
164 #define READ_SHORT(stream, var) \
166 STREAM_CHECK_SIZE ((stream), 2); \
167 (var) = (short) (((stream)->buf[(stream)->pos] << 8) \
168 | (stream)->buf[(stream)->pos + 1]); \
169 (stream)->pos += 2; \
172 #define READ_ULONG(stream, var) \
174 STREAM_CHECK_SIZE ((stream), 4); \
175 (var) = (((stream)->buf[(stream)->pos] << 24) \
176 | ((stream)->buf[(stream)->pos + 1] << 16) \
177 | ((stream)->buf[(stream)->pos + 2] << 8) \
178 | (stream)->buf[(stream)->pos + 3]); \
179 (stream)->pos += 4; \
182 #define READ_LONG(stream, var) \
184 STREAM_CHECK_SIZE ((stream), 4); \
185 (var) = (int) (((stream)->buf[(stream)->pos] << 24) \
186 | ((stream)->buf[(stream)->pos + 1] << 16) \
187 | ((stream)->buf[(stream)->pos + 2] << 8) \
188 | (stream)->buf[(stream)->pos + 3]); \
189 (stream)->pos += 4; \
193 #define READ_FIXED(stream, fixed) \
195 READ_USHORT ((stream), (fixed).high); \
196 READ_USHORT ((stream), (fixed).low); \
200 #define READ_BYTES(stream, p, nbytes) \
202 STREAM_CHECK_SIZE ((stream), (nbytes)); \
203 memcpy ((p), (stream)->buf + (stream)->pos, (nbytes)); \
204 (stream)->pos += (nbytes); \
208 #define READ_TAG READ_ULONG
209 #define READ_OFFSET READ_USHORT
210 #define READ_UINT16 READ_USHORT
211 #define READ_INT16 READ_SHORT
212 #define READ_GLYPHID READ_USHORT
215 /*** (1) Structures for OTF Layout tables and OTF itself */
217 /*** (1-1) Basic types and functions */
230 #define OTF_MEMORY_RECORD_SIZE 1024
232 struct OTF_MemoryRecord
235 void *memory[OTF_MEMORY_RECORD_SIZE];
236 struct OTF_MemoryRecord *next;
239 typedef struct OTF_MemoryRecord OTF_MemoryRecord;
243 /* Points to one of OTF->head, OTF->name, etc. */
245 /* Function to read one of OTF tables. */
246 void *(*reader) (OTF *otf, OTF_Stream *stream);
247 /* Stream given to <reader>. */
251 struct OTF_InternalData
253 /* Information about each OTF table. */
254 OTF_TableInfo table_info[OTF_TABLE_TYPE_MAX];
256 /* Stream used to read the header part of OTF. */
257 OTF_Stream *header_stream;
259 /* Records of allocated memories. */
260 OTF_MemoryRecord *memory_record;
264 static OTF_MemoryRecord *
265 allocate_memory_record (OTF *otf)
267 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
268 OTF_MemoryRecord *memrec = malloc (sizeof (OTF_MemoryRecord));
273 memrec->next = internal_data->memory_record;
274 internal_data->memory_record = memrec;
278 /* Memory allocation macros. */
280 #define OTF_MALLOC(p, size, arg) \
286 OTF_MemoryRecord *memrec \
287 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
288 (p) = malloc (sizeof (*(p)) * (size)); \
290 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
291 && ! (memrec = allocate_memory_record (otf)))) \
292 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
293 memrec->memory[memrec->used++] = (p); \
298 #define OTF_CALLOC(p, size, arg) \
304 OTF_MemoryRecord *memrec \
305 = ((OTF_InternalData *) otf->internal_data)->memory_record; \
306 (p) = calloc ((size), sizeof (*(p))); \
308 || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
309 && ! (memrec = allocate_memory_record (otf)))) \
310 OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
311 memrec->memory[memrec->used++] = (p); \
316 /*** (1-2) "head" table */
319 read_head_table (OTF *otf, OTF_Stream *stream)
321 char *errfmt = "head%s";
325 OTF_CALLOC (head, 1, "");
326 READ_FIXED (stream, head->TableVersionNumber);
327 READ_FIXED (stream, head->fontRevision);
328 READ_ULONG (stream, head->checkSumAdjustment);
329 READ_ULONG (stream, head->magicNumber);
330 READ_USHORT (stream, head->flags);
331 READ_USHORT (stream, head->unitsPerEm);
337 /*** (1-3) "name" table */
340 read_name (OTF *otf, OTF_Stream *stream, OTF_NameRecord *rec, int bytes)
342 char *errfmt = "nameID (%d)";
344 OTF_StreamState state;
349 SAVE_STREAM (stream, state);
350 SEEK_STREAM (stream, stream->pos + rec->offset);
354 OTF_MALLOC (str, rec->length + 1, (void *) rec->nameID);
355 READ_BYTES (stream, str, rec->length);
356 for (i = 0; i < rec->length; i++)
362 OTF_MALLOC (str, rec->length / 2 + 1, (void *) rec->nameID);
363 for (i = 0; i < rec->length / 2; i++)
365 READ_USHORT (stream, c);
373 OTF_MALLOC (str, rec->length / 4 + 1, (void *) rec->nameID);
374 for (i = 0; i < rec->length / 4; i++)
376 READ_ULONG (stream, c);
383 RESTORE_STREAM (stream, state);
388 read_name_table (OTF *otf, OTF_Stream *stream)
390 char *errfmt = "name%s";
395 OTF_CALLOC (name, 1, "");
396 READ_USHORT (stream, name->format);
397 READ_USHORT (stream, name->count);
398 READ_USHORT (stream, name->stringOffset);
399 OTF_MALLOC (name->nameRecord, name->count, "");
400 for (i = 0; i < name->count; i++)
402 OTF_NameRecord *rec = name->nameRecord + i;
404 READ_USHORT (stream, rec->platformID);
405 READ_USHORT (stream, rec->encodingID);
406 READ_USHORT (stream, rec->languageID);
407 READ_USHORT (stream, rec->nameID);
408 READ_USHORT (stream, rec->length);
409 READ_USHORT (stream, rec->offset);
411 for (i = 0; i < name->count; i++)
413 OTF_NameRecord *rec = name->nameRecord + i;
414 int nameID = rec->nameID;
416 if (nameID <= OTF_max_nameID
417 && ! name->name[nameID])
419 if (rec->platformID == 0)
420 name->name[nameID] = read_name (otf, stream, rec,
421 rec->encodingID <= 3 ? 2 : 4);
422 else if (rec->platformID == 1
423 && rec->encodingID == 0)
424 name->name[nameID] = read_name (otf, stream, rec, 1);
425 else if (rec->platformID == 3
426 && (rec->encodingID == 1 || rec->encodingID == 10))
427 name->name[nameID] = read_name (otf, stream,
428 rec, rec->encodingID == 1 ? 2 : 4);
436 /*** (1-4) "cmap" table */
439 read_cmap_table (OTF *otf, OTF_Stream *stream)
441 char *errfmt = "cmap%s";
446 OTF_CALLOC (cmap, 1, "");
447 READ_USHORT (stream, cmap->version);
448 READ_USHORT (stream, cmap->numTables);
449 OTF_MALLOC (cmap->EncodingRecord, cmap->numTables, "");
450 for (i = 0; i < cmap->numTables; i++)
452 READ_USHORT (stream, cmap->EncodingRecord[i].platformID);
453 READ_USHORT (stream, cmap->EncodingRecord[i].encodingID);
454 READ_ULONG (stream, cmap->EncodingRecord[i].offset);
455 if (cmap->EncodingRecord[i].platformID == 3
456 && cmap->EncodingRecord[i].encodingID == 1)
457 cmap->Unicode = cmap->EncodingRecord + i;
459 for (i = 0; i < cmap->numTables; i++)
463 SEEK_STREAM (stream, cmap->EncodingRecord[i].offset);
464 READ_USHORT (stream, format);
465 cmap->EncodingRecord[i].subtable.format = format;
466 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.length);
467 if (format == 8 || format == 10 || format == 12)
469 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.length);
470 READ_ULONG (stream, cmap->EncodingRecord[i].subtable.language);
474 READ_USHORT (stream, cmap->EncodingRecord[i].subtable.language);
480 OTF_MALLOC (cmap->EncodingRecord[i].subtable.f.f0, 1,
481 " (EncodingRecord)");
483 cmap->EncodingRecord[i].subtable.f.f0->glyphIdArray,
493 OTF_EncodingSubtable4 *sub4;
498 OTF_MALLOC (sub4, 1, " (EncodingSubtable4)");
499 cmap->EncodingRecord[i].subtable.f.f4 = sub4;
500 READ_USHORT (stream, sub4->segCountX2);
501 segCount = sub4->segCountX2 / 2;
502 READ_USHORT (stream, sub4->searchRange);
503 READ_USHORT (stream, sub4->entrySelector);
504 READ_USHORT (stream, sub4->rangeShift);
505 OTF_MALLOC (sub4->segments, segCount, " (segCount)");
506 for (j = 0; j < segCount; j++)
507 READ_USHORT (stream, sub4->segments[j].endCount);
508 READ_USHORT (stream, dummy);
509 for (j = 0; j < segCount; j++)
510 READ_USHORT (stream, sub4->segments[j].startCount);
511 for (j = 0; j < segCount; j++)
512 READ_SHORT (stream, sub4->segments[j].idDelta);
513 for (j = 0; j < segCount; j++)
516 unsigned rest = 2 * (segCount - j);
518 READ_USHORT (stream, off);
520 sub4->segments[j].idRangeOffset = 0xFFFF;
522 sub4->segments[j].idRangeOffset = (off - rest) / 2;
524 j = (cmap->EncodingRecord[i].subtable.length
525 - (14 + 2 * (segCount * 4 + 1)));
526 sub4->GlyphCount = j / 2;
527 OTF_MALLOC (sub4->glyphIdArray, sub4->GlyphCount, " (GlyphCount)");
528 for (j = 0; j < sub4->GlyphCount; j++)
529 READ_USHORT (stream, sub4->glyphIdArray[j]);
535 OTF_EncodingSubtable6 *sub6;
538 OTF_MALLOC (sub6, 1, " (EncodingSubtable6)");
539 cmap->EncodingRecord[i].subtable.f.f6 = sub6;
540 READ_USHORT (stream, sub6->firstCode);
541 READ_USHORT (stream, sub6->entryCount);
542 OTF_MALLOC (sub6->glyphIdArray, sub6->entryCount, " (GlyphCount)");
543 for (j = 0; j < sub6->entryCount; j++)
544 READ_USHORT (stream, sub6->glyphIdArray[j]);
552 /*** (1-5) Structures common to GDEF, GSUB, and GPOS */
554 /* Read Glyph-IDs from STREAM. Allocate memory for IDS, and store the
555 Glyph-IDs there. If COUNT is negative, read the number of
556 Glyphs-IDs at first. MINUS if nozero is how few the actual
557 Glyph-IDs are in STREAM than COUNT. */
560 read_glyph_ids (OTF *otf, OTF_Stream *stream, OTF_GlyphID **ids,
561 int minus, int count)
563 char *errfmt = "GlyphID List%s";
568 READ_UINT16 (stream, count);
571 OTF_MALLOC (*ids, count, "");
572 for (i = 0; i < count + minus; i++)
573 READ_GLYPHID (stream, (*ids)[i]);
578 read_range_records (OTF *otf, OTF_Stream *stream, OTF_RangeRecord **record)
580 char *errfmt = "RangeRecord%s";
585 READ_UINT16 (stream, count);
588 OTF_MALLOC (*record, count, "");
589 for (i = 0; i < count; i++)
591 READ_GLYPHID (stream, (*record)[i].Start);
592 READ_GLYPHID (stream, (*record)[i].End);
593 READ_UINT16 (stream, (*record)[i].StartCoverageIndex);
600 read_coverage (OTF *otf, OTF_Stream *stream, long offset,
601 OTF_Coverage *coverage)
603 char *errfmt = "Coverage%s";
605 OTF_StreamState state;
608 READ_OFFSET (stream, coverage->offset);
609 SAVE_STREAM (stream, state);
610 SEEK_STREAM (stream, offset + coverage->offset);
611 READ_UINT16 (stream, coverage->CoverageFormat);
612 if (coverage->CoverageFormat == 1)
613 count = read_glyph_ids (otf, stream, &coverage->table.GlyphArray, 0, -1);
614 else if (coverage->CoverageFormat == 2)
615 count = read_range_records (otf, stream, &coverage->table.RangeRecord);
617 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid Format)");
620 coverage->Count = (unsigned) count;
621 RESTORE_STREAM (stream, state);
625 /* Read list of Coverages from STREAM. Allocate memory for COVERAGE,
626 and store the Coverages there. If COUNT is negative, read the
627 number of Coverages at first. */
630 read_coverage_list (OTF *otf, OTF_Stream *stream, long offset,
631 OTF_Coverage **coverage, int count)
633 char *errfmt = "Coverage List%s";
638 READ_UINT16 (stream, count);
641 OTF_MALLOC (*coverage, count, "");
642 for (i = 0; i < count; i++)
643 if (read_coverage (otf, stream, offset, (*coverage) + i) < 0)
650 read_class_def_without_offset (OTF *otf, OTF_Stream *stream,
653 char *errfmt = "ClassDef%s";
656 SEEK_STREAM (stream, class->offset);
657 READ_UINT16 (stream, class->ClassFormat);
658 if (class->ClassFormat == 1)
660 READ_GLYPHID (stream, class->f.f1.StartGlyph);
661 class->f.f1.GlyphCount
663 (otf, stream, (OTF_GlyphID **) &class->f.f1.ClassValueArray, 0, -1));
664 if (! class->f.f1.GlyphCount)
665 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
667 else if (class->ClassFormat == 2)
669 class->f.f2.ClassRangeCount
670 = (read_range_records
671 (otf, stream, (OTF_RangeRecord **) &class->f.f2.ClassRangeRecord));
672 if (! class->f.f2.ClassRangeCount)
673 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
676 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
682 read_class_def (OTF *otf, OTF_Stream *stream, long offset, OTF_ClassDef *class)
684 char *errfmt = "ClassDef%s";
686 OTF_StreamState state;
688 READ_OFFSET (stream, class->offset);
691 SAVE_STREAM (stream, state);
692 SEEK_STREAM (stream, offset + class->offset);
693 READ_UINT16 (stream, class->ClassFormat);
694 if (class->ClassFormat == 1)
696 READ_GLYPHID (stream, class->f.f1.StartGlyph);
697 class->f.f1.GlyphCount
698 = read_glyph_ids (otf, stream,
699 (OTF_GlyphID **) &class->f.f1.ClassValueArray,
701 if (! class->f.f1.GlyphCount)
704 else if (class->ClassFormat == 2)
706 class->f.f2.ClassRangeCount
707 = read_range_records (otf, stream,
709 &class->f.f2.ClassRangeRecord);
710 if (! class->f.f2.ClassRangeCount)
714 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
716 RESTORE_STREAM (stream, state);
722 read_device_table (OTF *otf, OTF_Stream *stream, long offset,
723 OTF_DeviceTable *table)
725 char *errfmt = "Device Table%s";
736 SEEK_STREAM (stream, offset + table->offset);
737 READ_UINT16 (stream, table->StartSize);
738 READ_UINT16 (stream, table->EndSize);
739 READ_UINT16 (stream, table->DeltaFormat);
740 num = table->EndSize - table->StartSize + 1;
741 OTF_MALLOC (table->DeltaValue, num, "");
743 if (table->DeltaFormat == 1)
744 for (i = 0; i < num; i++)
747 READ_UINT16 (stream, val);
748 intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
749 table->DeltaValue[i] = intval.int2;
751 else if (table->DeltaFormat == 2)
752 for (i = 0; i < num; i++)
755 READ_UINT16 (stream, val);
756 intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
757 table->DeltaValue[i] = intval.int4;
759 else if (table->DeltaFormat == 3)
760 for (i = 0; i < num; i++)
764 READ_UINT16 (stream, val);
765 intval.int8 = val >> 8;
766 table->DeltaValue[i] = intval.int8;
770 intval.int8 = val >> 8;
771 table->DeltaValue[i] = intval.int8;
775 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
780 /*** (1-6) "GDEF" table */
783 read_attach_list (OTF *otf, OTF_Stream *stream, long offset,
784 OTF_AttachList *list)
786 char *errfmt = "AttachList%s";
790 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
792 READ_UINT16 (stream, list->GlyphCount);
793 OTF_MALLOC (list->AttachPoint, list->GlyphCount, "");
794 for (i = 0; i < list->GlyphCount; i++)
795 READ_OFFSET (stream, list->AttachPoint[i].offset);
796 for (i = 0; i < list->GlyphCount; i++)
800 SEEK_STREAM (stream, offset + list->AttachPoint[i].offset);
801 READ_UINT16 (stream, count);
802 list->AttachPoint[i].PointCount = count;
803 OTF_MALLOC (list->AttachPoint[i].PointIndex, count, " (PointIndex)");
804 for (j = 0; j < count; j++)
805 READ_UINT16 (stream, list->AttachPoint[i].PointIndex[j]);
811 read_caret_value (OTF *otf, OTF_Stream *stream, long offset,
812 OTF_CaretValue *caret)
814 char *errfmt = "CaretValue%s";
817 SEEK_STREAM (stream, offset + caret->offset);
818 READ_UINT16 (stream, caret->CaretValueFormat);
819 if (caret->CaretValueFormat == 1)
820 READ_INT16 (stream, caret->f.f1.Coordinate);
821 else if (caret->CaretValueFormat == 2)
822 READ_UINT16 (stream, caret->f.f2.CaretValuePoint);
823 else if (caret->CaretValueFormat == 3)
825 READ_INT16 (stream, caret->f.f3.Coordinate);
826 if (read_device_table (otf, stream, offset + caret->offset,
827 &caret->f.f3.DeviceTable) < 0)
831 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
836 read_lig_caret_list (OTF *otf, OTF_Stream *stream, long offset,
837 OTF_LigCaretList *list)
839 char *errfmt = "LigCaretList%s";
843 if (read_coverage (otf, stream, offset, &list->Coverage) < 0)
845 READ_UINT16 (stream, list->LigGlyphCount);
846 OTF_MALLOC (list->LigGlyph, list->LigGlyphCount, "");
847 for (i = 0; i < list->LigGlyphCount; i++)
848 READ_OFFSET (stream, list->LigGlyph[i].offset);
849 for (i = 0; i < list->LigGlyphCount; i++)
853 SEEK_STREAM (stream, offset + list->LigGlyph[i].offset);
854 READ_UINT16 (stream, count);
855 list->LigGlyph[i].CaretCount = count;
856 OTF_MALLOC (list->LigGlyph[i].CaretValue, count, " (CaretValue)");
857 for (j = 0; j < count; j++)
858 READ_OFFSET (stream, list->LigGlyph[i].CaretValue[j].offset);
859 for (j = 0; j < count; j++)
860 if (read_caret_value (otf, stream, offset + list->LigGlyph[i].offset,
861 &list->LigGlyph[i].CaretValue[j]) < 0)
868 read_gdef_header (OTF_Stream *stream, OTF_GDEFHeader *header)
872 READ_FIXED (stream, header->Version);
873 READ_OFFSET (stream, header->GlyphClassDef);
874 READ_OFFSET (stream, header->AttachList);
875 READ_OFFSET (stream, header->LigCaretList);
876 READ_OFFSET (stream, header->MarkAttachClassDef);
881 read_gdef_table (OTF *otf, OTF_Stream *stream)
883 char *errfmt = "GDEF%s";
887 OTF_CALLOC (gdef, 1, "");
888 read_gdef_header (stream, (OTF_GDEFHeader *) &gdef->header);
889 if (gdef->header.GlyphClassDef)
891 gdef->glyph_class_def.offset = gdef->header.GlyphClassDef;
892 read_class_def_without_offset (otf, stream, &gdef->glyph_class_def);
894 if (gdef->header.AttachList)
895 read_attach_list (otf, stream, gdef->header.AttachList,
897 if (gdef->header.LigCaretList)
898 read_lig_caret_list (otf, stream, gdef->header.LigCaretList,
899 &gdef->lig_caret_list);
900 if (gdef->header.MarkAttachClassDef)
902 gdef->mark_attach_class_def.offset = gdef->header.MarkAttachClassDef;
903 read_class_def_without_offset (otf, stream, &gdef->mark_attach_class_def);
910 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
913 read_script_list (OTF *otf, OTF_Stream *stream, long offset,
914 OTF_ScriptList *list)
916 char *errfmt = "Script List%s";
920 SEEK_STREAM (stream, offset);
921 READ_USHORT (stream, list->ScriptCount);
922 OTF_CALLOC (list->Script, list->ScriptCount, "");
924 for (i = 0; i < list->ScriptCount; i++)
926 READ_TAG (stream, list->Script[i].ScriptTag);
927 READ_OFFSET (stream, list->Script[i].offset);
929 for (i = 0; i < list->ScriptCount; i++)
931 OTF_Script *script = list->Script + i;
932 long script_offset = offset + script->offset;
934 SEEK_STREAM (stream, script_offset);
935 READ_OFFSET (stream, script->DefaultLangSysOffset);
936 READ_USHORT (stream, script->LangSysCount);
937 OTF_MALLOC (script->LangSysRecord, script->LangSysCount, " (LangSys)");
938 OTF_CALLOC (script->LangSys, script->LangSysCount, " (LangSys)");
939 for (j = 0; j < script->LangSysCount; j++)
941 READ_TAG (stream, script->LangSysRecord[j].LangSysTag);
942 READ_OFFSET (stream, script->LangSysRecord[j].LangSys);
945 if (script->DefaultLangSysOffset)
947 OTF_LangSys *langsys = &script->DefaultLangSys;
949 SEEK_STREAM (stream, script_offset + script->DefaultLangSysOffset);
950 READ_OFFSET (stream, langsys->LookupOrder);
951 READ_USHORT (stream, langsys->ReqFeatureIndex);
952 READ_USHORT (stream, langsys->FeatureCount);
953 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
955 for (k = 0; k < langsys->FeatureCount; k++)
956 READ_USHORT (stream, langsys->FeatureIndex[k]);
959 for (j = 0; j < script->LangSysCount; j++)
961 OTF_LangSys *langsys = script->LangSys + j;
964 script_offset + script->LangSysRecord[j].LangSys);
965 READ_OFFSET (stream, langsys->LookupOrder);
966 READ_USHORT (stream, langsys->ReqFeatureIndex);
967 READ_USHORT (stream, langsys->FeatureCount);
968 OTF_MALLOC (langsys->FeatureIndex, langsys->FeatureCount,
970 for (k = 0; k < langsys->FeatureCount; k++)
971 READ_USHORT (stream, langsys->FeatureIndex[k]);
979 read_feature_list (OTF *otf, OTF_Stream *stream, long offset,
980 OTF_FeatureList *list)
982 char *errfmt = "Feature List%s";
986 READ_UINT16 (stream, list->FeatureCount);
987 OTF_CALLOC (list->Feature, list->FeatureCount, "");
988 for (i = 0; i < list->FeatureCount; i++)
990 READ_TAG (stream, list->Feature[i].FeatureTag);
991 READ_OFFSET (stream, list->Feature[i].offset);
993 for (i = 0; i < list->FeatureCount; i++)
995 OTF_Feature *feature = list->Feature + i;
997 SEEK_STREAM (stream, offset + feature->offset);
998 READ_OFFSET (stream, feature->FeatureParams);
999 READ_UINT16 (stream, feature->LookupCount);
1000 OTF_MALLOC (feature->LookupListIndex, feature->LookupCount,
1001 " (LookupListIndex)");
1002 for (j = 0; j < feature->LookupCount; j++)
1003 READ_UINT16 (stream, feature->LookupListIndex[j]);
1009 static int read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream,
1010 long offset, unsigned type,
1011 OTF_LookupSubTableGSUB *subtable);
1012 static int read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1013 long offset, unsigned type,
1014 OTF_LookupSubTableGPOS *subtable);
1017 read_lookup_list (OTF *otf, OTF_Stream *stream, long offset,
1018 OTF_LookupList *list, int gsubp)
1020 char *errfmt = "Lookup List%s";
1024 SEEK_STREAM (stream, offset);
1025 READ_UINT16 (stream, list->LookupCount);
1026 OTF_CALLOC (list->Lookup, list->LookupCount, "");
1028 for (i = 0; i < list->LookupCount; i++)
1029 READ_OFFSET (stream, list->Lookup[i].offset);
1030 for (i = 0; i < list->LookupCount; i++)
1032 OTF_Lookup *lookup = list->Lookup + i;
1034 SEEK_STREAM (stream, offset + lookup->offset);
1035 READ_UINT16 (stream, lookup->LookupType);
1036 READ_UINT16 (stream, lookup->LookupFlag);
1037 READ_UINT16 (stream, lookup->SubTableCount);
1038 OTF_MALLOC (lookup->SubTableOffset, lookup->SubTableCount,
1039 " (SubTableOffset)");
1041 OTF_CALLOC (lookup->SubTable.gsub, lookup->SubTableCount,
1044 OTF_CALLOC (lookup->SubTable.gpos, lookup->SubTableCount,
1046 for (j = 0; j < lookup->SubTableCount; j++)
1047 READ_OFFSET (stream, lookup->SubTableOffset[j]);
1048 for (j = 0; j < lookup->SubTableCount; j++)
1051 = offset + lookup->offset + lookup->SubTableOffset[j];
1054 ? read_lookup_subtable_gsub (otf, stream, this_offset,
1056 lookup->SubTable.gsub + j) < 0
1057 : read_lookup_subtable_gpos (otf, stream, this_offset,
1059 lookup->SubTable.gpos + j) < 0)
1068 /*** (1-8) Structures common to GSUB and GPOS */
1071 read_lookup_record_list (OTF *otf, OTF_Stream *stream,
1072 OTF_LookupRecord **record, int count)
1074 char *errfmt = "LookupRecord%s";
1075 unsigned errret = 0;
1079 READ_UINT16 (stream, count);
1081 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1082 OTF_MALLOC (*record, count, "");
1083 for (i = 0; i < count; i++)
1085 READ_UINT16 (stream, (*record)[i].SequenceIndex);
1086 READ_UINT16 (stream, (*record)[i].LookupListIndex);
1092 read_rule_list (OTF *otf, OTF_Stream *stream, long offset, OTF_Rule **rule)
1094 char *errfmt = "List of Rule%s";
1095 unsigned errret = 0;
1096 OTF_StreamState state;
1100 READ_UINT16 (stream, count);
1102 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1103 OTF_MALLOC (*rule, count, "");
1104 for (i = 0; i < count; i++)
1106 READ_OFFSET (stream, (*rule)[i].offset);
1107 if (! (*rule)[i].offset)
1108 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1110 SAVE_STREAM (stream, state);
1111 for (i = 0; i < count; i++)
1113 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1114 READ_UINT16 (stream, (*rule)[i].GlyphCount);
1115 if ((*rule)[i].GlyphCount == 0)
1116 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1117 READ_UINT16 (stream, (*rule)[i].LookupCount);
1118 if (read_glyph_ids (otf, stream, &(*rule)[i].Input, 0,
1119 (*rule)[i].GlyphCount) < 0)
1121 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1122 (*rule)[i].LookupCount) == 0)
1125 RESTORE_STREAM (stream, state);
1131 read_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1134 char *errfmt = "List of RuleSet%s";
1135 unsigned errret = 0;
1136 OTF_StreamState state;
1140 READ_UINT16 (stream, count);
1142 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1143 OTF_MALLOC (*set, count, "");
1144 for (i = 0; i < count; i++)
1146 READ_OFFSET (stream, (*set)[i].offset);
1147 if (! (*set)[i].offset)
1148 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1150 SAVE_STREAM (stream, state);
1151 for (i = 0; i < count; i++)
1153 SEEK_STREAM (stream, offset + (*set)[i].offset);
1155 = read_rule_list (otf, stream, offset + (*set)[i].offset,
1157 if (! (*set)[i].RuleCount)
1160 RESTORE_STREAM (stream, state);
1165 read_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1166 OTF_ClassRule **rule)
1168 char *errfmt = "ClassRule%s";
1169 unsigned errret = 0;
1170 OTF_StreamState state;
1174 READ_UINT16 (stream, count);
1176 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1177 OTF_MALLOC (*rule, count, "");
1178 for (i = 0; i < count; i++)
1180 READ_OFFSET (stream, (*rule)[i].offset);
1181 if (! (*rule)[i].offset)
1182 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1184 SAVE_STREAM (stream, state);
1185 for (i = 0; i < count; i++)
1187 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1188 READ_USHORT (stream, (*rule)[i].GlyphCount);
1189 if (! (*rule)[i].GlyphCount)
1190 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1191 READ_USHORT (stream, (*rule)[i].LookupCount);
1192 if (read_glyph_ids (otf, stream, (OTF_GlyphID **) &(*rule)[i].Class,
1193 0, (*rule)[i].GlyphCount - 1) < 0)
1195 if (read_lookup_record_list (otf, stream, &(*rule)[i].LookupRecord,
1196 (*rule)[i].LookupCount) == 0)
1199 RESTORE_STREAM (stream, state);
1204 read_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1207 char *errfmt = "ClassSet%s";
1208 unsigned errret = 0;
1209 OTF_StreamState state;
1213 READ_UINT16 (stream, count);
1215 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1216 OTF_MALLOC (*set, count, "");
1217 for (i = 0; i < count; i++)
1218 /* Offset can be zero. */
1219 READ_OFFSET (stream, (*set)[i].offset);
1220 SAVE_STREAM (stream, state);
1221 for (i = 0; i < count; i++)
1222 if ((*set)[i].offset)
1224 SEEK_STREAM (stream, offset + (*set)[i].offset);
1225 (*set)[i].ClassRuleCnt
1226 = read_class_rule_list (otf, stream, offset + (*set)[i].offset,
1227 &(*set)[i].ClassRule);
1228 if (! (*set)[i].ClassRuleCnt)
1231 RESTORE_STREAM (stream, state);
1236 read_chain_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1237 OTF_ChainRule **rule)
1239 char *errfmt = "ChainRule%s";
1240 unsigned errret = 0;
1244 READ_UINT16 (stream, count);
1246 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1247 OTF_MALLOC (*rule, count, "");
1248 for (i = 0; i < count; i++)
1249 READ_OFFSET (stream, (*rule)[i].offset);
1250 for (i = 0; i < count; i++)
1252 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1253 (*rule)[i].BacktrackGlyphCount
1254 = read_glyph_ids (otf, stream, &(*rule)[i].Backtrack, 0, -1);
1255 (*rule)[i].InputGlyphCount
1256 = read_glyph_ids (otf, stream, &(*rule)[i].Input, -1, -1);
1257 if (! (*rule)[i].InputGlyphCount)
1258 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1259 (*rule)[i].LookaheadGlyphCount
1260 = read_glyph_ids (otf, stream, &(*rule)[i].LookAhead, 0, -1);
1261 (*rule)[i].LookupCount
1262 = read_lookup_record_list (otf, stream,
1263 &(*rule)[i].LookupRecord, -1);
1264 if (! (*rule)[i].LookupCount)
1272 read_chain_rule_set_list (OTF *otf, OTF_Stream *stream, long offset,
1273 OTF_ChainRuleSet **set)
1275 char *errfmt = "ChainRuleSet%s";
1276 unsigned errret = 0;
1277 OTF_StreamState state;
1281 READ_UINT16 (stream, count);
1283 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1284 OTF_MALLOC (*set, count, "");
1285 for (i = 0; i < count; i++)
1287 READ_OFFSET (stream, (*set)[i].offset);
1288 if (! (*set)[i].offset)
1289 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1291 SAVE_STREAM (stream, state);
1292 for (i = 0; i < count; i++)
1294 SEEK_STREAM (stream, offset + (*set)[i].offset);
1295 (*set)[i].ChainRuleCount
1296 = read_chain_rule_list (otf, stream, offset + (*set)[i].offset,
1297 &(*set)[i].ChainRule);
1298 if (! (*set)[i].ChainRuleCount)
1301 RESTORE_STREAM (stream, state);
1306 read_chain_class_rule_list (OTF *otf, OTF_Stream *stream, long offset,
1307 OTF_ChainClassRule **rule)
1309 char *errfmt = "ChainClassRule%s";
1310 unsigned errret = 0;
1314 READ_UINT16 (stream, count);
1316 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1317 OTF_MALLOC (*rule, count, "");
1318 for (i = 0; i < count; i++)
1320 READ_OFFSET (stream, (*rule)[i].offset);
1321 if (! (*rule)[i].offset)
1322 OTF_ERROR (OTF_ERROR_TABLE, " (zero offset)");
1324 for (i = 0; i < count; i++)
1326 SEEK_STREAM (stream, offset + (*rule)[i].offset);
1327 (*rule)[i].BacktrackGlyphCount
1328 = read_glyph_ids (otf, stream,
1329 (OTF_GlyphID **) &(*rule)[i].Backtrack, 0, -1);
1330 (*rule)[i].InputGlyphCount
1331 = read_glyph_ids (otf, stream,
1332 (OTF_GlyphID **) &(*rule)[i].Input, -1, -1);
1333 if (! (*rule)[i].InputGlyphCount)
1334 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1335 (*rule)[i].LookaheadGlyphCount
1336 = read_glyph_ids (otf, stream,
1337 (OTF_GlyphID **) &(*rule)[i].LookAhead, 0, -1);
1338 (*rule)[i].LookupCount
1339 = read_lookup_record_list (otf, stream,
1340 &(*rule)[i].LookupRecord, -1);
1341 if (! (*rule)[i].LookupCount)
1348 read_chain_class_set_list (OTF *otf, OTF_Stream *stream, long offset,
1349 OTF_ChainClassSet **set)
1351 char *errfmt = "ChainClassSet%s";
1352 unsigned errret = 0;
1353 OTF_StreamState state;
1357 READ_UINT16 (stream, count);
1359 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1360 OTF_MALLOC (*set, count, "");
1361 for (i = 0; i < count; i++)
1362 /* Offset may be zero. */
1363 READ_OFFSET (stream, (*set)[i].offset);
1364 SAVE_STREAM (stream, state);
1365 for (i = 0; i < count; i++)
1366 if ((*set)[i].offset)
1368 SEEK_STREAM (stream, offset + (*set)[i].offset);
1369 (*set)[i].ChainClassRuleCnt
1370 = read_chain_class_rule_list (otf, stream, offset + (*set)[i].offset,
1371 &(*set)[i].ChainClassRule);
1372 if (! (*set)[i].ChainClassRuleCnt)
1375 RESTORE_STREAM (stream, state);
1380 read_context1 (OTF *otf, OTF_Stream *stream, long offset,
1381 OTF_Coverage *coverage,OTF_Context1 *context1)
1383 if (read_coverage (otf, stream, offset, coverage) < 0)
1385 context1->RuleSetCount
1386 = read_rule_set_list (otf, stream, offset, &context1->RuleSet);
1387 if (! context1->RuleSetCount)
1393 read_context2 (OTF *otf, OTF_Stream *stream, long offset,
1394 OTF_Coverage *coverage,OTF_Context2 *context2)
1396 if (read_coverage (otf, stream, offset, coverage) < 0
1397 || read_class_def (otf, stream, offset, &context2->ClassDef) < 0)
1399 context2->ClassSetCnt
1400 = read_class_set_list (otf, stream, offset, &context2->ClassSet);
1401 if (! context2->ClassSetCnt)
1407 read_context3 (OTF *otf, OTF_Stream *stream, long offset,
1408 OTF_Coverage *coverage,OTF_Context3 *context3)
1410 char *errfmt = "Context1%s";
1413 READ_USHORT (stream, context3->GlyphCount);
1414 if (context3->GlyphCount < 0)
1415 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1416 READ_USHORT (stream, context3->LookupCount);
1417 if (read_coverage_list (otf, stream, offset, &context3->Coverage,
1418 context3->GlyphCount) < 0)
1420 if (read_lookup_record_list (otf, stream, &context3->LookupRecord,
1421 context3->LookupCount) < 0)
1427 read_chain_context1 (OTF *otf, OTF_Stream *stream, long offset,
1428 OTF_Coverage *coverage, OTF_ChainContext1 *chain_context1)
1430 if (read_coverage (otf, stream, offset, coverage) < 0)
1432 chain_context1->ChainRuleSetCount
1433 = read_chain_rule_set_list (otf, stream, offset,
1434 &chain_context1->ChainRuleSet);
1435 if (! chain_context1->ChainRuleSetCount)
1441 read_chain_context2 (OTF *otf, OTF_Stream *stream, long offset,
1442 OTF_Coverage *coverage, OTF_ChainContext2 *chain_context2)
1444 if (read_coverage (otf, stream, offset, coverage) < 0
1445 || read_class_def (otf, stream, offset,
1446 &chain_context2->BacktrackClassDef) < 0
1447 || read_class_def (otf, stream, offset,
1448 &chain_context2->InputClassDef) < 0
1449 || read_class_def (otf, stream, offset,
1450 &chain_context2->LookaheadClassDef) < 0)
1452 chain_context2->ChainClassSetCnt
1453 = read_chain_class_set_list (otf, stream, offset,
1454 &chain_context2->ChainClassSet);
1455 if (! chain_context2->ChainClassSetCnt)
1461 read_chain_context3 (OTF *otf, OTF_Stream *stream, long offset,
1462 OTF_Coverage *coverage, OTF_ChainContext3 *chain_context3)
1466 count = read_coverage_list (otf, stream, offset,
1467 &chain_context3->Backtrack, -1);
1470 chain_context3->BacktrackGlyphCount = (unsigned) count;
1471 count = read_coverage_list (otf, stream, offset,
1472 &chain_context3->Input, -1);
1475 chain_context3->InputGlyphCount = (unsigned) count;
1476 *coverage = chain_context3->Input[0];
1477 count = read_coverage_list (otf, stream, offset,
1478 &chain_context3->LookAhead, -1);
1479 chain_context3->LookaheadGlyphCount = (unsigned) count;
1480 chain_context3->LookupCount
1481 = read_lookup_record_list (otf, stream,
1482 &chain_context3->LookupRecord, -1);
1487 read_gsub_gpos_table (OTF *otf, OTF_Stream *stream, int gsubp)
1489 char *errfmt = gsubp ? "GSUB%s" : "GPOS%s";
1490 void *errret = NULL;
1491 OTF_GSUB_GPOS *gsub_gpos;
1493 OTF_CALLOC (gsub_gpos, 1, "");
1494 READ_FIXED (stream, gsub_gpos->Version);
1495 READ_OFFSET (stream, gsub_gpos->ScriptList.offset);
1496 READ_OFFSET (stream, gsub_gpos->FeatureList.offset);
1497 READ_OFFSET (stream, gsub_gpos->LookupList.offset);
1499 if (read_script_list (otf, stream, gsub_gpos->ScriptList.offset,
1500 &gsub_gpos->ScriptList) < 0
1501 || read_feature_list (otf, stream, gsub_gpos->FeatureList.offset,
1502 &gsub_gpos->FeatureList) < 0
1503 || read_lookup_list (otf, stream, gsub_gpos->LookupList.offset,
1504 &gsub_gpos->LookupList, gsubp) < 0)
1510 /* (1-9) "GSUB" table */
1513 read_sequence (OTF *otf, OTF_Stream *stream, long offset, OTF_Sequence **seq)
1515 char *errfmt = "Sequence%s";
1516 unsigned errret = 0;
1520 READ_UINT16 (stream, count);
1522 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1523 OTF_MALLOC (*seq, count, "");
1524 for (i = 0; i < count; i++)
1525 READ_OFFSET (stream, (*seq)[i].offset);
1526 for (i = 0; i < count; i++)
1528 SEEK_STREAM (stream, offset + (*seq)[i].offset);
1529 (*seq)[i].GlyphCount = read_glyph_ids (otf, stream,
1530 &(*seq)[i].Substitute, 0, -1);
1531 if (! (*seq)[i].GlyphCount)
1538 read_ligature (OTF *otf, OTF_Stream *stream, long offset,
1539 OTF_Ligature **ligature)
1541 char *errfmt = "Ligature%s";
1546 READ_UINT16 (stream, count);
1549 OTF_MALLOC (*ligature, count, "");
1550 for (i = 0; i < count; i++)
1551 READ_OFFSET (stream, (*ligature)[i].offset);
1552 for (i = 0; i < count; i++)
1554 SEEK_STREAM (stream, offset + (*ligature)[i].offset);
1555 READ_GLYPHID (stream, (*ligature)[i].LigGlyph);
1556 (*ligature)[i].CompCount
1557 = read_glyph_ids (otf, stream, &(*ligature)[i].Component, -1, -1);
1558 if (! (*ligature)[i].CompCount)
1565 read_ligature_set_list (OTF *otf, OTF_Stream *stream, long offset,
1566 OTF_LigatureSet **ligset)
1568 char *errfmt = "LigatureSet%s";
1573 READ_UINT16 (stream, count);
1576 OTF_MALLOC (*ligset, count, "");
1577 for (i = 0; i < count; i++)
1578 READ_OFFSET (stream, (*ligset)[i].offset);
1579 for (i = 0; i < count; i++)
1583 SEEK_STREAM (stream, offset + (*ligset)[i].offset);
1584 lig_count = read_ligature (otf, stream, offset + (*ligset)[i].offset,
1585 &(*ligset)[i].Ligature);
1588 (*ligset)[i].LigatureCount = (unsigned) lig_count;
1594 read_alternate_set_list (OTF *otf, OTF_Stream *stream, long offset,
1595 OTF_AlternateSet **altset)
1597 char *errfmt = "AlternateSet%s";
1602 READ_UINT16 (stream, count);
1604 OTF_ERROR (OTF_ERROR_TABLE, " (zero count)");
1605 OTF_MALLOC (*altset, count, "");
1606 for (i = 0; i < count; i++)
1607 READ_OFFSET (stream, (*altset)[i].offset);
1608 for (i = 0; i < count; i++)
1612 SEEK_STREAM (stream, offset + (*altset)[i].offset);
1613 alt_count = read_glyph_ids (otf, stream, &(*altset)[i].Alternate, 0, -1);
1616 (*altset)[i].GlyphCount = (unsigned) alt_count;
1622 read_reverse_chain1 (OTF *otf, OTF_Stream *stream, long offset,
1623 OTF_Coverage *coverage,
1624 OTF_GSUB_ReverseChain1 *reverse_chain)
1628 if (read_coverage (otf, stream, offset, coverage) < 0)
1630 count = read_coverage_list (otf, stream, offset,
1631 &reverse_chain->Backtrack, -1);
1634 reverse_chain->BacktrackGlyphCount = (unsigned) count;
1635 count = read_coverage_list (otf, stream, offset,
1636 &reverse_chain->LookAhead, -1);
1639 reverse_chain->LookaheadGlyphCount = (unsigned) count;
1640 count = read_glyph_ids (otf, stream, &reverse_chain->Substitute, 0, -1);
1643 reverse_chain->GlyphCount = count;
1648 read_lookup_subtable_gsub (OTF *otf, OTF_Stream *stream, long offset,
1649 unsigned type, OTF_LookupSubTableGSUB *subtable)
1654 SEEK_STREAM (stream, offset);
1655 READ_USHORT (stream, subtable->Format);
1656 sprintf (errfmt, "GSUB Lookup %d-%d%%s", type, subtable->Format);
1660 if (subtable->Format == 1)
1662 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
1664 READ_INT16 (stream, subtable->u.single1.DeltaGlyphID);
1666 else if (subtable->Format == 2)
1668 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
1670 subtable->u.single2.GlyphCount
1671 = read_glyph_ids (otf, stream, &subtable->u.single2.Substitute,
1673 if (! subtable->u.single2.GlyphCount)
1677 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1681 if (subtable->Format == 1)
1683 read_coverage (otf, stream, offset, &subtable->Coverage);
1684 subtable->u.multiple1.SequenceCount
1685 = read_sequence (otf, stream, offset,
1686 &subtable->u.multiple1.Sequence);
1689 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1693 if (subtable->Format == 1)
1695 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
1697 subtable->u.alternate1.AlternateSetCount
1698 = read_alternate_set_list (otf, stream, offset,
1699 &subtable->u.alternate1.AlternateSet);
1700 if (! subtable->u.alternate1.AlternateSetCount)
1704 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1708 if (subtable->Format == 1)
1710 if (read_coverage (otf, stream, offset, &subtable->Coverage) < 0)
1712 subtable->u.ligature1.LigSetCount
1713 = read_ligature_set_list (otf, stream, offset,
1714 &subtable->u.ligature1.LigatureSet);
1715 if (! subtable->u.ligature1.LigSetCount)
1719 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1723 if (subtable->Format == 1)
1725 if (read_context1 (otf, stream, offset, &subtable->Coverage,
1726 &subtable->u.context1) < 0)
1729 else if (subtable->Format == 2)
1731 if (read_context2 (otf, stream, offset, &subtable->Coverage,
1732 &subtable->u.context2) < 0)
1735 else if (subtable->Format == 3)
1737 if (read_context3 (otf, stream, offset, &subtable->Coverage,
1738 &subtable->u.context3) < 0)
1742 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1746 if (subtable->Format == 1)
1748 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
1749 &subtable->u.chain_context1) < 0)
1752 else if (subtable->Format == 2)
1754 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
1755 &subtable->u.chain_context2) < 0)
1758 else if (subtable->Format == 3)
1760 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
1761 &subtable->u.chain_context3) < 0)
1765 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1769 if (subtable->Format == 1)
1773 OTF_LookupSubTableGSUB *ex_subtable;
1775 READ_USHORT (stream, ex_type);
1776 READ_ULONG (stream, ex_offset);
1777 OTF_CALLOC (ex_subtable, 1, " (SubTable)");
1778 if (read_lookup_subtable_gsub (otf, stream, offset + ex_offset,
1779 ex_type, ex_subtable) < 0)
1781 subtable->u.extension1.ExtensionLookupType = ex_type;
1782 subtable->u.extension1.ExtensionOffset = ex_offset;
1783 subtable->u.extension1.ExtensionSubtable = ex_subtable;
1786 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1790 if (subtable->Format == 1)
1792 if (read_reverse_chain1 (otf, stream, offset, &subtable->Coverage,
1793 &subtable->u.reverse_chain1) < 0)
1797 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
1801 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
1807 read_gsub_table (OTF *otf, OTF_Stream *stream)
1809 return read_gsub_gpos_table (otf, stream, 1);
1813 /* (1-10) "GPOS" table */
1816 read_value_record (OTF *otf, OTF_Stream *stream, long offset,
1817 enum OTF_ValueFormat bit, OTF_ValueRecord *value_record)
1820 OTF_StreamState state;
1825 for (i = 0, size = 0; i < 8; i++)
1829 if (bit & OTF_XPlacement)
1830 READ_INT16 (stream, value_record->XPlacement);
1831 if (bit & OTF_XPlacement)
1832 READ_INT16 (stream, value_record->YPlacement);
1833 if (bit & OTF_XAdvance)
1834 READ_INT16 (stream, value_record->XAdvance);
1835 if (bit & OTF_YAdvance)
1836 READ_INT16 (stream, value_record->YAdvance);
1837 if (bit & OTF_XPlaDevice)
1838 READ_OFFSET (stream, value_record->XPlaDevice.offset);
1839 if (bit & OTF_YPlaDevice)
1840 READ_OFFSET (stream, value_record->YPlaDevice.offset);
1841 if (bit & OTF_XAdvDevice)
1842 READ_OFFSET (stream, value_record->XAdvDevice.offset);
1843 if (bit & OTF_YAdvDevice)
1844 READ_OFFSET (stream, value_record->YAdvDevice.offset);
1845 SAVE_STREAM (stream, state);
1846 if (value_record->XPlaDevice.offset)
1848 if (read_device_table (otf, stream, offset, &value_record->XPlaDevice) < 0)
1851 if (value_record->YPlaDevice.offset)
1853 if (read_device_table (otf, stream, offset, &value_record->YPlaDevice) < 0)
1856 if (value_record->XAdvDevice.offset)
1858 if (read_device_table (otf, stream, offset, &value_record->XAdvDevice) < 0)
1861 if (value_record->YAdvDevice.offset)
1863 if (read_device_table (otf, stream, offset, &value_record->YAdvDevice) < 0)
1866 RESTORE_STREAM (stream, state);
1872 read_anchor (OTF *otf, OTF_Stream *stream, long offset, OTF_Anchor *anchor)
1874 char *errfmt = "Anchor%s";
1877 SEEK_STREAM (stream, offset + anchor->offset);
1878 READ_UINT16 (stream, anchor->AnchorFormat);
1879 READ_INT16 (stream, anchor->XCoordinate);
1880 READ_INT16 (stream, anchor->YCoordinate);
1881 if (anchor->AnchorFormat == 1)
1883 else if (anchor->AnchorFormat == 2)
1885 READ_UINT16 (stream, anchor->f.f1.AnchorPoint);
1887 else if (anchor->AnchorFormat == 3)
1889 READ_OFFSET (stream, anchor->f.f2.XDeviceTable.offset);
1890 READ_OFFSET (stream, anchor->f.f2.YDeviceTable.offset);
1891 if (anchor->f.f2.XDeviceTable.offset)
1893 if (read_device_table (otf, stream, offset + anchor->offset,
1894 &anchor->f.f2.XDeviceTable) < 0)
1897 if (anchor->f.f2.YDeviceTable.offset)
1899 if (read_device_table (otf, stream, offset + anchor->offset,
1900 &anchor->f.f2.YDeviceTable) < 0)
1905 OTF_ERROR (OTF_ERROR_TABLE, " (invalid format)");
1911 read_mark_array (OTF *otf, OTF_Stream *stream, long offset,
1912 OTF_MarkArray *array)
1914 char *errfmt = "MarkArray%s";
1916 OTF_StreamState state;
1919 READ_OFFSET (stream, array->offset);
1920 SAVE_STREAM (stream, state);
1921 SEEK_STREAM (stream, offset + array->offset);
1922 READ_UINT16 (stream, array->MarkCount);
1923 OTF_MALLOC (array->MarkRecord, array->MarkCount, "");
1924 for (i = 0; i < array->MarkCount; i++)
1926 READ_UINT16 (stream, array->MarkRecord[i].Class);
1927 READ_OFFSET (stream, array->MarkRecord[i].MarkAnchor.offset);
1929 for (i = 0; i < array->MarkCount; i++)
1930 if (read_anchor (otf, stream, offset + array->offset,
1931 &array->MarkRecord[i].MarkAnchor) < 0)
1933 RESTORE_STREAM (stream, state);
1938 read_anchor_array (OTF *otf, OTF_Stream *stream, long offset,
1939 unsigned ClassCount, OTF_AnchorArray *array)
1941 char *errfmt = "AnchorArray%s";
1943 OTF_StreamState state;
1946 READ_OFFSET (stream, array->offset);
1947 SAVE_STREAM (stream, state);
1948 SEEK_STREAM (stream, offset + array->offset);
1949 READ_UINT16 (stream, array->Count);
1950 OTF_MALLOC (array->AnchorRecord, array->Count, "");
1951 for (i = 0; i < array->Count; i++)
1953 OTF_MALLOC (array->AnchorRecord[i].Anchor, ClassCount,
1955 for (j = 0; j < ClassCount; j++)
1956 READ_OFFSET (stream, array->AnchorRecord[i].Anchor[j].offset);
1958 for (i = 0; i < array->Count; i++)
1959 for (j = 0; j < ClassCount; j++)
1960 if (read_anchor (otf, stream, offset + array->offset,
1961 &array->AnchorRecord[i].Anchor[j]) < 0)
1963 RESTORE_STREAM (stream, state);
1968 static OTF_Class1Record *
1969 read_class1_record_list (OTF *otf, OTF_Stream *stream, long offset,
1970 unsigned num1, enum OTF_ValueFormat bit1,
1971 unsigned num2, enum OTF_ValueFormat bit2)
1973 char *errfmt = "Class1Record%s";
1974 void *errret = NULL;
1975 OTF_Class1Record *rec;
1978 OTF_MALLOC (rec, num1, "");
1979 for (i = 0; i < num1; i++)
1981 OTF_CALLOC (rec[i].Class2Record, num2, " (Class2Record)");
1982 for (j = 0; j < num2; j++)
1984 if (read_value_record (otf, stream, offset,
1985 bit1, &rec[i].Class2Record[j].Value1) < 0
1986 || read_value_record (otf, stream, offset,
1987 bit2, &rec[i].Class2Record[j].Value2) < 0)
1995 read_lookup_subtable_gpos (OTF *otf, OTF_Stream *stream,
1996 long offset, unsigned type,
1997 OTF_LookupSubTableGPOS *subtable)
2002 SEEK_STREAM (stream, offset);
2003 READ_UINT16 (stream, subtable->Format);
2004 sprintf (errfmt, "GPOS Lookup %d-%d%%s", type, subtable->Format);
2008 if (subtable->Format == 1)
2010 READ_UINT16 (stream, subtable->u.single1.ValueFormat);
2011 read_value_record (otf, stream, offset,
2012 subtable->u.single1.ValueFormat,
2013 &subtable->u.single1.Value);
2015 else if (subtable->Format == 2)
2017 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
2020 READ_UINT16 (stream, single2->ValueFormat);
2021 READ_UINT16 (stream, single2->ValueCount);
2022 OTF_CALLOC (single2->Value, single2->ValueCount," (ValueRecord)");
2023 for (i = 0; i < single2->ValueCount; i++)
2024 read_value_record (otf, stream, offset, single2->ValueFormat,
2025 single2->Value + i);
2028 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2032 if (subtable->Format == 1)
2034 OTF_ERROR (OTF_ERROR_TABLE, " (not yet supported)");
2036 else if (subtable->Format == 2)
2038 SEEK_STREAM (stream, offset + 2);
2039 read_coverage (otf, stream, offset, &subtable->Coverage);
2040 READ_UINT16 (stream, subtable->u.pair2.ValueFormat1);
2041 READ_UINT16 (stream, subtable->u.pair2.ValueFormat2);
2042 read_class_def (otf, stream, offset,
2043 &subtable->u.pair2.ClassDef1);
2044 read_class_def (otf, stream, offset,
2045 &subtable->u.pair2.ClassDef2);
2046 READ_UINT16 (stream, subtable->u.pair2.Class1Count);
2047 READ_UINT16 (stream, subtable->u.pair2.Class2Count);
2048 subtable->u.pair2.Class1Record
2049 = read_class1_record_list (otf, stream, offset,
2050 subtable->u.pair2.Class1Count,
2051 subtable->u.pair2.ValueFormat1,
2052 subtable->u.pair2.Class2Count,
2053 subtable->u.pair2.ValueFormat2);
2056 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2060 OTF_ERROR (OTF_ERROR_TABLE, " (not yet supported)");
2064 if (subtable->Format == 1)
2066 read_coverage (otf, stream, offset, &subtable->Coverage);
2067 read_coverage (otf, stream, offset,
2068 &subtable->u.mark_base1.BaseCoverage);
2069 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2070 read_mark_array (otf, stream, offset,
2071 &subtable->u.mark_base1.MarkArray);
2072 read_anchor_array (otf, stream, offset,
2073 subtable->u.mark_base1.ClassCount,
2074 &subtable->u.mark_base1.BaseArray);
2077 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2081 OTF_ERROR (OTF_ERROR_TABLE, " (not yet supported)");
2085 if (subtable->Format == 1)
2087 read_coverage (otf, stream, offset, &subtable->Coverage);
2088 read_coverage (otf, stream, offset,
2089 &subtable->u.mark_mark1.Mark2Coverage);
2090 READ_UINT16 (stream, subtable->u.mark_base1.ClassCount);
2091 read_mark_array (otf, stream, offset,
2092 &subtable->u.mark_mark1.Mark1Array);
2093 read_anchor_array (otf, stream, offset,
2094 subtable->u.mark_mark1.ClassCount,
2095 &subtable->u.mark_mark1.Mark2Array);
2098 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2102 if (subtable->Format == 1)
2104 if (read_context1 (otf, stream, offset, &subtable->Coverage,
2105 &subtable->u.context1) < 0)
2108 else if (subtable->Format == 2)
2110 if (read_context2 (otf, stream, offset, &subtable->Coverage,
2111 &subtable->u.context2) < 0)
2114 else if (subtable->Format == 3)
2116 if (read_context3 (otf, stream, offset, &subtable->Coverage,
2117 &subtable->u.context3) < 0)
2121 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2125 if (subtable->Format == 1)
2127 if (read_chain_context1 (otf, stream, offset, &subtable->Coverage,
2128 &subtable->u.chain_context1) < 0)
2131 else if (subtable->Format == 2)
2133 if (read_chain_context2 (otf, stream, offset, &subtable->Coverage,
2134 &subtable->u.chain_context2) < 0)
2137 else if (subtable->Format == 3)
2139 if (read_chain_context3 (otf, stream, offset, &subtable->Coverage,
2140 &subtable->u.chain_context3) < 0)
2144 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid SubFormat)");
2148 OTF_ERROR (OTF_ERROR_TABLE, " (not yet supported)");
2152 OTF_ERROR (OTF_ERROR_TABLE, " (Invalid LookupType)");
2158 read_gpos_table (OTF *otf, OTF_Stream *stream)
2160 return read_gsub_gpos_table (otf, stream, 0);
2168 read_base_table (OTF_Stream *stream, long offset)
2172 OTF_MALLOC (base, 1);
2181 read_jstf_table (OTF_Stream *stream, long offset)
2185 OTF_MALLOC (jstf, 1);
2191 /*** (1-11) Structure for OTF */
2194 read_offset_table (OTF *otf, OTF_Stream *stream, OTF_OffsetTable *table)
2198 READ_FIXED (stream, table->sfnt_version);
2199 READ_USHORT (stream, table->numTables);
2200 READ_USHORT (stream, table->searchRange);
2201 READ_USHORT (stream, table->enterSelector);
2202 READ_USHORT (stream, table->rangeShift);
2207 read_table_directory (OTF_Stream *stream, OTF_TableDirectory *table)
2212 READ_TAG (stream, tag);
2214 table->name[0] = tag >> 24;
2215 table->name[1] = (tag >> 16) & 0xFF;
2216 table->name[0] = (tag >> 8) & 0xFF;
2217 table->name[0] = tag >> 8;
2218 table->name[0] = '\0';
2219 READ_ULONG (stream, table->checkSum);
2220 READ_ULONG (stream, table->offset);
2221 READ_ULONG (stream, table->length);
2226 read_header_part (OTF *otf, FILE *fp)
2228 char *errfmt = "otf header%s";
2230 OTF_Tag head_tag, name_tag, cmap_tag, gdef_tag, gsub_tag, gpos_tag;
2233 OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
2235 internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
2236 internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
2237 internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
2238 internal_data->table_info[OTF_TABLE_TYPE_NAME].reader = read_name_table;
2239 internal_data->table_info[OTF_TABLE_TYPE_CMAP].address = (void *) &otf->cmap;
2240 internal_data->table_info[OTF_TABLE_TYPE_CMAP].reader = read_cmap_table;
2241 internal_data->table_info[OTF_TABLE_TYPE_GDEF].address = (void *) &otf->gdef;
2242 internal_data->table_info[OTF_TABLE_TYPE_GDEF].reader = read_gdef_table;
2243 internal_data->table_info[OTF_TABLE_TYPE_GSUB].address = (void *) &otf->gsub;
2244 internal_data->table_info[OTF_TABLE_TYPE_GSUB].reader = read_gsub_table;
2245 internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
2246 internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
2248 head_tag = OTF_tag ("head");
2249 name_tag = OTF_tag ("name");
2250 cmap_tag = OTF_tag ("cmap");
2251 gdef_tag = OTF_tag ("GDEF");
2252 gsub_tag = OTF_tag ("GSUB");
2253 gpos_tag = OTF_tag ("GPOS");
2255 stream = make_stream ();
2259 internal_data->header_stream = stream;
2261 /* Size of Offset Table is 12 bytes. */
2262 if (setup_stream (stream, fp, 0, 12, "Offset Table") < 0)
2264 if (read_offset_table (otf, stream, &otf->offset_table) < 0)
2267 /* Size of each Table Directory is 16 bytes. */
2268 if (setup_stream (stream, fp, 12, 16 * otf->offset_table.numTables,
2269 "Table Directory") < 0)
2272 OTF_CALLOC (otf->table_dirs, otf->offset_table.numTables, " (OffsetTable)");
2273 for (i = 0; i < otf->offset_table.numTables; i++)
2275 OTF_Tag tag = read_table_directory (stream, otf->table_dirs + i);
2276 OTF_TableInfo *table_info = NULL;
2280 if (tag == head_tag)
2281 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2282 else if (tag == name_tag)
2283 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2284 else if (tag == cmap_tag)
2285 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2286 else if (tag == gdef_tag)
2287 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2288 else if (tag == gsub_tag)
2289 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2290 else if (tag == gpos_tag)
2291 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2295 table_info->stream = make_stream ();
2296 if (setup_stream (table_info->stream, fp,
2297 otf->table_dirs[i].offset,
2298 otf->table_dirs[i].length,
2299 otf->table_dirs[i].name) < 0)
2304 internal_data->header_stream = NULL;
2305 free_stream (stream);
2309 static OTF_TableInfo *
2310 get_table_info (OTF *otf, char *name)
2312 char *errfmt = "OTF Table Read%s";
2313 OTF_TableInfo *errret = NULL;
2314 OTF_InternalData *internal_data = otf->internal_data;
2315 OTF_TableInfo *table_info;
2316 OTF_Tag tag = OTF_tag (name);
2319 OTF_ERROR (OTF_ERROR_TABLE, " (invalid table name)");
2321 if (tag == OTF_tag ("head"))
2322 table_info = internal_data->table_info + OTF_TABLE_TYPE_HEAD;
2323 else if (tag == OTF_tag ("name"))
2324 table_info = internal_data->table_info + OTF_TABLE_TYPE_NAME;
2325 else if (tag == OTF_tag ("cmap"))
2326 table_info = internal_data->table_info + OTF_TABLE_TYPE_CMAP;
2327 else if (tag == OTF_tag ("GDEF"))
2328 table_info = internal_data->table_info + OTF_TABLE_TYPE_GDEF;
2329 else if (tag == OTF_tag ("GSUB"))
2330 table_info = internal_data->table_info + OTF_TABLE_TYPE_GSUB;
2331 else if (tag == OTF_tag ("GPOS"))
2332 table_info = internal_data->table_info + OTF_TABLE_TYPE_GPOS;
2334 OTF_ERROR (OTF_ERROR_TABLE, " (not yet supported table name)");
2336 if (*table_info->address)
2339 if (! table_info->stream)
2340 OTF_ERROR (OTF_ERROR_TABLE, " (table not found)");
2341 if (! table_info->reader)
2342 OTF_ERROR (OTF_ERROR_TABLE, " (invalid contents)");
2348 /*** (2) API for reading OTF */
2350 /*** (2-1) OTF_open() */
2352 /* Note: We can't use memory allocation macros in the following
2353 functions because those macros return from the functions before
2354 freeing memory previously allocated. */
2357 OTF_open (char *otf_name)
2360 char *errfmt = "opening otf (%s)";
2361 void *errret = NULL;
2363 OTF_InternalData *internal_data;
2365 fp = fopen (otf_name, "r");
2367 OTF_ERROR (OTF_ERROR_FILE, otf_name);
2368 otf = calloc (1, sizeof (OTF));
2370 OTF_ERROR (OTF_ERROR_MEMORY, "body allocation");
2371 otf->filename = strdup (otf_name);
2372 if (! otf->filename)
2376 OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
2379 internal_data = calloc (1, sizeof (OTF_InternalData));
2380 if (! internal_data)
2381 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
2382 otf->internal_data = internal_data;
2383 if (! allocate_memory_record (otf))
2384 OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
2386 /* Here after, all pointers to allocated memory are recorded in
2387 otf->internal_data->memory_record except for what allocated by
2388 the functions allocate_memory_record and make_stream. */
2390 if (read_header_part (otf, fp) < 0)
2401 /*** (2-2) OTF_close() */
2404 OTF_close (OTF *otf)
2406 OTF_InternalData *internal_data = otf->internal_data;
2411 OTF_MemoryRecord *memrec = internal_data->memory_record;
2413 if (internal_data->header_stream)
2414 free_stream (internal_data->header_stream);
2416 for (i = 0; i < OTF_TABLE_TYPE_MAX; i++)
2417 if (internal_data->table_info[i].stream)
2418 free_stream (internal_data->table_info[i].stream);
2422 OTF_MemoryRecord *next = memrec->next;
2424 for (i = memrec->used - 1; i >= 0; i--)
2425 free (memrec->memory[i]);
2429 free (internal_data);
2434 /*** (2-3) OTF_get_table() */
2437 OTF_get_table (OTF *otf, char *name)
2439 OTF_TableInfo *table_info = get_table_info (otf, name);
2444 *table_info->address = (*table_info->reader) (otf, table_info->stream);
2445 free_stream (table_info->stream);
2446 table_info->stream = NULL;
2447 if (! *table_info->address)
2449 table_info->reader = NULL;
2455 /*** (2-4) OTF_check_table() */
2458 OTF_check_table (OTF *otf, char *name)
2460 return (get_table_info (otf, name) ? 0 : -1);
2466 /*** (5) API miscellaneous ***/
2469 OTF_tag (char *name)
2471 unsigned char *p = (unsigned char *) name;
2475 return (OTF_Tag) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
2479 OTF_tag_name (OTF_Tag tag, char *name)
2481 name[0] = (char) (tag >> 24);
2482 name[1] = (char) ((tag >> 16) & 0xFF);
2483 name[2] = (char) ((tag >> 8) & 0xFF);
2484 name[3] = (char) (tag & 0xFF);