| 1 |
#ifdef HAVE_CONFIG_H |
| 2 |
#include <config.h> |
| 3 |
#endif |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include "ttf.h" |
| 8 |
#include "ttfutil.h" |
| 9 |
|
| 10 |
/* $Id: loca.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */ |
| 11 |
|
| 12 |
static LOCAPtr ttfAllocLOCA(TTFontPtr font); |
| 13 |
static void ttfLoadLOCA(FILE *fp,LOCAPtr loca,ULONG offset); |
| 14 |
|
| 15 |
void ttfInitLOCA(TTFontPtr font) |
| 16 |
{ |
| 17 |
ULONG tag = FT_MAKE_TAG ('l', 'o', 'c', 'a'); |
| 18 |
TableDirPtr ptd; |
| 19 |
|
| 20 |
if ((ptd = ttfLookUpTableDir(tag,font)) != NULL) |
| 21 |
{ |
| 22 |
font->loca = (LOCAPtr) ttfAllocLOCA(font); |
| 23 |
ttfLoadLOCA(font->fp,font->loca,ptd->offset); |
| 24 |
} |
| 25 |
} |
| 26 |
static LOCAPtr ttfAllocLOCA(TTFontPtr font) |
| 27 |
{ |
| 28 |
USHORT n=0; |
| 29 |
LOCAPtr loca; |
| 30 |
|
| 31 |
loca = XCALLOC1 (LOCA); |
| 32 |
loca->indexToLocFormat = font->head->indexToLocFormat; |
| 33 |
loca->numGlyphs = n = font->maxp->numGlyphs; |
| 34 |
|
| 35 |
n += 1;/* the number of loca entry is numberOfGlyph+1 */ |
| 36 |
loca->offset = XCALLOC (n, ULONG); |
| 37 |
|
| 38 |
return loca; |
| 39 |
} |
| 40 |
static void ttfLoadLOCA(FILE *fp,LOCAPtr loca,ULONG offset) |
| 41 |
{ |
| 42 |
/* warning: the number of loca entry is numberOfGlyph+1 !! */ |
| 43 |
USHORT i,n = loca->numGlyphs+1; |
| 44 |
|
| 45 |
xfseek(fp, offset, SEEK_SET, "ttfLoadLOCA"); |
| 46 |
|
| 47 |
switch (loca->indexToLocFormat) |
| 48 |
{ |
| 49 |
case LOCA_OFFSET_SHORT: |
| 50 |
for (i=0;i<n;i++) |
| 51 |
{ |
| 52 |
(loca->offset)[i] = (ULONG) ttfGetUSHORT(fp)*2; |
| 53 |
} |
| 54 |
break; |
| 55 |
case LOCA_OFFSET_LONG: |
| 56 |
ttfReadULONG (loca->offset, n, fp); |
| 57 |
break; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void ttfPrintLOCA(FILE *fp,LOCAPtr loca) |
| 62 |
{ |
| 63 |
USHORT i; |
| 64 |
|
| 65 |
if (loca) |
| 66 |
{ |
| 67 |
fprintf(fp,"'loca' Table - Index to Location\n"); |
| 68 |
fprintf(fp,"--------------------------------\n"); |
| 69 |
for (i=0;i<loca->numGlyphs;i++) |
| 70 |
{ |
| 71 |
fprintf(fp,"\t Idx %6d -> GlyphOffset 0x%08x\n",i, |
| 72 |
(loca->offset)[i]); |
| 73 |
} |
| 74 |
fprintf (fp,"\t Ended at 0x%08x\n",(loca->offset)[loca->numGlyphs]); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
void ttfFreeLOCA(LOCAPtr loca) |
| 79 |
{ |
| 80 |
if (loca) |
| 81 |
{ |
| 82 |
free (loca->offset); |
| 83 |
free (loca); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
ULONG ttfLookUpGlyfLOCA(LOCAPtr loca,USHORT idx) |
| 88 |
{ |
| 89 |
/* out of bound or it is a non-glyph character */ |
| 90 |
if (idx >= loca->numGlyphs || |
| 91 |
loca->offset[idx] == loca->offset[idx+1]) |
| 92 |
return (loca->offset)[0]; |
| 93 |
|
| 94 |
return (loca->offset)[idx]; |
| 95 |
} |