From: <sil...@li...> - 2003-04-14 21:34:41
|
Update of /cvsroot/silgraphite/silgraphite/src/TtfUtil In directory sc8-pr-cvs1:/tmp/cvs-serv17948/src/TtfUtil Modified Files: Tt.h TtSfnt.h TtfUtil.cpp TtfUtil.h Log Message: Synchronized with FW, 14 Apr 2003, changelist #06701 Index: Tt.h =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/src/TtfUtil/Tt.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Tt.h 5 Nov 2002 21:29:24 -0000 1.1.1.1 +++ Tt.h 14 Apr 2003 21:34:33 -0000 1.2 @@ -3,7 +3,8 @@ * TT.H -- Header file TrueType font structures and declarations * * Includes Apple supplied headers, then adds definitions they forgot. - * Modifed 4/25/2000 by Alan Ward + * Modified 4/25/2000 by Alan Ward + * Modified 3/27/2003 by Alan Ward */ @@ -39,7 +40,7 @@ typedef struct { uint16 format; uint16 length; - uint16 version; + uint16 version; // 21 Mar 2002 spec shows this as language uint16 segCountX2; uint16 searchRange; uint16 entrySelector; @@ -54,6 +55,23 @@ */ } sfnt_Cmap4; +/* Add the sftn_Cmap12 structs to handle cmap format added for UCS-4 - AW */ + +typedef struct { + uint32 startCharCode; + uint32 endCharCode; + uint32 startGlyphID; +} sfnt_Cmap12Group; + +typedef struct { + uint16 format; + uint16 reserved; + uint32 length; + uint32 language; + uint32 nGroups; + sfnt_Cmap12Group groupArray[1]; /* groupArray[nGroups] */ +} sfnt_Cmap12; +#define SIZEOFCMAP12 16 // Add this typedef to parse the header for a glyf entry typedef struct{ Index: TtSfnt.h =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/src/TtfUtil/TtSfnt.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- TtSfnt.h 5 Nov 2002 21:29:24 -0000 1.1.1.1 +++ TtSfnt.h 14 Apr 2003 21:34:34 -0000 1.2 @@ -141,7 +141,7 @@ typedef struct { uint16 format; uint16 length; - uint16 version; + uint16 version; // 21 Mar 2002 spec shows this as language } sfnt_mappingTable; typedef struct { Index: TtfUtil.cpp =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/src/TtfUtil/TtfUtil.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TtfUtil.cpp 11 Nov 2002 23:53:12 -0000 1.2 +++ TtfUtil.cpp 14 Apr 2003 21:34:34 -0000 1.3 @@ -383,7 +383,7 @@ /*---------------------------------------------------------------------------------------------- Get the offset and size of the font family name in English for the MS Platform with Unicode - encoding. The offset is within the pName data. The string is double byte with MSB first. + writing system. The offset is within the pName data. The string is double byte with MSB first. ----------------------------------------------------------------------------------------------*/ bool TtfUtil::Get31EngFamilyInfo(const void * pName, long & lOffset, long & lSize) { @@ -392,7 +392,7 @@ /*---------------------------------------------------------------------------------------------- Get the offset and size of the full font name in English for the MS Platform with Unicode - encoding. The offset is within the pName data. The string is double byte with MSB first. + writing system. The offset is within the pName data. The string is double byte with MSB first. ----------------------------------------------------------------------------------------------*/ bool TtfUtil::Get31EngFullFontInfo(const void * pName, long & lOffset, long & lSize) { @@ -401,7 +401,7 @@ /*---------------------------------------------------------------------------------------------- Get the offset and size of the font family name in English for the MS Platform with Symbol - encoding. The offset is within the pName data. The string is double byte with MSB first. + writing system. The offset is within the pName data. The string is double byte with MSB first. ----------------------------------------------------------------------------------------------*/ bool TtfUtil::Get30EngFamilyInfo(const void * pName, long & lOffset, long & lSize) { @@ -410,7 +410,7 @@ /*---------------------------------------------------------------------------------------------- Get the offset and size of the full font name in English for the MS Platform with Symbol - encoding. The offset is within the pName data. The string is double byte with MSB first. + writing system. The offset is within the pName data. The string is double byte with MSB first. ----------------------------------------------------------------------------------------------*/ bool TtfUtil::Get30EngFullFontInfo(const void * pName, long & lOffset, long & lSize) { @@ -663,7 +663,7 @@ { const sfnt_mappingTable * pTable = reinterpret_cast<const sfnt_mappingTable *>(pCmap31); // Bob H says ome freeware TT fonts have version 1 (eg, CALIGULA.TTF) - // so don't check subtable version + // so don't check subtable version. 21 Mar 2002 spec changes version to language. if (// swapw(pTable->version) == 0 && swapw(pTable->format) == 4) return true; @@ -675,7 +675,6 @@ Return the Glyph ID for the given Unicode ID in the Microsoft Unicode subtable. (Actually this code only depends on subtable being format 4.) Return 0 if the Unicode ID is not in the subtable. - This is the source of Glyph IDs used through out the rest of this code. ----------------------------------------------------------------------------------------------*/ int TtfUtil::Cmap31Lookup(const void * pCmap31, int nUnicodeId) { @@ -722,13 +721,52 @@ uint16 idRangeOffset = swapw(*(pMid += nSeg)); if (idRangeOffset == 0) - return idDelta + nUnicodeId; + return (uint16)(idDelta + nUnicodeId); // must use modulus 2^16 // Look up value in glyphIdArray int nGlyphId = swapw(*(pMid + (nUnicodeId - chStart) + (idRangeOffset >> 1))); // If this value is 0, return 0. Else add the idDelta return nGlyphId ? nGlyphId + idDelta : 0; } + + return 0; +} + +/*---------------------------------------------------------------------------------------------- + Check the Microsoft UCS-4 subtable for expected values +----------------------------------------------------------------------------------------------*/ +bool TtfUtil::CheckCmap310Subtable(const void *pCmap310) +{ + const sfnt_mappingTable * pTable = reinterpret_cast<const sfnt_mappingTable *>(pCmap310); + if (swapw(pTable->format) == 12) + return true; + + return false; +} + +/*---------------------------------------------------------------------------------------------- + Return the Glyph ID for the given Unicode ID in the Microsoft UCS-4 subtable. + (Actually this code only depends on subtable being format 12.) + Return 0 if the Unicode ID is not in the subtable. +----------------------------------------------------------------------------------------------*/ +int TtfUtil::Cmap310Lookup(const void * pCmap310, unsigned int uUnicodeId) +{ + const sfnt_Cmap12 * pTable = reinterpret_cast<const sfnt_Cmap12 *>(pCmap310); + + uint32 uLength = swapl(pTable->length); //could use to test for premature end of table + uint32 ucGroups = swapl(pTable->nGroups); + + for (unsigned int i = 0; i < ucGroups; i++) + { + uint32 uStartCode = swapl(pTable->groupArray[i].startCharCode); + uint32 uEndCode = swapl(pTable->groupArray[i].endCharCode); + if (uUnicodeId >= uStartCode && uUnicodeId <= uEndCode) + { + uint32 uDiff = uUnicodeId - uStartCode; + uint32 uStartGid = swapl(pTable->groupArray[i].startGlyphID); + return uStartGid + uDiff; + } + } return 0; } Index: TtfUtil.h =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/src/TtfUtil/TtfUtil.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TtfUtil.h 11 Nov 2002 23:57:29 -0000 1.2 +++ TtfUtil.h 14 Apr 2003 21:34:34 -0000 1.3 @@ -72,6 +72,8 @@ int nEncodingId = 1); static bool CheckCmap31Subtable(const void * pCmap31); static int Cmap31Lookup(const void * pCmap31, int nUnicodeId); + static bool CheckCmap310Subtable(const void *pCmap310); + static int Cmap310Lookup(const void * pCmap310, unsigned int uUnicodeId); ///////////////////////////////// horizontal metric data for a glyph static bool HorMetrics(int nGlyphId, const void * pHmtx, long lHmtxSize, |