summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttfdump/libttf/vdmx.c
blob: ad5629acfe79451b63eab7f188238209cab29190 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* vdmx.c -- Vertical Device Metrics
 * Copyright (C) 1996 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: vdmx.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $	 */

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

static VDMXPtr ttfAllocVDMX(TTFontPtr font);
static void ttfLoadVDMX(FILE *fp,VDMXPtr vdmx,ULONG offset);

void ttfInitVDMX(TTFontPtr font)
{
    ULONG tag = 'V' | 'D' << 8 | 'M' << 16 | 'X' << 24;
    TableDirPtr ptd;
     
    if ((ptd = ttfLookUpTableDir(tag,font)) != NULL)
	{
	    font->vdmx = ttfAllocVDMX(font);
	    ttfLoadVDMX(font->fp,font->vdmx,ptd->offset);
	}
}
static VDMXPtr ttfAllocVDMX(TTFontPtr font)
{
    VDMXPtr vdmx;
    
    if ((vdmx = (VDMXPtr) calloc(1,sizeof(VDMX))) == NULL)
	{
	    ttfError("Out of Memory in __FILE__:__LINE__\n");
	    return NULL;
	}
    return vdmx;
}
static void ttfLoadVDMX (FILE *fp,VDMXPtr vdmx,ULONG offset)
{
    int i;

    if (fseek(fp,offset,SEEK_SET) != 0)
	ttfError("Fseek Failed in ttfLoadVDMX \n");	
    
    vdmx->version = ttfGetUSHORT(fp);
    vdmx->numRecs = ttfGetUSHORT(fp);
    vdmx->numRatios = ttfGetUSHORT(fp);
    vdmx->ratRange = (Ratios *) calloc(vdmx->numRatios, sizeof(Ratios));
    vdmx->offset = (USHORT *) calloc(vdmx->numRatios, sizeof(USHORT));
    vdmx->groups = (Vdmx *) calloc(vdmx->numRecs, sizeof(Vdmx));

    for (i=0;i<vdmx->numRatios;i++)
	{
	    (vdmx->ratRange+i)->CharSet = ttfGetBYTE(fp);
	    (vdmx->ratRange+i)->xRatio = ttfGetBYTE(fp);
	    (vdmx->ratRange+i)->yStartRatio = ttfGetBYTE(fp);
	    (vdmx->ratRange+i)->yEndRatio = ttfGetBYTE(fp);
	    
	}
    if (fread(vdmx->offset, sizeof(USHORT), vdmx->numRatios,fp) != 
	vdmx->numRatios)
	ttfError("Error when getting Offset\n");
#ifndef WORDS_BIGENDIAN
    TwoByteSwap((unsigned char *) vdmx->offset,
		vdmx->numRatios*sizeof(USHORT));
#endif

    for (i=0;i<vdmx->numRecs;i++)
	{
	    int j;
	    (vdmx->groups+i)->recs = ttfGetUSHORT(fp);
	    (vdmx->groups+i)->startsz = ttfGetBYTE(fp);
	    (vdmx->groups+i)->endsz = ttfGetBYTE(fp);
    
	    (vdmx->groups+i)->entry = 
		(vTable *) calloc((vdmx->groups+i)->recs, sizeof(vTable));

	    for (j=0;j<(vdmx->groups+i)->recs;j++)
		{
		    ((vdmx->groups+i)->entry+j)->yPelHeight = ttfGetUSHORT(fp);
		    ((vdmx->groups+i)->entry+j)->yMax = ttfGetSHORT(fp);
		    ((vdmx->groups+i)->entry+j)->yMin = ttfGetSHORT(fp);
		}
	}
}

void ttfPrintVDMX(FILE *fp,VDMXPtr vdmx)
{
    int i;

    fprintf(fp,"'VDMX' Table - Precomputed Vertical Device Metrics\n");
    fprintf(fp,"--------------------------------------------------\n");


    fprintf(fp,"Version:\t %d\n", vdmx->version);
    fprintf(fp,"Number of Hgt Records:\t %d\n",vdmx->numRecs);
    fprintf(fp,"Number of Ratio Records:\t %d\n",vdmx->numRecs);

    for (i=0;i<vdmx->numRatios;i++)
	{ 
	    fprintf(fp,"\t Ratio Record #%d\n",i+1);
	    fprintf(fp,"\t\t CharSetId \t %d\n",(vdmx->ratRange+i)->CharSet);
	    fprintf(fp,"\t\t xRatio \t %d\n",(vdmx->ratRange+i)->xRatio);
	    fprintf(fp,"\t\t yStartRatio \t %d\n",(vdmx->ratRange+i)->yStartRatio);
	    fprintf(fp,"\t\t yEndRatio \t %d\n",(vdmx->ratRange+i)->yEndRatio);
	    fprintf(fp,"\t\t Record Offset %d (group #%d)\n\n",vdmx->offset[i],i);
	}
    
    fprintf(fp,"\t VDMX Height Record Groups\n");
    fprintf(fp,"\t -------------------------\n\n");

    for (i=0;i<vdmx->numRecs;i++)
	{
	    int j;
	    	    
	    fprintf(fp,"\t %d.  Number of Hgt Records %d\n",i,
		    (vdmx->groups+i)->recs);
	    fprintf(fp,"\t Starting Y Pel Height  %d\n",
		    (vdmx->groups+i)->startsz);
	    fprintf(fp,"\t Ending Y Pel Height %d\n",
		    (vdmx->groups+i)->endsz); 
    
	    for (j=0;j<(vdmx->groups+i)->recs;j++)
		{
		    fprintf(fp,"\t\t %d. Pel Height= %d\n",j+1,
			    ((vdmx->groups+i)->entry+j)->yPelHeight);
		    fprintf(fp,"\t\t yMax= \t %d\n",
			    ((vdmx->groups+i)->entry+j)->yMax);
		    fprintf(fp,"\t\t yMin= \t %d\n\n",
			    ((vdmx->groups+i)->entry+j)->yMin);		   
		}
	}

}

void ttfFreeVDMX(VDMXPtr vdmx)
{
    int i;
    if (vdmx != NULL)
	{
	    for (i=0;i<vdmx->numRecs;i++)
		{
		    free((vdmx->groups+i)->entry);
		}
	    free(vdmx->ratRange);
	    free(vdmx->offset);
	    free(vdmx->groups);
	    free(vdmx);
	}
}