Skip to content

Commit c6e3860

Browse files
committed
Add fontlib_LoadFont to replace fontlib_SetFont
1 parent dcddaae commit c6e3860

3 files changed

Lines changed: 50 additions & 25 deletions

File tree

src/fontlibc/fontlibc.asm

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include '../include/library.inc'
33
include '../include/include_library.inc'
44
;-------------------------------------------------------------------------------
55

6-
library FONTLIBC,2
6+
library FONTLIBC,3
77

88
;-------------------------------------------------------------------------------
99
; Dependencies
@@ -23,7 +23,7 @@ include_library '../graphx/graphx.asm'
2323
export fontlib_GetCursorX
2424
export fontlib_GetCursorY
2525
export fontlib_ShiftCursorPosition
26-
export fontlib_SetFont
26+
export fontlib_Deprecated
2727
export fontlib_SetForegroundColor
2828
export fontlib_SetBackgroundColor
2929
export fontlib_SetColors
@@ -78,7 +78,11 @@ include_library '../graphx/graphx.asm'
7878
export fontlib_ScrollWindowUp
7979
export fontlib_Home
8080
export fontlib_HomeUp
81-
81+
;-------------------------------------------------------------------------------
82+
; v3 functions
83+
;-------------------------------------------------------------------------------
84+
; replacement for fontlib_SetFont
85+
export fontlib_LoadFont
8286

8387
;-------------------------------------------------------------------------------
8488
CurrentBuffer := ti.mpLcdLpbase
@@ -140,6 +144,11 @@ virtual at 0
140144
strucFontPackHeader strucFontPackHeader
141145
end virtual
142146

147+
;-------------------------------------------------------------------------------
148+
; fontlib_load_options_t
149+
150+
bLoadOption_IgnoreLineSpacing := 0
151+
mLoadOption_IgnoreLineSpacing := 1 shl bLoadOption_IgnoreLineSpacing
143152

144153
;-------------------------------------------------------------------------------
145154
macro mIsHLLessThanDE?
@@ -404,7 +413,19 @@ fontlib_Home:
404413

405414

406415
;-------------------------------------------------------------------------------
407-
fontlib_SetFont:
416+
fontlib_Deprecated:
417+
; formerly fontlib_SetFont
418+
; performs fontlib_LoadFont(font_data, FONTLIB_IGNORE_LINE_SPACING)
419+
ld hl,arg1
420+
add hl,sp
421+
ld bc,mLoadOption_IgnoreLineSpacing
422+
ld (hl),bc
423+
424+
; Fall through to fontlib_LoadFont
425+
assert $ = fontlib_LoadFont
426+
427+
;-------------------------------------------------------------------------------
428+
fontlib_LoadFont:
408429
; Sets the current font to the data at the pointer given
409430
; Arguments:
410431
; arg0: Pointer to font
@@ -435,12 +456,12 @@ fontlib_SetFont:
435456
or a,a
436457
ret z ; Also unreasonable: a zero-height font
437458
and a,$80
438-
jr nz,.false
459+
jr nz,.failure
439460
ld a,63
440461
cp a,(iy + strucFont.spaceAbove)
441-
jr c,.false
462+
jr c,.failure
442463
cp a,(iy + strucFont.spaceBelow)
443-
jr c,.false
464+
jr c,.failure
444465
.validateOffsets:
445466
; Now convert offsets into actual pointers
446467
; Validate that offset is at least semi-reasonable
@@ -459,21 +480,20 @@ fontlib_SetFont:
459480
add hl,bc
460481
ld (iy + strucFont.bitmapsTablePtr),hl
461482
; Check for the ignore line spacing flag
462-
; Due to a bug, flags must be ignored, and treated as FONTLIB_IGNORE_LINE_SPACING
463-
; ld hl,arg1
464-
; add hl,sp
465-
; ld a,(hl)
466-
; or a,a
467-
; jr z,.true
483+
ld hl,arg1
484+
add hl,sp
485+
bit bLoadOption_IgnoreLineSpacing,(hl)
486+
jr z,.finish_load
468487
lea hl,iy + strucFont.spaceAbove
469488
xor a,a
470489
ld (hl),a
471490
inc hl
472491
ld (hl),a
473-
.true:
492+
.finish_load:
474493
ld a,1
475494
ret
476-
.false:
495+
496+
.failure:
477497
xor a,a
478498
ret
479499

src/fontlibc/fontlibc.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ typedef enum {
4949
} fontlib_newline_options_t;
5050

5151
/**
52-
* @warning Flags are currently ignored due to a bug, and treated as FONTLIB_IGNORE_LINE_SPACING
5352
* Options for controlling how SetFont functions.
54-
* @see fontlib_SetFont
53+
* @see fontlib_LoadFont
5554
*/
5655
typedef enum {
5756
/**
@@ -162,7 +161,7 @@ typedef struct fontlib_metadata_t {
162161
* unsigned char baseline;
163162
* fontlib_font_t *my_font = fontlib_GetFontByStyle("FONTPACK", 12, 12,
164163
* FONTLIB_NORMAL, FONTLIB_NORMAL, FONTLIB_SERIF, 0);
165-
* if (!my_font || !fontlib_SetFont(my_font))
164+
* if (!my_font || !fontlib_LoadFont(my_font, 0))
166165
* return;
167166
* baseline = my_font->baseline_height;
168167
* @endcode
@@ -382,16 +381,22 @@ void fontlib_HomeUp();
382381
*/
383382
void fontlib_Home();
384383

384+
/**
385+
* @warning fontlib_SetFont is deprecated, use fontlib_LoadFont instead
386+
*/
387+
bool fontlib_Deprecated(const fontlib_font_t *font_data, fontlib_load_options_t flags);
388+
389+
#define fontlib_SetFont _Pragma("GCC warning \"'fontlib_SetFont' is deprecated, use 'fontlib_LoadFont' instead\"") fontlib_Deprecated
390+
385391
/**
386392
* Sets the current font
387393
* @param[in] font_data Pointer to font data
388-
* @param[in] Unused and treated as FONTLIB_IGNORE_LINE_SPACING
394+
* @param[in] flags Information about how to process the font
389395
* @return Returns false if the font seems invalid for any reason
390396
* @warning If false is returned, no valid font is currently loaded and trying
391-
* @note Flags are currently ignored due to a bug, and treated as FONTLIB_IGNORE_LINE_SPACING
392397
* to print will print garbage!
393398
*/
394-
bool fontlib_SetFont(const fontlib_font_t *font_data, fontlib_load_options_t flags);
399+
bool fontlib_LoadFont(const fontlib_font_t *font_data, fontlib_load_options_t flags);
395400

396401
/**
397402
* Sets the current foreground color FontLibC will use for drawing.

test/fontlibc/glyph_width/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
int run_tests(void) {
1616

1717
/* 256 glyph test */
18-
fontlib_SetFont(test_font, 0);
18+
fontlib_LoadFont(test_font, 0);
1919
C(fontlib_GetFirstGlyph() == 0);
2020
C(fontlib_GetTotalGlyphs() == 256);
2121
C(fontlib_GetTotalGlyphs() == 256);
@@ -27,7 +27,7 @@ int run_tests(void) {
2727
/* 255 glyph test */
2828
test_font->first_glyph = 1;
2929
test_font->total_glyphs = 255;
30-
fontlib_SetFont(test_font, 0);
30+
fontlib_LoadFont(test_font, 0);
3131
C(fontlib_GetFirstGlyph() == 1);
3232
C(fontlib_GetTotalGlyphs() == 255);
3333
C(fontlib_GetGlyphWidth(0) == 0);
@@ -39,7 +39,7 @@ int run_tests(void) {
3939
/* 128 glyph test */
4040
test_font->first_glyph = 0;
4141
test_font->total_glyphs = 128;
42-
fontlib_SetFont(test_font, 0);
42+
fontlib_LoadFont(test_font, 0);
4343
C(fontlib_GetFirstGlyph() == 0);
4444
C(fontlib_GetTotalGlyphs() == 128);
4545
for (unsigned i = 0; i <= 127; i++) {
@@ -54,7 +54,7 @@ int run_tests(void) {
5454
/* 64 glyph test */
5555
test_font->first_glyph = 32;
5656
test_font->total_glyphs = 64;
57-
fontlib_SetFont(test_font, 0);
57+
fontlib_LoadFont(test_font, 0);
5858
C(fontlib_GetFirstGlyph() == 32);
5959
C(fontlib_GetTotalGlyphs() == 64);
6060
for (unsigned i = 0; i <= 31; i++) {

0 commit comments

Comments
 (0)