1 #ifndef _SFNT_INT_H
2 #define _SFNT_INT_H
3 
get_USHORT(const char * buf)4 static inline unsigned short get_USHORT(const char *buf) // {{{
5 {
6   return ((unsigned char)buf[0]<<8)|((unsigned char)buf[1]);
7 }
8 // }}}
get_SHORT(const char * buf)9 static inline short get_SHORT(const char *buf) // {{{
10 {
11   return (buf[0]<<8)|((unsigned char)buf[1]);
12 }
13 // }}}
get_UINT24(const char * buf)14 static inline unsigned int get_UINT24(const char *buf) // {{{
15 {
16   return ((unsigned char)buf[0]<<16)|
17          ((unsigned char)buf[1]<<8)|
18          ((unsigned char)buf[2]);
19 }
20 // }}}
get_ULONG(const char * buf)21 static inline unsigned int get_ULONG(const char *buf) // {{{
22 {
23   return ((unsigned char)buf[0]<<24)|
24          ((unsigned char)buf[1]<<16)|
25          ((unsigned char)buf[2]<<8)|
26          ((unsigned char)buf[3]);
27 }
28 // }}}
get_LONG(const char * buf)29 static inline int get_LONG(const char *buf) // {{{
30 {
31   return (buf[0]<<24)|
32          ((unsigned char)buf[1]<<16)|
33          ((unsigned char)buf[2]<<8)|
34          ((unsigned char)buf[3]);
35 }
36 // }}}
37 
set_USHORT(char * buf,unsigned short val)38 static inline void set_USHORT(char *buf,unsigned short val) // {{{
39 {
40   buf[0]=val>>8;
41   buf[1]=val&0xff;
42 }
43 // }}}
set_ULONG(char * buf,unsigned int val)44 static inline void set_ULONG(char *buf,unsigned int val) // {{{
45 {
46   buf[0]=val>>24;
47   buf[1]=(val>>16)&0xff;
48   buf[2]=(val>>8)&0xff;
49   buf[3]=val&0xff;
50 }
51 // }}}
52 
otf_checksum(const char * buf,unsigned int len)53 static inline unsigned int otf_checksum(const char *buf, unsigned int len) // {{{
54 {
55   unsigned int ret=0;
56   for (len=(len+3)/4;len>0;len--,buf+=4) {
57     ret+=get_ULONG(buf);
58   }
59   return ret;
60 }
61 // }}}
get_width_fast(OTF_FILE * otf,int gid)62 static inline int get_width_fast(OTF_FILE *otf,int gid) // {{{
63 {
64   if (gid>=otf->numberOfHMetrics) {
65     return get_USHORT(otf->hmtx+(otf->numberOfHMetrics-1)*4);
66   } else {
67     return get_USHORT(otf->hmtx+gid*4);
68   }
69 }
70 // }}}
71 
72 int otf_load_glyf(OTF_FILE *otf); //  - 0 on success
73 int otf_load_more(OTF_FILE *otf); //  - 0 on success
74 
75 int otf_find_table(OTF_FILE *otf,unsigned int tag); // - table_index  or -1 on error
76 
77 int otf_action_copy(void *param,int csum,OUTPUT_FN output,void *context);
78 int otf_action_replace(void *param,int csum,OUTPUT_FN output,void *context);
79 
80 // Note: don't use this directly. otf_write_sfnt will internally replace otf_action_copy for head with this
81 int otf_action_copy_head(void *param,int csum,OUTPUT_FN output,void *context);
82 
83 struct _OTF_WRITE {
84   unsigned long tag;
85   int (*action)(void *param,int length,OUTPUT_FN output,void *context); // -1 on error, num_bytes_written on success; if >output==NULL return checksum in (unsigned int *)context  instead.
86   void *param;
87   int length;
88 };
89 
90 int otf_write_sfnt(struct _OTF_WRITE *otw,unsigned int version,int numTables,OUTPUT_FN output,void *context);
91 
92 /** from sfnt_subset.c: **/
93 
94 // otw {0,}-terminated, will be modified; returns numTables for otf_write_sfnt
95 int otf_intersect_tables(OTF_FILE *otf,struct _OTF_WRITE *otw);
96 
97 #endif
98