Verified Commit 9abb4efb authored by RobLoach's avatar RobLoach
Browse files

Add TrueType font loading

parent 4df25427
......@@ -28,3 +28,6 @@
[submodule "vendor/zlib"]
path = vendor/zlib
url = https://github.com/madler/zlib.git
[submodule "vendor/libretro-deps"]
path = vendor/libretro-deps
url = https://github.com/libretro/libretro-deps.git
......@@ -52,12 +52,68 @@ SOURCES_C += $(wildcard \
vendor/sdl-libretro/tests/SDL_gfx-2.0.26/*.c \
)
# FreeType
# See https://github.com/emscripten-ports/FreeType/blob/master/builds/amiga/makefile
FLAGS += -Ivendor/libretro-deps/freetype/include
FLAGS += -DFT2_BUILD_LIBRARY \
-DFT_USE_AUTOFIT \
-DFT_USE_RASTER \
-DFT_USE_SMOOTH \
-DFT_USE_TT \
-DFT_USE_T1 \
-DFT_USE_T42 \
-DFT_USE_T1CID \
-DFT_USE_CFF \
-DFT_USE_OTV \
-DFT_USE_GXV
SOURCES_C += \
vendor/libretro-deps/freetype/src/base/ftbase.c \
vendor/libretro-deps/freetype/src/base/ftinit.c \
vendor/libretro-deps/freetype/src/base/ftsystem.c \
vendor/libretro-deps/freetype/src/base/ftdebug.c \
vendor/libretro-deps/freetype/src/base/ftbbox.c \
vendor/libretro-deps/freetype/src/base/ftbdf.c \
vendor/libretro-deps/freetype/src/base/ftstroke.c \
vendor/libretro-deps/freetype/src/base/ftbitmap.c \
vendor/libretro-deps/freetype/src/base/ftcid.c \
vendor/libretro-deps/freetype/src/base/ftfntfmt.c \
vendor/libretro-deps/freetype/src/base/ftfstype.c \
vendor/libretro-deps/freetype/src/base/ftgasp.c \
vendor/libretro-deps/freetype/src/base/ftglyph.c \
vendor/libretro-deps/freetype/src/base/ftgxval.c \
vendor/libretro-deps/freetype/src/base/ftlcdfil.c \
vendor/libretro-deps/freetype/src/base/ftmm.c \
vendor/libretro-deps/freetype/src/base/ftotval.c \
vendor/libretro-deps/freetype/src/base/ftpatent.c \
vendor/libretro-deps/freetype/src/base/ftpfr.c \
vendor/libretro-deps/freetype/src/base/ftsynth.c \
vendor/libretro-deps/freetype/src/base/fttype1.c \
vendor/libretro-deps/freetype/src/base/ftwinfnt.c \
vendor/libretro-deps/freetype/src/autofit/autofit.c \
vendor/libretro-deps/freetype/src/pshinter/pshinter.c \
vendor/libretro-deps/freetype/src/psaux/psaux.c \
vendor/libretro-deps/freetype/src/psnames/psnames.c \
vendor/libretro-deps/freetype/src/raster/raster.c \
vendor/libretro-deps/freetype/src/smooth/smooth.c \
vendor/libretro-deps/freetype/src/cache/ftcache.c \
vendor/libretro-deps/freetype/src/bdf/bdf.c \
vendor/libretro-deps/freetype/src/cff/cff.c \
vendor/libretro-deps/freetype/src/pcf/pcf.c \
vendor/libretro-deps/freetype/src/winfonts/winfnt.c \
vendor/libretro-deps/freetype/src/sfnt/sfnt.c \
vendor/libretro-deps/freetype/src/pfr/pfr.c \
vendor/libretro-deps/freetype/src/truetype/truetype.c \
vendor/libretro-deps/freetype/src/type1/type1.c \
vendor/libretro-deps/freetype/src/type42/type42.c \
vendor/libretro-deps/freetype/src/cid/type1cid.c \
vendor/libretro-deps/freetype/src/gzip/ftgzip.c \
vendor/libretro-deps/freetype/src/bzip2/ftbzip2.c \
vendor/libretro-deps/freetype/src/lzw/ftlzw.c
# SDL_ttf
# TODO Fix TTF Support https://github.com/RobLoach/ChaiLove/issues/48
#FLAGS += -Ivendor/sdl-libretro/tests/SDL_ttf-2.0.11/VisualC/external/include
#SOURCES_C += $(wildcard \
# vendor/sdl-libretro/tests/SDL_ttf-2.0.11/*.c \
#)
FLAGS += -Ivendor/sdl-libretro/tests/SDL_ttf-2.0.11/VisualC/external/include
SOURCES_C += vendor/sdl-libretro/tests/SDL_ttf-2.0.11/SDL_ttf.c
# SDL_stbimage
FLAGS += -Ivendor/Snippets
......
#include <string>
#include <iostream>
#include "SDL.h"
//#include "SDL_ttf.h"
#include "SDL_ttf.h"
#include "font.h"
#include "../Types/Graphics/Font.h"
namespace Modules {
bool font::load() {
/*int result = TTF_Init();
int result = TTF_Init();
if(result == -1) {
const char* errorChar = TTF_GetError();
std::string errString("");
if (errorChar != NULL) {
errString = errorChar;
}
std::cout << "[ChaiLove] TTF_Init failed to initialize font system: {}", errString);
std::cout << "[ChaiLove] TTF_Init failed to initialize font system: {}" << errString << std::endl;
return false;
}*/
}
return true;
}
bool font::unload() {
TTF_Quit();
return true;
}
bool font::isOpen() {
return true;
/*
return TTF_WasInit();
*/
}
}
#include "Font.h"
#include "SDL.h"
#include <string>
//#include "SDL_ttf.h"
#include "SDL_ttf.h"
#include <SDL_gfxPrimitives.h>
#include <SDL_fnt.h>
#include "../../ChaiLove.h"
......@@ -30,8 +30,6 @@ namespace Types {
}
Font::Font(const std::string& filename, int ptsize) {
std::cout << "[ChaiLove] TTF fonts are not supported by ChaiLove, currently." << std::endl;
/*
SDL_RWops* rwops = ChaiLove::getInstance()->filesystem.openRW(filename);
if (rwops) {
TTF_Font* newFont = TTF_OpenFontRW(rwops, 1, ptsize);
......@@ -41,13 +39,12 @@ namespace Types {
if (errorChar != NULL) {
errString = errorChar;
}
std::cout << "TTF_OpenFontRW: {}", errString);
std::cout << "TTF_OpenFontRW: {}" << errString << std::endl;
return;
}
ttfFont = newFont;
}
*/
}
Font::~Font() {
......@@ -55,14 +52,14 @@ namespace Types {
}
bool Font::loaded() {
return /*ttfFont != NULL ||*/ ttyFont != NULL;
return ttfFont != NULL || ttyFont != NULL;
}
bool Font::destroy() {
/*if (ttfFont != NULL) {
if (ttfFont != NULL) {
TTF_CloseFont(ttfFont);
ttfFont = NULL;
}*/
}
if (ttyFont != NULL) {
FNT_Free(ttyFont);
......@@ -76,9 +73,9 @@ namespace Types {
}
int Font::getHeight(const std::string& text) {
/*if (ttfFont != NULL) {
if (ttfFont != NULL) {
return TTF_FontHeight(ttfFont);
}*/
}
if (ttyFont != NULL) {
return FNT_GetTextHeight(ttyFont, text.c_str());
}
......@@ -87,9 +84,9 @@ namespace Types {
}
int Font::getHeight() {
/*if (ttfFont != NULL) {
if (ttfFont != NULL) {
return TTF_FontHeight(ttfFont);
}*/
}
if (ttyFont != NULL) {
return ttyFontHeight;
}
......@@ -98,12 +95,12 @@ namespace Types {
}
int Font::getWidth(const std::string& text) {
/*if (ttfFont != NULL) {
if (ttfFont != NULL) {
int w;
if (TTF_SizeText(ttfFont, text.c_str(), &w, NULL) == 0) {
return w;
}
}*/
}
if (ttyFont != NULL) {
return FNT_GetTextWidth(ttyFont, text.c_str());
......@@ -115,7 +112,6 @@ namespace Types {
void Font::print(const std::string& text, int x, int y, int r, int g, int b, int a) {
SDL_Surface* screen = ChaiLove::getInstance()->screen;
/*
// Attempt to render the TTF Font.
if (ttfFont != NULL) {
SDL_Color color = {(Uint8)r, (Uint8)g, (Uint8)b};
......@@ -126,7 +122,7 @@ namespace Types {
if (errorChar != NULL) {
errString = errorChar;
}
std::cout << "[ChaiLove] Font::print - %s", errString);
std::cout << "[ChaiLove] Font::print - %s" << errString << std::endl;
return;
}
......@@ -138,7 +134,7 @@ namespace Types {
// TODO: Allow re-use of text renderings.
SDL_FreeSurface(surface);
return;
}*/
}
// Use TTY to print the bitmap font?
if (ttyFont != NULL) {
......
......@@ -2,7 +2,7 @@
#define CHAILOVE_UTILITY_FONT_H
#include "SDL.h"
//#include "SDL_ttf.h"
#include "SDL_ttf.h"
#include <string>
#include <SDL_fnt.h>
#include "Image.h"
......@@ -21,7 +21,7 @@ namespace Types {
bool loaded();
bool destroy();
void print(const std::string& text, int x, int y, int r, int g, int b, int a);
//TTF_Font* ttfFont = NULL;
TTF_Font* ttfFont = NULL;
TTY_Font* ttyFont = NULL;
int ttyFontWidth, ttyFontHeight;
/**
......
Subproject commit f761146020ae9c06b25899569bb44c74ca8ca2ca
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment