diff options
Diffstat (limited to 'firmware/loadfont.c')
-rw-r--r-- | firmware/loadfont.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/firmware/loadfont.c b/firmware/loadfont.c index 7f572a4841..e78f208b13 100644 --- a/firmware/loadfont.c +++ b/firmware/loadfont.c | |||
@@ -39,9 +39,8 @@ | |||
39 | /* static buffer allocation structures*/ | 39 | /* static buffer allocation structures*/ |
40 | static unsigned char mbuf[MAX_FONT_SIZE]; | 40 | static unsigned char mbuf[MAX_FONT_SIZE]; |
41 | static unsigned char *freeptr = mbuf; | 41 | static unsigned char *freeptr = mbuf; |
42 | typedef unsigned char CFILE; | 42 | static unsigned char *fileptr; |
43 | static CFILE *fileptr; | 43 | static unsigned char *eofptr; |
44 | static CFILE *eofptr; | ||
45 | 44 | ||
46 | static int | 45 | static int |
47 | READSHORT(unsigned short *sp) | 46 | READSHORT(unsigned short *sp) |
@@ -101,9 +100,9 @@ PMWCFONT | |||
101 | rbf_load_font(char *path, PMWCFONT pf) | 100 | rbf_load_font(char *path, PMWCFONT pf) |
102 | { | 101 | { |
103 | int fd, filesize; | 102 | int fd, filesize; |
104 | unsigned short maxwidth, height, ascent; | 103 | unsigned short maxwidth, height, ascent, pad; |
105 | unsigned long firstchar, defaultchar, size; | 104 | unsigned long firstchar, defaultchar, size; |
106 | unsigned long nbits, noffset, nwidth; | 105 | unsigned long i, nbits, noffset, nwidth; |
107 | char version[4+1]; | 106 | char version[4+1]; |
108 | char copyright[256+1]; | 107 | char copyright[256+1]; |
109 | 108 | ||
@@ -115,10 +114,12 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
115 | DEBUGF("Can't open font: %s\n", path); | 114 | DEBUGF("Can't open font: %s\n", path); |
116 | return NULL; | 115 | return NULL; |
117 | } | 116 | } |
117 | freeptr = (unsigned char *)(((int)mbuf + 3) & ~3); | ||
118 | fileptr = freeptr; | 118 | fileptr = freeptr; |
119 | filesize = read(fd, fileptr, MAX_FONT_SIZE); | 119 | filesize = read(fd, fileptr, MAX_FONT_SIZE); |
120 | freeptr += filesize; | ||
121 | eofptr = fileptr + filesize; | 120 | eofptr = fileptr + filesize; |
121 | //freeptr += filesize; | ||
122 | //freeptr = (unsigned char *)(freeptr + 3) & ~3; /* pad freeptr*/ | ||
122 | close(fd); | 123 | close(fd); |
123 | if (filesize == MAX_FONT_SIZE) { | 124 | if (filesize == MAX_FONT_SIZE) { |
124 | DEBUGF("Font %s too large: %d\n", path, filesize); | 125 | DEBUGF("Font %s too large: %d\n", path, filesize); |
@@ -151,6 +152,8 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
151 | if (!READSHORT(&ascent)) | 152 | if (!READSHORT(&ascent)) |
152 | return NULL; | 153 | return NULL; |
153 | pf->ascent = ascent; | 154 | pf->ascent = ascent; |
155 | if (!READSHORT(&pad)) | ||
156 | return NULL; | ||
154 | if (!READLONG(&firstchar)) | 157 | if (!READLONG(&firstchar)) |
155 | return NULL; | 158 | return NULL; |
156 | pf->firstchar = firstchar; | 159 | pf->firstchar = firstchar; |
@@ -177,16 +180,22 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
177 | 180 | ||
178 | /* variable font data*/ | 181 | /* variable font data*/ |
179 | pf->bits = (MWIMAGEBITS *)fileptr; | 182 | pf->bits = (MWIMAGEBITS *)fileptr; |
180 | fileptr += nbits*sizeof(MWIMAGEBITS); | 183 | for (i=0; i<nbits; ++i) |
184 | if (!READSHORT(&pf->bits[i])) | ||
185 | return NULL; | ||
186 | /* pad to longword boundary*/ | ||
187 | fileptr = (unsigned char *)(((int)fileptr + 3) & ~3); | ||
181 | 188 | ||
182 | if (noffset) { | 189 | if (noffset) { |
183 | pf->offset = (unsigned long *)fileptr; | 190 | pf->offset = (unsigned long *)fileptr; |
184 | fileptr += noffset*sizeof(unsigned long); | 191 | for (i=0; i<noffset; ++i) |
192 | if (!READLONG(&pf->offset[i])) | ||
193 | return NULL; | ||
185 | } else pf->offset = NULL; | 194 | } else pf->offset = NULL; |
186 | 195 | ||
187 | if (nwidth) { | 196 | if (nwidth) { |
188 | pf->width = (unsigned char *)fileptr; | 197 | pf->width = (unsigned char *)fileptr; |
189 | fileptr += noffset*sizeof(unsigned char); | 198 | fileptr += nwidth*sizeof(unsigned char); |
190 | } else pf->width = NULL; | 199 | } else pf->width = NULL; |
191 | 200 | ||
192 | if (fileptr > eofptr) | 201 | if (fileptr > eofptr) |
@@ -198,5 +207,6 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
198 | /* ----------------------------------------------------------------- | 207 | /* ----------------------------------------------------------------- |
199 | * local variables: | 208 | * local variables: |
200 | * eval: (load-file "rockbox-mode.el") | 209 | * eval: (load-file "rockbox-mode.el") |
210 | * vim: et sw=4 ts=8 sts=4 tw=78 | ||
201 | * end: | 211 | * end: |
202 | */ | 212 | */ |