Build more of font_sdl.cpp with Emscripten since there is an SDL2_ttf port now (nw)

This commit is contained in:
Justin Kerk 2016-03-17 01:42:48 +00:00
parent 157de7d935
commit d0ce8784a7
3 changed files with 16 additions and 8 deletions

View file

@ -1059,6 +1059,7 @@ configuration { "asmjs" }
buildoptions { buildoptions {
"-std=gnu89", "-std=gnu89",
"-Wno-implicit-function-declaration", "-Wno-implicit-function-declaration",
"-s USE_SDL_TTF=2",
} }
buildoptions_cpp { buildoptions_cpp {
"-x c++", "-x c++",

View file

@ -109,6 +109,7 @@ end
local emccopts = "" local emccopts = ""
emccopts = emccopts .. " -O3" emccopts = emccopts .. " -O3"
emccopts = emccopts .. " -s USE_SDL=2" emccopts = emccopts .. " -s USE_SDL=2"
emccopts = emccopts .. " -s USE_SDL_TTF=2"
emccopts = emccopts .. " --memory-init-file 0" emccopts = emccopts .. " --memory-init-file 0"
emccopts = emccopts .. " -s ALLOW_MEMORY_GROWTH=0" emccopts = emccopts .. " -s ALLOW_MEMORY_GROWTH=0"
emccopts = emccopts .. " -s TOTAL_MEMORY=268435456" emccopts = emccopts .. " -s TOTAL_MEMORY=268435456"

View file

@ -8,15 +8,19 @@
#include "font_module.h" #include "font_module.h"
#include "modules/osdmodule.h" #include "modules/osdmodule.h"
#if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX) && !defined(SDLMAME_SOLARIS) && !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN) #if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX) && !defined(SDLMAME_SOLARIS) && !defined(SDLMAME_HAIKU)
#include "corestr.h" #include "corestr.h"
#include "corealloc.h" #include "corealloc.h"
#include "fileio.h" #include "fileio.h"
#include "unicode.h" #include "unicode.h"
#ifdef SDLMAME_EMSCRIPTEN
#include <SDL_ttf.h>
#else
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#ifndef SDLMAME_HAIKU #endif
#if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#endif #endif
@ -52,7 +56,7 @@ private:
static constexpr double POINT_SIZE = 144.0; static constexpr double POINT_SIZE = 144.0;
#ifndef SDLMAME_HAIKU #if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
TTF_Font_ptr search_font_config(std::string const &name, bool bold, bool italic, bool underline, bool &bakedstyles); TTF_Font_ptr search_font_config(std::string const &name, bool bold, bool italic, bool underline, bool &bakedstyles);
#endif #endif
bool BDF_Check_Magic(std::string const &name); bool BDF_Check_Magic(std::string const &name);
@ -97,7 +101,7 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
} }
// if that didn't work, crank up the FontConfig database // if that didn't work, crank up the FontConfig database
#ifndef SDLMAME_HAIKU #if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
if (!font) if (!font)
{ {
font = search_font_config(name, bold, italic, underline, bakedstyles); font = search_font_config(name, bold, italic, underline, bakedstyles);
@ -214,7 +218,7 @@ bool osd_font_sdl::BDF_Check_Magic(std::string const &name)
return false; return false;
} }
#ifndef SDLMAME_HAIKU #if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
osd_font_sdl::TTF_Font_ptr osd_font_sdl::search_font_config(std::string const &name, bool bold, bool italic, bool underline, bool &bakedstyles) osd_font_sdl::TTF_Font_ptr osd_font_sdl::search_font_config(std::string const &name, bool bold, bool italic, bool underline, bool &bakedstyles)
{ {
TTF_Font_ptr font(nullptr, &TTF_CloseFont); TTF_Font_ptr font(nullptr, &TTF_CloseFont);
@ -296,12 +300,12 @@ public:
{ {
} }
osd_font::ptr font_alloc() osd_font::ptr font_alloc() override
{ {
return std::make_unique<osd_font_sdl>(); return std::make_unique<osd_font_sdl>();
} }
virtual int init(const osd_options &options) virtual int init(const osd_options &options) override
{ {
if (TTF_Init() == -1) if (TTF_Init() == -1)
{ {
@ -311,7 +315,7 @@ public:
return 0; return 0;
} }
virtual void exit() virtual void exit() override
{ {
TTF_Quit(); TTF_Quit();
} }
@ -326,6 +330,7 @@ bool font_sdl::get_font_families(std::string const &font_path, std::vector<std::
// TODO: enumerate TTF files in font path, since we can load them, too // TODO: enumerate TTF files in font path, since we can load them, too
#if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
FcConfig *const config = FcConfigGetCurrent(); FcConfig *const config = FcConfigGetCurrent();
std::unique_ptr<FcPattern, void (*)(FcPattern *)> pat(FcPatternCreate(), &FcPatternDestroy); std::unique_ptr<FcPattern, void (*)(FcPattern *)> pat(FcPatternCreate(), &FcPatternDestroy);
FcPatternAddString(pat.get(), FC_FONTFORMAT, (const FcChar8 *)"TrueType"); FcPatternAddString(pat.get(), FC_FONTFORMAT, (const FcChar8 *)"TrueType");
@ -355,6 +360,7 @@ bool font_sdl::get_font_families(std::string const &font_path, std::vector<std::
if ((result.end() == pos) || (pos->first != font.first)) result.emplace(pos, std::move(font)); if ((result.end() == pos) || (pos->first != font.first)) result.emplace(pos, std::move(font));
} }
} }
#endif
return true; return true;
} }