-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcff_int.h
175 lines (164 loc) · 3.39 KB
/
cff_int.h
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
#ifndef _CFF_INT_H
#define _CFF_INT_H
#include <assert.h>
/*
CFF Data Types:
Card8 uint8_t
Card16 uint16_t
Offset uint32_t // TODO? int32?
OffSize uint8_t // 1-4
SID uint16_t // string id
*/
static inline uint8_t cff_read_Card8(const char **buf) // {{{
{
return *((*buf)++);
}
// }}}
static inline uint16_t cff_read_Card16(const char **buf) // {{{
{
const char *b=*buf;
uint16_t ret=((unsigned char)b[0]<<8)|((unsigned char)b[1]);
(*buf)+=2;
return ret;
}
// }}}
static inline uint32_t cff_read_Card24(const char **buf) // {{{
{
const char *b=*buf;
uint32_t ret=((unsigned char)b[0]<<16)|
((unsigned char)b[1]<<8)|
((unsigned char)b[2]);
(*buf)+=3;
return ret;
}
// }}}
static inline uint32_t cff_read_Card32(const char **buf) // {{{
{
const char *b=*buf;
uint32_t ret=((unsigned char)b[0]<<24)|
((unsigned char)b[1]<<16)|
((unsigned char)b[2]<<8)|
((unsigned char)b[3]);
(*buf)+=4;
return ret;
}
// }}}
static inline CFF_OffSize cff_read_OffSize(const char **buf) // {{{
{
uint8_t res=cff_read_Card8(buf);
if ( (res<1)||(res>4) ) {
return OFFERR;
}
return (CFF_OffSize)res;
}
// }}}
static inline uint32_t cff_read_Offset(const char **buf,CFF_OffSize offSize) // {{{
{
switch (offSize) {
case 1:
return cff_read_Card8(buf);
case 2:
return cff_read_Card16(buf);
case 3:
return cff_read_Card24(buf);
case 4:
return cff_read_Card32(buf);
default:
break;
}
assert(0);
return 0;
}
// }}}
static inline void cff_write_Card8(char **buf,uint8_t val) // {{{
{
*((*buf)++)=val;
}
// }}}
static inline void cff_write_Card16(char **buf,uint16_t val) // {{{
{
char *b=*buf;
b[0]=(val>>8)&0xff;
b[1]=val&0xff;
(*buf)+=2;
}
// }}}
static inline void cff_write_Card24(char **buf,uint32_t val) // {{{
{
char *b=*buf;
b[0]=(val>>16)&0xff;
b[1]=(val>>8)&0xff;
b[2]=val&0xff;
(*buf)+=3;
}
// }}}
static inline void cff_write_Card32(char **buf,uint32_t val) // {{{
{
char *b=*buf;
b[0]=val>>24;
b[1]=(val>>16)&0xff;
b[2]=(val>>8)&0xff;
b[3]=val&0xff;
(*buf)+=4;
}
// }}}
static inline void cff_write_OffSize(char **buf,CFF_OffSize val) // {{{
{
cff_write_Card8(buf,val);
}
// }}}
static inline void cff_write_Offset(char **buf,CFF_OffSize offSize,uint32_t val) // {{{
{
switch (offSize) {
case 1:
return cff_write_Card8(buf,val);
case 2:
return cff_write_Card16(buf,val);
case 3:
return cff_write_Card24(buf,val);
case 4:
return cff_write_Card32(buf,val);
default:
break;
}
assert(0);
}
// }}}
static inline const char *cff_index_get(struct CFF_Index *idx,int entry) // {{{
{
if ( (entry<0)||(entry>=idx->count) ) {
return NULL;
}
return idx->dataStart+idx->offset[entry]-1;
}
// }}}
static inline int cff_index_length(struct CFF_Index *idx,int entry) // {{{
{
if ( (entry<0)||(entry>=idx->count) ) {
return -1;
}
return idx->offset[entry+1]-idx->offset[entry];
}
// }}}
struct CFF_OPS; // from cff_tables.h
struct _CFF_VALUE {
enum {
CFF_VAL_ERROR,
CFF_VAL_OP,
CFF_VAL_INT,
CFF_VAL_REAL
} type;
union {
const struct CFF_OPS *op;
int32_t number;
double real;
};
};
struct _CFF_DICT {
int len,alloc;
struct _CFF_VALUE data[];
};
// ?
struct _CFF_DICT *cff_read_dict(const char *start,int length);
const char *cff_get_string(CFF_FILE *cff,int sid,int *retlen); // or NULL
#endif