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
33#define RETROFONT_FLAG_OUTLINE 0x04
39#define RETROFONT_FLAG_SZ_MIN 0x08
55 const char* font_name, MAUG_MHANDLE* p_font_h,
56 uint8_t glyph_h, uint16_t first_glyph, uint16_t glyphs_count );
69 const char* str,
size_t str_sz,
70 MAUG_MHANDLE font_h,
size_t x,
size_t y,
71 size_t max_w,
size_t max_h, uint8_t flags );
73void retrofont_string_indent(
75 const char* str,
size_t str_sz,
76 MAUG_MHANDLE font_h,
size_t x,
size_t y,
77 size_t max_w,
size_t max_h,
size_t x_iter, uint8_t flags );
80 retroflat_blit_t* target,
const char* str,
size_t str_sz,
84void retrofont_free( MAUG_MHANDLE* p_font_h );
91 struct RETROFONT* font,
const char* sub_name,
void* data );
98 mfile_t* font_file,
char* glyph_idx_str,
char** p_glyph_bytes
101 size_t last_char_idx = 0;
103 retval = font_file->read_line(
104 font_file, glyph_idx_str, RETROFONT_LINE_SZ, 0 );
105 maug_cleanup_if_not_ok();
107 *p_glyph_bytes = maug_strchr( glyph_idx_str,
':' );
108 if( NULL == *p_glyph_bytes ) { \
109 error_printf(
"invalid line: %s", glyph_idx_str );
113 retval = MERROR_WAIT;
119 (*p_glyph_bytes)[0] =
'\0'; \
123 if( 0 == strncmp(
"SUB", glyph_idx_str, 3 ) ) {
124 last_char_idx = maug_strlen( *p_glyph_bytes ) - 1;
126 '\n' == (*p_glyph_bytes)[last_char_idx] ||
127 '\r' == (*p_glyph_bytes)[last_char_idx] ||
128 '\t' == (*p_glyph_bytes)[last_char_idx] ||
129 ' ' == (*p_glyph_bytes)[last_char_idx]
131 (*p_glyph_bytes)[last_char_idx] =
'\0';
133 debug_printf( RETROFONT_TRACE_LVL,
"found sub: \"%s\"", *p_glyph_bytes );
134 retval = MERROR_PARSE;
145 const char* font_name,
struct RETROFONT* font,
147 void* try_platform_data
152 char line[RETROFONT_LINE_SZ];
153 char* line_bytes = NULL;
157 mfile_assign_path( font_stub_name, font_name, 0 );
158 font_stub_name[strlen( font_stub_name ) - 5] =
'x';
159 debug_printf( RETROFONT_TRACE_LVL,
"stub font_name: %s", font_stub_name );
160 maug_mzero( &font_file,
sizeof( mfile_t ) );
163 maug_cleanup_if_not_ok();
167 retval = retrofont_read_line( &font_file, line, &line_bytes );
168 if( MERROR_WAIT == retval || MERROR_OK == retval ) {
170 retval = MERROR_PARSE;
173 }
else if( MERROR_PARSE != retval ) {
176 debug_printf( RETROFONT_TRACE_LVL,
"attempting substitute: %s",
178 retval = try_platform( font, line_bytes, try_platform_data );
179 }
while( MERROR_PARSE == retval );
190size_t retrofont_sz_from_filename(
const char* font_name ) {
191 const char* p_c = NULL;
194 char glyph_h_buf[10];
196 maug_mzero( glyph_h_buf, 10 );
198 assert( NULL != font_name );
199 assert(
' ' <= font_name[0] );
201 p_c = maug_strrchr( font_name,
'.' );
202 while( p_c - 1 > font_name ) {
205 if(
'-' == *p_c ||
'_' == *p_c ) {
212 for( i = 9 ; 0 < i ; i-- ) {
213 glyph_h_buf[i] = glyph_h_buf[i - 1];
217 glyph_h_buf[0] = *p_c;
220 glyph_h = atoi( glyph_h_buf );
223 RETROFONT_TRACE_LVL,
"detected glyph height: " SIZE_T_FMT, glyph_h );
232 const char* str,
size_t str_sz,
233 MAUG_MHANDLE font_h,
size_t x,
size_t y,
234 size_t max_w,
size_t max_h, uint8_t flags
236 retrofont_string_indent(
237 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:19
MERROR_RETVAL mfile_open_read(const char *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().
char retroflat_asset_path[MAUG_PATH_SZ_MAX+1]
Path/name used to load an asset from disk.
Definition mfile.h:129
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:325
size_t retroflat_pxxy_t
Type used for surface pixel coordinates.
Definition retroflt.h:870
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:90
void retrofont_string(retroflat_blit_t *target, RETROFLAT_COLOR color, const char *str, size_t str_sz, MAUG_MHANDLE font_h, size_t x, size_t y, size_t max_w, size_t max_h, uint8_t flags)
Draw a string with the given font.
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.