17#define RETROFONT_PRESENT 1
19#ifndef RETROFONT_LINE_SZ
20# define RETROFONT_LINE_SZ 80
23#ifndef RETROFONT_TRACE_LVL
24# define RETROFONT_TRACE_LVL 0
31#define RETROFONT_FLAG_OUTLINE 0x04
40#define RETROFONT_FLAG_OUTLINE_LIGHT 0x0c
46#define RETROFONT_FLAG_SZ_MIN 0x10
62 const char* font_name, MAUG_MHANDLE* p_font_h,
63 uint8_t glyph_h, uint16_t first_glyph, uint16_t glyphs_count );
76 const char* str,
size_t str_sz,
80void retrofont_string_indent(
82 const char* str,
size_t str_sz,
88 retroflat_blit_t* target,
const char* str,
size_t str_sz,
92void retrofont_free( MAUG_MHANDLE* p_font_h );
99 struct RETROFONT* font,
const char* sub_name,
void* data );
106 mfile_t* font_file,
char* glyph_idx_str,
char** p_glyph_bytes
109 size_t last_char_idx = 0;
111 retval = font_file->read_line(
112 font_file, glyph_idx_str, RETROFONT_LINE_SZ, 0 );
113 maug_cleanup_if_not_ok();
115 *p_glyph_bytes = maug_strchr( glyph_idx_str,
':' );
116 if( NULL == *p_glyph_bytes ) { \
117 error_printf(
"invalid line: %s", glyph_idx_str );
121 retval = MERROR_WAIT;
127 (*p_glyph_bytes)[0] =
'\0'; \
131 if( 0 == strncmp(
"SUB", glyph_idx_str, 3 ) ) {
132 last_char_idx = maug_strlen( *p_glyph_bytes ) - 1;
134 '\n' == (*p_glyph_bytes)[last_char_idx] ||
135 '\r' == (*p_glyph_bytes)[last_char_idx] ||
136 '\t' == (*p_glyph_bytes)[last_char_idx] ||
137 ' ' == (*p_glyph_bytes)[last_char_idx]
139 (*p_glyph_bytes)[last_char_idx] =
'\0';
141 debug_printf( RETROFONT_TRACE_LVL,
"found sub: \"%s\"", *p_glyph_bytes );
142 retval = MERROR_PARSE;
153 const char* font_name,
struct RETROFONT* font,
155 void* try_platform_data
160 char line[RETROFONT_LINE_SZ];
161 char* line_bytes = NULL;
164 maug_mzero( font_stub_name,
sizeof(
maug_path ) );
166 font_stub_name[strlen( font_stub_name ) - 5] =
'x';
167 debug_printf( RETROFONT_TRACE_LVL,
"stub font_name: %s", font_stub_name );
168 maug_mzero( &font_file,
sizeof(
mfile_t ) );
171 maug_cleanup_if_not_ok();
175 retval = retrofont_read_line( &font_file, line, &line_bytes );
176 if( MERROR_WAIT == retval || MERROR_OK == retval ) {
178 retval = MERROR_PARSE;
181 }
else if( MERROR_PARSE != retval ) {
184 debug_printf( RETROFONT_TRACE_LVL,
"attempting substitute: %s",
186 retval = try_platform( font, line_bytes, try_platform_data );
187 }
while( MERROR_PARSE == retval );
198size_t retrofont_sz_from_filename(
const char* font_name ) {
199 const char* p_c = NULL;
202 char glyph_h_buf[10];
204 maug_mzero( glyph_h_buf, 10 );
206 assert( NULL != font_name );
207 assert(
' ' <= font_name[0] );
209 p_c = maug_strrchr( font_name,
'.' );
210 while( p_c - 1 > font_name ) {
213 if(
'-' == *p_c ||
'_' == *p_c ) {
220 for( i = 9 ; 0 < i ; i-- ) {
221 glyph_h_buf[i] = glyph_h_buf[i - 1];
225 glyph_h_buf[0] = *p_c;
228 glyph_h = maug_atou32( glyph_h_buf, 9, 10 );
231 RETROFONT_TRACE_LVL,
"detected glyph height: " SIZE_T_FMT, glyph_h );
240 const char* str,
size_t str_sz,
244 retrofont_string_indent(
245 target, color, str, str_sz, font_h, x, y, max_w, max_h, 0, flags );
uint16_t MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition: merror.h:28
MERROR_RETVAL mfile_open_read(const maug_path filename, mfile_t *p_file)
Open a file and read it into memory or memory-map it.
void mfile_close(mfile_t *p_file)
Close a file opened with mfile_open_read().
MERROR_RETVAL mfile_assign_path(maug_path tgt, const maug_path src, uint8_t flags)
Copy a maug_path from one place to another, safely observing character limits, etc.
char maug_path[MAUG_PATH_SZ_MAX]
Path/name used to load an asset from disk or access other files.
Definition: mfile.h:141
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition: retroflt.h:326
int16_t retroflat_pxxy_t
Type used for surface pixel coordinates.
Definition: retroflt.h:879
MERROR_RETVAL(* retrofont_try_platform_t)(struct RETROFONT *font, const char *sub_name, void *data)
Callback for platform-specific font substitute loader to attempt to use font substitute.
Definition: retrofnt.h:98
MERROR_RETVAL retrofont_load(const char *font_name, MAUG_MHANDLE *p_font_h, uint8_t glyph_h, uint16_t first_glyph, uint16_t glyphs_count)
Load a font for drawing.
void retrofont_string(retroflat_blit_t *target, RETROFLAT_COLOR color, const char *str, size_t str_sz, MAUG_MHANDLE font_h, retroflat_pxxy_t x, retroflat_pxxy_t y, retroflat_pxxy_t max_w, retroflat_pxxy_t max_h, uint8_t flags)
Draw a string with the given font.