summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttfdump/libttf/ttfread.c
blob: 5947484e00b7f2517178df17dd198fe7b8f42485 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* ttfread.c
 * read data element form ttf file
 * swap byte order carefully for MSBFirst
 * presume that int is 32 bits
 */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>

#if defined(__GNUC__) && defined(_IBMR2)
/* Workaround for missing typedef in gcc (egcs-2.90.27 980315 (egcs-1.0.2 release)) */
typedef long		blkcnt_t;	/* number of blocks in the file */
#endif

#include "ttf.h"
#include "ttfutil.h"

/* 	$Id: ttfread.c,v 1.2 1998/07/04 13:17:51 werner Exp $	 */

BYTE ttfGetBYTE(FILE *fp)
{
    int cc;
    if ((cc = fgetc(fp)) == EOF)
	{
	    if (feof(fp) != 0)
		ttfError("Unexpected EOF\n");
	    else
		ttfError("Error Getting BYTE\n");
	}
    return (BYTE) cc;
}

CHAR ttfGetCHAR(FILE *fp)
{
    int cc;
    if ((cc = fgetc(fp)) == EOF)
	{
	    if (feof(fp) != 0)
		ttfError("Unexpected EOF\n");
	    else
		ttfError("Error Getting CHAR\n");
	}
    return (CHAR) cc;
}

USHORT ttfGetUSHORT(FILE *fp)
{
    int cc;
    cc = ttfGetBYTE(fp) << 8;
    cc |= ttfGetBYTE(fp);
    
    return (USHORT) cc;
}

SHORT ttfGetSHORT(FILE *fp)
{
    int cc;
    cc = ttfGetBYTE(fp) << 8;
    cc |= ttfGetBYTE(fp);
    
    return (SHORT) cc;
}

ULONG ttfGetULONG(FILE *fp)
{
    int cc;
    cc = ttfGetBYTE(fp) << 24;
    cc |= ttfGetBYTE(fp) << 16;
    cc |= ttfGetBYTE(fp) << 8;
    cc |= ttfGetBYTE(fp);

    return (ULONG) cc;
}

LONG ttfGetLONG(FILE *fp)
{
    int cc;
    cc = ttfGetBYTE(fp) << 24;
    cc |= ttfGetBYTE(fp) << 16;
    cc |= ttfGetBYTE(fp) << 8;
    cc |= ttfGetBYTE(fp);

    return (LONG) cc;
}

Fixed ttfGetFixed(FILE *fp)
{
    return (Fixed) ttfGetULONG(fp);
}

FUnit ttfGetFUnit(FILE *fp)
{
    return (FUnit) ttfGetUSHORT(fp);
}

FWord ttfGetFWord(FILE *fp)
{
    return (FWord) ttfGetSHORT(fp);
}

uFWord ttfGetuFWord(FILE *fp)
{
    return (uFWord) ttfGetUSHORT(fp);
}

F2Dot14 ttfGetF2Dot14(FILE *fp)
{
    return (F2Dot14) ttfGetUSHORT(fp);
}

/* Read arrays.  */
void ttfReadUSHORT(USHORT *array, size_t nelem, FILE *fp)
{
    int i;
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetUSHORT (fp);
}

void ttfReadULONG(ULONG *array, size_t nelem, FILE *fp)
{
    int i;
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetULONG (fp);
}

void ttfReadFWord(FWord *array, size_t nelem, FILE *fp)
{
    int i;
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetFWord (fp);
}

/* Allocate and read arrays.  */
BYTE *ttfMakeBYTE(size_t nelem, FILE *fp)
{
    int i;
    BYTE *array = XTALLOC (nelem, BYTE);
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetBYTE (fp);
    return array;
}

USHORT *ttfMakeUSHORT(size_t nelem, FILE *fp)
{
    int i;
    USHORT *array = XTALLOC (nelem, USHORT);
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetUSHORT (fp);
    return array;
}

SHORT *ttfMakeSHORT(size_t nelem, FILE *fp)
{
    int i;
    SHORT *array = XTALLOC (nelem, SHORT);
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetSHORT (fp);
    return array;
}

ULONG *ttfMakeULONG(size_t nelem, FILE *fp)
{
    int i;
    ULONG *array = XTALLOC (nelem, ULONG);
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetULONG (fp);
    return array;
}

LONG *ttfMakeLONG(size_t nelem, FILE *fp)
{
    int i;
    LONG *array = XTALLOC (nelem, LONG);
    for (i = 0; i < nelem; i++)
        array[i] = ttfGetLONG (fp);
    return array;
}