From 7eba046aa412630309485a15681927b751a3fa1d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 10 Jun 2014 21:23:58 -0400 Subject: [PATCH] add FontManager, Font classes --- Rakefile.rb | 6 +++--- src/gui/Font.cc | 18 ++++++++++++++++++ src/gui/Font.h | 21 +++++++++++++++++++++ src/gui/FontManager.cc | 14 ++++++++++++++ src/gui/FontManager.h | 21 +++++++++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/gui/Font.cc create mode 100644 src/gui/Font.h create mode 100644 src/gui/FontManager.cc create mode 100644 src/gui/FontManager.h diff --git a/Rakefile.rb b/Rakefile.rb index 15df8a7..815fb4c 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -22,9 +22,9 @@ end task :gui => :library do base_env.clone(clone: :all) do |env| - env["CFLAGS"] += `sdl2-config --cflags`.split(" ") - env["CXXFLAGS"] += `sdl2-config --cflags`.split(" ") - env["LDCMD"] += `sdl2-config --libs`.split(" ") + env["CFLAGS"] += `sdl2-config --cflags`.split(" ") + `freetype-config --cflags`.split(" ") + env["CXXFLAGS"] += `sdl2-config --cflags`.split(" ") + `freetype-config --cflags`.split(" ") + env["LDCMD"] += `sdl2-config --libs`.split(" ") + `freetype-config --libs`.split(" ") env["LIBS"] += ["dl", "GL"] env.Program("^/jes", Dir["src/gui/**/*.{cc,c}"]) end diff --git a/src/gui/Font.cc b/src/gui/Font.cc new file mode 100644 index 0000000..3c0491d --- /dev/null +++ b/src/gui/Font.cc @@ -0,0 +1,18 @@ +#include "Font.h" +#include + +namespace jes +{ + bool Font::load(FT_Library ft, const char * fname, size_t size) + { + if (FT_New_Face(ft, fname, 0, &m_face) != 0) + { + std::cerr << "Could not load font " << fname << std::endl; + return false; + } + + FT_Set_Pixel_Sizes(m_face, 0, size); + + return true; + } +} diff --git a/src/gui/Font.h b/src/gui/Font.h new file mode 100644 index 0000000..3dfffa6 --- /dev/null +++ b/src/gui/Font.h @@ -0,0 +1,21 @@ +#ifndef JES_FONT_H +#define JES_FONT_H + +#include "jes/Ref.h" +#include +#include FT_FREETYPE_H + +namespace jes +{ + class Font + { + public: + bool load(FT_Library ft, const char * fname, size_t size); + protected: + FT_Face m_face; + }; + + typedef Ref FontRef; +} + +#endif diff --git a/src/gui/FontManager.cc b/src/gui/FontManager.cc new file mode 100644 index 0000000..b89ebfe --- /dev/null +++ b/src/gui/FontManager.cc @@ -0,0 +1,14 @@ +#include "FontManager.h" +#include + +namespace jes +{ + FontManager::FontManager() + { + if (FT_Init_FreeType(&m_ft) != 0) + { + std::cerr << "Error initializing FreeType" << std::endl; + return; + } + } +} diff --git a/src/gui/FontManager.h b/src/gui/FontManager.h new file mode 100644 index 0000000..f20e535 --- /dev/null +++ b/src/gui/FontManager.h @@ -0,0 +1,21 @@ +#ifndef JES_FONTMANAGER_H +#define JES_FONTMANAGER_H + +#include "jes/Ref.h" +#include +#include FT_FREETYPE_H + +namespace jes +{ + class FontManager + { + public: + FontManager(); + protected: + FT_Library m_ft; + }; + + typedef Ref FontManagerRef; +} + +#endif