Allow fonts to use smaller buffers than the default size. use font_load_ex() to spefi...
[maemo-rb.git] / firmware / export / font.h
blob582c08f2099f0acab9a7af13a7198e685197e49a
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 <stdlib.h>
25 #include "inttypes.h"
26 #include "stdbool.h"
29 * Incore font and image definitions
31 #include "config.h"
33 #if defined(HAVE_LCD_BITMAP) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
34 #ifndef __PCTOOL__
35 #include "font_cache.h"
36 #include "sysfont.h"
37 #endif
41 * Fonts are specified by number, and used for display
42 * of menu information as well as mp3 filename data.
43 * At system startup, up to MAXFONTS fonts are initialized,
44 * either by being compiled-in, or loaded from disk.
45 * If the font asked for does not exist, then the
46 * system uses the next lower font number. Font 0
47 * must be available at system startup.
48 * Fonts are specified in firmware/font.c.
50 enum {
51 FONT_SYSFIXED = -1, /* system fixed pitch font*/
52 FONT_FIRSTUSERFONT = 0, /* first id for the user fonts */
54 #define MAXUSERFONTS 8
56 /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */
57 #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS)
58 #define FONT_UI MAXFONTS
61 * .fnt loadable font file format definition
63 * format len description
64 * ------------------------- ---- ------------------------------
65 * UCHAR version[4] 4 magic number and version bytes
66 * USHORT maxwidth 2 font max width in pixels
67 * USHORT height 2 font height in pixels
68 * USHORT ascent 2 font ascent (baseline) in pixels
69 * USHORT depth 2 depth of the font, 0=1bit and 1=4bit
70 * ULONG firstchar 4 first character code in font
71 * ULONG defaultchar 4 default character code in font
72 * ULONG size 4 # characters in font
73 * ULONG nbits 4 # bytes imagebits data in file
74 * ULONG noffset 4 # longs offset data in file
75 * ULONG nwidth 4 # bytes width data in file
76 * MWIMAGEBITS bits nbits image bits variable data
77 * [MWIMAGEBITS padded to 16-bit boundary]
78 * USHORT offset noffset*2 offset variable data
79 * UCHAR width nwidth*1 width variable data
82 /* loadable font magic and version #*/
83 #define VERSION "RB12"
85 /* builtin C-based proportional/fixed font structure */
86 /* based on The Microwindows Project http://microwindows.org */
87 struct font {
88 int maxwidth; /* max width in pixels*/
89 unsigned int height; /* height in pixels*/
90 int ascent; /* ascent (baseline) height*/
91 int firstchar; /* first character in bitmap*/
92 int size; /* font size in glyphs*/
93 int depth; /* depth of the font, 0=1bit and 1=4bit */
94 const unsigned char *bits; /* 8-bit column bitmap data*/
95 const void *offset; /* offsets into bitmap data,
96 uint16_t if bits_size < 0xFFDB else uint32_t*/
97 const unsigned char *width; /* character widths or NULL if fixed*/
98 int defaultchar; /* default char (not glyph index)*/
99 int32_t bits_size; /* # bytes of glyph bits*/
101 /* file, buffer and cache management */
102 int fd; /* fd for the font file. >= 0 if cached */
103 unsigned char *buffer_start; /* buffer to store the font in */
104 unsigned char *buffer_position; /* position in the buffer */
105 unsigned char *buffer_end; /* end of the buffer */
106 size_t buffer_size; /* size of the buffer in bytes */
107 #ifndef __PCTOOL__
108 struct font_cache cache;
109 uint32_t file_width_offset; /* offset to file width data */
110 uint32_t file_offset_offset; /* offset to file offset data */
111 int long_offset;
112 #endif
116 /* font routines*/
117 void font_init(void) INIT_ATTR;
118 const char* font_filename(int font_id);
119 int font_load(const char *path);
120 int font_load_ex(const char *path, size_t buffer_size);
121 int font_glyphs_to_bufsize(const char *path, int glyphs);
122 void font_unload(int font_id);
124 struct font* font_get(int font);
126 int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
127 int font_get_width(struct font* ft, unsigned short ch);
128 const unsigned char * font_get_bits(struct font* ft, unsigned short ch);
129 void glyph_cache_save(struct font* pf);
131 #else /* HAVE_LCD_BITMAP */
133 #define font_init()
134 #define font_load(x)
136 #endif
138 #endif