diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-09-20 08:07:51 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-09-20 08:07:51 +0000 |
commit | bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7 (patch) | |
tree | 59ef1faa129f0813071d5e81b2e55b5d04886202 /firmware/loadfont.c | |
parent | eb5cc653dba373f2d2ce48f8efbc0b19a424971e (diff) | |
download | rockbox-bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7.tar.gz rockbox-bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7.zip |
New full ISO-8859-1 system font.
Added font loading from dir browser.
Changed default font location to /.rockbox/default.fnt.
Code-policed font code.
Removed old font tools.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2347 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/loadfont.c')
-rw-r--r-- | firmware/loadfont.c | 212 |
1 files changed, 0 insertions, 212 deletions
diff --git a/firmware/loadfont.c b/firmware/loadfont.c deleted file mode 100644 index e78f208b13..0000000000 --- a/firmware/loadfont.c +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (c) 2002 by Greg Haerr <greg@censoft.com> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | /* | ||
20 | * Load an rbf font, store in incore format. | ||
21 | */ | ||
22 | #include "config.h" | ||
23 | |||
24 | #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR) | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <string.h> | ||
28 | #include "font.h" | ||
29 | #include "file.h" | ||
30 | |||
31 | #ifndef DEBUGF | ||
32 | #include "debug.h" | ||
33 | #endif | ||
34 | |||
35 | #ifndef O_BINARY | ||
36 | #define O_BINARY 0 | ||
37 | #endif | ||
38 | |||
39 | /* static buffer allocation structures*/ | ||
40 | static unsigned char mbuf[MAX_FONT_SIZE]; | ||
41 | static unsigned char *freeptr = mbuf; | ||
42 | static unsigned char *fileptr; | ||
43 | static unsigned char *eofptr; | ||
44 | |||
45 | static int | ||
46 | READSHORT(unsigned short *sp) | ||
47 | { | ||
48 | unsigned short s; | ||
49 | |||
50 | s = *fileptr++ & 0xff; | ||
51 | *sp = (*fileptr++ << 8) | s; | ||
52 | return (fileptr <= eofptr); | ||
53 | } | ||
54 | |||
55 | static int | ||
56 | READLONG(unsigned long *lp) | ||
57 | { | ||
58 | unsigned long l; | ||
59 | |||
60 | l = *fileptr++ & 0xff; | ||
61 | l |= *fileptr++ << 8; | ||
62 | l |= *fileptr++ << 16; | ||
63 | *lp = (*fileptr++ << 24) | l; | ||
64 | return (fileptr <= eofptr); | ||
65 | } | ||
66 | |||
67 | /* read count bytes*/ | ||
68 | static int | ||
69 | READSTR(char *buf, int count) | ||
70 | { | ||
71 | int n = count; | ||
72 | |||
73 | while (--n >= 0) | ||
74 | *buf++ = *fileptr++; | ||
75 | return (fileptr <= eofptr)? count: 0; | ||
76 | } | ||
77 | |||
78 | /* read totlen bytes, return NUL terminated string*/ | ||
79 | /* may write 1 past buf[totlen]; removes blank pad*/ | ||
80 | static int | ||
81 | READSTRPAD(char *buf, int totlen) | ||
82 | { | ||
83 | char *p = buf; | ||
84 | int n = totlen; | ||
85 | |||
86 | while (--n >= 0) | ||
87 | *p++ = *fileptr++; | ||
88 | if (fileptr > eofptr) | ||
89 | return 0; | ||
90 | |||
91 | p = &buf[totlen]; | ||
92 | *p-- = 0; | ||
93 | while (*p == ' ' && p >= buf) | ||
94 | *p-- = '\0'; | ||
95 | return totlen; | ||
96 | } | ||
97 | |||
98 | /* read and load font into incore font structure*/ | ||
99 | PMWCFONT | ||
100 | rbf_load_font(char *path, PMWCFONT pf) | ||
101 | { | ||
102 | int fd, filesize; | ||
103 | unsigned short maxwidth, height, ascent, pad; | ||
104 | unsigned long firstchar, defaultchar, size; | ||
105 | unsigned long i, nbits, noffset, nwidth; | ||
106 | char version[4+1]; | ||
107 | char copyright[256+1]; | ||
108 | |||
109 | memset(pf, 0, sizeof(MWCFONT)); | ||
110 | |||
111 | /* open and read entire font file*/ | ||
112 | fd = open(path, O_RDONLY|O_BINARY); | ||
113 | if (fd < 0) { | ||
114 | DEBUGF("Can't open font: %s\n", path); | ||
115 | return NULL; | ||
116 | } | ||
117 | freeptr = (unsigned char *)(((int)mbuf + 3) & ~3); | ||
118 | fileptr = freeptr; | ||
119 | filesize = read(fd, fileptr, MAX_FONT_SIZE); | ||
120 | eofptr = fileptr + filesize; | ||
121 | //freeptr += filesize; | ||
122 | //freeptr = (unsigned char *)(freeptr + 3) & ~3; /* pad freeptr*/ | ||
123 | close(fd); | ||
124 | if (filesize == MAX_FONT_SIZE) { | ||
125 | DEBUGF("Font %s too large: %d\n", path, filesize); | ||
126 | return NULL; | ||
127 | } | ||
128 | |||
129 | /* read magic and version #*/ | ||
130 | memset(version, 0, sizeof(version)); | ||
131 | if (READSTR(version, 4) != 4) | ||
132 | return NULL; | ||
133 | if (strcmp(version, VERSION) != 0) | ||
134 | return NULL; | ||
135 | |||
136 | /* internal font name*/ | ||
137 | pf->name = fileptr; | ||
138 | if (READSTRPAD(pf->name, 64) != 64) | ||
139 | return NULL; | ||
140 | |||
141 | /* copyright, not currently stored*/ | ||
142 | if (READSTRPAD(copyright, 256) != 256) | ||
143 | return NULL; | ||
144 | |||
145 | /* font info*/ | ||
146 | if (!READSHORT(&maxwidth)) | ||
147 | return NULL; | ||
148 | pf->maxwidth = maxwidth; | ||
149 | if (!READSHORT(&height)) | ||
150 | return NULL; | ||
151 | pf->height = height; | ||
152 | if (!READSHORT(&ascent)) | ||
153 | return NULL; | ||
154 | pf->ascent = ascent; | ||
155 | if (!READSHORT(&pad)) | ||
156 | return NULL; | ||
157 | if (!READLONG(&firstchar)) | ||
158 | return NULL; | ||
159 | pf->firstchar = firstchar; | ||
160 | if (!READLONG(&defaultchar)) | ||
161 | return NULL; | ||
162 | pf->defaultchar = defaultchar; | ||
163 | if (!READLONG(&size)) | ||
164 | return NULL; | ||
165 | pf->size = size; | ||
166 | |||
167 | /* get variable font data sizes*/ | ||
168 | /* # words of MWIMAGEBITS*/ | ||
169 | if (!READLONG(&nbits)) | ||
170 | return NULL; | ||
171 | pf->bits_size = nbits; | ||
172 | |||
173 | /* # longs of offset*/ | ||
174 | if (!READLONG(&noffset)) | ||
175 | return NULL; | ||
176 | |||
177 | /* # bytes of width*/ | ||
178 | if (!READLONG(&nwidth)) | ||
179 | return NULL; | ||
180 | |||
181 | /* variable font data*/ | ||
182 | pf->bits = (MWIMAGEBITS *)fileptr; | ||
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); | ||
188 | |||
189 | if (noffset) { | ||
190 | pf->offset = (unsigned long *)fileptr; | ||
191 | for (i=0; i<noffset; ++i) | ||
192 | if (!READLONG(&pf->offset[i])) | ||
193 | return NULL; | ||
194 | } else pf->offset = NULL; | ||
195 | |||
196 | if (nwidth) { | ||
197 | pf->width = (unsigned char *)fileptr; | ||
198 | fileptr += nwidth*sizeof(unsigned char); | ||
199 | } else pf->width = NULL; | ||
200 | |||
201 | if (fileptr > eofptr) | ||
202 | return NULL; | ||
203 | return pf; /* success!*/ | ||
204 | } | ||
205 | #endif /* HAVE_LCD_BITMAP */ | ||
206 | |||
207 | /* ----------------------------------------------------------------- | ||
208 | * local variables: | ||
209 | * eval: (load-file "rockbox-mode.el") | ||
210 | * vim: et sw=4 ts=8 sts=4 tw=78 | ||
211 | * end: | ||
212 | */ | ||