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