1 /* otf.h -- Header file for the OTF (OpenType font) library.
4 by AIST (National Institute of Advanced Industrial Science and Technology)
5 Registration Number H14PRO???
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. */
30 (1) Structures for OTF tables and OTF itself
35 (1-5) Structures common to the following tables
41 (2) APIs for reading OTF
44 (2-3) otf_get_table ()
46 (3) APIs for driving OTF
47 (3-1) Structure for glyph string
48 (3-2) otf_drive_cmap ()
49 (3-3) otf_drive_gdef ()
50 (3-4) otf_drive_gsub ()
51 (3-5) otf_drive_gpos ()
53 (4) APIs for error handling
57 (5) APIs miscellaneous
61 /*** (1) Structures for OTF tables and OTF itself */
63 /*** (1-1) Basic types */
65 typedef unsigned OTF_Tag;
66 typedef unsigned OTF_GlyphID;
67 typedef unsigned OTF_Offset;
76 /*** (1-2) "head" table */
80 OTF_Fixed TableVersionNumber;
81 OTF_Fixed fontRevision;
82 unsigned checkSumAdjustment;
89 /*** (1-3) "name" table */
101 #define OTF_max_nameID 23
108 OTF_NameRecord *nameRecord;
109 char *name[OTF_max_nameID + 1];
113 /*** (1-4) "cmap" table */
117 unsigned char glyphIdArray[256];
118 } OTF_EncodingSubtable0;
125 unsigned idRangeOffset;
130 unsigned subHeaderKeys[256];
131 OTF_cmapSubHeader *subHeaders;
132 unsigned *glyphIndexArray;
133 } OTF_EncodingSubtable2;
140 unsigned idRangeOffset;
146 unsigned searchRange;
147 unsigned entrySelector;
149 OTF_cmapSegument *segments;
151 unsigned *glyphIdArray;
152 } OTF_EncodingSubtable4;
158 unsigned *glyphIdArray;
159 } OTF_EncodingSubtable6;
163 unsigned startCharCode;
164 unsigned endCharCode;
165 unsigned startGlyphID;
170 unsigned char is32[8192];
172 OTF_cmapGroup *Groups;
173 } OTF_EncodingSubtable8;
177 unsigned startCharCode;
180 } OTF_EncodingSubtable10;
185 OTF_cmapGroup *Groups;
186 } OTF_EncodingSubtable12;
194 OTF_EncodingSubtable0 *f0;
195 OTF_EncodingSubtable2 *f2;
196 OTF_EncodingSubtable4 *f4;
197 OTF_EncodingSubtable6 *f6;
198 OTF_EncodingSubtable8 *f8;
199 OTF_EncodingSubtable10 *f10;
200 OTF_EncodingSubtable12 *f12;
202 } OTF_EncodingSubtable;
209 OTF_EncodingSubtable subtable;
210 } OTF_EncodingRecord;
216 OTF_EncodingRecord *EncodingRecord;
217 OTF_EncodingRecord *Unicode;
221 /*** (1-5) Structures common to GDEF, GSUB, GPOS */
227 unsigned StartCoverageIndex;
233 unsigned CoverageFormat;
236 OTF_GlyphID *GlyphArray;
237 OTF_RangeRecord *RangeRecord;
246 unsigned DeltaFormat;
255 } OTF_ClassRangeRecord;
260 unsigned ClassFormat;
263 OTF_GlyphID StartGlyph;
265 unsigned *ClassValueArray;
268 unsigned ClassRangeCount;
269 OTF_ClassRangeRecord *ClassRangeRecord;
274 /*** (1-6) "GDEF" table */
279 OTF_Offset GlyphClassDef;
280 OTF_Offset AttachList;
281 OTF_Offset LigCaretList;
282 OTF_Offset MarkAttachClassDef;
285 enum OTF_GlyphClassDef
288 OTF_GlyphClassBase = 1,
289 OTF_GlyphClassLigature = 2,
290 OTF_GlyphClassMark = 3,
291 OTF_GlyphClassComponent = 4
298 unsigned *PointIndex;
303 OTF_Coverage Coverage;
305 OTF_AttachPoint *AttachPoint;
311 unsigned CaretValueFormat; /* 1, 2, or 3 */
317 unsigned CaretValuePoint;
321 OTF_DeviceTable DeviceTable;
330 OTF_CaretValue *CaretValue;
335 OTF_Coverage Coverage;
336 unsigned LigGlyphCount;
337 OTF_LigGlyph *LigGlyph;
342 OTF_GDEFHeader header;
343 OTF_ClassDef glyph_class_def;
344 OTF_AttachList attach_list;
345 OTF_LigCaretList lig_caret_list;
346 OTF_ClassDef mark_attach_class_def;
386 OTF_Offset LookupOrder;
387 unsigned ReqFeatureIndex;
388 unsigned FeatureCount;
389 unsigned *FeatureIndex;
402 OTF_Offset DefaultLangSysOffset;
403 OTF_LangSys DefaultLangSys;
404 unsigned LangSysCount;
405 OTF_LangSysRecord *LangSysRecord;
406 OTF_LangSys *LangSys;
412 unsigned ScriptCount;
420 OTF_Offset FeatureParams;
421 unsigned LookupCount;
422 unsigned *LookupListIndex;
428 unsigned FeatureCount;
429 OTF_Feature *Feature;
432 typedef struct OTF_LookupSubTable OTF_LookupSubTable;
439 unsigned SubTableCount;
440 OTF_Offset *SubTableOffset;
441 OTF_LookupSubTable *SubTable;
447 unsigned LookupCount;
451 enum OTF_LookupFlagBit
453 OTF_RightToLeft = 0x0001,
454 OTF_IgnoreBaseGlyphs = 0x0002,
455 OTF_IgnoreLigatures = 0x0004,
456 OTF_IgnoreMarks = 0x8000,
457 OTF_Reserved = 0x00F0,
458 OTF_MarkAttachmentType = 0xFF00
472 OTF_GlyphID *Substitute;
475 typedef struct OTF_Sequence OTF_Sequence;
479 unsigned SequenceCount;
480 OTF_Sequence *Sequence;
481 } OTF_GSUB_Multiple1;
487 OTF_GlyphID *Substitute;
490 typedef struct OTF_AlternateSet OTF_AlternateSet;
494 unsigned AlternateSetCount;
495 OTF_AlternateSet *AlternateSet;
496 } OTF_GSUB_Alternate1;
498 struct OTF_AlternateSet
502 OTF_GlyphID *Alternate;
505 typedef struct OTF_LigatureSet OTF_LigatureSet;
506 typedef struct OTF_Ligature OTF_Ligature;
510 unsigned LigSetCount;
511 OTF_LigatureSet *LigatureSet;
512 } OTF_GSUB_Ligature1;
514 struct OTF_LigatureSet
517 unsigned LigatureCount;
518 OTF_Ligature *Ligature;
524 OTF_GlyphID LigGlyph;
526 OTF_GlyphID *Component;
531 unsigned SequenceIndex;
532 unsigned LookupListIndex;
533 } OTF_SubstLookupRecord;
535 typedef struct OTF_SubRuleSet OTF_SubRuleSet;
539 unsigned SubRuleSetCount;
540 OTF_SubRuleSet *SubRuleSet;
543 typedef struct OTF_SubRule OTF_SubRule;
545 struct OTF_SubRuleSet
548 unsigned SubRuleCount;
549 OTF_SubRule *SubRule;
558 OTF_SubstLookupRecord *SubstLookupRecord;
561 typedef struct OTF_SubClassSet OTF_SubClassSet;
565 OTF_ClassDef ClassDef;
566 unsigned SubClassSetCount;
567 OTF_SubClassSet *SubClassSet;
570 typedef struct OTF_SubClassRule OTF_SubClassRule;
572 struct OTF_SubClassSet
574 unsigned SubClassRuleCnt;
575 OTF_SubClassRule *SubClassRule;
578 struct OTF_SubClassRule
584 OTF_SubstLookupRecord *SubstLookupRecord;
591 OTF_Coverage *Coverage;
592 OTF_SubstLookupRecord *SubstLookupRecord;
595 typedef struct OTF_ChainSubRuleSet OTF_ChainSubRuleSet;
599 unsigned ChainSubRuleSetCount;
600 OTF_ChainSubRuleSet *ChainSubRuleSet;
601 } OTF_GSUB_ChainContext1;
603 typedef struct OTF_ChainSubRule OTF_ChainSubRule;
605 struct OTF_ChainSubRuleSet
608 unsigned ChainSubRuleCount;
609 OTF_ChainSubRule *ChainSubRule;
612 struct OTF_ChainSubRule
615 unsigned BacktrackGlyphCount;
616 OTF_GlyphID *Backtrack;
617 unsigned InputGlyphCount;
619 unsigned LookaheadGlyphCount;
620 OTF_GlyphID *LookAhead;
622 OTF_SubstLookupRecord *SubstLookupRecord;
625 typedef struct OTF_ChainSubClassSet OTF_ChainSubClassSet;
629 OTF_ClassDef Backtrack;
631 OTF_ClassDef LookAhead;
632 unsigned ChainSubClassSetCnt;
633 OTF_ChainSubClassSet *ChainSubClassSet;
634 } OTF_GSUB_ChainContext2;
636 typedef struct OTF_ChainSubClassRule OTF_ChainSubClassRule;
638 struct OTF_ChainSubClassSet
641 unsigned ChainSubClassRuleCnt;
642 OTF_ChainSubClassRule *ChainSubClassRule;
645 struct OTF_ChainSubClassRule
648 unsigned BacktrackGlyphCount;
650 unsigned InputGlyphCount;
652 unsigned LookaheadGlyphCount;
655 OTF_SubstLookupRecord *SubstLookupRecord;
661 unsigned BacktrackGlyphCount;
662 OTF_Coverage *Backtrack;
663 unsigned InputGlyphCount;
665 unsigned LookaheadGlyphCount;
666 OTF_Coverage *LookAhead;
668 OTF_SubstLookupRecord *SubstLookupRecord;
669 } OTF_GSUB_ChainContext3;
673 unsigned ExtensionLookupType;
674 unsigned ExtentionOffset;
675 } OTF_GSUB_Extension1;
679 unsigned BacktrackGlyphCount;
680 OTF_Coverage *Backtrack;
681 unsigned LookaheadGlyphCount;
682 OTF_Coverage *LookAhead;
684 OTF_GlyphID *Substitute;
685 } OTF_GSUB_ReverseChainSingle1;
691 OTF_XPlacement = 0x0001,
692 OTF_YPlacement = 0x0002,
693 OTF_XAdvance = 0x0004,
694 OTF_YAdvance = 0x0008,
695 OTF_XPlaDevice = 0x0010,
696 OTF_YPlaDevice = 0x0020,
697 OTF_XAdvDevice = 0x0040,
698 OTF_YAdvDevice = 0x0080
707 OTF_DeviceTable XPlaDevice;
708 OTF_DeviceTable YPlaDevice;
709 OTF_DeviceTable XAdvDevice;
710 OTF_DeviceTable YAdvDevice;
716 unsigned AnchorFormat;
721 unsigned AnchorPoint;
724 OTF_DeviceTable XDeviceTable;
725 OTF_DeviceTable YDeviceTable;
733 OTF_Anchor MarkAnchor;
740 OTF_MarkRecord *MarkRecord;
760 OTF_ValueRecord Value1;
761 OTF_ValueRecord Value2;
766 OTF_Class2Record *Class2Record;
771 unsigned ValueFormat1;
772 unsigned ValueFormat2;
773 OTF_ClassDef ClassDef1;
774 OTF_ClassDef ClassDef2;
775 unsigned Class1Count;
776 unsigned Class2Count;
777 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
787 OTF_Anchor *BaseAnchor;
794 OTF_BaseRecord *BaseRecord;
799 OTF_Coverage BaseCoverage;
801 OTF_MarkArray MarkArray;
802 OTF_BaseArray BaseArray;
803 } OTF_GPOS_MarkBase1;
813 } OTF_GPOS_MarkMark1;
833 } OTF_GPOS_ChainContext1;
838 } OTF_GPOS_ChainContext2;
843 } OTF_GPOS_ChainContext3;
848 } OTF_GPOS_Extension1;
851 struct OTF_LookupSubTable
854 OTF_Coverage Coverage;
858 OTF_GSUB_Single1 single1;
859 OTF_GSUB_Single2 single2;
861 OTF_GSUB_Multiple1 multiple1;
863 OTF_GSUB_Alternate1 alternate1;
865 OTF_GSUB_Ligature1 ligature1;
867 OTF_GSUB_Context1 context1;
868 OTF_GSUB_Context2 context2;
869 OTF_GSUB_Context3 context3;
871 OTF_GSUB_ChainContext1 chain_context1;
872 OTF_GSUB_ChainContext2 chain_context2;
873 OTF_GSUB_ChainContext3 chain_context3;
875 OTF_GSUB_Extension1 extension1;
877 OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
882 OTF_GPOS_Single1 single1;
883 OTF_GPOS_Single2 single2;
885 OTF_GPOS_Pair1 pair1;
886 OTF_GPOS_Pair2 pair2;
888 OTF_GPOS_Cursive1 cursive1;
890 OTF_GPOS_MarkBase1 mark_base1;
892 OTF_GPOS_MarkLig1 mark_lig1;
894 OTF_GPOS_MarkMark1 mark_mark1;
896 OTF_GPOS_Context1 context1;
897 OTF_GPOS_Context2 context2;
898 OTF_GPOS_Context3 context3;
900 OTF_GPOS_ChainContext1 chain_context1;
901 OTF_GPOS_ChainContext2 chain_context2;
902 OTF_GPOS_ChainContext3 chain_context3;
904 OTF_GPOS_Extension1 extension1;
915 OTF_ScriptList ScriptList;
916 OTF_FeatureList FeatureList;
917 OTF_LookupList LookupList;
926 OTF_ScriptList ScriptList;
927 OTF_FeatureList FeatureList;
928 OTF_LookupList LookupList;
950 OTF_Fixed sfnt_version;
952 unsigned searchRange;
953 unsigned enterSelector;
964 } OTF_TableDirectory;
966 typedef struct OTF_InternalData OTF_InternalData;
971 OTF_OffsetTable offset_table;
972 OTF_TableDirectory *table_dirs;
979 /* The following tables are not yet supported. */
982 OTF_InternalData *internal_data;
987 /* Character code of the glyph. This is the only member that a
988 client has to set before calling the function otfdrive(). */
991 /* Glyph ID of the glyph. */
992 OTF_GlyphID glyph_id;
994 /* GlyphClass of the glyph. The value is extracted from the GDEF
996 enum OTF_GlyphClassDef GlyphClass;
998 /* MarkAttachClassDef of the glyph. The value is extracted from the
1000 unsigned MarkAttachClass;
1002 /* Positioning format type of the glyph. The value is the same as
1003 the LookupType of the GPOS's Lookup table that is used to decide
1004 the positioning of the glyph. */
1005 int positioning_type;
1008 enum OTF_ValueFormat format;
1009 OTF_ValueRecord *value;
1012 enum OTF_ValueFormat format;
1013 OTF_ValueRecord *value;
1016 OTF_Anchor *entry_anchor;
1017 OTF_Anchor *exit_anchor;
1020 OTF_Anchor *mark_anchor;
1021 OTF_Anchor *base_anchor;
1024 OTF_Anchor *mark_anchor;
1025 OTF_Anchor *ligature_anchor;
1028 OTF_Anchor *mark1_anchor;
1029 OTF_Anchor *mark2_anchor;
1043 @brief Open an OpenType font file.
1045 The function otf_open () reads the OpenType font file whose name
1046 is $NAME, and return a pointer to the structure of type OTF. */
1048 extern OTF *otf_open (char *name);
1049 extern void otf_close (OTF *otf);
1050 extern int otf_get_table (OTF *otf, char *name);
1052 extern int otf_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1053 extern int otf_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1054 extern int otf_drive_gsub (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1055 OTF_GlyphString *gstring);
1056 extern int otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1057 OTF_GlyphString *gstring);
1058 extern int otf_drive_table (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1059 OTF_GlyphString *gstring);
1062 /*** (4) APIs for error handling ***/
1064 /*** (4-1) Error codes ***/
1067 Global variable holding an error code.
1069 The variable otf_error is set to one of OTF_ERROR_XXX macros when
1070 an error is detected in the OTF library. */
1071 extern int otf_error;
1074 Memory allocation error.
1076 This error indicates that the library couldn't allocate
1078 #define OTF_ERROR_MEMORY 1
1083 This error indicates that the library fails in opening, reading,
1084 or seeking an OTF file. */
1085 #define OTF_ERROR_FILE 2
1088 Invalid table contents.
1090 This error indicates that an OTF file contains invalid data. */
1091 #define OTF_ERROR_TABLE 3
1096 See the function otf_drive_cmap() for more detail. */
1097 #define OTF_ERROR_CMAP_DRIVE 4
1102 See the function otf_drive_gdef() for more detail. */
1103 #define OTF_ERROR_GDEF_DRIVE 5
1108 See the function otf_drive_gsub() for more detail. */
1109 #define OTF_ERROR_GSUB_DRIVE 6
1114 See the function otf_drive_gpos() for more detail. */
1115 #define OTF_ERROR_GPOS_DRIVE 7
1119 Print an OTF error message
1121 The otf_perror() function produces a message on the standard error
1122 output, describing the last error encountered during a call to the
1123 OTF library function. If $PREFIX is not NULL, is is printed
1124 first, followed by a colon and a blank. Then the message and a
1127 extern void otf_perror (char *prefix);
1130 /*** (5) APIs miscellaneous ***/
1133 Return OTF tag of a specified name string.
1135 The otf_tag() function returns OTF tag of name $NAME. If $NAME is
1136 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1137 Only the first 4 characters are took into an account. */
1139 extern OTF_Tag otf_tag (char *name);
1142 Convert OTF tag to name string.
1144 The otf_tag_name() function converts OTF tag $TAG to a 5-byte
1145 name string (including the terminating NUL), and store it in
1146 $NAME. At least 5-byte space must be at $NAME. */
1148 extern void otf_tag_name (OTF_Tag tag, char *name);
1151 #endif /* not _OTF_H_ */