summaryrefslogtreecommitdiff
path: root/firmware/export/font.h
blob: f2f83e54c88ff7296e557cd8ad6d9e0c71f736d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef _FONT_H
#define _FONT_H

/*
 * Incore font and image definitions
 */
#include "config.h"

#if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)

/* max static loadable fonts buffer*/
#ifndef MAX_FONT_SIZE
#define MAX_FONT_SIZE	9000	/* max total fontsize allocation*/
#endif

/*
 * Fonts are specified by number, and used for display
 * of menu information as well as mp3 filename data.
 * At system startup, up to MAXFONTS fonts are initialized,
 * either by being compiled-in, or loaded from disk.
 * If the font asked for does not exist, then the
 * system uses the next lower font number.  Font 0
 * must be available at system startup.
 * Fonts are specified in firmware/font.c.
 */
enum {
    FONT_SYSFIXED, /* system fixed pitch font*/
    FONT_UI,       /* system porportional font*/
    MAXFONTS
};

/*
 * .fnt loadable font file format definition
 *
 * format                     len	description
 * -------------------------  ----	------------------------------
 * UCHAR version[4]		4	magic number and version bytes
 * UCHAR name[64]	       64	font name, space padded
 * UCHAR copyright[256]	      256	copyright info, space padded
 * USHORT maxwidth		2	font max width in pixels
 * USHORT height		2	font height in pixels
 * USHORT ascent		2	font ascent (baseline) in pixels
 * USHORT pad                   2       unused, pad to 32-bit boundary
 * ULONG firstchar		4	first character code in font
 * ULONG defaultchar		4	default character code in font
 * ULONG size			4	# characters in font
 * ULONG nbits			4	# words imagebits data in file
 * ULONG noffset		4	# longs offset data in file
 * ULONG nwidth			4	# bytes width data in file
 * MWIMAGEBITS bits	  nbits*2	image bits variable data
 * [MWIMAGEBITS padded to 32-bit boundary]
 * ULONG offset         noffset*4	offset variable data
 * UCHAR width		 nwidth*1	width variable data
 */

/* loadable font magic and version #*/
#define VERSION		"RB11"

typedef unsigned short bitmap_t; /* bitmap image unit size*/

/* bitmap_t helper macros*/
#define BITMAP_WORDS(x)         (((x)+15)/16)	/* image size in words*/
#define BITMAP_BYTES(x)         (BITMAP_WORDS(x)*sizeof(bitmap_t))
#define	BITMAP_BITSPERIMAGE     (sizeof(bitmap_t) * 8)
#define	BITMAP_BITVALUE(n)      ((bitmap_t) (((bitmap_t) 1) << (n)))
#define	BITMAP_FIRSTBIT         (BITMAP_BITVALUE(BITMAP_BITSPERIMAGE - 1))
#define	BITMAP_TESTBIT(m)       ((m) & BITMAP_FIRSTBIT)
#define	BITMAP_SHIFTBIT(m)      ((bitmap_t) ((m) << 1))

/* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */
struct font {
    char *	name;		/* font name*/
    int		maxwidth;	/* max width in pixels*/
    unsigned int height;	/* height in pixels*/
    int		ascent;		/* ascent (baseline) height*/
    int		firstchar;	/* first character in bitmap*/
    int		size;		/* font size in glyphs*/
    bitmap_t *bits;		/* 16-bit right-padded bitmap data*/
    unsigned long *offset;	/* offsets into bitmap data*/
    unsigned char *width;	/* character widths or NULL if fixed*/
    int		defaultchar;	/* default char (not glyph index)*/
    long	bits_size;	/* # words of bitmap_t bits*/
};

/* font routines*/
void font_init(void);
struct font* font_load(char *path);
struct font* font_get(int font);
void font_reset(void);

#else /* HAVE_LCD_BITMAP */

#define font_init()
#define font_load(x)

#endif

#endif
/* -----------------------------------------------------------------
 * vim: et sw=4 ts=8 sts=4 tw=78
 */