DirectWrite support #28
12 changed files with 20963 additions and 15 deletions
commit
f938162899
|
|
@ -9,6 +9,7 @@ include(GNUInstallDirs)
|
||||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
|
||||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
option(MW_CLASSIC_THEME "Use classic theme" OFF)
|
option(MW_CLASSIC_THEME "Use classic theme" OFF)
|
||||||
option(MW_BUILD_EXAMPLES "Build examples" OFF)
|
option(MW_BUILD_EXAMPLES "Build examples" OFF)
|
||||||
|
|
@ -29,12 +30,18 @@ endif()
|
||||||
|
|
||||||
option(MW_INSTALL_HEADERS "Install headers" ON)
|
option(MW_INSTALL_HEADERS "Install headers" ON)
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin OR ${CMAKE_SYSTEM_NAME} MATCHES Retro)
|
if( ${CMAKE_SYSTEM_NAME} STREQUAL Darwin
|
||||||
|
OR ${CMAKE_SYSTEM_NAME} MATCHES Retro
|
||||||
|
OR ${CMAKE_SYSTEM_NAME} MATCHES Windows)
|
||||||
option(MW_USE_FREETYPE2 "Use FreeType 2" OFF)
|
option(MW_USE_FREETYPE2 "Use FreeType 2" OFF)
|
||||||
else()
|
else()
|
||||||
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
|
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
||||||
|
option(MW_USE_DIRECTWRITE "Use DirectWrite" ON)
|
||||||
|
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)
|
||||||
option(MW_USE_WAYLAND "Enable Wayland backend" ON)
|
option(MW_USE_WAYLAND "Enable Wayland backend" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -132,10 +139,10 @@ if(MW_USE_FREETYPE2)
|
||||||
if(Freetype_FOUND)
|
if(Freetype_FOUND)
|
||||||
message(STATUS "FreeType2 found")
|
message(STATUS "FreeType2 found")
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
Mw
|
Mw
|
||||||
PRIVATE
|
PRIVATE
|
||||||
USE_FREETYPE2
|
USE_FREETYPE2
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
|
list(APPEND INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
|
||||||
list(APPEND LIBRARY_DIRS ${FREETYPE_LIBRARY_DIRS})
|
list(APPEND LIBRARY_DIRS ${FREETYPE_LIBRARY_DIRS})
|
||||||
|
|
@ -144,6 +151,14 @@ if(MW_USE_FREETYPE2)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MW_USE_DIRECTWRITE)
|
||||||
|
target_compile_definitions(
|
||||||
|
Mw
|
||||||
|
PRIVATE
|
||||||
|
USE_DIRECTWRITE
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(MW_USE_WAYLAND)
|
if(MW_USE_WAYLAND)
|
||||||
function(scan_wayland_protocol_core)
|
function(scan_wayland_protocol_core)
|
||||||
execute_process(
|
execute_process(
|
||||||
|
|
|
||||||
4
WatMakefile
generated
4
WatMakefile
generated
|
|
@ -319,7 +319,7 @@ examples/gldemos/tripaint.obj: examples/gldemos/tripaint.c
|
||||||
|
|
||||||
src/Mw.dll: external/libz/src/adler32.obj external/libz/src/compress.obj external/libz/src/crc32.obj external/libz/src/deflate.obj external/libz/src/gzclose.obj external/libz/src/gzlib.obj external/libz/src/gzread.obj external/libz/src/gzwrite.obj external/libz/src/infback.obj external/libz/src/inffast.obj external/libz/src/inflate.obj external/libz/src/inftrees.obj external/libz/src/trees.obj external/libz/src/uncompr.obj external/libz/src/zutil.obj external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/charset.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/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/font/boldfont.obj src/text/font/boldmonottf.obj src/text/font/boldttf.obj src/text/font/font.obj src/text/font/monottf.obj src/text/font/ttf.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/calendar.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/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
|
src/Mw.dll: external/libz/src/adler32.obj external/libz/src/compress.obj external/libz/src/crc32.obj external/libz/src/deflate.obj external/libz/src/gzclose.obj external/libz/src/gzlib.obj external/libz/src/gzread.obj external/libz/src/gzwrite.obj external/libz/src/infback.obj external/libz/src/inffast.obj external/libz/src/inflate.obj external/libz/src/inftrees.obj external/libz/src/trees.obj external/libz/src/uncompr.obj external/libz/src/zutil.obj external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/charset.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/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/font/boldfont.obj src/text/font/boldmonottf.obj src/text/font/boldttf.obj src/text/font/font.obj src/text/font/monottf.obj src/text/font/ttf.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/calendar.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/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
|
||||||
$(LD) $(MW_LDFLAGS) option implib=src/Mw.lib name $@ file external/libz/src/adler32.obj file external/libz/src/compress.obj file external/libz/src/crc32.obj file external/libz/src/deflate.obj file external/libz/src/gzclose.obj file external/libz/src/gzlib.obj file external/libz/src/gzread.obj file external/libz/src/gzwrite.obj file external/libz/src/infback.obj file external/libz/src/inffast.obj file external/libz/src/inflate.obj file external/libz/src/inftrees.obj file external/libz/src/trees.obj file external/libz/src/uncompr.obj file external/libz/src/zutil.obj file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/charset.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/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/font/boldfont.obj file src/text/font/boldmonottf.obj file src/text/font/boldttf.obj file src/text/font/font.obj file src/text/font/monottf.obj file src/text/font/ttf.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/calendar.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/subwindow.obj file src/widget/tab.obj file src/widget/table.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 library advapi32.lib
|
$(LD) $(MW_LDFLAGS) option implib=src/Mw.lib name $@ file external/libz/src/adler32.obj file external/libz/src/compress.obj file external/libz/src/crc32.obj file external/libz/src/deflate.obj file external/libz/src/gzclose.obj file external/libz/src/gzlib.obj file external/libz/src/gzread.obj file external/libz/src/gzwrite.obj file external/libz/src/infback.obj file external/libz/src/inffast.obj file external/libz/src/inflate.obj file external/libz/src/inftrees.obj file external/libz/src/trees.obj file external/libz/src/uncompr.obj file external/libz/src/zutil.obj file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/charset.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/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/font/boldfont.obj file src/text/font/boldmonottf.obj file src/text/font/boldttf.obj file src/text/font/font.obj file src/text/font/monottf.obj file src/text/font/ttf.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/calendar.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/subwindow.obj file src/widget/tab.obj file src/widget/table.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 library advapi32.lib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
external/libz/src/adler32.obj: external/libz/src/adler32.c
|
external/libz/src/adler32.obj: external/libz/src/adler32.c
|
||||||
|
|
@ -444,6 +444,8 @@ src/text/font/ttf.obj: src/text/font/ttf.c
|
||||||
$(CC) $(MW_CFLAGS) -fo=$@ src/text/font/ttf.c
|
$(CC) $(MW_CFLAGS) -fo=$@ src/text/font/ttf.c
|
||||||
src/text/ft2.obj: src/text/ft2.c
|
src/text/ft2.obj: src/text/ft2.c
|
||||||
$(CC) $(MW_CFLAGS) -fo=$@ src/text/ft2.c
|
$(CC) $(MW_CFLAGS) -fo=$@ src/text/ft2.c
|
||||||
|
src/text/directwrite.obj: src/text/directwrite.c
|
||||||
|
$(CC) $(MW_CFLAGS) -fo=$@ src/text/directwrite.c
|
||||||
src/text/stbtt.obj: src/text/stbtt.c
|
src/text/stbtt.obj: src/text/stbtt.c
|
||||||
$(CC) $(MW_CFLAGS) -fo=$@ src/text/stbtt.c
|
$(CC) $(MW_CFLAGS) -fo=$@ src/text/stbtt.c
|
||||||
src/text/text.obj: src/text/text.c
|
src/text/text.obj: src/text/text.c
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,9 @@ MWDECL int MWFL_FT2Setup(void);
|
||||||
#ifdef USE_STB_TRUETYPE
|
#ifdef USE_STB_TRUETYPE
|
||||||
MWDECL int MwFL_STBTTSetup(void);
|
MWDECL int MwFL_STBTTSetup(void);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DIRECTWRITE
|
||||||
|
MWDECL int MWFL_DWSetup(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
|
||||||
MwAddTickList(h);
|
MwAddTickList(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
if(IsFirstVisible(h)) {
|
if(IsFirstVisible(h)) {
|
||||||
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
|
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
|
||||||
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
|
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
|
||||||
|
|
@ -732,7 +732,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
|
||||||
return MwDEFAULT;
|
return MwDEFAULT;
|
||||||
} else {
|
} else {
|
||||||
if(shgeti(handle->integer, key) == -1) {
|
if(shgeti(handle->integer, key) == -1) {
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 0);
|
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 0);
|
||||||
#else
|
#else
|
||||||
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 1);
|
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 1);
|
||||||
|
|
@ -783,7 +783,7 @@ const char* MwGetText(MwWidget handle, const char* key) {
|
||||||
return shget(handle->text, key);
|
return shget(handle->text, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
static void* inherit_void(MwWidget handle, const char* key) {
|
static void* inherit_void(MwWidget handle, const char* key) {
|
||||||
void* v;
|
void* v;
|
||||||
|
|
||||||
|
|
@ -799,7 +799,7 @@ void* MwGetVoid(MwWidget handle, const char* key) {
|
||||||
|
|
||||||
if(v != NULL) return v;
|
if(v != NULL) return v;
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0 || strcmp(key, MwNmonospaceFont) == 0 || strcmp(key, MwNboldMonospaceFont) == 0) {
|
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0 || strcmp(key, MwNmonospaceFont) == 0 || strcmp(key, MwNboldMonospaceFont) == 0) {
|
||||||
v = inherit_void(handle, key);
|
v = inherit_void(handle, key);
|
||||||
|
|
||||||
|
|
|
||||||
217
src/text/directwrite.c
Normal file
217
src/text/directwrite.c
Normal file
|
|
@ -0,0 +1,217 @@
|
||||||
|
#ifdef USE_DIRECTWRITE
|
||||||
|
#define INITGUID
|
||||||
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#include <d2d1.h>
|
||||||
|
|
||||||
|
#ifndef WINBOOL
|
||||||
|
#define WINBOOL int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "dwrite_c.h"
|
||||||
|
#include "dwrite_3_c.h"
|
||||||
|
|
||||||
|
static struct dw {
|
||||||
|
HMODULE d2d1_lib;
|
||||||
|
HMODULE dwrite_lib;
|
||||||
|
|
||||||
|
HRESULT (*D2D1CreateFactory)(D2D1_FACTORY_TYPE factoryType, const IID* const riid, const D2D1_FACTORY_OPTIONS* pFactoryOptions, void** ppIFactory);
|
||||||
|
HRESULT (*DWriteCreateFactory)(int factoryType, const IID* const iid, IUnknown** factory);
|
||||||
|
} dw_table;
|
||||||
|
|
||||||
|
|
||||||
|
struct _MwFLFont {
|
||||||
|
int px;
|
||||||
|
void * data;
|
||||||
|
MwBool valid;
|
||||||
|
|
||||||
|
IDWriteFactory* dWriteFactory;
|
||||||
|
IDWriteTextFormat* dTextFormat;
|
||||||
|
ID2D1Factory* d2dFactory;
|
||||||
|
ID2D1HwndRenderTarget* rt;
|
||||||
|
ID2D1SolidColorBrush* blackBrush;
|
||||||
|
IDWriteGdiInterop *gdiInterop;
|
||||||
|
|
||||||
|
IDWriteFontFile * file;
|
||||||
|
IDWriteFontFace * font_face;
|
||||||
|
|
||||||
|
LOGFONT logfont;
|
||||||
|
HFONT font;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int unpack_ttf_data(WCHAR * temp_path_name, unsigned char* data, unsigned int size) {
|
||||||
|
WCHAR temp_path_dir[MAX_PATH];
|
||||||
|
HANDLE tempFile;
|
||||||
|
int hr;
|
||||||
|
|
||||||
|
hr = GetTempPath2W(MAX_PATH, temp_path_dir);
|
||||||
|
if (hr == 0)
|
||||||
|
{
|
||||||
|
printf("GetTempPath2 failed for TTF, cannot use DirectWrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
hr = GetTempFileNameW(temp_path_dir, TEXT(L"MILSKO"), 0, temp_path_name);
|
||||||
|
if (hr == 0)
|
||||||
|
{
|
||||||
|
printf("GetTempFileName failed for TTF, cannot use DirectWrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tempFile = CreateFileW(temp_path_name,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
CREATE_NEW,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
NULL);
|
||||||
|
if (tempFile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
if(err == ERROR_FILE_EXISTS) {
|
||||||
|
tempFile = CreateFileW(temp_path_name,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
OPEN_ALWAYS,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
NULL);
|
||||||
|
if (tempFile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
goto success;
|
||||||
|
} else {
|
||||||
|
err = GetLastError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("CreateFile failed for TTF (%ld), cannot use DirectWrite\n", err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
success:
|
||||||
|
|
||||||
|
hr = WriteFile(tempFile, data, size, NULL, NULL);
|
||||||
|
if(!hr) {
|
||||||
|
printf("WriteFile failed for TTF (%ld), cannot use DirectWrite\n", GetLastError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(tempFile);
|
||||||
|
|
||||||
|
printf("unpacked ttf data %p into %ws\n",data, temp_path_name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* dw_MwFontLoad(unsigned char* data, unsigned int size, int px) {
|
||||||
|
MwFLFont ttf = malloc(sizeof(*ttf));
|
||||||
|
HRESULT hr;
|
||||||
|
WCHAR font_name[MAX_PATH];
|
||||||
|
D2D1_FACTORY_OPTIONS d2d1_options;
|
||||||
|
|
||||||
|
d2d1_options.debugLevel = D2D1_DEBUG_LEVEL_ERROR;
|
||||||
|
|
||||||
|
memset(ttf, 0, sizeof(*ttf));
|
||||||
|
ttf->data = malloc(size);
|
||||||
|
memcpy(ttf->data, data, size);
|
||||||
|
|
||||||
|
ttf->px = px;
|
||||||
|
|
||||||
|
hr = dw_table.D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, &d2d1_options, (void**)&ttf->d2dFactory);
|
||||||
|
if(!SUCCEEDED(hr)) {
|
||||||
|
printf("D2D1CreateFactory failed for TTF (%08lX), cannot use DirectWrite\n", hr);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = dw_table.DWriteCreateFactory(0 /*DWRITE_FACTORY_TYPE_SHARED*/,&IID_IDWriteFactory, (struct IUnknown**)&ttf->dWriteFactory);
|
||||||
|
|
||||||
|
if(!SUCCEEDED(hr)) {
|
||||||
|
printf("DWriteCreateFactory failed for TTF (%08lx), cannot use DirectWrite\n", hr);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(unpack_ttf_data(font_name, data, size) != 0) {
|
||||||
|
goto fail;
|
||||||
|
};
|
||||||
|
|
||||||
|
hr = ttf->dWriteFactory->lpVtbl->CreateFontFileReference(ttf->dWriteFactory, font_name, NULL, &ttf->file);
|
||||||
|
if(!SUCCEEDED(hr)) {
|
||||||
|
printf("CreateFontFileReference failed for TTF (%08lx), cannot use DirectWrite\n",hr);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = ttf->dWriteFactory->lpVtbl->CreateFontFace(ttf->dWriteFactory, DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &ttf->file, 0, DWRITE_FONT_SIMULATIONS_NONE, &ttf->font_face);
|
||||||
|
if(!SUCCEEDED(hr)) {
|
||||||
|
printf("CreateFontFace failed for TTF (%08lx), cannot use DirectWrite\n",hr);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = ttf->dWriteFactory->lpVtbl->GetGdiInterop(ttf->dWriteFactory, &ttf->gdiInterop);
|
||||||
|
if(!SUCCEEDED(hr)) {
|
||||||
|
printf("GetGdiInterop failed for TTF (%08lx), cannot use DirectWrite\n",hr);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
ttf->valid = MwTRUE;
|
||||||
|
return ttf;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
ttf->valid = MwFALSE;
|
||||||
|
return ttf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dw_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dw_MwTextWidth(MwFLFont ttf, const char* text) {
|
||||||
|
int tw = 15;
|
||||||
|
|
||||||
|
return tw + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dw_MwTextHeight(MwFLFont ttf, int count) {
|
||||||
|
DWRITE_FONT_METRICS metrics;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
IDWriteFontFace_GetMetrics(ttf->font_face, &metrics);
|
||||||
|
|
||||||
|
height = ceil(((float)metrics.xHeight * ttf->px / metrics.designUnitsPerEm) * count);
|
||||||
|
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void dw_MwFontFree(void* handle) {
|
||||||
|
MwFLFont ttf = handle;
|
||||||
|
|
||||||
|
free(ttf->data);
|
||||||
|
free(ttf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int MWFL_DWSetup(void) {
|
||||||
|
/* Try and load DirectWrite. If it fails, return 1, signifying we default to bitmap drawing. */
|
||||||
|
dw_table.d2d1_lib = LoadLibrary("D2d1.dll");
|
||||||
|
if(!dw_table.d2d1_lib) {
|
||||||
|
printf("D2d1.dll not found, cannot use DirectWrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
dw_table.dwrite_lib = LoadLibrary("dwrite.dll");
|
||||||
|
if(!dw_table.dwrite_lib) {
|
||||||
|
printf("dwrite.dll not found, cannot use DirectWrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define D2D1_LOAD(x) dw_table.x = (typeof(dw_table.x))GetProcAddress(dw_table.d2d1_lib, #x); if(!dw_table.x) {printf("Can't use DirectWrite, "#x " not found."); return 1;}
|
||||||
|
|
||||||
|
#define DWRITE_LOAD(x) dw_table.x = (typeof(dw_table.x))GetProcAddress(dw_table.dwrite_lib, #x); if(!dw_table.x) {printf("Can't use DirectWrite, "#x " not found."); return 1;}
|
||||||
|
|
||||||
|
D2D1_LOAD(D2D1CreateFactory);
|
||||||
|
DWRITE_LOAD(DWriteCreateFactory);
|
||||||
|
|
||||||
|
MwFLDrawText = dw_MwDrawText;
|
||||||
|
MwFLTextWidth = dw_MwTextWidth;
|
||||||
|
MwFLTextHeight = dw_MwTextHeight;
|
||||||
|
MwFLFontLoad = dw_MwFontLoad;
|
||||||
|
MwFLFontFree = dw_MwFontFree;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
15191
src/text/dwrite_3_c.h
Normal file
15191
src/text/dwrite_3_c.h
Normal file
File diff suppressed because it is too large
Load diff
5517
src/text/dwrite_c.h
Normal file
5517
src/text/dwrite_c.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
unsigned char MwBoldMonospaceTTFData[] = {
|
unsigned char MwBoldMonospaceTTFData[] = {
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
|
||||||
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x44, 0x00, 0x00, 0x8d, 0x3c,
|
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x44, 0x00, 0x00, 0x8d, 0x3c,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
unsigned char MwBoldTTFData[] = {
|
unsigned char MwBoldTTFData[] = {
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
|
||||||
0x46, 0x46, 0x54, 0x4d, 0x94, 0x9f, 0x60, 0x18, 0x00, 0x00, 0x8e, 0xa8,
|
0x46, 0x46, 0x54, 0x4d, 0x94, 0x9f, 0x60, 0x18, 0x00, 0x00, 0x8e, 0xa8,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
unsigned char MwMonospaceTTFData[] = {
|
unsigned char MwMonospaceTTFData[] = {
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
|
||||||
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x23, 0x00, 0x00, 0x8d, 0x3c,
|
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x23, 0x00, 0x00, 0x8d, 0x3c,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
|
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_DIRECTWRITE)
|
||||||
unsigned char MwTTFData[] = {
|
unsigned char MwTTFData[] = {
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
|
||||||
0x46, 0x46, 0x54, 0x4d, 0x94, 0x92, 0x79, 0xd4, 0x00, 0x00, 0x89, 0xa4,
|
0x46, 0x46, 0x54, 0x4d, 0x94, 0x92, 0x79, 0xd4, 0x00, 0x00, 0x89, 0xa4,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ int (*MwFLTextHeight)(MwFLFont font, int count) = 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;
|
||||||
|
|
||||||
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)
|
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE) || defined(USE_DIRECTWRITE)
|
||||||
#define TTF
|
#define TTF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -297,6 +297,9 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
|
||||||
typedef int (*call_t)(void);
|
typedef int (*call_t)(void);
|
||||||
void MwFLSetup(void) {
|
void MwFLSetup(void) {
|
||||||
call_t calls[] = {
|
call_t calls[] = {
|
||||||
|
#ifdef USE_DIRECTWRITE
|
||||||
|
MWFL_DWSetup,
|
||||||
|
#endif
|
||||||
#ifdef USE_FREETYPE2
|
#ifdef USE_FREETYPE2
|
||||||
MWFL_FT2Setup,
|
MWFL_FT2Setup,
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue