Embed the fonts in the EXE
Now CSE2.exe should be drop-in replacement for Doukutsu.exe, with no extra files needed.
This commit is contained in:
parent
1f179f9287
commit
a6ac6787d3
6 changed files with 55 additions and 25 deletions
|
@ -255,6 +255,13 @@ if(MSVC)
|
||||||
target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS) # Shut up those stupid warnings
|
target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS) # Shut up those stupid warnings
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Decide the embedded font
|
||||||
|
if(JAPANESE)
|
||||||
|
list(APPEND RESOURCES "FONT/msgothic.ttc")
|
||||||
|
elseif(NOT WIN32)
|
||||||
|
list(APPEND RESOURCES "FONT/cour.ttf")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Magic to convert resources to header files
|
# Magic to convert resources to header files
|
||||||
add_executable(bin2h "src/misc/bin2h.c")
|
add_executable(bin2h "src/misc/bin2h.c")
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -183,8 +183,13 @@ RESOURCES = \
|
||||||
|
|
||||||
ifeq ($(JAPANESE), 1)
|
ifeq ($(JAPANESE), 1)
|
||||||
RESOURCES += BITMAP/pixel_jp.bmp
|
RESOURCES += BITMAP/pixel_jp.bmp
|
||||||
|
RESOURCES += FONT/msgothic.ttc
|
||||||
else
|
else
|
||||||
RESOURCES += BITMAP/pixel.bmp
|
RESOURCES += BITMAP/pixel.bmp
|
||||||
|
|
||||||
|
ifneq ($(WINDOWS), 1)
|
||||||
|
RESOURCES += FONT/cour.ttf
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(WINDOWS), 1)
|
ifneq ($(WINDOWS), 1)
|
||||||
|
|
45
src/Draw.cpp
45
src/Draw.cpp
|
@ -525,9 +525,6 @@ static unsigned char* GetFontFromWindows(size_t *data_size, const char *font_nam
|
||||||
|
|
||||||
HFONT hfont = CreateFontA(fontHeight, fontWidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE, font_name);
|
HFONT hfont = CreateFontA(fontHeight, fontWidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE, font_name);
|
||||||
|
|
||||||
if (hfont == NULL)
|
|
||||||
hfont = CreateFontA(fontHeight, fontWidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE, NULL);
|
|
||||||
|
|
||||||
if (hfont != NULL)
|
if (hfont != NULL)
|
||||||
{
|
{
|
||||||
HDC hdc = CreateCompatibleDC(NULL);
|
HDC hdc = CreateCompatibleDC(NULL);
|
||||||
|
@ -539,14 +536,14 @@ static unsigned char* GetFontFromWindows(size_t *data_size, const char *font_nam
|
||||||
|
|
||||||
if (size != GDI_ERROR)
|
if (size != GDI_ERROR)
|
||||||
{
|
{
|
||||||
buffer = new unsigned char[size];
|
buffer = (unsigned char*)malloc(size);
|
||||||
|
|
||||||
if (data_size != NULL)
|
if (data_size != NULL)
|
||||||
*data_size = size;
|
*data_size = size;
|
||||||
|
|
||||||
if (GetFontData(hdc, 0, 0, buffer, size) != size)
|
if (GetFontData(hdc, 0, 0, buffer, size) != size)
|
||||||
{
|
{
|
||||||
delete[] buffer;
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,33 +573,39 @@ void InitTextObject(const char *font_name)
|
||||||
fontHeight = 10 * magnification;
|
fontHeight = 10 * magnification;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
size_t data_size;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
// Actually use the font Config.dat specifies
|
// Actually use the font Config.dat specifies
|
||||||
size_t data_size;
|
unsigned char *data;
|
||||||
unsigned char *data = GetFontFromWindows(&data_size, font_name, fontWidth, fontHeight);
|
data = GetFontFromWindows(&data_size, font_name, fontWidth, fontHeight);
|
||||||
|
if (data)
|
||||||
if (data != NULL)
|
|
||||||
{
|
{
|
||||||
gFont = LoadFontFromData(data, data_size, fontWidth, fontHeight);
|
gFont = LoadFontFromData(data, data_size, fontWidth, fontHeight);
|
||||||
|
free(data);
|
||||||
delete[] data;
|
}
|
||||||
|
|
||||||
if (gFont)
|
if (gFont)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifndef JAPANESE
|
||||||
|
// Fall back on a default font
|
||||||
|
data = GetFontFromWindows(&data_size, "Courier New", fontWidth, fontHeight);
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
gFont = LoadFontFromData(data, data_size, fontWidth, fontHeight);
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gFont)
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
// Fall back on the built-in fonts
|
#endif
|
||||||
|
// Fall back on the built-in font
|
||||||
(void)font_name;
|
(void)font_name;
|
||||||
|
const unsigned char *res_data = FindResource("DEFAULT_FONT", "FONT", &data_size);
|
||||||
|
|
||||||
//Open Font.ttf
|
if (res_data != NULL)
|
||||||
char path[PATH_LENGTH];
|
gFont = LoadFontFromData(res_data, data_size, fontWidth, fontHeight);
|
||||||
#ifdef JAPANESE
|
|
||||||
sprintf(path, "%s/font/msgothic.ttc", gModulePath);
|
|
||||||
#else
|
|
||||||
sprintf(path, "%s/font/cour.ttf", gModulePath);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gFont = LoadFont(path, fontWidth, fontHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PutText(int x, int y, const char *text, uint32_t color)
|
void PutText(int x, int y, const char *text, uint32_t color)
|
||||||
|
|
|
@ -74,6 +74,14 @@
|
||||||
#include "Resource/CURSOR/CURSOR_IKA.bmp.h"
|
#include "Resource/CURSOR/CURSOR_IKA.bmp.h"
|
||||||
#include "Resource/CURSOR/CURSOR_NORMAL.bmp.h"
|
#include "Resource/CURSOR/CURSOR_NORMAL.bmp.h"
|
||||||
|
|
||||||
|
#ifdef JAPANESE
|
||||||
|
#include "Resource/FONT/msgothic.ttc.h"
|
||||||
|
#else
|
||||||
|
#ifndef WINDOWS
|
||||||
|
#include "Resource/FONT/cour.ttf.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
{
|
{
|
||||||
const char *type;
|
const char *type;
|
||||||
|
@ -156,6 +164,13 @@ static const struct
|
||||||
{"CURSOR", "CURSOR_NORMAL", rCURSOR_NORMAL, sizeof(rCURSOR_NORMAL)},
|
{"CURSOR", "CURSOR_NORMAL", rCURSOR_NORMAL, sizeof(rCURSOR_NORMAL)},
|
||||||
{"CURSOR", "CURSOR_IKA", rCURSOR_IKA, sizeof(rCURSOR_IKA)},
|
{"CURSOR", "CURSOR_IKA", rCURSOR_IKA, sizeof(rCURSOR_IKA)},
|
||||||
|
|
||||||
|
#ifdef JAPANESE
|
||||||
|
{"FONT", "DEFAULT_FONT", rmsgothic, sizeof(rmsgothic)},
|
||||||
|
#else
|
||||||
|
#ifndef WINDOWS
|
||||||
|
{"FONT", "DEFAULT_FONT", rcour, sizeof(rcour)},
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const unsigned char* FindResource(const char *name, const char *type, size_t *size)
|
const unsigned char* FindResource(const char *name, const char *type, size_t *size)
|
||||||
|
|
Loading…
Add table
Reference in a new issue