1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alex Gitelman
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
29 static unsigned char font_buf
[MAX_FONT_BUFLEN
];
31 unsigned char* ajf_read_font(char* fname
)
35 int fd
= open(fname
, O_RDONLY
|O_BINARY
);
37 int fd
= open(fname
, O_RDONLY
);
43 DEBUGF("Failed opening font file: %d %s. ", _errno(), fname
);
45 DEBUGF("Failed opening font file: %d %s. ", errno
, fname
);
51 count
= read(fd
, font_buf
, MAX_FONT_BUFLEN
);
52 if (count
==MAX_FONT_BUFLEN
) {
53 DEBUGF("Font is larger than allocated %d bytes!\n",MAX_FONT_BUFLEN
);
58 if (font_buf
[0]!=MAGIC1
|| font_buf
[1]!=MAGIC2
) {
59 DEBUGF("Bad magic word in font");
66 unsigned char* ajf_get_charbuf(unsigned char c
, unsigned char* font
,
69 int height
= READ_SHORT(&font
[HEIGHT_OFFSET
]);
70 int size
= READ_SHORT(&font
[SIZE_OFFSET
]);
71 int chars_offset
= LOOKUP_MAP_OFFSET
+ size
*3;
72 int rows
= (height
-1)/8 + 1;
73 int first_char
= READ_SHORT(&font
[FIRST_CHAR_OFFSET
]);
74 int map_idx
= LOOKUP_MAP_OFFSET
+ (c
-first_char
)*3;
75 int byte_count
= font
[map_idx
];
82 char_idx
= READ_SHORT(&font
[map_idx
]);
83 return &font
[chars_offset
+ char_idx
];
86 void ajf_get_charsize(unsigned char c
, unsigned char* font
,
87 int *width
, int *height
)
89 int first_char
= READ_SHORT(&font
[FIRST_CHAR_OFFSET
]);
90 int map_idx
= LOOKUP_MAP_OFFSET
+ (c
-first_char
)*3;
92 *height
= READ_SHORT(&font
[HEIGHT_OFFSET
]);
93 rows
= (*height
-1)/8 + 1;
94 *width
= font
[map_idx
]/rows
;
97 int ajf_get_fontheight(unsigned char* font
)
99 return READ_SHORT(&font
[HEIGHT_OFFSET
]);