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); } }
static void ttfLoadCMAP6(FILE *fp,SubTablePtr subTable,ULONG offset) { USHORT * array,len; if (fseek(fp,offset,SEEK_SET) !=0) ttfError("Fseek Failed in ttfLoadCMAP6 \n"); subTable->map.cmap6 = (CMAP6 *) calloc(1,sizeof(CMAP6)); subTable->map.cmap6->firstCode = ttfGetUSHORT(fp); subTable->map.cmap6->entryCount = len = ttfGetUSHORT(fp); subTable->map.cmap6->glyphIndexArray = array = (USHORT *) calloc(subTable->map.cmap6->entryCount,sizeof(USHORT)); if (fread(array,sizeof(USHORT),len,fp) != len) ttfError("Error when getting idRangeOffset\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,len*sizeof(USHORT)); #endif }
static FT_Error PCF_Glyph_Load( FT_GlyphSlot slot, FT_Size size, FT_UInt glyph_index, FT_Int32 load_flags ) { PCF_Face face = (PCF_Face)FT_SIZE_FACE( size ); FT_Stream stream = face->root.stream; FT_Error error = PCF_Err_Ok; FT_Bitmap* bitmap = &slot->bitmap; PCF_Metric metric; int bytes; FT_UNUSED( load_flags ); FT_TRACE4(( "load_glyph %d ---", glyph_index )); if ( !face ) { error = PCF_Err_Invalid_Argument; goto Exit; } if ( glyph_index > 0 ) glyph_index--; metric = face->metrics + glyph_index; bitmap->rows = metric->ascent + metric->descent; bitmap->width = metric->rightSideBearing - metric->leftSideBearing; bitmap->num_grays = 1; bitmap->pixel_mode = FT_PIXEL_MODE_MONO; FT_TRACE6(( "BIT_ORDER %d ; BYTE_ORDER %d ; GLYPH_PAD %d\n", PCF_BIT_ORDER( face->bitmapsFormat ), PCF_BYTE_ORDER( face->bitmapsFormat ), PCF_GLYPH_PAD( face->bitmapsFormat ) )); switch ( PCF_GLYPH_PAD( face->bitmapsFormat ) ) { case 1: bitmap->pitch = ( bitmap->width + 7 ) >> 3; break; case 2: bitmap->pitch = ( ( bitmap->width + 15 ) >> 4 ) << 1; break; case 4: bitmap->pitch = ( ( bitmap->width + 31 ) >> 5 ) << 2; break; case 8: bitmap->pitch = ( ( bitmap->width + 63 ) >> 6 ) << 3; break; default: return PCF_Err_Invalid_File_Format; } /* XXX: to do: are there cases that need repadding the bitmap? */ bytes = bitmap->pitch * bitmap->rows; error = ft_glyphslot_alloc_bitmap( slot, bytes ); if ( error ) goto Exit; if ( FT_STREAM_SEEK( metric->bits ) || FT_STREAM_READ( bitmap->buffer, bytes ) ) goto Exit; if ( PCF_BIT_ORDER( face->bitmapsFormat ) != MSBFirst ) BitOrderInvert( bitmap->buffer, bytes ); if ( ( PCF_BYTE_ORDER( face->bitmapsFormat ) != PCF_BIT_ORDER( face->bitmapsFormat ) ) ) { switch ( PCF_SCAN_UNIT( face->bitmapsFormat ) ) { case 1: break; case 2: TwoByteSwap( bitmap->buffer, bytes ); break; case 4: FourByteSwap( bitmap->buffer, bytes ); break; } } slot->bitmap_left = metric->leftSideBearing; slot->bitmap_top = metric->ascent; slot->metrics.horiAdvance = metric->characterWidth << 6; slot->metrics.horiBearingX = metric->leftSideBearing << 6; slot->metrics.horiBearingY = metric->ascent << 6; slot->metrics.width = ( metric->rightSideBearing - metric->leftSideBearing ) << 6; slot->metrics.height = bitmap->rows << 6; slot->linearHoriAdvance = (FT_Fixed)bitmap->width << 16; slot->format = FT_GLYPH_FORMAT_BITMAP; FT_TRACE4(( " --- ok\n" )); Exit: return error; }
static void ttfLoadCMAP4(FILE *fp,SubTablePtr subTable,ULONG offset) { USHORT segCount; USHORT * array,len; if (fseek(fp,offset,SEEK_SET) !=0) ttfError("Fseek Failed in ttfLoadCMAP4 \n"); subTable->map.cmap4 = (CMAP4 *) calloc(1,sizeof(CMAP4)); subTable->map.cmap4->segCountX2 = segCount = ttfGetUSHORT(fp); subTable->map.cmap4->searchRange = ttfGetUSHORT(fp); subTable->map.cmap4->entrySelector = ttfGetUSHORT(fp); subTable->map.cmap4->rangeShift = ttfGetUSHORT(fp); segCount /= 2; subTable->map.cmap4->endCount = array = (USHORT *) calloc(segCount,sizeof(USHORT)); if (fread(array,sizeof(USHORT),segCount,fp) != segCount) ttfError("Error when getting endCount\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,segCount*sizeof(USHORT)); #endif subTable->map.cmap4->reservedPad = ttfGetUSHORT(fp); subTable->map.cmap4->startCount = array = (USHORT *) calloc(segCount,sizeof(USHORT)); if (fread(array,sizeof(USHORT),segCount,fp) != segCount) ttfError("Error when getting startCount\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,segCount*sizeof(USHORT)); #endif subTable->map.cmap4->idDelta = array = (USHORT *) calloc(segCount,sizeof(USHORT)); if (fread(array,sizeof(USHORT),segCount,fp) != segCount) ttfError("Error when getting idDelta\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,segCount*sizeof(USHORT)); #endif subTable->map.cmap4->idRangeOffset = array = (USHORT *) calloc(segCount,sizeof(USHORT)); if (fread(array,sizeof(USHORT),segCount,fp) != segCount) ttfError("Error when getting idRangeOffset\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,segCount*sizeof(USHORT)); #endif /* caculate the length of glyphIndexArray, this is ugly, there should be * a better way to get this information. */ len = subTable->length - 8*sizeof(USHORT) - 4*segCount*sizeof(USHORT); len /= sizeof(USHORT); subTable->map.cmap4->glyphIndexArray = array = (USHORT *) calloc(len,sizeof(USHORT)); if (fread(array,sizeof(USHORT),len,fp) != len) ttfError("Error when getting idRangeOffset\n"); #ifndef WORDS_BIGENDIAN TwoByteSwap((unsigned char *) array,len*sizeof(USHORT)); #endif }