| 1 |
/* hmtx.c -- Horizontal Metrics Table |
| 2 |
* Copyright (C) 1997 Li-Da Lho, All right reserved |
| 3 |
*/ |
| 4 |
#ifdef HAVE_CONFIG_H |
| 5 |
#include <config.h> |
| 6 |
#endif |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include "ttf.h" |
| 11 |
#include "ttfutil.h" |
| 12 |
|
| 13 |
/* $Id: hmtx.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */ |
| 14 |
|
| 15 |
static void ttfLoadHMTX(FILE *fp,HMTXPtr hmtx,ULONG offset); |
| 16 |
|
| 17 |
/* Caution: Because of interdependency between tables, |
| 18 |
* table hhea and maxp should be well initalized before |
| 19 |
* ttfInitHMTX is been called |
| 20 |
*/ |
| 21 |
void ttfInitHMTX(TTFontPtr font) |
| 22 |
{ |
| 23 |
ULONG tag = FT_MAKE_TAG ('h', 'm', 't', 'x'); |
| 24 |
TableDirPtr ptd; |
| 25 |
|
| 26 |
if ((ptd = ttfLookUpTableDir(tag,font)) != NULL) |
| 27 |
{ |
| 28 |
font->hmtx = XCALLOC1 (HMTX); |
| 29 |
font->hmtx->numberOfHMetrics = font->hhea->numberOfHMetrics; |
| 30 |
font->hmtx->numberOfLSB = font->maxp->numGlyphs - |
| 31 |
font->hhea->numberOfHMetrics; |
| 32 |
ttfLoadHMTX(font->fp,font->hmtx,ptd->offset); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
static void ttfLoadHMTX(FILE *fp,HMTXPtr hmtx,ULONG offset) |
| 37 |
{ |
| 38 |
USHORT i,n = hmtx->numberOfHMetrics,m=hmtx->numberOfLSB; |
| 39 |
|
| 40 |
xfseek(fp, offset, SEEK_SET, "ttfLoadHMTX"); |
| 41 |
|
| 42 |
hmtx->hMetrics = XCALLOC (n, longHorMetric); |
| 43 |
for (i=0;i<n;i++) |
| 44 |
{ |
| 45 |
(hmtx->hMetrics+i)->advanceWidth = ttfGetuFWord(fp); |
| 46 |
(hmtx->hMetrics+i)->lsb = ttfGetFWord(fp); |
| 47 |
} |
| 48 |
|
| 49 |
/* codes dealing with leftSideBearing entry */ |
| 50 |
if (m) |
| 51 |
{ |
| 52 |
hmtx->leftSideBearing = XCALLOC (m, FWord); |
| 53 |
for (i=0;i<m;i++) |
| 54 |
{ |
| 55 |
(hmtx->leftSideBearing)[i] = ttfGetFWord(fp); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void ttfPrintHMTX(FILE *fp,HMTXPtr hmtx) |
| 61 |
{ |
| 62 |
int i; |
| 63 |
|
| 64 |
fprintf(fp,"'hmtx' Table - Horizontal Metrics\n"); |
| 65 |
fprintf(fp,"---------------------------------\n"); |
| 66 |
|
| 67 |
for (i=0;i<hmtx->numberOfHMetrics;i++) |
| 68 |
{ |
| 69 |
fprintf(fp,"\t %4d. advWid: %4d, LSBear: %4d\n",i, |
| 70 |
(hmtx->hMetrics+i)->advanceWidth, |
| 71 |
(hmtx->hMetrics+i)->lsb); |
| 72 |
} |
| 73 |
|
| 74 |
for (i=0;i<hmtx->numberOfLSB;i++) |
| 75 |
{ |
| 76 |
fprintf(fp,"\t %4d. LSbear: %4d\n",i+hmtx->numberOfHMetrics, |
| 77 |
(hmtx->leftSideBearing)[i]); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
void ttfFreeHMTX(HMTXPtr hmtx) |
| 82 |
{ |
| 83 |
free(hmtx->hMetrics); |
| 84 |
|
| 85 |
if (hmtx->numberOfLSB) |
| 86 |
free(hmtx->leftSideBearing); |
| 87 |
|
| 88 |
free(hmtx); |
| 89 |
} |