示例#1
0
static void ttfLoadPREP(FILE *fp,BYTE *prep,USHORT length,ULONG offset)
{
    if (fseek(fp,offset,SEEK_SET) != 0)
	ttfError("Fseek Failed in ttfLoadPREP \n");

    if (fread(prep, sizeof(BYTE), length, fp) != length)
	ttfError("Error when getting PREP\n");
}
示例#2
0
static void ttfLoadFPGM(FILE *fp,BYTE *fpgm,USHORT length,ULONG offset)
{
    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadCVT \n");

    if (fread(fpgm, sizeof(BYTE), length, fp) != length)
	ttfError("Error when getting CVT\n");
}
示例#3
0
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);
	}	
}
示例#4
0
CHAR ttfGetCHAR(FILE *fp)
{
    int cc;
    if ((cc = fgetc(fp)) == EOF)
	{
	    if (feof(fp) != 0)
		ttfError("Unexpected EOF\n");
	    else
		ttfError("Error Getting CHAR\n");
	}
    return (CHAR) cc;
}
示例#5
0
BYTE ttfGetBYTE(FILE *fp)
{
    int cc;
    if ((cc = fgetc(fp)) == EOF)
	{
	    if (feof(fp) != 0)
		ttfError("Unexpected EOF\n");
	    else
		ttfError("Error Getting BYTE\n");
	}
    return (BYTE) cc;
}
示例#6
0
/* ULONG offset: address of the beginning of the actual data (base actually)
 * base: start of data storage, specified by NAME.offset
 * offset: specified by NameRecord.offset */
static void ttfLoadNameRecordData(FILE *fp,NameRecordPtr rec,ULONG offset)
{
    ULONG pos;

    pos =  offset  +  rec->offset;
    if (fseek(fp,pos,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadSubTable\n");

    if ((rec->data = (char *) calloc(rec->length,sizeof(char))) == NULL)
	ttfError("Out Of Memory\n");
    if (fread(rec->data,sizeof(char),rec->length,fp) != rec->length)
	ttfError("Error when getting Name Record Data\n");
}
示例#7
0
static void ttfPrintSubTable(FILE* fp,SubTablePtr ptable)
{
    USHORT format = ptable->format;
    
    /* print encoding table */
    fprintf(fp,    " PlatformID: %2d\n",ptable->PlatformID);
    fprintf(fp,"\t\t EcodingID:  %2d\n",ptable->EncodingID);
    fprintf(fp,"\t\t 'cmap' Offset: 0x%08x\n",ptable->offset);
    
    /* print SubTable part */
    fprintf(fp,"\t\t Length:  %6d\n",ptable->length);
    fprintf(fp,"\t\t Version: %6d\n",ptable->version);

    switch(format)
	{
	case 0:
	    fprintf(fp,"\t\t Format 0 - Byte encoding table\n");
	    ttfPrintCMAP0(fp,ptable);
	    break;
	case 2:
	    fprintf(fp,"\t\t Format 2 - High-byte mapping through table\n");
	    ttfPrintCMAP2(fp,ptable);
	    break;
	case 4:
	    fprintf(fp,"\t\t Format 4 - Segment mapping to delta values\n");
	    ttfPrintCMAP4(fp,ptable);
	    break;
	case 6:
	    fprintf(fp,"\t\t Format 6 - Trimmed table mapping\n");
	    ttfPrintCMAP6(fp,ptable);
	    break;
	default:
	    ttfError("Unrecognized CMAP format\n");
	}
}
示例#8
0
static void ttfLoadCMAP0(FILE *fp,SubTablePtr subTable,ULONG offset)
{
    BYTE * array;
    
    subTable->map.cmap0 = ttfAllocCMAP0(subTable);
    array = subTable->map.cmap0->glyphIndexArray; 

    if (fseek(fp,offset,SEEK_SET) != 0)
	ttfError("Fseek Failed in ttfLoadCMAP0 \n");

    /* Attention: we get lots of bytes at once as a work around of the
     * usual ttfGet*, this cause byte sex trouble as will be seen
     * in the fellowing procedures */
    if (fread(array,sizeof(BYTE),256,fp) != 256)
	ttfError("Error when getting glyphIndexArray \n");
}
示例#9
0
void ttfInitStack(TTFontPtr font)
{
    font->vm.sp = 0;
    font->vm.Stack = (LONG *) calloc (font->maxp->maxStackElements, sizeof(LONG));
    if (font->vm.Stack == NULL)
	ttfError("Out of memory\n");
}
示例#10
0
/* actually, EncodingTable is a part of SubTable */
static void ttfLoadEncodingTable(FILE *fp,SubTablePtr subTable,ULONG offset)
{
    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadEncodingTable \n");
    
    subTable->PlatformID = ttfGetUSHORT(fp);
    subTable->EncodingID = ttfGetUSHORT(fp);
    subTable->offset = ttfGetULONG(fp);
}
示例#11
0
static CMAPPtr ttfAllocCMAP(TTFontPtr font)
{
    CMAPPtr cmap;
    if ((cmap = (CMAPPtr) calloc(1,sizeof(CMAP))) == NULL)
	{
	    ttfError("Out Of Memory in  __FILE_ : __LINE__ \n");
	    return NULL;
	}
    return cmap;
}
示例#12
0
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
}
示例#13
0
static NAMEPtr ttfAllocNAME(TTFontPtr font)
{
    NAMEPtr name;

    if((name = (NAMEPtr) calloc(1,sizeof(NAME))) == NULL)
	{
	    ttfError("Out of Memory in __FILE__:__LINE__\n");
	    return NULL;
	}
    return name;
}
示例#14
0
static KERNPtr ttfAllocKERN(TTFontPtr font)
{
    KERNPtr kern;
    
    if ((kern = (KERNPtr) calloc(1,sizeof(KERN))) == NULL)
	{
	    ttfError("Out of Memory in __FILE__:__LINE__\n");
	    return NULL;
	}
    return kern;
}
示例#15
0
static CMAP0 * ttfAllocCMAP0(SubTablePtr subTable)
{
    CMAP0 * cmap0;
  
    if ((cmap0 = (CMAP0 *) calloc(1,sizeof(CMAP0))) == NULL)
	{
	    ttfError("Out Of Memory in  __FILE__ : __LINE__ \n");
	    return NULL;
	}
    return cmap0;
}
示例#16
0
static SubTablePtr ttfAllocSubTable(CMAPPtr cmap)
{
    SubTablePtr subTable;
    
    if ((subTable = (SubTablePtr) calloc(cmap->numberOfEncodings,sizeof(SubTable))) == NULL)
	{
	    ttfError("Out Of Memory in  __FILE__ : __LINE__ \n");
	    return NULL;
	}
    return subTable;
}
示例#17
0
/* offset: address of the beginning of the name record */
static void ttfLoadNameRecord(FILE *fp,NameRecordPtr rec,ULONG offset)
{
    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadNameRecord \n");

    rec->PlatformID = ttfGetUSHORT(fp);
    rec->EncodingID = ttfGetUSHORT(fp);
    rec->LanguageID = ttfGetUSHORT(fp);
    rec->NameID = ttfGetUSHORT(fp);
    rec->length = ttfGetUSHORT(fp);
    rec->offset = ttfGetUSHORT(fp);
}
示例#18
0
static void ttfLoadKERN (FILE *fp,KERNPtr kern,ULONG offset)
{
    int i;

    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadKERN \n");	
    
    kern->version = ttfGetUSHORT(fp);
    kern->nTables = ttfGetUSHORT(fp);

    kern->subtable = (KernSubtable *) calloc(kern->nTables,
						 sizeof(KernSubtable));

    for (i=0;i<kern->nTables;i++)
	{
	    struct kernpair *pairs;
	    int j,n;
	    (kern->subtable+i)->version = ttfGetUSHORT(fp);
	    (kern->subtable+i)->length = ttfGetUSHORT(fp);
	    (kern->subtable+i)->coverage = ttfGetUSHORT(fp);

	    switch ((kern->subtable+i)->coverage >> 8)
		{
		case 0:
		    (kern->subtable+i)->kern.kern0.nPairs = n = 
			ttfGetUSHORT(fp);
		    (kern->subtable+i)->kern.kern0.searchRange =
			ttfGetUSHORT(fp);
		    (kern->subtable+i)->kern.kern0.entrySelector =
			ttfGetUSHORT(fp);
		    (kern->subtable+i)->kern.kern0.rangeShift =
			ttfGetUSHORT(fp);
		    (kern->subtable+i)->kern.kern0.pairs = pairs =
			(struct kernpair *) calloc(n,sizeof (struct kernpair));

		    for (j=0;j<n;j++)
			{
			    (pairs+j)->left = ttfGetUSHORT(fp);
			    (pairs+j)->right = ttfGetUSHORT(fp);
			    (pairs+j)->value = ttfGetFWord(fp);
			}
		    break;
		case 2:
		    /* not implemented yet */
		    break;
		default:
		    /* do nothing */
		    break;
		}
	}
}
示例#19
0
static void ttfLoadNAME(FILE *fp,NAMEPtr name,ULONG offset)
{
    USHORT i,n;
    ULONG pos;

    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLOADNAME \n");	

    name->format = ttfGetUSHORT(fp);
    name->numberOfRecords = n = ttfGetUSHORT(fp);
    name->offset = ttfGetUSHORT(fp);

    if ((name->NameRecords = (NameRecordPtr) calloc(n,sizeof(NameRecord))) == NULL)
	ttfError("Out Of Memory\n");

    pos = offset + sizeof(USHORT)*3;

    for(i=0;i<n;i++,pos+=12 /*sizeof(NameRecord)*/)
	{
	    ttfLoadNameRecord(fp,name->NameRecords+i,pos);
	    ttfLoadNameRecordData(fp,name->NameRecords+i,offset+name->offset);
	}
}
示例#20
0
/* should this one be static ? */
static void ttfLoadSubTable(FILE *fp,SubTablePtr subTable,ULONG base)
{
    ULONG pos;
    USHORT format;

    /* seek to the actuall position for this subtable
     * base: beginning of cmap
     * offset: offset field of each encoding table */
    pos =  base  +  subTable->offset;
    if (fseek(fp,pos,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLoadSubTable\n");

    subTable->format = format = ttfGetUSHORT(fp); 
    subTable->length = ttfGetUSHORT(fp);
    subTable->version = ttfGetUSHORT(fp);
   
    pos += 6;/* step over format independent data,USHORT*3 */

    switch(format)
	{
	case 0:
	    ttfLoadCMAP0(fp,subTable,pos);
	    break;
	case 2:
	    ttfLoadCMAP2(fp,subTable,pos);
	    break;
	case 4:
	    ttfLoadCMAP4(fp,subTable,pos);
	    break;
	case 6:
	    ttfLoadCMAP6(fp,subTable,pos);
	    break;
	default:
	    ttfError("Unrecognized CMAP format\n");
	}
}
示例#21
0
static void ttfLoadCMAP(FILE *fp,CMAPPtr cmap,ULONG offset)
{
    USHORT i,n;
    ULONG posEnc;            /* beginning of the Encoding Table */
    ULONG baseSub = offset;  /* base of SubTable offset */

    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLOADCMAP \n");	

    cmap->version = ttfGetUSHORT(fp);
    cmap->numberOfEncodings = n = ttfGetUSHORT(fp);
    cmap->subTables = ttfAllocSubTable(cmap);

    posEnc = baseSub + sizeof(USHORT)*2; /* step over the beginning of encoding
					  * table */
    
    /* for each encoding scheme, load the encoding table (EncodingTable) and 
     * the real cmap data (SubTable) */
    for (i=0;i<n;i++,posEnc += 8)
	{   /* 8 == ushort*2 + ulong*1 */
	    ttfLoadEncodingTable(fp,cmap->subTables+i,posEnc);
	    ttfLoadSubTable(fp,cmap->subTables+i,baseSub);
	}
}
示例#22
0
USHORT ttfLookUpCMAP(SubTablePtr subTable,USHORT cc)
{
    USHORT idx,format = subTable->format;

    switch (format)
	{
	case 0:
	    idx = ttfLookUpCMAP0(subTable,cc);
	    break;
	case 2:
	    idx = ttfLookUpCMAP2(subTable,cc);
	    break;
	case 4:
	    idx = ttfLookUpCMAP4(subTable,cc);
	    break;
	case 6:
	    idx = ttfLookUpCMAP6(subTable,cc);
	    break;
	default:
	    ttfError("Unrecognized CMAP format\n");
	    return 0;
	}
    return idx;
}
示例#23
0
void ttfInitStorageArea(TTFontPtr font)
{
    font->vm.StorageArea = (LONG *) calloc (font->maxp->maxStorage, sizeof(LONG));
    if (font->vm.StorageArea == NULL)
	ttfError("Out of memory\n");
}
示例#24
0
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
}