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