From: handa Date: Mon, 9 Dec 2002 01:33:26 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: REL-0-9-1~120 X-Git-Url: http://git.chise.org/gitweb/?p=m17n%2Flibotf.git;a=commitdiff_plain;h=2be0e8bf2c5158ed1f9f8a4d1b5cb2b1ed9a8d8d *** empty log message *** --- diff --git a/configure.ac b/configure.ac index ea84dba..c4bfce6 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ AM_CONFIG_HEADER(src/config.h) # Checks for programs. AC_PROG_CC -AC_PROG_LIBTOOL +AM_PROG_LIBTOOL # Checks for libraries. AC_PATH_XTRA diff --git a/example/Makefile.am b/example/Makefile.am index 516aa7a..fae79da 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -11,7 +11,7 @@ otfdump_LDFLAGS = ${CommonLDFLAGS} -lefence otfdraw_SOURCE = otfdraw otfdraw_LDADD = ${CommonLDADD} -otfdraw_LDFLAGS = `freetype-config --libs` ${X_LIBS} ${X_PRE_LIBS} -lX11 ${CommonLDFLAGS} +otfdraw_LDFLAGS = `freetype-config --libs` ${X_LIBS} ${X_PRE_LIBS} -lX11 -ldl ${CommonLDFLAGS} # We should not install any programs in this directory. diff --git a/example/otfdraw.c b/example/otfdraw.c index fb768b1..c71ee43 100644 --- a/example/otfdraw.c +++ b/example/otfdraw.c @@ -78,7 +78,10 @@ main (int argc, char **argv) otf = otf_open (argv[1]); if (! otf) - otf_perror ("otfdraw:", 1); + { + otf_perror ("otfdraw"); + exit (1); + } gstring.size = 10; gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * 30); memset (gstring.glyphs, 0, sizeof (OTF_Glyph) * 30); diff --git a/example/otfdump.c b/example/otfdump.c index 18d0a53..02ca4d3 100644 --- a/example/otfdump.c +++ b/example/otfdump.c @@ -5,10 +5,6 @@ #include #include -extern int EF_ALIGNMENT; -extern int EF_PROTECT_BELOW; -extern int EF_PROTECT_FREE; - #include char *indent_spaces[] = @@ -1000,10 +996,6 @@ main (int argc, char **argv) { OTF *otf; - EF_ALIGNMENT = 1; - EF_PROTECT_BELOW = 1; - EF_PROTECT_FREE = 1; - if (argc != 2) { fprintf (stderr, "Usage, dtfdump OTF-FILE"); @@ -1012,7 +1004,10 @@ main (int argc, char **argv) otf = otf_open (argv[1]); if (! otf) - otf_perror ("otfdump: ", 1); + { + otf_perror ("otfdump"); + exit (1); + } otf_get_table (otf, "head"); otf_get_table (otf, "name"); otf_get_table (otf, "cmap"); diff --git a/src/otf.h b/src/otf.h index 75b9a81..5b58e3b 100644 --- a/src/otf.h +++ b/src/otf.h @@ -1,108 +1,355 @@ +/* otf.h -- Header file for the OTF (OpenType font) library. + +Copyright (C) 2002 + by AIST (National Institute of Advanced Industrial Science and Technology) + Registration Number H14PRO??? + +This file is part of the OTF library. + +The OTF library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2, or (at +your option) any later version. + +The OTF library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the OTF library; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + #ifndef _OTF_H_ #define _OTF_H_ /*** - @file otf.h + Table of contents: - @brief This file defines APIs for the OTF library. + (1) Structures for OTF tables and OTF itself + (1-1) Basic types + (1-2) "head" table + (1-3) "name" table + (1-4) "cmap" table + (1-5) Structures common to the following tables + (1-6) "GDEF" table + (1-7) "GSUB" table + (1-8) "GPOS" table + (1-9) OTF - The @e OTF @e library is for reading and driving OpenType font - tables. It can handle the tables of the following names. + (2) APIs for reading OTF + (2-1) otf_open () + (2-2) otf_close () + (2-3) otf_get_table () - @li @e head: + (3) APIs for driving OTF + (3-1) Structure for glyph string + (3-2) otf_drive_cmap () + (3-3) otf_drive_gdef () + (3-4) otf_drive_gsub () + (3-5) otf_drive_gpos () - @li @e name: + (4) APIs for error handling + (4-1) Error codes + (4-2) otf_perror () - @li @e cmap: + (5) APIs miscellaneous +***/ - @li @e GDEF: - @li @e GSUB: +/*** (1) Structures for OTF tables and OTF itself */ - @li @e GPOS: +/*** (1-1) Basic types */ -*/ +typedef unsigned OTF_Tag; +typedef unsigned OTF_GlyphID; +typedef unsigned OTF_Offset; +typedef struct +{ + unsigned high; + unsigned low; +} OTF_Fixed; -//// -/*** - @defgroup Error handling +/*** (1-2) "head" table */ - @brief Handling errors that occur in the OTF library. - */ +typedef struct +{ + OTF_Fixed TableVersionNumber; + OTF_Fixed fontRevision; + unsigned checkSumAdjustment; + unsigned magicNumber; + unsigned flags; + int unitsPerEm; +} OTF_head; -/*** @{ */ -/*** - @brief Global variable holding an error code. +/*** (1-3) "name" table */ - The variable otf_error is set to one of OTF_ERROR_XXX when an - error is detected in OTF library. */ -extern int otf_error; +typedef struct +{ + int platformID; + int encodingID; + int languageID; + int nameID; + int length; + int offset; +} OTF_NameRecord; -/*** - @brief Print error message. +#define OTF_max_nameID 23 - The function otf_perror () prints $PREFIX and an error message to - the standard output according to the value of otf_error. If this - variable is zero, do nothing. */ +typedef struct +{ + int format; + int count; + int stringOffset; + OTF_NameRecord *nameRecord; + char *name[OTF_max_nameID + 1]; +} OTF_name; -extern void otf_perror (char *prefix, int exit_code); +/*** (1-4) "cmap" table */ -/*** Macros for error codes. */ +typedef struct +{ + unsigned char glyphIdArray[256]; +} OTF_EncodingSubtable0; -/*** - @brief Memory allocation error. +typedef struct +{ + unsigned firstCode; + unsigned entryCount; + int idDelta; + unsigned idRangeOffset; +} OTF_cmapSubHeader; - When the OTF library fails to allocate memory, the variable - otf_error is set to this value. */ -#define OTF_ERROR_MEMORY -1 +typedef struct +{ + unsigned subHeaderKeys[256]; + OTF_cmapSubHeader *subHeaders; + unsigned *glyphIndexArray; +} OTF_EncodingSubtable2; -/*** - @brief File read error. +typedef struct +{ + unsigned startCount; + unsigned endCount; + int idDelta; + unsigned idRangeOffset; +} OTF_cmapSegument; - When the OTF library fails to read a file, the variable otf_error - is set to this value. */ -#define OTF_ERROR_FILE -2 +typedef struct +{ + unsigned segCountX2; + unsigned searchRange; + unsigned entrySelector; + unsigned rangeShift; + OTF_cmapSegument *segments; + int GlyphCount; + unsigned *glyphIdArray; +} OTF_EncodingSubtable4; -/*** - @brief OTF table read error. +typedef struct +{ + unsigned firstCode; + unsigned entryCount; + unsigned *glyphIdArray; +} OTF_EncodingSubtable6; - When the OTF library detects an invalid data in an OTF table, the - variable otf_error is set to this value. */ -#define OTF_ERROR_TABLE -3 +typedef struct +{ + unsigned startCharCode; + unsigned endCharCode; + unsigned startGlyphID; +} OTF_cmapGroup; -/*** - @brief CMAP driving error. +typedef struct +{ + unsigned char is32[8192]; + unsigned nGroups; + OTF_cmapGroup *Groups; +} OTF_EncodingSubtable8; - When the OTF library an invalid data in an OTF table, the variable - otf_error is set to this value. */ -#define OTF_ERROR_CMAP_DRIVE -4 -#define OTF_ERROR_GDEF_DRIVE -5 -#define OTF_ERROR_GSUB_DRIVE -6 -#define OTF_ERROR_GPOS_DRIVE -7 +typedef struct +{ + unsigned startCharCode; + unsigned numChars; + unsigned *glyphs; +} OTF_EncodingSubtable10; -/*** @} */ +typedef struct +{ + unsigned nGroups; + OTF_cmapGroup *Groups; +} OTF_EncodingSubtable12; -//// +typedef struct +{ + unsigned format; + unsigned length; + unsigned language; + union { + OTF_EncodingSubtable0 *f0; + OTF_EncodingSubtable2 *f2; + OTF_EncodingSubtable4 *f4; + OTF_EncodingSubtable6 *f6; + OTF_EncodingSubtable8 *f8; + OTF_EncodingSubtable10 *f10; + OTF_EncodingSubtable12 *f12; + }f; +} OTF_EncodingSubtable; -/*** */ +typedef struct +{ + unsigned platformID; + unsigned encodingID; + unsigned offset; + OTF_EncodingSubtable subtable; +} OTF_EncodingRecord; -/* BASIC */ +typedef struct +{ + unsigned version; + unsigned numTables; + OTF_EncodingRecord *EncodingRecord; + OTF_EncodingRecord *Unicode; +} OTF_cmap; -typedef unsigned OTF_Tag; -typedef unsigned OTF_GlyphID; -typedef unsigned OTF_Offset; + +/*** (1-5) Structures common to GDEF, GSUB, GPOS */ typedef struct { - unsigned high; - unsigned low; -} OTF_Fixed; + OTF_GlyphID Start; + OTF_GlyphID End; + unsigned StartCoverageIndex; +} OTF_RangeRecord; + +typedef struct +{ + OTF_Offset offset; + unsigned CoverageFormat; + unsigned Count; + union { + OTF_GlyphID *GlyphArray; + OTF_RangeRecord *RangeRecord; + } table; +} OTF_Coverage; + +typedef struct +{ + OTF_Offset offset; + unsigned StartSize; + unsigned EndSize; + unsigned DeltaFormat; + char *DeltaValue; +} OTF_DeviceTable; + +typedef struct +{ + OTF_GlyphID Start; + OTF_GlyphID End; + unsigned Class; +} OTF_ClassRangeRecord; + +typedef struct +{ + OTF_Offset offset; + unsigned ClassFormat; + union { + struct { + OTF_GlyphID StartGlyph; + unsigned GlyphCount; + unsigned *ClassValueArray; + } f1; + struct { + unsigned ClassRangeCount; + OTF_ClassRangeRecord *ClassRangeRecord; + } f2; + } f; +} OTF_ClassDef; + +/*** (1-6) "GDEF" table */ + +typedef struct +{ + OTF_Fixed Version; + OTF_Offset GlyphClassDef; + OTF_Offset AttachList; + OTF_Offset LigCaretList; + OTF_Offset MarkAttachClassDef; +} OTF_GDEFHeader; + +enum OTF_GlyphClassDef + { + OTF_GlyphClass0 = 0, + OTF_GlyphClassBase = 1, + OTF_GlyphClassLigature = 2, + OTF_GlyphClassMark = 3, + OTF_GlyphClassComponent = 4 + }; + +typedef struct +{ + OTF_Offset offset; + unsigned PointCount; + unsigned *PointIndex; +} OTF_AttachPoint; + +typedef struct +{ + OTF_Coverage Coverage; + unsigned GlyphCount; + OTF_AttachPoint *AttachPoint; +} OTF_AttachList; + +typedef struct +{ + OTF_Offset offset; + unsigned CaretValueFormat; /* 1, 2, or 3 */ + union { + union { + int Coordinate; + } f1; + union { + unsigned CaretValuePoint; + } f2; + union { + int Coordinate; + OTF_DeviceTable DeviceTable; + } f3; + } f; +} OTF_CaretValue; + +typedef struct +{ + OTF_Offset offset; + unsigned CaretCount; + OTF_CaretValue *CaretValue; +} OTF_LigGlyph; + +typedef struct +{ + OTF_Coverage Coverage; + unsigned LigGlyphCount; + OTF_LigGlyph *LigGlyph; +} OTF_LigCaretList; + +typedef struct +{ + OTF_GDEFHeader header; + OTF_ClassDef glyph_class_def; + OTF_AttachList attach_list; + OTF_LigCaretList lig_caret_list; + OTF_ClassDef mark_attach_class_def; +} OTF_GDEF; + + + /* COMMON */ /* ScriptList @@ -207,75 +454,11 @@ enum OTF_LookupFlagBit OTF_IgnoreBaseGlyphs = 0x0002, OTF_IgnoreLigatures = 0x0004, OTF_IgnoreMarks = 0x8000, - OTF_Reserved = 0x00F0, - OTF_MarkAttachmentType = 0xFF00 - }; - -typedef struct -{ - OTF_GlyphID Start; - OTF_GlyphID End; - unsigned StartCoverageIndex; -} OTF_RangeRecord; - -typedef struct -{ - OTF_Offset offset; - unsigned CoverageFormat; - unsigned Count; - union { - OTF_GlyphID *GlyphArray; - OTF_RangeRecord *RangeRecord; - } table; -} OTF_Coverage; - -typedef struct -{ - OTF_GlyphID Start; - OTF_GlyphID End; - unsigned Class; -} OTF_ClassRangeRecord; - -typedef struct -{ - OTF_Offset offset; - unsigned ClassFormat; - union { - struct { - OTF_GlyphID StartGlyph; - unsigned GlyphCount; - unsigned *ClassValueArray; - } f1; - struct { - unsigned ClassRangeCount; - OTF_ClassRangeRecord *ClassRangeRecord; - } f2; - } f; -} OTF_ClassDef; - -typedef struct -{ - OTF_Offset offset; - unsigned StartSize; - unsigned EndSize; - unsigned DeltaFormat; - char *DeltaValue; -} OTF_DeviceTable; - - -/* head */ -typedef struct -{ - OTF_Fixed TableVersionNumber; - OTF_Fixed fontRevision; - unsigned checkSumAdjustment; - unsigned magicNumber; - unsigned flags; - int unitsPerEm; -} OTF_head; - + OTF_Reserved = 0x00F0, + OTF_MarkAttachmentType = 0xFF00 + }; + - /* GSUB */ typedef struct @@ -760,213 +943,7 @@ typedef struct } OTF_JSTF; -/* GDEF */ -typedef struct -{ - OTF_Fixed Version; - OTF_Offset GlyphClassDef; - OTF_Offset AttachList; - OTF_Offset LigCaretList; - OTF_Offset MarkAttachClassDef; -} OTF_GDEFHeader; - -enum OTF_GlyphClassDef - { - OTF_GlyphClass0 = 0, - OTF_GlyphClassBase = 1, - OTF_GlyphClassLigature = 2, - OTF_GlyphClassMark = 3, - OTF_GlyphClassComponent = 4 - }; - -typedef struct -{ - OTF_Offset offset; - unsigned PointCount; - unsigned *PointIndex; -} OTF_AttachPoint; - -typedef struct -{ - OTF_Coverage Coverage; - unsigned GlyphCount; - OTF_AttachPoint *AttachPoint; -} OTF_AttachList; - -typedef struct -{ - OTF_Offset offset; - unsigned CaretValueFormat; /* 1, 2, or 3 */ - union { - union { - int Coordinate; - } f1; - union { - unsigned CaretValuePoint; - } f2; - union { - int Coordinate; - OTF_DeviceTable DeviceTable; - } f3; - } f; -} OTF_CaretValue; - -typedef struct -{ - OTF_Offset offset; - unsigned CaretCount; - OTF_CaretValue *CaretValue; -} OTF_LigGlyph; - -typedef struct -{ - OTF_Coverage Coverage; - unsigned LigGlyphCount; - OTF_LigGlyph *LigGlyph; -} OTF_LigCaretList; - -typedef struct -{ - OTF_GDEFHeader header; - OTF_ClassDef glyph_class_def; - OTF_AttachList attach_list; - OTF_LigCaretList lig_caret_list; - OTF_ClassDef mark_attach_class_def; -} OTF_GDEF; - - - -/* cmap */ - -typedef struct -{ - unsigned char glyphIdArray[256]; -} OTF_EncodingSubtable0; - -typedef struct -{ - unsigned firstCode; - unsigned entryCount; - int idDelta; - unsigned idRangeOffset; -} OTF_cmapSubHeader; - -typedef struct -{ - unsigned subHeaderKeys[256]; - OTF_cmapSubHeader *subHeaders; - unsigned *glyphIndexArray; -} OTF_EncodingSubtable2; - -typedef struct -{ - unsigned startCount; - unsigned endCount; - int idDelta; - unsigned idRangeOffset; -} OTF_cmapSegument; - -typedef struct -{ - unsigned segCountX2; - unsigned searchRange; - unsigned entrySelector; - unsigned rangeShift; - OTF_cmapSegument *segments; - int GlyphCount; - unsigned *glyphIdArray; -} OTF_EncodingSubtable4; - -typedef struct -{ - unsigned firstCode; - unsigned entryCount; - unsigned *glyphIdArray; -} OTF_EncodingSubtable6; - -typedef struct -{ - unsigned startCharCode; - unsigned endCharCode; - unsigned startGlyphID; -} OTF_cmapGroup; - -typedef struct -{ - unsigned char is32[8192]; - unsigned nGroups; - OTF_cmapGroup *Groups; -} OTF_EncodingSubtable8; - -typedef struct -{ - unsigned startCharCode; - unsigned numChars; - unsigned *glyphs; -} OTF_EncodingSubtable10; - -typedef struct -{ - unsigned nGroups; - OTF_cmapGroup *Groups; -} OTF_EncodingSubtable12; - -typedef struct -{ - unsigned format; - unsigned length; - unsigned language; - union { - OTF_EncodingSubtable0 *f0; - OTF_EncodingSubtable2 *f2; - OTF_EncodingSubtable4 *f4; - OTF_EncodingSubtable6 *f6; - OTF_EncodingSubtable8 *f8; - OTF_EncodingSubtable10 *f10; - OTF_EncodingSubtable12 *f12; - }f; -} OTF_EncodingSubtable; - -typedef struct -{ - unsigned platformID; - unsigned encodingID; - unsigned offset; - OTF_EncodingSubtable subtable; -} OTF_EncodingRecord; - -typedef struct -{ - unsigned version; - unsigned numTables; - OTF_EncodingRecord *EncodingRecord; - OTF_EncodingRecord *Unicode; -} OTF_cmap; - - -/* name */ -typedef struct -{ - int platformID; - int encodingID; - int languageID; - int nameID; - int length; - int offset; -} OTF_NameRecord; - -#define OTF_max_nameID 23 - -typedef struct -{ - int format; - int count; - int stringOffset; - OTF_NameRecord *nameRecord; - char *name[OTF_max_nameID + 1]; -} OTF_name; - /* OTF */ typedef struct { @@ -1008,8 +985,7 @@ typedef struct typedef struct { /* Character code of the glyph. This is the only member that a - client has to set before calling the OTF library function - otfdrive. */ + client has to set before calling the function otfdrive(). */ int c; /* Glyph ID of the glyph. */ @@ -1064,17 +1040,6 @@ typedef struct /*** - @brief Convert a string to OTF tag. - - The function otf_tag () converts the string $STR to OTF tag, and - return that tag. If $STR is NULL, return 0. - - If $STR is not NULL, the length should be at least 4, and the - first 4 characters are took into an account. */ - -extern OTF_Tag otf_tag (char *str); - -/*** @brief Open an OpenType font file. The function otf_open () reads the OpenType font file whose name @@ -1094,4 +1059,93 @@ extern int otf_drive_table (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag, OTF_GlyphString *gstring); +/*** (4) APIs for error handling ***/ + +/*** (4-1) Error codes ***/ + +/*** + Global variable holding an error code. + + The variable otf_error is set to one of OTF_ERROR_XXX macros when + an error is detected in the OTF library. */ +extern int otf_error; + +/*** + Memory allocation error. + + This error indicates that the library couldn't allocate + memory. */ +#define OTF_ERROR_MEMORY 1 + +/*** + File error. + + This error indicates that the library fails in opening, reading, + or seeking an OTF file. */ +#define OTF_ERROR_FILE 2 + +/*** + Invalid table contents. + + This error indicates that an OTF file contains invalid data. */ +#define OTF_ERROR_TABLE 3 + +/*** + CMAP driving error. + + See the function otf_drive_cmap() for more detail. */ +#define OTF_ERROR_CMAP_DRIVE 4 + +/*** + GDEF driving error. + + See the function otf_drive_gdef() for more detail. */ +#define OTF_ERROR_GDEF_DRIVE 5 + +/*** + GSUB driving error. + + See the function otf_drive_gsub() for more detail. */ +#define OTF_ERROR_GSUB_DRIVE 6 + +/*** + GPOS driving error. + + See the function otf_drive_gpos() for more detail. */ +#define OTF_ERROR_GPOS_DRIVE 7 + + +/*** + Print an OTF error message + + The otf_perror() function produces a message on the standard error + output, describing the last error encountered during a call to the + OTF library function. If $PREFIX is not NULL, is is printed + first, followed by a colon and a blank. Then the message and a + newline. */ + +extern void otf_perror (char *prefix); + + +/*** (5) APIs miscellaneous ***/ + +/*** + Return OTF tag of a specified name string. + + The otf_tag() function returns OTF tag of name $NAME. If $NAME is + NULL, return 0. Otherwise, $NAME must be at least 4-byte length. + Only the first 4 characters are took into an account. */ + +extern OTF_Tag otf_tag (char *name); + +/*** + Convert OTF tag to name string. + + The otf_tag_name() function converts OTF tag $TAG to a 5-byte + name string (including the terminating NUL), and store it in + $NAME. At least 5-byte space must be at $NAME. */ + +extern void otf_tag_name (OTF_Tag tag, char *name); + + #endif /* not _OTF_H_ */ diff --git a/src/otfopen.c b/src/otfopen.c index 790451b..db35e6f 100644 --- a/src/otfopen.c +++ b/src/otfopen.c @@ -187,12 +187,12 @@ typedef struct OTF_MemoryRecord OTF_MemoryRecord; typedef struct { - /* Points to one of OTF->head, OTF->name, etc. */ - void **address; - /* Function to read one of OTF tables. */ - void *(*reader) (OTF *otf, OTF_Stream *stream); - /* Stream given to . */ - OTF_Stream *stream; + /* Points to one of OTF->head, OTF->name, etc. */ + void **address; + /* Function to read one of OTF tables. */ + void *(*reader) (OTF *otf, OTF_Stream *stream); + /* Stream given to . */ + OTF_Stream *stream; } OTF_TableInfo; struct OTF_InternalData @@ -212,7 +212,7 @@ static OTF_MemoryRecord * allocate_memory_record (OTF *otf) { OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data; - OTF_MemoryRecord *memrec = calloc (1, sizeof (OTF_MemoryRecord)); + OTF_MemoryRecord *memrec = malloc (sizeof (OTF_MemoryRecord)); if (! memrec) return NULL; @@ -242,17 +242,21 @@ allocate_memory_record (OTF *otf) } while (0) -#define OTF_CALLOC(p, size, arg) \ - do { \ - (p) = calloc ((size), sizeof (*(p))); \ - if (! (p) \ - || ((((OTF_InternalData *) otf->internal_data)->memory_record->used \ - >= OTF_MEMORY_RECORD_SIZE) \ - && (allocate_memory_record (otf) < 0))) \ - OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \ - ((OTF_InternalData *) otf->internal_data)->memory_record->memory \ - [((OTF_InternalData *) otf->internal_data)->memory_record->used++] \ - = (p); \ +#define OTF_CALLOC(p, size, arg) \ + do { \ + if (size == 0) \ + (p) = NULL; \ + else \ + { \ + OTF_MemoryRecord *memrec \ + = ((OTF_InternalData *) otf->internal_data)->memory_record; \ + (p) = calloc ((size), sizeof (*(p))); \ + if (! (p) \ + || (memrec->used >= OTF_MEMORY_RECORD_SIZE \ + && ! (memrec = allocate_memory_record (otf)))) \ + OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \ + memrec->memory[memrec->used++] = (p); \ + } \ } while (0) @@ -302,15 +306,11 @@ read_header_part (OTF *otf, FILE *fp) { char *errfmt = "otf header%s"; int errret = -1; - OTF_InternalData *internal_data; OTF_Tag head_tag, name_tag, cmap_tag, gdef_tag, gsub_tag, gpos_tag; OTF_Stream *stream; int i; + OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data; - internal_data = calloc (1, sizeof (OTF_InternalData)); - if (! internal_data) - OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData"); - otf->internal_data = internal_data; internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head; internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table; internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name; @@ -324,9 +324,6 @@ read_header_part (OTF *otf, FILE *fp) internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos; internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table; - if (allocate_memory_record (otf) < 0) - OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)"); - head_tag = otf_tag ("head"); name_tag = otf_tag ("name"); cmap_tag = otf_tag ("cmap"); @@ -1867,6 +1864,27 @@ read_name_table (OTF *otf, OTF_Stream *stream) /* APIs */ +OTF_Tag +otf_tag (char *name) +{ + unsigned char *p = (unsigned char *) name; + + if (! name) + return (OTF_Tag) 0; + return (OTF_Tag) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); +} + +void +otf_tag_name (OTF_Tag tag, char *name) +{ + name[0] = (char) (tag >> 24); + name[1] = (char) ((tag >> 16) & 0xFF); + name[2] = (char) ((tag >> 8) & 0xFF); + name[3] = (char) (tag & 0xFF); + name[4] = '\0'; +} + + /* We can't use memory allocation macros in the following functions because those macros returns from the functions before freeing memory previously allocated. */ @@ -1878,6 +1896,7 @@ otf_open (char *otf_name) char *errfmt = "opening otf (%s)"; void *errret = NULL; OTF *otf; + OTF_InternalData *internal_data; fp = fopen (otf_name, "r"); if (! fp) @@ -1893,6 +1912,17 @@ otf_open (char *otf_name) OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation"); } + internal_data = calloc (1, sizeof (OTF_InternalData)); + if (! internal_data) + OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData"); + otf->internal_data = internal_data; + if (! allocate_memory_record (otf)) + OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)"); + + /* Here after, all pointers to allocated memory are recorded in + otf->internal_data->memory_record except for what allocated by + the functions allocate_memory_record and make_stream. */ + if (read_header_part (otf, fp) < 0) { otf_close (otf); @@ -1911,10 +1941,8 @@ otf_close (OTF *otf) OTF_InternalData *internal_data = otf->internal_data; int i; - if (otf->filename) - free (otf->filename); - if (otf->table_dirs) - free (otf->table_dirs); + //if (otf->filename) + //free (otf->filename); if (internal_data) { OTF_MemoryRecord *memrec = internal_data->memory_record; @@ -1930,7 +1958,7 @@ otf_close (OTF *otf) { OTF_MemoryRecord *next = memrec->next; - for (i = 0; i < memrec->used; i++) + for (i = memrec->used - 1; i >= 0; i--) free (memrec->memory[i]); free (memrec); memrec = next; diff --git a/src/otfutil.c b/src/otfutil.c index a5d1be0..9481afc 100644 --- a/src/otfutil.c +++ b/src/otfutil.c @@ -9,9 +9,14 @@ int otf_error; static char *error_string[] = { + "No error", "Memory shortage", "File error", - "Invalid OTF table contents" + "Invalid table" + "CMAP drive" + "GDEF drive" + "GSUB drive" + "GPOS drive" }; int @@ -19,34 +24,19 @@ otf__error (int err, char *fmt, void *arg) { if (! error_message) error_message = (char *) malloc (256); - sprintf (error_message, "OTF-Error (%s): ", error_string[-err - 1]); + sprintf (error_message, "OTF-Error (%s): ", error_string[err]); sprintf (error_message + strlen (error_message), fmt, arg); otf_error = err; return 0; } void -otf_perror (char *prefix, int exit_code) +otf_perror (char *prefix) { - if (otf_error < 0) - { - if (prefix) - fprintf (stderr, "%s%s\n", prefix, error_message); - else - fprintf (stderr, "%s\n", error_message); - if (exit_code > 0) - exit (exit_code); - } + if (otf_error == 0) + error_message = error_string[0]; + if (prefix) + fprintf (stderr, "%s: %s\n", prefix, error_message); + else + fprintf (stderr, "%s\n", error_message); } - - -OTF_Tag -otf_tag (char *str) -{ - unsigned char *p = (unsigned char *) str; - - if (! str) - return (OTF_Tag) 0; - return (OTF_Tag) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); -} -