Skip to content

Commit

Permalink
Merge pull request QB64-Phoenix-Edition#503 from a740g/font-kern-y-test
Browse files Browse the repository at this point in the history
Font fixes
  • Loading branch information
a740g committed Jun 6, 2024
2 parents 5fb0604 + 12c9bfa commit dae5749
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 194 deletions.
4 changes: 2 additions & 2 deletions internal/c/libqb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11413,7 +11413,7 @@ int32_t chrwidth(uint32_t character) {
// Custom font
// a740g: No need to render just to find the pixel length
if ((fontflags[f] & FONT_LOAD_UNICODE)) { // UNICODE character
w = FontPrintWidthUTF32(font[f], (uint32_t *)&character, 1);
w = FontPrintWidthUTF32(font[f], (char32_t *)&character, 1);
} else { // ASCII character
character &= 255;
w = FontPrintWidthASCII(font[f], (uint8_t *)&character, 1);
Expand Down Expand Up @@ -30354,7 +30354,7 @@ void display() {
render_option = 1;
if (rt_data_last)
free(rt_data_last);
ok = FontRenderTextUTF32(font[f], &chr_utf32, 1, render_option, &rt_data, &rt_w, &rt_h);
ok = FontRenderTextUTF32(font[f], (char32_t *)&chr_utf32, 1, render_option, &rt_data, &rt_w, &rt_h);
rt_data_last = rt_data;
cp2 = rt_data;
f_pitch = 0;
Expand Down
9 changes: 5 additions & 4 deletions internal/c/libqb/include/font.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------------------------------------------------------------------------------------------------------
// QB64-PE Font Library
// Powered by FreeType 2.4.12 (https://github.com/vinniefalco/FreeTypeAmalgam)
// Powered by FreeType (https://freetype.org/)
//----------------------------------------------------------------------------------------------------------------------

#pragma once
Expand Down Expand Up @@ -45,14 +45,15 @@ uint8_t *FontLoadFileToMemory(const char *file_path_name, int32_t *out_bytes);
int32_t FontLoad(const uint8_t *content_original, int32_t content_bytes, int32_t default_pixel_height, int32_t which_font, int32_t &options);
void FontFree(int32_t fh);
int32_t FontWidth(int32_t fh);
bool FontRenderTextUTF32(int32_t fh, const uint32_t *codepoint, int32_t codepoints, int32_t options, uint8_t **out_data, int32_t *out_x, int32_t *out_y);
bool FontRenderTextUTF32(int32_t fh, const char32_t *codepoint, int32_t codepoints, int32_t options, uint8_t **out_data, int32_t *out_x, int32_t *out_y);
bool FontRenderTextASCII(int32_t fh, const uint8_t *codepoint, int32_t codepoints, int32_t options, uint8_t **out_data, int32_t *out_x, int32_t *out_y);
int32_t FontPrintWidthUTF32(int32_t fh, const uint32_t *codepoint, int32_t codepoints);
int32_t FontPrintWidthUTF32(int32_t fh, const char32_t *codepoint, int32_t codepoints);
int32_t FontPrintWidthASCII(int32_t fh, const uint8_t *codepoint, int32_t codepoints);

qbs *func__md5(qbs *text);
int32_t func__UFontHeight(int32_t qb64_fh, int32_t passed);
int32_t func__UPrintWidth(const qbs *text, int32_t utf_encoding, int32_t qb64_fh, int32_t passed);
int32_t func__ULineSpacing(int32_t qb64_fh, int32_t passed);
void sub__UPrintString(int32_t start_x, int32_t start_y, const qbs *text, int32_t max_width, int32_t utf_encoding, int32_t qb64_fh, int32_t passed);
void sub__UPrintString(int32_t start_x, int32_t start_y, const qbs *text, int32_t max_width, int32_t utf_encoding, int32_t qb64_fh, int32_t dst_img,
int32_t passed);
int32_t func__UCharPos(const qbs *text, void *arr, int32_t utf_encoding, int32_t qb64_fh, int32_t passed);
292 changes: 127 additions & 165 deletions internal/c/parts/video/font/font.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/c/parts/video/font/stub_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int32_t FontWidth(int32_t fh) {
return 0;
}

bool FontRenderTextUTF32(int32_t fh, const uint32_t *codepoint, int32_t codepoints, int32_t options, uint8_t **out_data, int32_t *out_x, int32_t *out_y) {
bool FontRenderTextUTF32(int32_t fh, const char32_t *codepoint, int32_t codepoints, int32_t options, uint8_t **out_data, int32_t *out_x, int32_t *out_y) {
(void)fh;
(void)codepoint;
(void)codepoints;
Expand All @@ -46,7 +46,7 @@ bool FontRenderTextASCII(int32_t fh, const uint8_t *codepoint, int32_t codepoint
return 0;
}

int32_t FontPrintWidthUTF32(int32_t fh, const uint32_t *codepoint, int32_t codepoints) {
int32_t FontPrintWidthUTF32(int32_t fh, const char32_t *codepoint, int32_t codepoints) {
(void)fh;
(void)codepoint;
(void)codepoints;
Expand Down
8 changes: 4 additions & 4 deletions source/subs_functions/subs_functions.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,10 @@ id.n = qb64prefix$ + "UPrintString"
id.Dependency = DEPENDENCY_LOADFONT
id.subfunc = 2
id.callname = "sub__UPrintString"
id.args = 6
id.arg = MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER)
id.specialformat = "(?,?),?[,[?][,[?][,?]]]"
id.hr_syntax = "_UPRINTSTRING (x&, y&), text$[, maxWidth&][, utfEncoding&][, fontHandle&]"
id.args = 7
id.arg = MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER)
id.specialformat = "(?,?),?[,[?][,[?][,[?][,?]]]]"
id.hr_syntax = "_UPRINTSTRING (x&, y&), text$[, maxWidth&][, utfEncoding&][, fontHandle&][, imageHandle&]"
regid

clearid
Expand Down
2 changes: 1 addition & 1 deletion tests/compile_tests/filesystem/filesys_test.bas
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SYSTEM 1

FUNCTION CreateDummyFile$ (directory AS STRING, extension AS STRING)
DO
DIM fileName AS STRING: fileName = directory + LTRIM$(STR$(100! * (TIMER + RND))) + extension
DIM fileName AS STRING: fileName = directory + LTRIM$(STR$(INT(100! * (TIMER + RND)))) + extension
LOOP WHILE _FILEEXISTS(fileName)

DIM h AS LONG: h = FREEFILE
Expand Down
4 changes: 2 additions & 2 deletions tests/compile_tests/font/test.bas
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ SUB PrintFontDetails (handle AS LONG, testFileName AS STRING)
_DEST image
_FONT handle
COLOR _RGB32(255)
_UPRINTSTRING (0, 0), SAMPLE_TEXT_1
_UPRINTSTRING (0, uLineSpacing), SAMPLE_TEXT_2
_UPRINTSTRING (0, 0), SAMPLE_TEXT_1, , , handle
_UPRINTSTRING (0, uLineSpacing), SAMPLE_TEXT_2, , , , image
'_SAVEIMAGE testFileName + "u", image, TEST_IMAGE_FORMAT

_FONT 16
Expand Down
22 changes: 11 additions & 11 deletions tests/compile_tests/font/test.output
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Success, images are identical!
Loading font from memory (automono) ... done.
_FONTWIDTH = 0
_FONTHEIGHT = 22
_UFONTHEIGHT = 27
_ULINESPACING = 27
_UFONTHEIGHT = 28
_ULINESPACING = 28
_PRINTWIDTH = 1088
_UPRINTWIDTH = 1088
_UCHARPOS = 95
Expand All @@ -78,7 +78,7 @@ Loading font LiberationSans-Regular.ttf () ... done.
_FONTWIDTH = 0
_FONTHEIGHT = 12
_UFONTHEIGHT = 13
_ULINESPACING = 13
_ULINESPACING = 14
_PRINTWIDTH = 606
_UPRINTWIDTH = 606
_UCHARPOS = 95
Expand All @@ -89,7 +89,7 @@ Success, images are identical!
Loading font LiberationSans-Regular.ttf (monospace) ... done.
_FONTWIDTH = 15
_FONTHEIGHT = 16
_UFONTHEIGHT = 17
_UFONTHEIGHT = 18
_ULINESPACING = 18
_PRINTWIDTH = 1425
_UPRINTWIDTH = 1425
Expand All @@ -101,7 +101,7 @@ Success, images are identical!
Loading font LiberationSans-Regular.ttf (automono) ... done.
_FONTWIDTH = 0
_FONTHEIGHT = 22
_UFONTHEIGHT = 24
_UFONTHEIGHT = 25
_ULINESPACING = 25
_PRINTWIDTH = 1094
_UPRINTWIDTH = 1094
Expand All @@ -114,7 +114,7 @@ Loading font LiberationSerif-Regular.ttf () ... done.
_FONTWIDTH = 0
_FONTHEIGHT = 12
_UFONTHEIGHT = 13
_ULINESPACING = 13
_ULINESPACING = 14
_PRINTWIDTH = 583
_UPRINTWIDTH = 583
_UCHARPOS = 95
Expand All @@ -125,7 +125,7 @@ Success, images are identical!
Loading font LiberationSerif-Regular.ttf (monospace) ... done.
_FONTWIDTH = 15
_FONTHEIGHT = 16
_UFONTHEIGHT = 17
_UFONTHEIGHT = 18
_ULINESPACING = 18
_PRINTWIDTH = 1425
_UPRINTWIDTH = 1425
Expand All @@ -149,8 +149,8 @@ Success, images are identical!
Loading font LiberationMono-Regular.ttf () ... done.
_FONTWIDTH = 0
_FONTHEIGHT = 12
_UFONTHEIGHT = 13
_ULINESPACING = 13
_UFONTHEIGHT = 14
_ULINESPACING = 14
_PRINTWIDTH = 665
_UPRINTWIDTH = 665
_UCHARPOS = 95
Expand All @@ -173,8 +173,8 @@ Success, images are identical!
Loading font LiberationMono-Regular.ttf (automono) ... done.
_FONTWIDTH = 13
_FONTHEIGHT = 22
_UFONTHEIGHT = 24
_ULINESPACING = 24
_UFONTHEIGHT = 25
_ULINESPACING = 25
_PRINTWIDTH = 1235
_UPRINTWIDTH = 1235
_UCHARPOS = 95
Expand Down
Binary file modified tests/compile_tests/font/test06u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test07u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test08u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test09u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test10u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test11u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test13u.bmp
Binary file not shown.
Binary file modified tests/compile_tests/font/test15u.bmp
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/compile_tests/utilities/imageassert.bm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ SUB AssertImage2 (originalActualImage AS LONG, expectedFileName AS STRING)

DIM actual AS _MEM, expected AS _MEM

actual = _MEMIMAGE(actualImage)
expected = _MEMIMAGE(expectedImage)

IF _WIDTH(actualImage) <> _WIDTH(expectedImage) THEN
PRINT "Failure! Image width differs, actual:"; _WIDTH(actualImage); ", Expected:"; _WIDTH(expectedImage)
GOTO freeImages
Expand All @@ -158,9 +161,6 @@ SUB AssertImage2 (originalActualImage AS LONG, expectedFileName AS STRING)
GOTO freeImages
END IF

actual = _MEMIMAGE(actualImage)
expected = _MEMIMAGE(expectedImage)

IF actual.SIZE <> expected.SIZE THEN
PRINT "Failure! Image sizes differ, Actual:"; actual.SIZE; ", Expected:"; expected.SIZE
GOTO freeImages
Expand Down

0 comments on commit dae5749

Please sign in to comment.