Merge pull request #4980 from janisozaur/ttf-less

Add configuration allowing builds without SDL2_ttf
This commit is contained in:
Michał Janiszewski 2017-01-04 15:52:52 +01:00 committed by GitHub
commit 360018a82b
11 changed files with 99 additions and 17 deletions

View File

@ -51,7 +51,7 @@ matrix:
- os: linux
env: OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt -DFORCE32=on" TARGET=windows
- os: linux
env: TARGET=docker64
env: TARGET=docker64 OPENRCT2_CMAKE_OPTS="-DDISABLE_TTF=ON"
services:
- docker
- os: linux

View File

@ -105,10 +105,6 @@ endif (APPLE)
# Options
option(DISABLE_HTTP_TWITCH "Disable HTTP and Twitch support.")
if (DISABLE_HTTP_TWITCH)
add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH)
endif (DISABLE_HTTP_TWITCH)
option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.")
option(STATIC "Create a static build.")
option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags")
@ -116,6 +112,7 @@ option(DISABLE_OPENGL "Disable OpenGL support.")
option(DISABLE_RCT2 "Build a standalone version, without using code and data segments from vanilla. On by default." ON)
option(USE_MMAP "Use mmap to try loading rct2's data segment into memory.")
option(WITH_TESTS "Build tests")
option(DISABLE_TTF "Disable support for TTF provided by SDL2_ttf.")
set(COMMON_COMPILE_OPTIONS "${COMMON_COMPILE_OPTIONS} -fstrict-aliasing -Werror -Wundef -Wmissing-declarations -Winit-self -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-missing-braces -Wno-comment")
@ -129,6 +126,14 @@ if (NOT DISABLE_RCT2)
message("DISABLE_RCT2 implies FORCE32")
endif()
if (DISABLE_HTTP_TWITCH)
add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH)
endif (DISABLE_HTTP_TWITCH)
if (DISABLE_TTF)
add_definitions(-DNO_TTF)
endif (DISABLE_TTF)
# Launchpad turns on -Wdate-time for compilers that support it, this shouldn't break our build
ADD_CHECK_C_COMPILER_FLAG(CMAKE_C_FLAGS C_WARN_WRITE_STRINGS -Wno-error=date-time)
ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_WRITE_STRINGS -Wno-error=date-time)
@ -278,13 +283,19 @@ endif (WITH_BREAKPAD)
PKG_CHECK_MODULES(LIBZIP REQUIRED libzip>=1.0)
# find and include SDL2
PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf)
PKG_CHECK_MODULES(SDL2 REQUIRED sdl2)
if (NOT DISABLE_TTF)
PKG_CHECK_MODULES(SDL2_TTF REQUIRED SDL2_ttf)
endif (NOT DISABLE_TTF)
if (STATIC)
# FreeType is required by SDL2_ttf, but not wired up properly in package
PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2)
SET(SDL2LIBS ${SDL2_STATIC_LIBRARIES} ${FREETYPE_STATIC_LIBRARIES})
if (NOT DISABLE_TTF)
# FreeType is required by SDL2_ttf, but not wired up properly in package
PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2)
endif (DISABLE_TTF)
SET(SDL2LIBS ${SDL2_STATIC_LIBRARIES} ${SDL2_TTF_STATIC_LIBRARIES} ${FREETYPE_STATIC_LIBRARIES})
else (STATIC)
SET(SDL2LIBS ${SDL2_LIBRARIES})
SET(SDL2LIBS ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES})
endif (STATIC)
if (STATIC)

View File

@ -354,8 +354,10 @@ void gfx_draw_string_centred_wrapped_partial(rct_drawpixelinfo *dpi, int x, int
void gfx_draw_string_with_y_offsets(rct_drawpixelinfo *dpi, const utf8 *text, int colour, int x, int y, const sint8 *yOffsets, bool forceSpriteFont);
int gfx_clip_string(char* buffer, int width);
void shorten_path(utf8 *buffer, size_t bufferSize, const utf8 *path, int availableWidth);
#ifndef NO_TTF
SDL_Surface *ttf_surface_cache_get_or_add(TTF_Font *font, const utf8 *text);
TTFFontDescriptor *ttf_get_font_from_sprite_base(uint16 spriteBase);
#endif // NO_TTF
bool ttf_initialise();
void ttf_dispose();

View File

@ -28,7 +28,9 @@ static uint8 _spriteFontCharacterWidths[896];
static uint8 *_spriteFontCharacterWidths = RCT2_ADDRESS(RCT2_ADDRESS_FONT_CHAR_WIDTH, uint8);
#endif
#ifndef NO_TTF
TTFFontSetDescriptor *gCurrentTTFFontSet;
#endif // NO_TTF
/**
*
@ -125,11 +127,15 @@ int font_get_size_from_sprite_base(uint16 spriteBase)
int font_get_line_height(int fontSpriteBase)
{
int fontSize = font_get_size_from_sprite_base(fontSpriteBase);
#ifndef NO_TTF
if (gUseTrueTypeFont) {
return gCurrentTTFFontSet->size[fontSize].line_height;
} else {
#endif // NO_TTF
return SpriteFontLineHeight[fontSize];
#ifndef NO_TTF
}
#endif // NO_TTF
}
int font_get_line_height_small(int fontSpriteBase)
@ -190,6 +196,7 @@ bool font_supports_string_sprite(const utf8 *text)
bool font_supports_string_ttf(const utf8 *text, int fontSize)
{
#ifndef NO_TTF
const utf8 *src = text;
const TTF_Font *font = gCurrentTTFFontSet->size[fontSize].font;
if (font == NULL) {
@ -204,6 +211,9 @@ bool font_supports_string_ttf(const utf8 *text, int fontSize)
}
}
return true;
#else
return false;
#endif // NO_TTF
}
bool font_supports_string(const utf8 *text, int fontSize)

View File

@ -17,7 +17,10 @@
#ifndef _DRAWING_FONT_H_
#define _DRAWING_FONT_H_
#ifndef NO_TTF
#include <SDL_ttf.h>
#endif // NO_TTF
#include "../common.h"
enum {
@ -39,6 +42,7 @@ enum {
FONT_SPRITE_BASE_BIG = 672
};
#ifndef NO_TTF
typedef struct TTFFontDescriptor {
const utf8 *filename;
const utf8 *font_name;
@ -54,6 +58,7 @@ typedef struct TTFFontSetDescriptor {
} TTFFontSetDescriptor;
extern TTFFontSetDescriptor *gCurrentTTFFontSet;
#endif // NO_TTF
void font_sprite_initialise_characters();
int font_sprite_get_codepoint_offset(int codepoint);

View File

@ -1509,6 +1509,7 @@ void scrolling_text_set_bitmap_for_sprite(utf8 *text, int scroll, uint8 *bitmap,
void scrolling_text_set_bitmap_for_ttf(utf8 *text, int scroll, uint8 *bitmap, const sint16 *scrollPositionOffsets)
{
#ifndef NO_TTF
TTFFontDescriptor *fontDesc = ttf_get_font_from_sprite_base(FONT_SPRITE_BASE_TINY);
if (fontDesc->font == NULL) {
scrolling_text_set_bitmap_for_sprite(text, scroll, bitmap, scrollPositionOffsets);
@ -1583,4 +1584,5 @@ void scrolling_text_set_bitmap_for_ttf(utf8 *text, int scroll, uint8 *bitmap, co
}
if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
#endif // NO_TTF
}

View File

@ -26,13 +26,16 @@ enum {
TEXT_DRAW_FLAG_DARK = 1 << 2,
TEXT_DRAW_FLAG_EXTRA_DARK = 1 << 3,
TEXT_DRAW_FLAG_Y_OFFSET_EFFECT = 1 << 29,
#ifndef NO_TTF
TEXT_DRAW_FLAG_TTF = 1 << 30,
#endif // NO_TTF
TEXT_DRAW_FLAG_NO_DRAW = 1u << 31
};
static int ttf_get_string_width(const utf8 *text);
static void ttf_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y);
#ifndef NO_TTF
static bool _ttfInitialised = false;
#define TTF_SURFACE_CACHE_SIZE 256
@ -61,6 +64,7 @@ static ttf_getwidth_cache_entry _ttfGetWidthCache[TTF_GETWIDTH_CACHE_SIZE] = { 0
static int _ttfGetWidthCacheCount = 0;
static int _ttfGetWidthCacheHitCount = 0;
static int _ttfGetWidthCacheMissCount = 0;
#endif // NO_TTF
/**
*
@ -702,6 +706,7 @@ void gfx_draw_string_centred_wrapped_partial(rct_drawpixelinfo *dpi, int x, int
}
}
#ifndef NO_TTF
static uint32 _ttf_surface_cache_hash(TTF_Font *font, const utf8 *text)
{
uint32 hash = (uint32)((((uintptr_t)font * 23) ^ 0xAAAAAAAA) & 0xFFFFFFFF);
@ -892,6 +897,14 @@ TTFFontDescriptor *ttf_get_font_from_sprite_base(uint16 spriteBase)
{
return &gCurrentTTFFontSet->size[font_get_size_from_sprite_base(spriteBase)];
}
#else
bool ttf_initialise()
{
return false;
}
void ttf_dispose() {}
#endif // NO_TTF
typedef struct text_draw_info {
int startX;
@ -935,6 +948,7 @@ static void ttf_draw_string_raw_sprite(rct_drawpixelinfo *dpi, const utf8 *text,
};
}
#ifndef NO_TTF
static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, text_draw_info *info)
{
if (!_ttfInitialised && !ttf_initialise())
@ -1038,14 +1052,19 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
}
}
}
#endif // NO_TTF
static void ttf_draw_string_raw(rct_drawpixelinfo *dpi, const utf8 *text, text_draw_info *info)
{
#ifndef NO_TTF
if (info->flags & TEXT_DRAW_FLAG_TTF) {
ttf_draw_string_raw_ttf(dpi, text, info);
} else {
#endif // NO_TTF
ttf_draw_string_raw_sprite(dpi, text, info);
#ifndef NO_TTF
}
#endif // NO_TTF
}
static const utf8 *ttf_process_format_code(rct_drawpixelinfo *dpi, const utf8 *text, text_draw_info *info)
@ -1159,7 +1178,11 @@ static const utf8 *ttf_process_glyph_run(rct_drawpixelinfo *dpi, const utf8 *tex
const utf8 *lastCh;
int codepoint;
#ifndef NO_TTF
bool isTTF = info->flags & TEXT_DRAW_FLAG_TTF;
#else
bool isTTF = false;
#endif // NO_TTF
while (!utf8_is_format_code(codepoint = utf8_get_next(ch, &lastCh))) {
if (isTTF && utf8_should_use_sprite_for_codepoint(codepoint)) {
break;
@ -1184,7 +1207,11 @@ static void ttf_process_string(rct_drawpixelinfo *dpi, const utf8 *text, text_dr
const utf8 *nextCh;
int codepoint;
#ifndef NO_TTF
bool isTTF = info->flags & TEXT_DRAW_FLAG_TTF;
#else
bool isTTF = false;
#endif // NO_TTF
while ((codepoint = utf8_get_next(ch, &nextCh)) != 0) {
if (utf8_is_format_code(codepoint)) {
@ -1264,7 +1291,9 @@ static void ttf_draw_string(rct_drawpixelinfo *dpi, char *text, int colour, int
info.x = x;
info.y = y;
#ifndef NO_TTF
if (gUseTrueTypeFont) info.flags |= TEXT_DRAW_FLAG_TTF;
#endif // NO_TTF
memcpy(info.palette, text_palette, sizeof(info.palette));
ttf_process_initial_colour(colour, &info);
@ -1291,7 +1320,9 @@ static int ttf_get_string_width(const utf8 *text)
info.maxY = 0;
info.flags |= TEXT_DRAW_FLAG_NO_DRAW;
#ifndef NO_TTF
if (gUseTrueTypeFont) info.flags |= TEXT_DRAW_FLAG_TTF;
#endif // NO_TTF
ttf_process_string(NULL, text, &info);
@ -1315,9 +1346,11 @@ void gfx_draw_string_with_y_offsets(rct_drawpixelinfo *dpi, const utf8 *text, in
info.flags |= TEXT_DRAW_FLAG_Y_OFFSET_EFFECT;
#ifndef NO_TTF
if (!forceSpriteFont && gUseTrueTypeFont) {
info.flags |= TEXT_DRAW_FLAG_TTF;
}
#endif // NO_TTF
memcpy(info.palette, text_palette, sizeof(info.palette));
ttf_process_initial_colour(colour, &info);

View File

@ -26,6 +26,7 @@ extern "C" {
#include "../localisation/language.h"
}
#ifndef NO_TTF
static TTFFontSetDescriptor TTFFontMSGothic = { {
{ "msgothic.ttc", "MS PGothic", 9, 1, 0, 15, nullptr },
{ "msgothic.ttc", "MS PGothic", 12, 1, 0, 17, nullptr },
@ -60,6 +61,10 @@ static TTFFontSetDescriptor TTFFontArial = { {
{ "arial.ttf", "Arial", 11, 0, -1, 12, nullptr },
{ "arial.ttf", "Arial", 12, 0, -1, 20, nullptr },
} };
#define FONT(x) x
#else
#define FONT(x) FONT_OPENRCT2_SPRITE
#endif // NO_TTF
const language_descriptor LanguagesDescriptors[LANGUAGE_COUNT] = {
{ "", "", "", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_UNDEFINED
@ -69,21 +74,21 @@ const language_descriptor LanguagesDescriptors[LANGUAGE_COUNT] = {
{ "nl-NL", "Dutch", "Nederlands", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_DUTCH }, // LANGUAGE_DUTCH
{ "fr-FR", "French", u8"Français", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_FRENCH }, // LANGUAGE_FRENCH
{ "hu-HU", "Hungarian", "Magyar", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_HUNGARIAN
{ "pl-PL", "Polish", "Polski", &TTFFontArial, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_POLISH
{ "pl-PL", "Polish", "Polski", FONT(&TTFFontArial), RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_POLISH
{ "es-ES", "Spanish", u8"Español", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_SPANISH }, // LANGUAGE_SPANISH
{ "sv-SE", "Swedish", "Svenska", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_SWEDISH }, // LANGUAGE_SWEDISH
{ "it-IT", "Italian", "Italiano", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_ITALIAN }, // LANGUAGE_ITALIAN
{ "pt-BR", "Portuguese (BR)", u8"Português (BR)", FONT_OPENRCT2_SPRITE,
RCT2_LANGUAGE_ID_PORTUGUESE }, // LANGUAGE_PORTUGUESE_BR
{ "zh-TW", "Chinese (Traditional)", "Chinese (Traditional)", &TTFFontMingLiu,
{ "zh-TW", "Chinese (Traditional)", "Chinese (Traditional)", FONT(&TTFFontMingLiu),
RCT2_LANGUAGE_ID_CHINESE_TRADITIONAL }, // LANGUAGE_CHINESE_TRADITIONAL
{ "zh-CN", "Chinese (Simplified)", "Chinese (Simplified)", &TTFFontSimSun,
{ "zh-CN", "Chinese (Simplified)", "Chinese (Simplified)", FONT(&TTFFontSimSun),
RCT2_LANGUAGE_ID_CHINESE_SIMPLIFIED }, // LANGUAGE_CHINESE_SIMPLIFIED
{ "fi-FI", "Finnish", "Suomi", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_FINNISH
{ "ko-KR", "Korean", "Korean", &TTFFontGulim, RCT2_LANGUAGE_ID_KOREAN }, // LANGUAGE_KOREAN
{ "ru-RU", "Russian", "Russian", &TTFFontArial, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_RUSSIAN
{ "cs-CZ", "Czech", "Czech", &TTFFontArial, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_CZECH
{ "ja-JP", "Japanese", "Japanese", &TTFFontMSGothic, RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_JAPANESE
{ "ko-KR", "Korean", "Korean", FONT(&TTFFontGulim), RCT2_LANGUAGE_ID_KOREAN }, // LANGUAGE_KOREAN
{ "ru-RU", "Russian", "Russian", FONT(&TTFFontArial), RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_RUSSIAN
{ "cs-CZ", "Czech", "Czech", FONT(&TTFFontArial), RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_CZECH
{ "ja-JP", "Japanese", "Japanese", FONT(&TTFFontMSGothic), RCT2_LANGUAGE_ID_ENGLISH_UK }, // LANGUAGE_JAPANESE
{
"nb-NO", "Norwegian", "Norsk", FONT_OPENRCT2_SPRITE, RCT2_LANGUAGE_ID_ENGLISH_UK,
}, // LANGUAGE_NORWEGIAN
@ -93,9 +98,12 @@ static void LoadSpriteFont()
{
ttf_dispose();
gUseTrueTypeFont = false;
#ifndef NO_TTF
gCurrentTTFFontSet = nullptr;
#endif // NO_TTF
}
#ifndef NO_TTF
static bool LoadFont(TTFFontSetDescriptor * font)
{
gUseTrueTypeFont = true;
@ -126,9 +134,11 @@ static bool LoadCustomConfigFont()
bool fontInitialised = ttf_initialise();
return fontInitialised;
}
#endif // NO_TTF
void TryLoadFonts()
{
#ifndef NO_TTF
TTFFontSetDescriptor * font = LanguagesDescriptors[gCurrentLanguage].font;
if (font != FONT_OPENRCT2_SPRITE)
{
@ -153,5 +163,6 @@ void TryLoadFonts()
}
Console::Error::WriteLine("Unable to initialise prefered TrueType font -- Falling back to sprite font.");
}
#endif // NO_TTF
LoadSpriteFont();
}

View File

@ -50,7 +50,11 @@ typedef struct language_descriptor {
const char *locale;
const utf8 *english_name;
const utf8 *native_name;
#ifndef NO_TTF
TTFFontSetDescriptor *font;
#else
void * font;
#endif // NO_TTF
uint8 rct2_original_id;
} language_descriptor;

View File

@ -522,6 +522,7 @@ void platform_show_messagebox(char *message) {
execute_cmd(cmd, 0, 0, 0);
}
#ifndef NO_TTF
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size)
{
assert(buffer != NULL);
@ -563,5 +564,6 @@ bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size)
FcFini();
return found;
}
#endif // NO_TTF
#endif

View File

@ -201,7 +201,9 @@ uint8 platform_get_currency_value(const char *currencyCode);
uint16 platform_get_locale_language();
uint8 platform_get_locale_measurement_format();
uint8 platform_get_locale_temperature_format();
#ifndef NO_TTF
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size);
#endif // NO_TTF
bool platform_check_steam_overlay_attached();