ffinish
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit

This commit is contained in:
IoI_xD 2026-07-17 17:36:16 -07:00
commit 0b7e5ab901
6 changed files with 143 additions and 28 deletions

View file

@ -39,7 +39,14 @@ else()
endif() endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
option(MW_USE_DIRECTWRITE "Use DirectWrite" ON) # DirectWrite stuff can only be used on Win10+
if(${CMAKE_SYSTEM_VERSION} GREATER_EQUAL 10)
message(STATUS "DirectWrite support has been enabled")
option(MW_USE_DIRECTWRITE "Use DirectWrite" ON)
else()
message(WARNING "DirectWrite support has been disabled (must be compiling on Win10+)")
option(MW_USE_DIRECTWRITE "Use DirectWrite" OFF)
endif()
endif() endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) if(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)

26
configure vendored
View file

@ -2,6 +2,11 @@
our $target = `uname -s`; our $target = `uname -s`;
$target =~ s/\r?\n$//; $target =~ s/\r?\n$//;
# MSYS with MinGW gives us some other shit idk
if (index($target, "MINGW") != -1) {
$target = "Windows";
}
foreach my $l (@ARGV) { foreach my $l (@ARGV) {
if ($l =~ /^--.+$/) { if ($l =~ /^--.+$/) {
} }
@ -39,14 +44,12 @@ require("./pl/utils.pl");
param_set("classic-theme", 0); param_set("classic-theme", 0);
param_set("stb-image", 1); param_set("stb-image", 1);
param_set("xrender", 1);
param_set("opengl", 0); param_set("opengl", 0);
param_set("vulkan", 0); param_set("vulkan", 0);
param_set("vulkan-string-helper", 1); param_set("vulkan-string-helper", 1);
param_set("shared", 1); param_set("shared", 1);
param_set("static", 1); param_set("static", 1);
param_set("examples", 1); param_set("examples", 1);
param_set("dbus", 1);
# (option that only makes sense on x11) # (option that only makes sense on x11)
param_set("allow-sloppy-focus", 0); param_set("allow-sloppy-focus", 0);
@ -56,7 +59,8 @@ my %features = (
"stb-image" => "use stb_image, instead use libjpeg/libpng", "stb-image" => "use stb_image, instead use libjpeg/libpng",
"stb-truetype" => "use stb_truetype", "stb-truetype" => "use stb_truetype",
"freetype2" => "use FreeType2", "freetype2" => "use FreeType2",
"xrender" => "use XRender", "directwrite" => "(Windows only) use DirectWrite",
"xrender" => "(X11 only) use XRender",
"opengl" => "build OpenGL widget", "opengl" => "build OpenGL widget",
"vulkan" => "build Vulkan widget", "vulkan" => "build Vulkan widget",
"vulkan-string-helper" => "use Vulkan string helper", "vulkan-string-helper" => "use Vulkan string helper",
@ -69,7 +73,7 @@ my %features = (
); );
my @features_keys = ( my @features_keys = (
"1classic-theme", "1stb-image", "1classic-theme", "1stb-image",
"1stb-truetype", "1freetype2", "1stb-truetype", "1freetype2", "1directwrite",
"1opengl", "2xrender", "1opengl", "2xrender",
"1vulkan", "2vulkan-string-helper", "1vulkan", "2vulkan-string-helper",
"1shared", "1static", "1shared", "1static",
@ -87,13 +91,27 @@ sub def_platform {
} }
if($target eq "Linux" || $target eq "FreeBSD") { if($target eq "Linux" || $target eq "FreeBSD") {
param_set("x11", 1); param_set("x11", 1);
param_set("xrender", 1);
if(!param_get("tiny")){ if(!param_get("tiny")){
param_set("wayland", 1); param_set("wayland", 1);
} }
param_set("dbus", 1);
} }
if($target eq "NetBSD" || $target eq "OpenBSD") { if($target eq "NetBSD" || $target eq "OpenBSD") {
param_set("x11", 1); param_set("x11", 1);
} }
if($target eq "Windows") {
use Win32;
my ( $osvername, $major, $minor, $id ) = Win32::GetOSVersion();
if($major >= 10) {
param_set("directwrite", 1);
} else {
param_set("directwrite", 0);
}
} else {
param_set("directwrite", 0);
}
} }
foreach my $l (@ARGV) { foreach my $l (@ARGV) {

View file

@ -351,6 +351,7 @@ MWDECL int MWFL_DWSetup(void);
MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color); MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text); MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count); MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL int (*MwFLTextHeightWithText)(MwFLFont ttf, const char * text);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px); MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
MWDECL void (*MwFLFontFree)(void* handle); MWDECL void (*MwFLFontFree)(void* handle);

View file

@ -134,6 +134,10 @@ if (param_get("freetype2")) {
} }
} }
if (param_get("directwrite")) {
add_cflags("-DUSE_DIRECTWRITE");
}
if (param_get("vulkan") && param_get("vulkan-string-helper")) { if (param_get("vulkan") && param_get("vulkan-string-helper")) {
add_cflags("-DHAS_VK_ENUM_STRING_HELPER"); add_cflags("-DHAS_VK_ENUM_STRING_HELPER");
} }

View file

@ -22,9 +22,10 @@ typedef struct CustomTextRenderer {
LONG refCount; LONG refCount;
IDWriteFactory6 * write_factory; IDWriteFactory6 * write_factory;
IDWriteBitmapRenderTarget * target; IDWriteBitmapRenderTarget * target;
int red, blue, green;
} CustomTextRenderer; } CustomTextRenderer;
static CustomTextRenderer *CustomTextRenderer_Create(IDWriteFactory6 * write_factory, IDWriteBitmapRenderTarget * target); static CustomTextRenderer *CustomTextRenderer_Create(IDWriteFactory6 * write_factory, IDWriteBitmapRenderTarget * target, MwLLColor color);
static struct dw { static struct dw {
HMODULE d2d1_lib; HMODULE d2d1_lib;
@ -111,8 +112,6 @@ success:
CloseHandle(tempFile); CloseHandle(tempFile);
printf("unpacked ttf data %p into %ws\n",data, temp_path_name);
return 0; return 0;
} }
@ -197,9 +196,6 @@ static void* dw_MwFontLoad(unsigned char* data, unsigned int size, int px) {
goto fail; goto fail;
} }
ttf->valid = MwTRUE; ttf->valid = MwTRUE;
return ttf; return ttf;
@ -208,6 +204,8 @@ fail:
return ttf; return ttf;
} }
static int dw_MwTextOffset(MwFLFont ttf, const char* text) ;
static int dw_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) { static int dw_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
IDWriteTextLayout * text_layout; IDWriteTextLayout * text_layout;
@ -216,11 +214,13 @@ static int dw_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const ch
RECT rc = {0}; RECT rc = {0};
HDC memoryHDC = NULL; HDC memoryHDC = NULL;
DWRITE_FONT_METRICS metrics = {0}; DWRITE_FONT_METRICS metrics = {0};
LONG width = 0, height = 0; LONG width = 0, height = 0, offset = 0;
size_t wtext_len = strlen(text) * sizeof(UINT32); WCHAR* wtext = NULL;
WCHAR* wtext = malloc(wtext_len);
CustomTextRenderer * texRenderer; CustomTextRenderer * texRenderer;
size_t wtext_len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
wtext = malloc(wtext_len * 2); /* we get a weird buffer overflow when we try to free this later? allocate well above wtext_len then to prevent that. */
memset(wtext, 0, wtext_len * 2);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, wtext_len); MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, wtext_len);
IDWriteFontFace_GetMetrics(ttf->font_face, &metrics); IDWriteFontFace_GetMetrics(ttf->font_face, &metrics);
@ -228,37 +228,111 @@ static int dw_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const ch
GetClientRect(handle->lowlevel->gdi.hWnd, &rc); GetClientRect(handle->lowlevel->gdi.hWnd, &rc);
MapWindowPoints(handle->lowlevel->gdi.hWnd, GetParent(handle->lowlevel->gdi.hWnd), (LPPOINT)&rc, 2); MapWindowPoints(handle->lowlevel->gdi.hWnd, GetParent(handle->lowlevel->gdi.hWnd), (LPPOINT)&rc, 2);
width = rc.right - rc.left; width = MwTextWidth(handle,ttf, text);
height = rc.bottom - rc.top; height = MwTextHeight(handle, ttf, text);
offset = dw_MwTextOffset(ttf, text);
hr = IDWriteFactory_CreateTextLayout(ttf->write_factory, wtext, wtext_len, ttf->text_format, width, height, &text_layout); hr = IDWriteFactory_CreateTextLayout(ttf->write_factory, wtext, wtext_len, ttf->text_format, width, height, &text_layout);
IDWriteGdiInterop_CreateBitmapRenderTarget(ttf->gdiInterop, handle->lowlevel->gdi.hDC, width, height, &target); IDWriteGdiInterop_CreateBitmapRenderTarget(ttf->gdiInterop, handle->lowlevel->gdi.hDC, width, height, &target);
texRenderer = CustomTextRenderer_Create(ttf->write_factory, target); texRenderer = CustomTextRenderer_Create(ttf->write_factory, target, color);
IDWriteTextLayout_Draw(text_layout, target, (IDWriteTextRenderer*)texRenderer, point->x, point->y); memoryHDC = IDWriteBitmapRenderTarget_GetMemoryDC(target);
SetBkMode(handle->lowlevel->gdi.hDC, TRANSPARENT);
BitBlt(memoryHDC, 0, 0, width, height, handle->lowlevel->gdi.hDC, point->x, point->y - (height / 2), SRCCOPY);
if (SUCCEEDED(hr)) {
IDWriteTextLayout_Draw(text_layout, target, (IDWriteTextRenderer*)texRenderer, offset, 0);
}
BitBlt(handle->lowlevel->gdi.hDC, point->x, point->y - (height / 2), width, height, memoryHDC, 0, 0, SRCCOPY | NOMIRRORBITMAP);
IDWriteBitmapRenderTarget_Release(target); IDWriteBitmapRenderTarget_Release(target);
free(wtext);
return 0; return 0;
} }
static int dw_MwTextWidth(MwFLFont ttf, const char* text) { static int dw_MwTextOffset(MwFLFont ttf, const char* text) {
int tw = (ttf->px * strlen(text)) / 2; IDWriteTextLayout * text_layout;
DWRITE_FONT_METRICS metrics = {0};
WCHAR* wtext = NULL;
size_t wtext_len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
UINT32 * codepoints = malloc(wtext_len * sizeof(UINT32));
UINT16 * glyphIndices = malloc(wtext_len * sizeof(UINT16));
int i;
DWRITE_GLYPH_METRICS * gmetrics;
int tw = 0;
return tw + 1; wtext = malloc(wtext_len * 2); /* we get a weird buffer overflow when we try to free this later? allocate well above wtext_len then to prevent that. */
} memset(wtext, 0, wtext_len * 2);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, wtext_len);
static int dw_MwTextHeight(MwFLFont ttf, int count) { for(i = 0; i < wtext_len; i++) codepoints[i] = wtext[i];
DWRITE_FONT_METRICS metrics;
int height;
IDWriteFontFace_GetMetrics(ttf->font_face, &metrics); IDWriteFontFace_GetMetrics(ttf->font_face, &metrics);
height = ceil(((float)metrics.capHeight * ttf->px / metrics.designUnitsPerEm) * count) * 2; IDWriteFactory_CreateTextLayout(ttf->write_factory, wtext, wtext_len, ttf->text_format, 0, 0, &text_layout);
return height; IDWriteFontFace_GetGlyphIndices(ttf->font_face, codepoints, wtext_len, glyphIndices);
gmetrics = malloc(wtext_len * sizeof(DWRITE_GLYPH_METRICS));
IDWriteFontFace_GetDesignGlyphMetrics(ttf->font_face, glyphIndices, wtext_len, gmetrics, FALSE);
for(i = 0; i < strlen(text); i++) {
int add = (gmetrics[i].leftSideBearing) * ((float)ttf->px / (float)metrics.designUnitsPerEm);
tw += add;
}
free(wtext);
return tw;
}
static int dw_MwTextWidth(MwFLFont ttf, const char* text) {
IDWriteTextLayout * text_layout;
DWRITE_FONT_METRICS metrics = {0};
WCHAR* wtext = NULL;
size_t wtext_len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
UINT32 * codepoints = malloc(wtext_len * sizeof(UINT32));
UINT16 * glyphIndices = malloc(wtext_len * sizeof(UINT16));
int i;
DWRITE_GLYPH_METRICS * gmetrics;
int tw = 0;
wtext = malloc(wtext_len * 2); /* we get a weird buffer overflow when we try to free this later? allocate well above wtext_len then to prevent that. */
memset(wtext, 0, wtext_len * 2);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, wtext_len);
for(i = 0; i < wtext_len; i++) codepoints[i] = wtext[i];
IDWriteFontFace_GetMetrics(ttf->font_face, &metrics);
IDWriteFactory_CreateTextLayout(ttf->write_factory, wtext, wtext_len, ttf->text_format, 0, 0, &text_layout);
IDWriteFontFace_GetGlyphIndices(ttf->font_face, codepoints, wtext_len, glyphIndices);
gmetrics = malloc(wtext_len * sizeof(DWRITE_GLYPH_METRICS));
IDWriteFontFace_GetDesignGlyphMetrics(ttf->font_face, glyphIndices, wtext_len, gmetrics, FALSE);
for(i = 0; i < strlen(text); i++) {
int add = (gmetrics[i].advanceWidth + gmetrics[i].leftSideBearing) * ((float)ttf->px / (float)metrics.designUnitsPerEm);
tw += add;
}
free(wtext);
return tw;
}
static int dw_MwTextHeight(MwFLFont ttf, int count) {
(void)count;
return (IDWriteTextFormat2_GetFontSize(ttf->text_format) / 72.0f) * GetDeviceCaps(GetDC(NULL), LOGPIXELSY);
} }
@ -356,9 +430,13 @@ static HRESULT STDMETHODCALLTYPE CTR_DrawGlyphRun(
IDWriteRenderingParams *params; IDWriteRenderingParams *params;
CustomTextRenderer * This = (CustomTextRenderer*)iface; CustomTextRenderer * This = (CustomTextRenderer*)iface;
(void)clientDrawingContext;
(void)glyphRunDescription;
(void)clientDrawingEffect;
IDWriteFactory6_CreateRenderingParams(This->write_factory, &params); IDWriteFactory6_CreateRenderingParams(This->write_factory, &params);
return IDWriteBitmapRenderTarget_DrawGlyphRun(This->target, baselineOriginX, baselineOriginY, measuringMode, glyphRun, params, RGB(255,255,255), NULL); return IDWriteBitmapRenderTarget_DrawGlyphRun(This->target, baselineOriginX, baselineOriginY, measuringMode, glyphRun, params, RGB(This->red,This->green,This->blue), NULL);
} }
static HRESULT STDMETHODCALLTYPE CTR_DrawUnderline( static HRESULT STDMETHODCALLTYPE CTR_DrawUnderline(
@ -420,7 +498,7 @@ static IDWriteTextRendererVtbl CTR_Vtbl = {
/* ---- Constructor ---- */ /* ---- Constructor ---- */
static CustomTextRenderer *CustomTextRenderer_Create(IDWriteFactory6 * write_factory, IDWriteBitmapRenderTarget * target) static CustomTextRenderer *CustomTextRenderer_Create(IDWriteFactory6 * write_factory, IDWriteBitmapRenderTarget * target, MwLLColor color)
{ {
CustomTextRenderer *obj = CustomTextRenderer *obj =
(CustomTextRenderer *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (CustomTextRenderer *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
@ -432,6 +510,10 @@ static CustomTextRenderer *CustomTextRenderer_Create(IDWriteFactory6 * write_fac
obj->refCount = 1; obj->refCount = 1;
obj->write_factory = write_factory; obj->write_factory = write_factory;
obj->target = target; obj->target = target;
obj->red = color->common.red;
obj->green = color->common.green;
obj->blue = color->common.blue;
return obj; return obj;
} }

View file

@ -3,6 +3,7 @@
int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL; int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL; int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL;
int (*MwFLTextHeight)(MwFLFont font, int count) = NULL; int (*MwFLTextHeight)(MwFLFont font, int count) = NULL;
int (*MwFLTextHeightWithText)(MwFLFont ttf, const char * text) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px) = NULL; void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px) = NULL;
void (*MwFLFontFree)(void* handle) = NULL; void (*MwFLFontFree)(void* handle) = NULL;
@ -220,6 +221,8 @@ int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
#ifdef TTF #ifdef TTF
if(MwFLTextHeight) if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeight(ttf, c)) != -1) return st; if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeight(ttf, c)) != -1) return st;
if(MwFLTextHeightWithText)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeightWithText(ttf, text)) != -1) return st;
#endif #endif
return FontHeight * c; return FontHeight * c;
} }