Debian Codegraph @

texk/ttfdump/libttf/vmtx.c

raw
1 /* vmtx.c -- Vertical 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: vmtx.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */
14
15 static void ttfLoadVMTX(FILE *fp,VMTXPtr vmtx,ULONG offset);
16
17 /* Caution: Because of interdependency between tables,
18 * table vhea and maxp should be well initalized before
19 * ttfInitVMTX has been called
20 */
21 void ttfInitVMTX(TTFontPtr font)
22 {
23 ULONG tag = FT_MAKE_TAG ('v', 'm', 't', 'x');
24 TableDirPtr ptd;
25
26 if ((ptd = ttfLookUpTableDir(tag,font)) != NULL)
27 {
28 font->vmtx = XCALLOC1 (VMTX);
29 font->vmtx->numOfLongVerMetrics =
30 font->vhea->numOfLongVerMetrics;
31 font->vmtx->numOfTSB = font->maxp->numGlyphs -
32 font->vhea->numOfLongVerMetrics;
33 ttfLoadVMTX(font->fp,font->vmtx,ptd->offset);
34 }
35 }
36
37 static void ttfLoadVMTX(FILE *fp,VMTXPtr vmtx,ULONG offset)
38 {
39 USHORT i,n = vmtx->numOfLongVerMetrics,m=vmtx->numOfTSB;
40
41 xfseek(fp, offset, SEEK_SET, "ttfLoadVMTX");
42
43 vmtx->vMetrics = XCALLOC (n, longVerMetric);
44 for (i=0;i<n;i++)
45 {
46 (vmtx->vMetrics+i)->advanceHeight = ttfGetuFWord(fp);
47 (vmtx->vMetrics+i)->topSideBearing = ttfGetFWord(fp);
48 }
49
50 /* codes dealing with topSideBearing entry */
51 if (m)
52 {
53 vmtx->topSideBearing = XCALLOC (m, FWord);
54 for (i=0;i<m;i++)
55 {
56 (vmtx->topSideBearing)[i] = ttfGetFWord(fp);
57 }
58 }
59 }
60
61 void ttfPrintVMTX(FILE *fp,VMTXPtr vmtx)
62 {
63 int i;
64
65 fprintf(fp,"'vmtx' Table - Vertical Metrics\n");
66 fprintf(fp,"---------------------------------\n");
67
68 for (i=0;i<vmtx->numOfLongVerMetrics;i++)
69 {
70 fprintf(fp,"\t %4d. advWid: %4d, TSBear: %4d\n",i,
71 (vmtx->vMetrics+i)->advanceHeight,
72 (vmtx->vMetrics+i)->topSideBearing);
73 }
74
75 for (i=0;i<vmtx->numOfTSB;i++)
76 {
77 fprintf(fp,"\t %4d. TSBear: %4d\n",i+vmtx->numOfLongVerMetrics,
78 (vmtx->topSideBearing)[i]);
79 }
80 }
81
82 void ttfFreeVMTX(VMTXPtr vmtx)
83 {
84 if (vmtx != NULL)
85 {
86 free(vmtx->vMetrics);
87
88 if (vmtx->numOfTSB)
89 free(vmtx->topSideBearing);
90
91 free(vmtx);
92 }
93 }