Merge branch 'master' into gsoc-dir-split
[kugel-rb.git] / firmware / export / font.h
blob7284564380a3e432b222828306de456be3e3fb32
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _FONT_H
22 #define _FONT_H
24 #include "inttypes.h"
27 * Incore font and image definitions
29 #include "config.h"
31 #if defined(HAVE_LCD_BITMAP) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
32 #ifndef __PCTOOL__
33 #include "font_cache.h"
34 #include "sysfont.h"
35 #endif
39 * Fonts are specified by number, and used for display
40 * of menu information as well as mp3 filename data.
41 * At system startup, up to MAXFONTS fonts are initialized,
42 * either by being compiled-in, or loaded from disk.
43 * If the font asked for does not exist, then the
44 * system uses the next lower font number. Font 0
45 * must be available at system startup.
46 * Fonts are specified in firmware/font.c.
48 enum {
49 FONT_SYSFIXED, /* system fixed pitch font*/
50 FONT_UI, /* system porportional font*/
51 #ifdef HAVE_REMOTE_LCD
52 FONT_UI_REMOTE, /* UI font for remote LCD */
53 #endif
54 SYSTEMFONTCOUNT, /* Number of fonts reserved for the system and ui */
55 FONT_FIRSTUSERFONT = 2
57 #define MAXUSERFONTS 8
59 /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */
60 #define MAXFONTS (SYSTEMFONTCOUNT + MAXUSERFONTS)
63 * .fnt loadable font file format definition
65 * format len description
66 * ------------------------- ---- ------------------------------
67 * UCHAR version[4] 4 magic number and version bytes
68 * USHORT maxwidth 2 font max width in pixels
69 * USHORT height 2 font height in pixels
70 * USHORT ascent 2 font ascent (baseline) in pixels
71 * USHORT pad 2 unused, pad to 32-bit boundary
72 * ULONG firstchar 4 first character code in font
73 * ULONG defaultchar 4 default character code in font
74 * ULONG size 4 # characters in font
75 * ULONG nbits 4 # bytes imagebits data in file
76 * ULONG noffset 4 # longs offset data in file
77 * ULONG nwidth 4 # bytes width data in file
78 * MWIMAGEBITS bits nbits image bits variable data
79 * [MWIMAGEBITS padded to 16-bit boundary]
80 * USHORT offset noffset*2 offset variable data
81 * UCHAR width nwidth*1 width variable data
84 /* loadable font magic and version #*/
85 #define VERSION "RB12"
87 /* builtin C-based proportional/fixed font structure */
88 /* based on The Microwindows Project http://microwindows.org */
89 struct font {
90 int maxwidth; /* max width in pixels*/
91 unsigned int height; /* height in pixels*/
92 int ascent; /* ascent (baseline) height*/
93 int firstchar; /* first character in bitmap*/
94 int size; /* font size in glyphs*/
95 const unsigned char *bits; /* 8-bit column bitmap data*/
96 const void *offset; /* offsets into bitmap data,
97 uint16_t if bits_size < 0xFFDB else uint32_t*/
98 const unsigned char *width; /* character widths or NULL if fixed*/
99 int defaultchar; /* default char (not glyph index)*/
100 int32_t bits_size; /* # bytes of glyph bits*/
102 /* file, buffer and cache management */
103 int fd; /* fd for the font file. >= 0 if cached */
104 unsigned char *buffer_start; /* buffer to store the font in */
105 unsigned char *buffer_position; /* position in the buffer */
106 unsigned char *buffer_end; /* end of the buffer */
107 int buffer_size; /* size of the buffer in bytes */
108 #ifndef __PCTOOL__
109 struct font_cache cache;
110 uint32_t file_width_offset; /* offset to file width data */
111 uint32_t file_offset_offset; /* offset to file offset data */
112 int long_offset;
113 #endif
117 /* font routines*/
118 void font_init(void) INIT_ATTR;
119 #ifdef HAVE_REMOTE_LCD
120 /* Load a font into the special remote ui font slot */
121 int font_load_remoteui(const char* path);
122 #endif
123 int font_load(struct font* pf, const char *path);
124 void font_unload(int font_id);
126 struct font* font_get(int font);
128 void font_reset(struct font *pf);
129 int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
130 int font_get_width(struct font* ft, unsigned short ch);
131 const unsigned char * font_get_bits(struct font* ft, unsigned short ch);
132 void glyph_cache_save(struct font* pf);
134 #else /* HAVE_LCD_BITMAP */
136 #define font_init()
137 #define font_load(x)
139 #endif
141 #endif