refactor font.c into an MwFL section (#9)

Reviewed-on: https://gitea.nishi.boats/pyrite-dev/milsko/pulls/9
Co-authored-by: IoIxD <alphaproject217@gmail.com>
Co-committed-by: IoIxD <alphaproject217@gmail.com>
This commit is contained in:
IoIxD 2026-03-04 13:59:28 -06:00 committed by IoI_xD
commit e09eccbf5f
15 changed files with 489 additions and 416 deletions

12
BorMakefile generated
View file

@ -27,10 +27,6 @@ clean:
del /f /q src\dialog\messagebox.obj
del /f /q src\draw.obj
del /f /q src\error.obj
del /f /q src\font\boldfont.obj
del /f /q src\font\boldttf.obj
del /f /q src\font\font.obj
del /f /q src\font\ttf.obj
del /f /q src\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -49,7 +45,9 @@ clean:
del /f /q src\icon\warning.obj
del /f /q src\lowlevel.obj
del /f /q src\string.obj
del /f /q src\text.obj
del /f /q src\text\ft2.obj
del /f /q src\text\stbtt.obj
del /f /q src\text\text.obj
del /f /q src\unicode.obj
del /f /q src\widget\box.obj
del /f /q src\widget\button.obj
@ -74,8 +72,8 @@ clean:
del /f /q src\Mw.dll
del /f /q src\Mw.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) -e$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj -lopengl32.lib -lgdi32.lib -luser32.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) -e$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj -lopengl32.lib -lgdi32.lib -luser32.lib
implib src\Mw.lib src\Mw.dll
.c.obj:

View file

@ -23,7 +23,7 @@ option(MW_INSTALL_HEADERS "Install headers" ON)
file(
GLOB
SOURCES
src/*.c src/cursor/*.c src/icon/*.c src/text.c src/widget/*.c src/math/*.c src/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
src/*.c src/cursor/*.c src/icon/*.c src/widget/*.c src/text/*.c src/text/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")

12
NTMakefile generated
View file

@ -27,10 +27,6 @@ clean:
del /f /q src\dialog\messagebox.obj
del /f /q src\draw.obj
del /f /q src\error.obj
del /f /q src\font\boldfont.obj
del /f /q src\font\boldttf.obj
del /f /q src\font\font.obj
del /f /q src\font\ttf.obj
del /f /q src\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -49,7 +45,9 @@ clean:
del /f /q src\icon\warning.obj
del /f /q src\lowlevel.obj
del /f /q src\string.obj
del /f /q src\text.obj
del /f /q src\text\ft2.obj
del /f /q src\text\stbtt.obj
del /f /q src\text\text.obj
del /f /q src\unicode.obj
del /f /q src\widget\box.obj
del /f /q src\widget\button.obj
@ -74,8 +72,8 @@ clean:
del /f /q src\Mw.dll
del /f /q src\Mw.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) /OUT:$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib user32.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) /OUT:$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib user32.lib
.c.obj:

26
WatMakefile generated
View file

@ -26,10 +26,6 @@ clean: .SYMBOLIC
%erase src/dialog/messagebox.obj
%erase src/draw.obj
%erase src/error.obj
%erase src/font/boldfont.obj
%erase src/font/boldttf.obj
%erase src/font/font.obj
%erase src/font/ttf.obj
%erase src/icon/back.obj
%erase src/icon/clock.obj
%erase src/icon/computer.obj
@ -48,7 +44,9 @@ clean: .SYMBOLIC
%erase src/icon/warning.obj
%erase src/lowlevel.obj
%erase src/string.obj
%erase src/text.obj
%erase src/text/ft2.obj
%erase src/text/stbtt.obj
%erase src/text/text.obj
%erase src/unicode.obj
%erase src/widget/box.obj
%erase src/widget/button.obj
@ -73,8 +71,8 @@ clean: .SYMBOLIC
%erase src/Mw.dll
%erase src/Mw.lib
src/Mw.dll: external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/cursor/arrow.obj src/cursor/cross.obj src/cursor/default.obj src/cursor/hidden.obj src/cursor/text.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/error.obj src/font/boldfont.obj src/font/boldttf.obj src/font/font.obj src/font/ttf.obj src/icon/back.obj src/icon/clock.obj src/icon/computer.obj src/icon/directory.obj src/icon/down.obj src/icon/error.obj src/icon/file.obj src/icon/forward.obj src/icon/info.obj src/icon/left.obj src/icon/news.obj src/icon/note.obj src/icon/right.obj src/icon/search.obj src/icon/up.obj src/icon/warning.obj src/lowlevel.obj src/string.obj src/text.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/opengl.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(LDFLAGS) option implib=src/Mw.lib name $@ file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/cursor/arrow.obj file src/cursor/cross.obj file src/cursor/default.obj file src/cursor/hidden.obj file src/cursor/text.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/error.obj file src/font/boldfont.obj file src/font/boldttf.obj file src/font/font.obj file src/font/ttf.obj file src/icon/back.obj file src/icon/clock.obj file src/icon/computer.obj file src/icon/directory.obj file src/icon/down.obj file src/icon/error.obj file src/icon/file.obj file src/icon/forward.obj file src/icon/info.obj file src/icon/left.obj file src/icon/news.obj file src/icon/note.obj file src/icon/right.obj file src/icon/search.obj file src/icon/up.obj file src/icon/warning.obj file src/lowlevel.obj file src/string.obj file src/text.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/opengl.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clib3r.lib library opengl32.lib library gdi32.lib library user32.lib
src/Mw.dll: external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/cursor/arrow.obj src/cursor/cross.obj src/cursor/default.obj src/cursor/hidden.obj src/cursor/text.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/error.obj src/icon/back.obj src/icon/clock.obj src/icon/computer.obj src/icon/directory.obj src/icon/down.obj src/icon/error.obj src/icon/file.obj src/icon/forward.obj src/icon/info.obj src/icon/left.obj src/icon/news.obj src/icon/note.obj src/icon/right.obj src/icon/search.obj src/icon/up.obj src/icon/warning.obj src/lowlevel.obj src/string.obj src/text/ft2.obj src/text/stbtt.obj src/text/text.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/opengl.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(LDFLAGS) option implib=src/Mw.lib name $@ file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/cursor/arrow.obj file src/cursor/cross.obj file src/cursor/default.obj file src/cursor/hidden.obj file src/cursor/text.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/error.obj file src/icon/back.obj file src/icon/clock.obj file src/icon/computer.obj file src/icon/directory.obj file src/icon/down.obj file src/icon/error.obj file src/icon/file.obj file src/icon/forward.obj file src/icon/info.obj file src/icon/left.obj file src/icon/news.obj file src/icon/note.obj file src/icon/right.obj file src/icon/search.obj file src/icon/up.obj file src/icon/warning.obj file src/lowlevel.obj file src/string.obj file src/text/ft2.obj file src/text/stbtt.obj file src/text/text.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/opengl.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clib3r.lib library opengl32.lib library gdi32.lib library user32.lib
@ -120,14 +118,6 @@ src/draw.obj: src/draw.c
$(CC) $(CFLAGS) -fo=$@ $<
src/error.obj: src/error.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/boldfont.obj: src/font/boldfont.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/boldttf.obj: src/font/boldttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/font.obj: src/font/font.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/ttf.obj: src/font/ttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/icon/back.obj: src/icon/back.c
$(CC) $(CFLAGS) -fo=$@ $<
src/icon/clock.obj: src/icon/clock.c
@ -164,7 +154,11 @@ src/lowlevel.obj: src/lowlevel.c
$(CC) $(CFLAGS) -fo=$@ $<
src/string.obj: src/string.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text.obj: src/text.c
src/text/ft2.obj: src/text/ft2.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/stbtt.obj: src/text/stbtt.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/text.obj: src/text/text.c
$(CC) $(CFLAGS) -fo=$@ $<
src/unicode.obj: src/unicode.c
$(CC) $(CFLAGS) -fo=$@ $<

View file

@ -18,10 +18,12 @@ typedef struct _MwLLCommonPixmap* MwLLCommonPixmap;
typedef union _MwLL* MwLL;
typedef union _MwLLColor* MwLLColor;
typedef union _MwLLPixmap* MwLLPixmap;
typedef struct _MwFLFont* MwFLFont;
#else
typedef void* MwLL;
typedef void* MwLLColor;
typedef void* MwLLPixmap;
typedef void* MwFLFont;
#endif
enum MwLLBackends {
@ -166,6 +168,14 @@ struct _MwLLHandler {
void (*dark_theme)(MwLL handle, void* data);
};
struct _MwLLTextDispatchTable {
int (*drawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
int (*textWidth)(MwWidget handle, const char* text);
int (*textHeight)(MwWidget handle, int count);
void* (*fontLoad)(unsigned char* data, unsigned int size);
void (*fontFree)(void* handle);
};
#ifdef __cplusplus
extern "C" {
#endif
@ -225,6 +235,22 @@ MWDECL void (*MwLLGetClipboard)(MwLL handle);
MWDECL void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
MWDECL void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
/*font renderer */
MWDECL void MwFLSetup();
#ifdef USE_FREETYPE2
MWDECL int MWFL_FT2Setup();
#endif
#ifdef USE_STB_TRUETYPE
MWDECL int MwFL_STBTTSetup();
#endif
MWDECL int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwWidget handle, const char* text);
MWDECL int (*MwFLTextHeight)(MwWidget handle, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size);
MWDECL void (*MwFLFontFree)(void* handle);
#ifdef __cplusplus
}
#endif

View file

@ -76,8 +76,9 @@ if (param_get("vulkan") && param_get("vulkan-string-helper")) {
}
new_object("src/icon/*.c");
new_object("src/font/*.c");
new_object("src/cursor/*.c");
new_object("src/text/*.c");
new_object("src/text/font/*.c");
new_object("src/widget/box.c");
new_object("src/widget/button.c");

View file

@ -784,6 +784,8 @@ int MwLibraryInit(void) {
NULL};
int i;
MwFLSetup();
for(i = 0; calls[i] != NULL; i++) {
if(calls[i]() == 0) return 0;
}

View file

@ -1,384 +0,0 @@
#include <Mw/Milsko.h>
#if defined(USE_FREETYPE2)
#include <ft2build.h>
#include FT_FREETYPE_H
typedef struct ttf {
FT_Library library;
FT_Face face;
void* data;
} ttf_t;
#define TTF
#elif defined(USE_STB_TRUETYPE)
#include "../external/stb_truetype.h"
typedef struct ttf {
stbtt_fontinfo font;
void* data;
float scale;
int ascent;
int descent;
} ttf_t;
#define TTF
#endif
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
int i = 0, x, y, sx, sy;
int tw, th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
sx = 0;
sy = 0;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out > 0xff) {
out = 0;
}
if(out == '\n') {
sx = 0;
sy += FontHeight;
} else {
for(y = 0; y < FontHeight; y++) {
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->common.red;
ppx[1] = color->common.green;
ppx[2] = color->common.blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
ppx[1] = 0;
ppx[2] = 0;
ppx[3] = 0;
}
}
}
sx += FontWidth;
}
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
}
#if defined(USE_STB_TRUETYPE)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
int x0, y0, x1, y1, cx, cy;
int ow, oh;
unsigned char* out;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
x = 0;
y += (ttf->ascent - ttf->descent) * ttf->scale;
continue;
}
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
ow = x1 - x0;
oh = y1 - y0;
out = malloc(ow * oh);
stbtt_MakeCodepointBitmap(&ttf->font, out, ow, oh, ow, ttf->scale, ttf->scale, c);
for(cy = 0; cy < oh; cy++) {
for(cx = 0; cx < ow; cx++) {
int ox = x + (lsb * ttf->scale) + cx;
int oy = y + (ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = out[cy * ow + cx];
}
}
x += ax * ttf->scale;
free(out);
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
text += MwUTF8ToUTF32(text, &c);
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
tw += ax * ttf->scale;
}
return tw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->ascent - ttf->descent) * ttf->scale * count;
}
#elif defined(USE_FREETYPE2)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
FT_Bitmap* bmp;
int cy, cx;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
x = 0;
y += ttf->face->height * 14 / ttf->face->units_per_EM;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
bmp = &ttf->face->glyph->bitmap;
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * 14 / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}
x += ttf->face->glyph->metrics.horiAdvance / 64;
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int tw = 0, mtw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
tw = 0;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
tw += ttf->face->glyph->metrics.horiAdvance / 64;
if(tw > mtw) mtw = tw;
}
return mtw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
}
#endif
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
if(strlen(text) == 0) return;
#ifdef TTF
if(MwGetInteger(handle, MwNbitmapFont) || ttf_MwDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, color);
}
int MwTextWidth(MwWidget handle, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if(!MwGetInteger(handle, MwNbitmapFont) && (st = ttf_MwTextWidth(handle, text)) != -1) return st;
#else
(void)handle;
#endif
return MwUTF8Length(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
(void)handle;
(void)text;
while(text[i] != 0) {
int out;
int l = MwUTF8ToUTF32(text + i, &out);
if(l == 0) break;
i += l;
if(out == '\n') c++;
}
#ifdef TTF
if(!MwGetInteger(handle, MwNbitmapFont) && (st = ttf_MwTextHeight(handle, c)) != -1) return st;
#endif
return FontHeight * c;
}
void* MwFontLoad(unsigned char* data, unsigned int size) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
FT_Init_FreeType(&ttf->library);
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
return ttf;
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForPixelHeight(&ttf->font, 16);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;
#else
(void)data;
(void)size;
return NULL;
#endif
}
void MwFontFree(void* handle) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = handle;
FT_Done_Face(ttf->face);
FT_Done_FreeType(ttf->library);
free(ttf->data);
free(ttf);
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = handle;
free(ttf->data);
free(ttf);
#else
(void)handle;
#endif
}

139
src/text/ft2.c Normal file
View file

@ -0,0 +1,139 @@
#ifdef USE_FREETYPE2
#include <Mw/Milsko.h>
#include <ft2build.h>
#include FT_FREETYPE_H
struct _MwFLFont {
FT_Library library;
FT_Face face;
void* data;
};
static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
FT_Bitmap* bmp;
int cy, cx;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
x = 0;
y += ttf->face->height * 14 / ttf->face->units_per_EM;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
bmp = &ttf->face->glyph->bitmap;
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * 14 / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}
x += ttf->face->glyph->metrics.horiAdvance / 64;
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ft2_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
int tw = 0, mtw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
tw = 0;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
tw += ttf->face->glyph->metrics.horiAdvance / 64;
if(tw > mtw) mtw = tw;
}
return mtw;
}
static int ft2_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
}
static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
FT_Init_FreeType(&ttf->library);
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
return ttf;
}
static void ft2_MwFontFree(void* handle) {
MwFLFont ttf = handle;
FT_Done_Face(ttf->face);
FT_Done_FreeType(ttf->library);
free(ttf->data);
free(ttf);
}
int MWFL_FT2Setup() {
MwFLDrawText = ft2_MwDrawText;
MwFLTextWidth = ft2_MwTextWidth;
MwFLTextHeight = ft2_MwTextHeight;
MwFLFontLoad = ft2_MwFontLoad;
MwFLFontFree = ft2_MwFontFree;
return 0;
}
#endif

141
src/text/stbtt.c Normal file
View file

@ -0,0 +1,141 @@
#ifdef USE_STB_TRUETYPE
#include <stdlib.h>
#include <Mw/Milsko.h>
#include "../../external/stb_truetype.h"
struct _MwFLFont {
stbtt_fontinfo font;
void* data;
float scale;
int ascent;
int descent;
};
static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
int x0, y0, x1, y1, cx, cy;
int ow, oh;
unsigned char* out;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
x = 0;
y += (ttf->ascent - ttf->descent) * ttf->scale;
continue;
}
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
ow = x1 - x0;
oh = y1 - y0;
out = malloc(ow * oh);
stbtt_MakeCodepointBitmap(&ttf->font, out, ow, oh, ow, ttf->scale, ttf->scale, c);
for(cy = 0; cy < oh; cy++) {
for(cx = 0; cx < ow; cx++) {
int ox = x + (lsb * ttf->scale) + cx;
int oy = y + (ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = out[cy * ow + cx];
}
}
x += ax * ttf->scale;
free(out);
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int stbtt_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
text += MwUTF8ToUTF32(text, &c);
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
tw += ax * ttf->scale;
}
return tw;
}
static int stbtt_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->ascent - ttf->descent) * ttf->scale * count;
}
static void* stbtt_MwFontLoad(unsigned char* data, unsigned int size) {
MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForPixelHeight(&ttf->font, 16);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;
}
static void stbtt_MwFontFree(void* handle) {
MwFLFont ttf = handle;
free(ttf->data);
free(ttf);
}
int MwFL_STBTTSetup() {
MwFLDrawText = stbtt_MwDrawText;
MwFLTextWidth = stbtt_MwTextWidth;
MwFLTextHeight = stbtt_MwTextHeight;
MwFLFontLoad = stbtt_MwFontLoad;
MwFLFontFree = stbtt_MwFontFree;
return 0;
}
#endif

158
src/text/text.c Normal file
View file

@ -0,0 +1,158 @@
#include <Mw/Milsko.h>
int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwWidget handle, const char* text) = NULL;
int (*MwFLTextHeight)(MwWidget handle, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size) = NULL;
void (*MwFLFontFree)(void* handle) = NULL;
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)
#define TTF
#endif
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
if(strlen(text) == 0) return;
#ifdef TTF
if(MwFLDrawText)
if(MwGetInteger(handle, MwNbitmapFont) || MwFLDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, color);
}
int MwTextWidth(MwWidget handle, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if(MwFLTextWidth)
if(!MwGetInteger(handle, MwNbitmapFont) && (st = MwFLTextWidth(handle, text)) != -1) return st;
#else
(void)handle;
#endif
return MwUTF8Length(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
(void)handle;
(void)text;
while(text[i] != 0) {
int out;
int l = MwUTF8ToUTF32(text + i, &out);
if(l == 0) break;
i += l;
if(out == '\n') c++;
}
#ifdef TTF
if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && (st = MwFLTextHeight(handle, c)) != -1) return st;
#endif
return FontHeight * c;
}
void* MwFontLoad(unsigned char* data, unsigned int size) {
if(MwFLFontLoad)
return MwFLFontLoad(data, size);
return NULL;
}
void MwFontFree(void* handle) {
if(MwFLFontFree)
return MwFLFontFree(handle);
}
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
int i = 0, x, y, sx, sy;
int tw, th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
sx = 0;
sy = 0;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out > 0xff) {
out = 0;
}
if(out == '\n') {
sx = 0;
sy += FontHeight;
} else {
for(y = 0; y < FontHeight; y++) {
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->common.red;
ppx[1] = color->common.green;
ppx[2] = color->common.blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
ppx[1] = 0;
ppx[2] = 0;
ppx[3] = 0;
}
}
}
sx += FontWidth;
}
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
}
typedef int (*call_t)();
void MwFLSetup() {
call_t calls[] = {
#ifdef USE_FREETYPE2
MWFL_FT2Setup,
#endif
#ifdef USE_STB_TRUETYPE
MwFL_STBTTSetup,
#endif
NULL};
int i;
for(i = 0; calls[i] != NULL; i++) {
if(calls[i]() == 0) return;
}
}