Debian Codegraph @

texk/ttfdump/libttf/ttfread.c

raw
1 /* ttfread.c
2 * read data element form ttf file
3 * swap byte order carefully for MSBFirst
4 * presume that int is 32 bits
5 */
6 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9
10 #include <stdio.h>
11
12 #if defined(__GNUC__) && defined(_IBMR2)
13 /* Workaround for missing typedef in gcc (egcs-2.90.27 980315 (egcs-1.0.2 release)) */
14 typedef long blkcnt_t; /* number of blocks in the file */
15 #endif
16
17 #include "ttf.h"
18 #include "ttfutil.h"
19
20 /* $Id: ttfread.c,v 1.2 1998/07/04 13:17:51 werner Exp $ */
21
22 BYTE ttfGetBYTE(FILE *fp)
23 {
24 int cc;
25 if ((cc = fgetc(fp)) == EOF)
26 {
27 if (feof(fp) != 0)
28 ttfError("Unexpected EOF\n");
29 else
30 ttfError("Error Getting BYTE\n");
31 }
32 return (BYTE) cc;
33 }
34
35 CHAR ttfGetCHAR(FILE *fp)
36 {
37 int cc;
38 if ((cc = fgetc(fp)) == EOF)
39 {
40 if (feof(fp) != 0)
41 ttfError("Unexpected EOF\n");
42 else
43 ttfError("Error Getting CHAR\n");
44 }
45 return (CHAR) cc;
46 }
47
48 USHORT ttfGetUSHORT(FILE *fp)
49 {
50 int cc;
51 cc = ttfGetBYTE(fp) << 8;
52 cc |= ttfGetBYTE(fp);
53
54 return (USHORT) cc;
55 }
56
57 SHORT ttfGetSHORT(FILE *fp)
58 {
59 int cc;
60 cc = ttfGetBYTE(fp) << 8;
61 cc |= ttfGetBYTE(fp);
62
63 return (SHORT) cc;
64 }
65
66 ULONG ttfGetULONG(FILE *fp)
67 {
68 int cc;
69 cc = ttfGetBYTE(fp) << 24;
70 cc |= ttfGetBYTE(fp) << 16;
71 cc |= ttfGetBYTE(fp) << 8;
72 cc |= ttfGetBYTE(fp);
73
74 return (ULONG) cc;
75 }
76
77 LONG ttfGetLONG(FILE *fp)
78 {
79 int cc;
80 cc = ttfGetBYTE(fp) << 24;
81 cc |= ttfGetBYTE(fp) << 16;
82 cc |= ttfGetBYTE(fp) << 8;
83 cc |= ttfGetBYTE(fp);
84
85 return (LONG) cc;
86 }
87
88 Fixed ttfGetFixed(FILE *fp)
89 {
90 return (Fixed) ttfGetULONG(fp);
91 }
92
93 FUnit ttfGetFUnit(FILE *fp)
94 {
95 return (FUnit) ttfGetUSHORT(fp);
96 }
97
98 FWord ttfGetFWord(FILE *fp)
99 {
100 return (FWord) ttfGetSHORT(fp);
101 }
102
103 uFWord ttfGetuFWord(FILE *fp)
104 {
105 return (uFWord) ttfGetUSHORT(fp);
106 }
107
108 F2Dot14 ttfGetF2Dot14(FILE *fp)
109 {
110 return (F2Dot14) ttfGetUSHORT(fp);
111 }
112
113 /* Read arrays. */
114 void ttfReadUSHORT(USHORT *array, size_t nelem, FILE *fp)
115 {
116 int i;
117 for (i = 0; i < nelem; i++)
118 array[i] = ttfGetUSHORT (fp);
119 }
120
121 void ttfReadULONG(ULONG *array, size_t nelem, FILE *fp)
122 {
123 int i;
124 for (i = 0; i < nelem; i++)
125 array[i] = ttfGetULONG (fp);
126 }
127
128 void ttfReadFWord(FWord *array, size_t nelem, FILE *fp)
129 {
130 int i;
131 for (i = 0; i < nelem; i++)
132 array[i] = ttfGetFWord (fp);
133 }
134
135 /* Allocate and read arrays. */
136 BYTE *ttfMakeBYTE(size_t nelem, FILE *fp)
137 {
138 int i;
139 BYTE *array = XTALLOC (nelem, BYTE);
140 for (i = 0; i < nelem; i++)
141 array[i] = ttfGetBYTE (fp);
142 return array;
143 }
144
145 USHORT *ttfMakeUSHORT(size_t nelem, FILE *fp)
146 {
147 int i;
148 USHORT *array = XTALLOC (nelem, USHORT);
149 for (i = 0; i < nelem; i++)
150 array[i] = ttfGetUSHORT (fp);
151 return array;
152 }
153
154 SHORT *ttfMakeSHORT(size_t nelem, FILE *fp)
155 {
156 int i;
157 SHORT *array = XTALLOC (nelem, SHORT);
158 for (i = 0; i < nelem; i++)
159 array[i] = ttfGetSHORT (fp);
160 return array;
161 }
162
163 ULONG *ttfMakeULONG(size_t nelem, FILE *fp)
164 {
165 int i;
166 ULONG *array = XTALLOC (nelem, ULONG);
167 for (i = 0; i < nelem; i++)
168 array[i] = ttfGetULONG (fp);
169 return array;
170 }
171
172 LONG *ttfMakeLONG(size_t nelem, FILE *fp)
173 {
174 int i;
175 LONG *array = XTALLOC (nelem, LONG);
176 for (i = 0; i < nelem; i++)
177 array[i] = ttfGetLONG (fp);
178 return array;
179 }
180