Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1
2
3/*
4 * font.h
5 *
6* Created on: Mar 15, 2022
7 * Author: micahbly
8 */
9
10#ifndef LIB_FONT_H_
11#define LIB_FONT_H_
12
13
14/* about this class: Font
15 *
16 * This provides functionality for loading and drawing bitmapped proportional and fixed-width fonts
17 *
18 *** things this library needs to be able to do
19 *
20 *
21 * STRETCH GOALS
22 *
23 *
24 * SUPER STRETCH GOALS
25 *
26 *
27 */
28
29
30/*****************************************************************************/
31/* Includes */
32/*****************************************************************************/
33
34// project includes
35
36// C includes
37#include <stdbool.h>
38
39
40// A2560 includes
41#include <mcp/syscalls.h>
42#include "a2560k.h"
43
44
45/*****************************************************************************/
46/* Macro Definitions */
47/*****************************************************************************/
48
49#define FONT_RECORD_SIZE 26
50
51#define FONT_CHAR_FOENIX_OUTLINE 0x11
52#define FONT_CHAR_CHECKMARK 0x12
53#define FONT_CHAR_DIAMOND 0x13
54#define FONT_CHAR_FOENIX_REG 0x14
55#define FONT_CHAR_MENU_RIGHT 0x15
56#define FONT_CHAR_MENU_RIGHT_WIDTH 7
57
58
59/*****************************************************************************/
60/* Enumerations */
61/*****************************************************************************/
62
63
64
65/*****************************************************************************/
66/* Structs */
67/*****************************************************************************/
68
71struct Font {
72 int16_t fontType;
73 int16_t firstChar;
74 int16_t lastChar;
75 int16_t widMax;
76 int16_t kernMax;
77 int16_t nDescent;
78 int16_t fRectWidth;
79 int16_t fRectHeight;
80 uint16_t owTLoc;
81 int16_t ascent;
82 int16_t descent;
83 int16_t leading;
84 int16_t rowWords;
85 uint16_t* image_table_;
86 uint16_t* loc_table_;
87 uint16_t* width_table_;
88 uint16_t* height_table_;
89};
90
91
92
93
94
95
96/*****************************************************************************/
97/* Global Variables */
98/*****************************************************************************/
99
100
101/*****************************************************************************/
102/* Public Function Prototypes */
103/*****************************************************************************/
104
105
106// **** CONSTRUCTOR AND DESTRUCTOR *****
107
108// constructor
115Font* Font_New(uint8_t* the_data, uint16_t data_size);
116
117// destructor
118// frees all allocated memory associated with the passed object, and the object itself
121bool Font_Destroy(Font** the_font);
122
123
124
125
126
127
128// **** xxx functions *****
129
130
131
132
133// **** Set xxx functions *****
134
135
136
137
138
139// **** Get xxx functions *****
140
141
142
143
144
145// **** Draw string functions *****
146
147
148// Draw a string at the current "pen" location, using the current pen color of the bitmap
149// Truncate, but still draw the string if it is too long to display on the line it started.
150// No word wrap is performed.
151// If max_chars is less than the string length, only that many characters will be drawn (as space allows)
152// If max_chars is -1, then the full string length will be drawn, as space allows.
153bool Font_DrawString(Bitmap* the_bitmap, char* the_string, int16_t max_chars);
154
166char* Font_DrawStringInBox(Bitmap* the_bitmap, int16_t width, int16_t height, char* the_string, int16_t num_chars, char** wrap_buffer, bool (* continue_function)(void));
167
177int16_t Font_MeasureStringWidth(Font* the_font, char* the_string, int16_t num_chars, int16_t available_width, int16_t fixed_char_width, int16_t* measured_width);
178
179
187int16_t Font_DrawChar(Bitmap* the_bitmap, uint8_t the_char, Font* the_font);
188
189
190
191// **** xxx functions *****
192
193
194
195
196// **** Debug functions *****
197
198void Font_Print(Font* the_font);
199
200
201
202#endif /* LIB_FONT_H_ */
203
204
Font * Font_New(uint8_t *the_data, uint16_t data_size)
Create a Font object, and populate it from the passed buffer.
Definition: font.c:148
char * Font_DrawStringInBox(Bitmap *the_bitmap, int16_t width, int16_t height, char *the_string, int16_t num_chars, char **wrap_buffer, bool(*continue_function)(void))
Draw a string in a rectangular block on the screen, with wrap.
Definition: font.c:459
bool Font_Destroy(Font **the_font)
Definition: font.c:317
int16_t Font_MeasureStringWidth(Font *the_font, char *the_string, int16_t num_chars, int16_t available_width, int16_t fixed_char_width, int16_t *measured_width)
Calculates how many characters of the passed string will fit into the passed pixel width.
Definition: font.c:642
int16_t Font_DrawChar(Bitmap *the_bitmap, uint8_t the_char, Font *the_font)
Draw one character on the bitmap, at the current bitmap pen coordinates NOTE: if the draw action is s...
Definition: font.c:707
Definition: bitmap.h:97
This Font object is essentially the Mac "fontRecord" struct, with added pointers for the data tables.
Definition: font.h:71
int16_t kernMax
negative of maximum character kern
Definition: font.h:76
int16_t descent
descent
Definition: font.h:82
int16_t leading
leading
Definition: font.h:83
int16_t nDescent
negative of descent
Definition: font.h:77
int16_t ascent
ascent
Definition: font.h:81
uint16_t * loc_table_
The location table.
Definition: font.h:86
int16_t widMax
maximum character width – Could be used if font is fixed-width
Definition: font.h:75
int16_t rowWords
row width of bit image / 2
Definition: font.h:84
int16_t fontType
Only bit we care about is the first. See https://developer.apple.com/library/archive/documentation/ma...
Definition: font.h:72
uint16_t * image_table_
The font image data.
Definition: font.h:85
int16_t firstChar
ASCII code of first character.
Definition: font.h:73
int16_t fRectWidth
width of font rectangle
Definition: font.h:78
uint16_t owTLoc
offset to offset/width table
Definition: font.h:80
int16_t lastChar
ASCII code of last character.
Definition: font.h:74
uint16_t * width_table_
Table containing h offset and widths for each glyph.
Definition: font.h:87
int16_t fRectHeight
height of font rectangle
Definition: font.h:79
uint16_t * height_table_
Table containing starting v offset and active v pixel count for each glyph.
Definition: font.h:88