blob: e3455f9c7014b367f119546f3772cf267831bbb5 [file] [log] [blame]
Daniel Stenbergf9b44902003-02-07 09:41:57 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Daniel Stenbergf9b44902003-02-07 09:41:57 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Björn Stenberg0dcc4a62003-06-29 14:57:44 +000021#ifndef _FONT_H
22#define _FONT_H
23
Nils Wallméniusdf155c82007-06-30 17:54:02 +000024#include "inttypes.h"
25
Daniel Stenbergf9b44902003-02-07 09:41:57 +000026/*
27 * Incore font and image definitions
28 */
29#include "config.h"
30
31#if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
Dave Chapman7418c352008-03-25 21:09:58 +000032#ifndef __PCTOOL__
Barry Wardell3f8d7322007-01-17 12:34:56 +000033#include "sysfont.h"
Dave Chapman7418c352008-03-25 21:09:58 +000034#endif
Daniel Stenbergf9b44902003-02-07 09:41:57 +000035
Daniel Stenberg0f820d62005-08-03 21:31:51 +000036/* max static loadable font buffer size */
Daniel Stenbergf9b44902003-02-07 09:41:57 +000037#ifndef MAX_FONT_SIZE
Daniel Stenberg0f820d62005-08-03 21:31:51 +000038#if LCD_HEIGHT > 64
Linus Nielsen Feltzinge06faa02007-03-05 08:32:35 +000039#if MEM > 2
40#define MAX_FONT_SIZE 60000
41#else
Daniel Stenberg0f820d62005-08-03 21:31:51 +000042#define MAX_FONT_SIZE 10000
Linus Nielsen Feltzinge06faa02007-03-05 08:32:35 +000043#endif
Daniel Stenberg0f820d62005-08-03 21:31:51 +000044#else
Marcoen Hirschbergb0fee172005-12-06 13:27:15 +000045#define MAX_FONT_SIZE 4000
Daniel Stenberg0f820d62005-08-03 21:31:51 +000046#endif
Daniel Stenbergf9b44902003-02-07 09:41:57 +000047#endif
48
Marcoen Hirschbergb0fee172005-12-06 13:27:15 +000049#ifndef FONT_HEADER_SIZE
50#define FONT_HEADER_SIZE 36
51#endif
52
53#define GLYPH_CACHE_FILE "/.rockbox/.glyphcache"
54
Daniel Stenbergf9b44902003-02-07 09:41:57 +000055/*
56 * Fonts are specified by number, and used for display
57 * of menu information as well as mp3 filename data.
58 * At system startup, up to MAXFONTS fonts are initialized,
59 * either by being compiled-in, or loaded from disk.
60 * If the font asked for does not exist, then the
61 * system uses the next lower font number. Font 0
62 * must be available at system startup.
63 * Fonts are specified in firmware/font.c.
64 */
65enum {
66 FONT_SYSFIXED, /* system fixed pitch font*/
67 FONT_UI, /* system porportional font*/
68 MAXFONTS
69};
70
71/*
72 * .fnt loadable font file format definition
73 *
Jörg Hohensohna8dbabe2004-08-27 20:03:02 +000074 * format len description
75 * ------------------------- ---- ------------------------------
76 * UCHAR version[4] 4 magic number and version bytes
77 * USHORT maxwidth 2 font max width in pixels
78 * USHORT height 2 font height in pixels
79 * USHORT ascent 2 font ascent (baseline) in pixels
80 * USHORT pad 2 unused, pad to 32-bit boundary
81 * ULONG firstchar 4 first character code in font
82 * ULONG defaultchar 4 default character code in font
83 * ULONG size 4 # characters in font
84 * ULONG nbits 4 # bytes imagebits data in file
85 * ULONG noffset 4 # longs offset data in file
86 * ULONG nwidth 4 # bytes width data in file
87 * MWIMAGEBITS bits nbits image bits variable data
88 * [MWIMAGEBITS padded to 16-bit boundary]
89 * USHORT offset noffset*2 offset variable data
90 * UCHAR width nwidth*1 width variable data
Daniel Stenbergf9b44902003-02-07 09:41:57 +000091 */
92
93/* loadable font magic and version #*/
Jörg Hohensohna8dbabe2004-08-27 20:03:02 +000094#define VERSION "RB12"
Daniel Stenbergf9b44902003-02-07 09:41:57 +000095
96/* builtin C-based proportional/fixed font structure */
97/* based on The Microwindows Project http://microwindows.org */
98struct font {
Nils Wallméniusd718c272007-09-14 16:04:01 +000099 int maxwidth; /* max width in pixels*/
100 unsigned int height; /* height in pixels*/
101 int ascent; /* ascent (baseline) height*/
102 int firstchar; /* first character in bitmap*/
103 int size; /* font size in glyphs*/
104 const unsigned char *bits; /* 8-bit column bitmap data*/
105 const unsigned short *offset; /* offsets into bitmap data*/
106 const unsigned char *width; /* character widths or NULL if fixed*/
107 int defaultchar; /* default char (not glyph index)*/
108 int32_t bits_size; /* # bytes of glyph bits*/
Daniel Stenbergf9b44902003-02-07 09:41:57 +0000109};
110
111/* font routines*/
112void font_init(void);
Jens Arnoldc76c5682004-08-16 23:37:23 +0000113struct font* font_load(const char *path);
Daniel Stenbergf9b44902003-02-07 09:41:57 +0000114struct font* font_get(int font);
115void font_reset(void);
Christian Gmeinerc6ec0f42005-04-19 12:47:16 +0000116int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
Marcoen Hirschbergb0fee172005-12-06 13:27:15 +0000117int font_get_width(struct font* ft, unsigned short ch);
118const unsigned char * font_get_bits(struct font* ft, unsigned short ch);
119void glyph_cache_save(void);
Daniel Stenbergf9b44902003-02-07 09:41:57 +0000120
121#else /* HAVE_LCD_BITMAP */
122
123#define font_init()
124#define font_load(x)
125
126#endif
127
Björn Stenberg0dcc4a62003-06-29 14:57:44 +0000128#endif