SHORT *ttfMakeSHORT(size_t nelem, FILE *fp) { int i; SHORT *array = XTALLOC (nelem, SHORT); for (i = 0; i < nelem; i++) array[i] = ttfGetSHORT (fp); return array; }
static void ttfLoadCMAP2(FILE *fp,SubTablePtr subTable,ULONG offset) { USHORT * array,i,n = 0; USHORT numGlyphId; SubHeaderPtr header; if (fseek(fp,offset,SEEK_SET) != 0) ttfError("Fseek Failed in ttfLoadCMAP2 \n"); subTable->map.cmap2 = (CMAP2 *) calloc(1,sizeof(CMAP2)); array = subTable->map.cmap2->subHeaderKeys; if (fread(array,sizeof(USHORT),256,fp) != 256) ttfError("Error when getting subHeaderKeys \n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,256*sizeof(USHORT)); #endif for (i=0;i<256;i++) { array[i] /= 8; if (n< array[i]) n = array[i]; /* find the max of subHeaderKeys */ } n += 1; /* the number of subHeaders is one plus the max of subHeaderKeys */ subTable->map.cmap2->subHeaders = header = (SubHeaderPtr) calloc(n,sizeof(SubHeader)); for (i=0;i<n;i++) { (header+i)->firstCode = ttfGetUSHORT(fp); (header+i)->entryCount = ttfGetUSHORT(fp); (header+i)->idDelta = ttfGetSHORT(fp); (header+i)->idRangeOffset = ttfGetUSHORT(fp); /* it makes things easier to let the offset starts from * the beginning of glyphIndexArray */ if ((header+i)->idRangeOffset != 0) (header+i)->idRangeOffset -= (sizeof(USHORT) + (n-i-1) * sizeof(SubHeader)) ; } /* caculate the length of glyphIndexArray, this is ugly, there should be * a better way to get this information. */ numGlyphId = subTable->length - (256 + 3) * sizeof(USHORT) - n * sizeof(SubHeader); numGlyphId /= sizeof(USHORT); subTable->map.cmap2->glyphIndexArray = (USHORT *) calloc(numGlyphId,sizeof(USHORT)); for (i=0;i<numGlyphId;i++) { subTable->map.cmap2->glyphIndexArray[i] = ttfGetUSHORT(fp); } }
FWord ttfGetFWord(FILE *fp) { return (FWord) ttfGetSHORT(fp); }