summaryrefslogtreecommitdiff
path: root/firmware/loadfont.c
diff options
context:
space:
mode:
authorEric Linenberg <elinenbe@umich.edu>2002-09-16 03:18:49 +0000
committerEric Linenberg <elinenbe@umich.edu>2002-09-16 03:18:49 +0000
commit038df5cdc99c53530f52f7c0755bd64c473908b0 (patch)
tree1e0e408a276d727270a7f0496abbb908b2d76dd9 /firmware/loadfont.c
parent8e1a00ccb290aacc5236698ea9159a377c822ec6 (diff)
downloadrockbox-038df5cdc99c53530f52f7c0755bd64c473908b0.tar.gz
rockbox-038df5cdc99c53530f52f7c0755bd64c473908b0.zip
Daniel,
The following patch makes loadable fonts actually work (finally!). It took me quite a while, but I finally figured out why the sim worked and the target didn't: the SH1 processor won't read longwords from a shortword alignment... I had to rev the .fnt file to version 1.1 (requires remaking *.fnt files) in order to fix this. Please apply the following patch completely. It's diffed against the latest CVS. I've also attached rockbox-fonts-1.1.tar.gz which includes known working *.fnt files, including a courB08 system.fnt, for demonstration. Now the real work can begin... Although the new system.fnt will work fine, if you try going to a really big font (try copying courB14.fnt to system.fnt), then you will find that it comes up and works in tree mode, but will crash the system when going into WPS mode... I'm sure this is because of the low-level lcd_bitmap not clipping properly when given a too-large bitmap, which the characters become. I haven't yet tried to debug the low-level driver. Of course, it all works on the sim... So the apps developers will now have to make sure that all apps screen sizes may vary according to the loaded font. The font height can be gotten through the lcd_getfontsize API. Files patched in fonts-6.patch 1. apps/menu.c - LCD_PROPFONTS error (2nd resubmission on this, please checkin) 2. firmware/font.c - fixes and reformatting. Please check this in as is, my vi editor requires more reformatting changes since I left tabs in the file, these are removed now (2nd resubmission on this, please checkin) 3. firmware/fonts.h - doc change on .fnt file format, .fnt version number incremented. 4. firmware/loadfont.c - fixes to load font properly, typedefs removed. 5. firmware/system.c - lcd_setfont(FONT_SYSFIXED) before issuing error, otherwise font may not exist. 6. tools/bdf2c - fixes for correct output when filename starts with a number, as well as when no DEFAULT_CHAR in .bdf file. (2nd resubmission on this, please checkin) 7. tools/writerbf.c - fixes for bugfixed fontfile format. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2294 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/loadfont.c')
-rw-r--r--firmware/loadfont.c28
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*/
40static unsigned char mbuf[MAX_FONT_SIZE]; 40static unsigned char mbuf[MAX_FONT_SIZE];
41static unsigned char *freeptr = mbuf; 41static unsigned char *freeptr = mbuf;
42typedef unsigned char CFILE; 42static unsigned char *fileptr;
43static CFILE *fileptr; 43static unsigned char *eofptr;
44static CFILE *eofptr;
45 44
46static int 45static int
47READSHORT(unsigned short *sp) 46READSHORT(unsigned short *sp)
@@ -101,9 +100,9 @@ PMWCFONT
101rbf_load_font(char *path, PMWCFONT pf) 100rbf_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 }
117freeptr = (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 */