summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttfdump/libttf/vmtx.c
blob: 990f824a66adf6ca9fa7b7f4f384e477897909c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* vmtx.c -- Vertical Metrics Table
 * Copyright (C) 1997 Li-Da Lho, All right reserved 
 */
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "ttf.h"
#include "ttfutil.h"

#ifdef MEMCHECK
#include <dmalloc.h>
#endif

/* 	$Id: vmtx.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $	 */

#ifndef lint
static char vcid[] = "$Id: vmtx.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $";
#endif /* lint */

static VMTXPtr ttfAllocVMTX(TTFontPtr font);
static void ttfLoadVMTX(FILE *fp,VMTXPtr vmtx,ULONG offset);

/* Caution: Because of interdependency between tables, 
 * table vhea and maxp should be well initalized before
 * ttfInitVMTX has been called
 */
void ttfInitVMTX(TTFontPtr font)
{
    ULONG tag = 'v' | 'm' << 8 | 't' << 16 | 'x' << 24;
    TableDirPtr ptd;
    
    if ((ptd = ttfLookUpTableDir(tag,font)) != NULL) 
	{
	    font->vmtx = ttfAllocVMTX(font);
	    font->vmtx->numOfLongVerMetrics = 
		font->vhea->numOfLongVerMetrics;
	    font->vmtx->numOfTSB = font->maxp->numGlyphs - 
		font->vhea->numOfLongVerMetrics; 
	    ttfLoadVMTX(font->fp,font->vmtx,ptd->offset);
	}
}
static VMTXPtr ttfAllocVMTX(TTFontPtr font)
{
    VMTXPtr vmtx;

    if ((vmtx = (VMTXPtr) calloc(1,sizeof(VMTX))) == NULL)
	{
	    ttfError("Out of Memory in __FILE__:__LINE__\n");
	    return NULL;
	}
    return vmtx;
}
static void ttfLoadVMTX(FILE *fp,VMTXPtr vmtx,ULONG offset)
{
    USHORT i,n = vmtx->numOfLongVerMetrics,m=vmtx->numOfTSB;

    if (fseek(fp,offset,SEEK_SET) !=0)
	ttfError("Fseek Failed in ttfLOADVMTX \n");
    
    if ((vmtx->vMetrics = (longVerMetric *) calloc(n,sizeof(longVerMetric))) != NULL)
	{
	    for (i=0;i<n;i++)
		{
		    (vmtx->vMetrics+i)->advanceHeight = ttfGetuFWord(fp);
		    (vmtx->vMetrics+i)->topSideBearing = ttfGetFWord(fp);
		}
	}
    else
	{
	    ttfError("Out Of Memory in __FILE__ : __LINE__\n"); 
	}

    /* codes dealing with leftSideBearing entry */
    if (m && ((vmtx->topSideBearing = (FWord *) calloc(m,sizeof(FWord))) != NULL))
	{
	    for (i=0;i<m;i++)
		{
		    (vmtx->topSideBearing)[i] = ttfGetFWord(fp);
		}
	}
}

void ttfPrintVMTX(FILE *fp,VMTXPtr vmtx)
{
    int i;
    
    fprintf(fp,"'vmtx' Table - Vertical Metrics\n");
    fprintf(fp,"---------------------------------\n");
    
    for (i=0;i<vmtx->numOfLongVerMetrics;i++)
	{
	    fprintf(fp,"\t %4d. advWid: %4d, TSBear: %4d\n",i,
		    (vmtx->vMetrics+i)->advanceHeight,
		    (vmtx->vMetrics+i)->topSideBearing);
	}

    for (i=0;i<vmtx->numOfTSB;i++)
	{
	    fprintf(fp,"\t %4d. TSBear: %4d\n",i+vmtx->numOfLongVerMetrics,
		    (vmtx->topSideBearing)[i]);
	}
}

void ttfFreeVMTX(VMTXPtr vmtx)
{
    if (vmtx != NULL)
	{
	    free(vmtx->vMetrics);

	    if (vmtx->numOfTSB)
		free(vmtx->topSideBearing);

	    free(vmtx);
	}
}