1 /*************************************************************************** 2 * 3 * Copyright (C) 1998-2002, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 * 6 ************************************************************************/ 7 8 9 #ifndef __FONTOBJECT_H 10 #define __FONTOBJECT_H 11 12 #include <stdio.h> 13 14 #include "LETypes.h" 15 16 17 #ifndef ANY_NUMBER 18 #define ANY_NUMBER 1 19 #endif 20 21 struct DirectoryEntry 22 { 23 le_uint32 tag; 24 le_uint32 checksum; 25 le_uint32 offset; 26 le_uint32 length; 27 }; 28 29 struct SFNTDirectory 30 { 31 le_uint32 scalerType; 32 le_uint16 numTables; 33 le_uint16 searchRange; 34 le_uint16 entrySelector; 35 le_uint16 rangeShift; 36 DirectoryEntry tableDirectory[ANY_NUMBER]; 37 }; 38 39 40 struct CMAPEncodingSubtableHeader 41 { 42 le_uint16 platformID; 43 le_uint16 platformSpecificID; 44 le_uint32 encodingOffset; 45 }; 46 47 struct CMAPTable 48 { 49 le_uint16 version; 50 le_uint16 numberSubtables; 51 CMAPEncodingSubtableHeader encodingSubtableHeaders[ANY_NUMBER]; 52 }; 53 54 struct CMAPEncodingSubtable 55 { 56 le_uint16 format; 57 le_uint16 length; 58 le_uint16 language; 59 }; 60 61 struct CMAPFormat0Encoding : CMAPEncodingSubtable 62 { 63 le_uint8 glyphIndexArray[256]; 64 }; 65 66 struct CMAPFormat2Subheader 67 { 68 le_uint16 firstCode; 69 le_uint16 entryCount; 70 le_int16 idDelta; 71 le_uint16 idRangeOffset; 72 }; 73 74 struct CMAPFormat2Encoding : CMAPEncodingSubtable 75 { 76 le_uint16 subHeadKeys[256]; 77 CMAPFormat2Subheader subheaders[ANY_NUMBER]; 78 }; 79 80 struct CMAPFormat4Encoding : CMAPEncodingSubtable 81 { 82 le_uint16 segCountX2; 83 le_uint16 searchRange; 84 le_uint16 entrySelector; 85 le_uint16 rangeShift; 86 le_uint16 endCodes[ANY_NUMBER]; 87 // le_uint16 reservedPad; 88 // le_uint16 startCodes[ANY_NUMBER]; 89 // le_uint16 idDelta[ANY_NUMBER]; 90 // le_uint16 idRangeOffset[ANY_NUMBER]; 91 // le_uint16 glyphIndexArray[ANY_NUMBER]; 92 }; 93 94 struct CMAPFormat6Encoding : CMAPEncodingSubtable 95 { 96 le_uint16 firstCode; 97 le_uint16 entryCount; 98 le_uint16 glyphIndexArray[ANY_NUMBER]; 99 }; 100 101 typedef le_int32 fixed; 102 103 struct BigDate 104 { 105 le_uint32 bc; 106 le_uint32 ad; 107 }; 108 109 struct HEADTable 110 { 111 fixed version; 112 fixed fontRevision; 113 le_uint32 checksumAdjustment; 114 le_uint32 magicNumber; 115 le_uint16 flags; 116 le_uint16 unitsPerEm; 117 BigDate created; 118 BigDate modified; 119 le_int16 xMin; 120 le_int16 yMin; 121 le_int16 xMax; 122 le_int16 yMax; 123 le_int16 lowestRecPPEM; 124 le_int16 fontDirectionHint; 125 le_int16 indexToLocFormat; 126 le_int16 glyphDataFormat; 127 }; 128 129 struct MAXPTable 130 { 131 fixed version; 132 le_uint16 numGlyphs; 133 le_uint16 maxPoints; 134 le_uint16 maxContours; 135 le_uint16 maxComponentPoints; 136 le_uint16 maxComponentContours; 137 le_uint16 maxZones; 138 le_uint16 maxTwilightPoints; 139 le_uint16 maxStorage; 140 le_uint16 maxFunctionDefs; 141 le_uint16 maxInstructionDefs; 142 le_uint16 maxStackElements; 143 le_uint16 maxSizeOfInstructions; 144 le_uint16 maxComponentElements; 145 le_uint16 maxComponentDepth; 146 }; 147 148 struct HHEATable 149 { 150 fixed version; 151 le_int16 ascent; 152 le_int16 descent; 153 le_int16 lineGap; 154 le_uint16 advanceWidthMax; 155 le_int16 minLeftSideBearing; 156 le_int16 minRightSideBearing; 157 le_int16 xMaxExtent; 158 le_int16 caretSlopeRise; 159 le_int16 caretSlopeRun; 160 le_int16 caretOffset; 161 le_int16 reserved1; 162 le_int16 reserved2; 163 le_int16 reserved3; 164 le_int16 reserved4; 165 le_int16 metricDataFormat; 166 le_uint16 numOfLongHorMetrics; 167 }; 168 169 struct LongHorMetric 170 { 171 le_uint16 advanceWidth; 172 le_int16 leftSideBearing; 173 }; 174 175 struct HMTXTable 176 { 177 LongHorMetric hMetrics[ANY_NUMBER]; // ANY_NUMBER = numOfLongHorMetrics from hhea table 178 // le_int16 leftSideBearing[ANY_NUMBER]; // ANY_NUMBER = numGlyphs - numOfLongHorMetrics 179 }; 180 181 class FontObject 182 { 183 public: 184 FontObject(char *fontName); 185 ~FontObject(); 186 187 void *readTable(LETag tag, le_uint32 *length); 188 void deleteTable(void *table); 189 190 LEGlyphID unicodeToGlyph(LEUnicode32 unicode); 191 192 #if 0 193 le_uint32 unicodesToGlyphs(LEUnicode *chars, le_uint32 nChars, LEGlyphID *glyphs, 194 le_uint32 *charIndices, le_bool rightToLeft); 195 #endif 196 197 le_uint16 getUnitsPerEM(); 198 199 le_uint16 getGlyphAdvance(LEGlyphID glyph); 200 201 private: 202 FontObject(); 203 204 DirectoryEntry *findTable(LETag tag); 205 CMAPEncodingSubtable *findCMAP(le_uint16 platformID, le_uint16 platformSpecificID); 206 void initUnicodeCMAP(); 207 208 SFNTDirectory *directory; 209 le_uint16 numTables; 210 le_uint16 searchRange; 211 le_uint16 entrySelector; 212 le_uint16 rangeShift; 213 214 CMAPTable *cmapTable; 215 le_uint16 cmSegCount; 216 le_uint16 cmSearchRange; 217 le_uint16 cmEntrySelector; 218 le_uint16 cmRangeShift; 219 le_uint16 *cmEndCodes; 220 le_uint16 *cmStartCodes; 221 le_uint16 *cmIdDelta; 222 le_uint16 *cmIdRangeOffset; 223 224 HEADTable *headTable; 225 226 HMTXTable *hmtxTable; 227 le_uint16 numGlyphs; 228 le_uint16 numOfLongHorMetrics; 229 230 FILE *file; 231 232 }; 233 234 #endif 235 236