Restored the new font system

This commit is contained in:
Clownacy 2019-09-04 15:43:28 +00:00
parent 0ec8997244
commit ae8aeae2ac
7 changed files with 1212 additions and 64 deletions

View file

@ -43,13 +43,13 @@ ifeq ($(DEBUG_SAVE), 1)
CXXFLAGS += -DDEBUG_SAVE CXXFLAGS += -DDEBUG_SAVE
endif endif
CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d `$(PKG_CONFIG) sdl2 --cflags` CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d `$(PKG_CONFIG) sdl2 --cflags` `$(PKG_CONFIG) freetype2 --cflags`
ifeq ($(STATIC), 1) ifeq ($(STATIC), 1)
LDFLAGS += -static LDFLAGS += -static
LIBS += `$(PKG_CONFIG) sdl2 --libs --static` LIBS += `$(PKG_CONFIG) sdl2 --libs --static` `$(PKG_CONFIG) freetype2 --libs --static`
else else
LIBS += `$(PKG_CONFIG) sdl2 --libs` LIBS += `$(PKG_CONFIG) sdl2 --libs` `$(PKG_CONFIG) freetype2 --libs`
endif endif
SOURCES = \ SOURCES = \
@ -77,6 +77,7 @@ SOURCES = \
src/File \ src/File \
src/Flags \ src/Flags \
src/Flash \ src/Flash \
src/Font \
src/Frame \ src/Frame \
src/Game \ src/Game \
src/Generic \ src/Generic \
@ -145,6 +146,7 @@ RESOURCES = \
BITMAP/Credit18.bmp \ BITMAP/Credit18.bmp \
CURSOR/CURSOR_IKA.bmp \ CURSOR/CURSOR_IKA.bmp \
CURSOR/CURSOR_NORMAL.bmp \ CURSOR/CURSOR_NORMAL.bmp \
FONT/LiberationMono.ttf \
ICON/ICON_MINI.bmp \ ICON/ICON_MINI.bmp \
ORG/Access.org \ ORG/Access.org \
ORG/Anzen.org \ ORG/Anzen.org \
@ -247,7 +249,7 @@ obj/$(FILENAME)/%.o: %.cpp
@echo Compiling $< @echo Compiling $<
@$(CXX) $(CXXFLAGS) $< -o $@ -c @$(CXX) $(CXXFLAGS) $< -o $@ -c
obj/$(FILENAME)/Resource.o: src/Resource.cpp $(addprefix src/Resource/, $(addsuffix .h, $(RESOURCES))) obj/$(FILENAME)/src/Resource.o: src/Resource.cpp $(addprefix src/Resource/, $(addsuffix .h, $(RESOURCES)))
@mkdir -p $(@D) @mkdir -p $(@D)
@echo Compiling $< @echo Compiling $<
@$(CXX) $(CXXFLAGS) $< -o $@ -c @$(CXX) $(CXXFLAGS) $< -o $@ -c

View file

@ -9,6 +9,7 @@ This branch migrates the engine from WinAPI to SDL2, and addresses numerous port
## Dependencies ## Dependencies
* SDL2 * SDL2
* Freetype
* FLTK * FLTK
* GLEW (if the OpenGL rendering backend is selected) * GLEW (if the OpenGL rendering backend is selected)

Binary file not shown.

View file

@ -11,6 +11,7 @@
#include "Backends/Rendering.h" #include "Backends/Rendering.h"
#include "CommonDefines.h" #include "CommonDefines.h"
#include "Ending.h" #include "Ending.h"
#include "Font.h"
#include "Generic.h" #include "Generic.h"
#include "Main.h" #include "Main.h"
#include "MapName.h" #include "MapName.h"
@ -37,6 +38,8 @@ static Backend_Surface *surf[SURFACE_ID_MAX];
static SDL_PixelFormat *rgb24_pixel_format; // Needed because SDL2 is stupid static SDL_PixelFormat *rgb24_pixel_format; // Needed because SDL2 is stupid
static FontObject *font;
// This doesn't exist in the Linux port, so none of these symbol names are accurate // This doesn't exist in the Linux port, so none of these symbol names are accurate
static struct static struct
{ {
@ -602,72 +605,24 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L
*/ */
// TODO - Inaccurate stack frame // TODO - Inaccurate stack frame
void InitTextObject(const char *name) void InitTextObject(const char *name)
{/* {
// Get font size size_t size;
unsigned int width, height; const unsigned char *data = FindResource("FONT", "FONT", &size);
switch (magnification) font = LoadFontFromData(data, size, 5 * magnification, 10 * magnification);
{ }
case 1:
height = 12;
width = 6;
break;
case 2:
height = 20;
width = 10;
break;
}
// The game uses DEFAULT_CHARSET when it should have used SHIFTJIS_CHARSET.
// This breaks the Japanese text on English Windows installations.
// Also, the game uses DEFAULT_QUALITY instead of NONANTIALIASED_QUALITY,
// causing font antialiasing to blend with the colour-key, giving text ab
// ugly black outline.
#ifdef FIX_BUGS
#define QUALITY NONANTIALIASED_QUALITY
#ifdef JAPANESE
#define CHARSET SHIFTJIS_CHARSET
#else
#define CHARSET DEFAULT_CHARSET
#endif
#else
#define QUALITY DEFAULT_QUALITY
#define CHARSET DEFAULT_CHARSET
#endif
font = CreateFontA(height, width, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, QUALITY, FIXED_PITCH | FF_DONTCARE, name);
if (font == NULL)
font = CreateFontA(height, width, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, QUALITY, FIXED_PITCH | FF_DONTCARE, NULL);
*/}
void PutText(int x, int y, const char *text, unsigned long color) void PutText(int x, int y, const char *text, unsigned long color)
{/* {
HDC hdc; DrawText(font, framebuffer, x * magnification, y * magnification, color, text);
backbuffer->GetDC(&hdc); }
HGDIOBJ hgdiobj = SelectObject(hdc, font);
SetBkMode(hdc, 1);
SetTextColor(hdc, color);
TextOutA(hdc, x * magnification, y * magnification, text, (int)strlen(text));
SelectObject(hdc, hgdiobj);
backbuffer->ReleaseDC(hdc);
*/}
void PutText2(int x, int y, const char *text, unsigned long color, SurfaceID surf_no) void PutText2(int x, int y, const char *text, unsigned long color, SurfaceID surf_no)
{/* {
HDC hdc; DrawText(font, surf[surf_no], x * magnification, y * magnification, color, text);
surf[surf_no]->GetDC(&hdc); }
HGDIOBJ hgdiobj = SelectObject(hdc, font);
SetBkMode(hdc, 1);
SetTextColor(hdc, color);
TextOutA(hdc, x * magnification, y * magnification, text, (int)strlen(text));
SelectObject(hdc, hgdiobj);
surf[surf_no]->ReleaseDC(hdc);
*/}
void EndTextObject(void) void EndTextObject(void)
{ {
// DeleteObject(font); UnloadFont(font);
} }

1176
src/Font.cpp Normal file

File diff suppressed because it is too large Load diff

12
src/Font.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <stddef.h>
#include "Backends/Rendering.h"
typedef struct FontObject FontObject;
FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height);
FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height);
void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string);
void UnloadFont(FontObject *font_object);

View file

@ -27,6 +27,7 @@
#endif #endif
#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"
#include "Resource/FONT/LiberationMono.ttf.h"
#include "Resource/ICON/ICON_MINI.bmp.h" #include "Resource/ICON/ICON_MINI.bmp.h"
#include "Resource/ORG/Access.org.h" #include "Resource/ORG/Access.org.h"
#include "Resource/ORG/Anzen.org.h" #include "Resource/ORG/Anzen.org.h"
@ -103,6 +104,7 @@ static const struct
#endif #endif
{"CURSOR", "CURSOR_IKA", rCURSOR_IKA, sizeof(rCURSOR_IKA)}, {"CURSOR", "CURSOR_IKA", rCURSOR_IKA, sizeof(rCURSOR_IKA)},
{"CURSOR", "CURSOR_NORMAL", rCURSOR_NORMAL, sizeof(rCURSOR_NORMAL)}, {"CURSOR", "CURSOR_NORMAL", rCURSOR_NORMAL, sizeof(rCURSOR_NORMAL)},
{"FONT", "FONT", rLiberationMono, sizeof(rLiberationMono)},
{"ICON", "ICON_MINI", rICON_MINI, sizeof(rICON_MINI)}, {"ICON", "ICON_MINI", rICON_MINI, sizeof(rICON_MINI)},
{"ORG", "ACCESS", rAccess, sizeof(rAccess)}, {"ORG", "ACCESS", rAccess, sizeof(rAccess)},
{"ORG", "ANZEN", rAnzen, sizeof(rAnzen)}, {"ORG", "ANZEN", rAnzen, sizeof(rAnzen)},