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
41 const char* font_name, MAUG_MHANDLE* p_font_h,
42 uint8_t glyph_h, uint16_t first_glyph, uint16_t glyphs_count );
55 const char* str,
size_t str_sz,
56 MAUG_MHANDLE font_h,
size_t x,
size_t y,
57 size_t max_w,
size_t max_h, uint8_t flags );
60 retroflat_blit_t* target,
const char* str,
size_t str_sz,
64void retrofont_free( MAUG_MHANDLE* p_font_h );
71 struct RETROFONT* font,
const char* sub_name,
void* data );
78 mfile_t* font_file,
char* glyph_idx_str,
char** p_glyph_bytes
81 size_t last_char_idx = 0;
83 retval = font_file->read_line(
84 font_file, glyph_idx_str, RETROFONT_LINE_SZ, 0 );
85 maug_cleanup_if_not_ok();
87 *p_glyph_bytes = maug_strchr( glyph_idx_str,
':' );
88 if( NULL == *p_glyph_bytes ) { \
89 error_printf(
"invalid line: %s", glyph_idx_str );
99 (*p_glyph_bytes)[0] =
'\0'; \
103 if( 0 == strncmp(
"SUB", glyph_idx_str, 3 ) ) {
104 last_char_idx = maug_strlen( *p_glyph_bytes ) - 1;
106 '\n' == (*p_glyph_bytes)[last_char_idx] ||
107 '\r' == (*p_glyph_bytes)[last_char_idx] ||
108 '\t' == (*p_glyph_bytes)[last_char_idx] ||
109 ' ' == (*p_glyph_bytes)[last_char_idx]
111 (*p_glyph_bytes)[last_char_idx] =
'\0';
113 debug_printf( RETROFONT_TRACE_LVL,
"found sub: \"%s\"", *p_glyph_bytes );
114 retval = MERROR_PARSE;
125 const char* font_name,
struct RETROFONT* font,
127 void* try_platform_data
132 char line[RETROFONT_LINE_SZ];
133 char* line_bytes = NULL;
137 mfile_assign_path( font_stub_name, font_name, 0 );
138 font_stub_name[strlen( font_stub_name ) - 5] =
'x';
139 debug_printf( RETROFONT_TRACE_LVL,
"stub font_name: %s", font_stub_name );
140 maug_mzero( &font_file,
sizeof( mfile_t ) );
143 maug_cleanup_if_not_ok();
147 retval = retrofont_read_line( &font_file, line, &line_bytes );
148 if( MERROR_WAIT == retval || MERROR_OK == retval ) {
150 retval = MERROR_PARSE;
153 }
else if( MERROR_PARSE != retval ) {
156 debug_printf( RETROFONT_TRACE_LVL,
"attempting substitute: %s",
158 retval = try_platform( font, line_bytes, try_platform_data );
159 }
while( MERROR_PARSE == retval );
170size_t retrofont_sz_from_filename(
const char* font_name ) {
171 const char* p_c = NULL;
174 char glyph_h_buf[10];
176 maug_mzero( glyph_h_buf, 10 );
178 assert( NULL != font_name );
179 assert(
' ' <= font_name[0] );
181 p_c = maug_strrchr( font_name,
'.' );
182 while( p_c - 1 > font_name ) {
185 if(
'-' == *p_c ||
'_' == *p_c ) {
192 for( i = 9 ; 0 < i ; i-- ) {
193 glyph_h_buf[i] = glyph_h_buf[i - 1];
197 glyph_h_buf[0] = *p_c;
200 glyph_h = atoi( glyph_h_buf );
203 RETROFONT_TRACE_LVL,
"detected glyph height: " SIZE_T_FMT, glyph_h );
int 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:103
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:70
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.