diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ced74958..d7e1826bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,12 +303,14 @@ find_package(OggVorbis REQUIRED) include_directories(${OGGVORBIS_INCLUDE_DIRS}) # Freetype -find_package(Freetype) -if(FREETYPE_FOUND) - include_directories(${FREETYPE_INCLUDE_DIRS}) -else() - message(FATAL_ERROR "Freetype not found. " - "Freetype is required to display characters in SuperTuxKart. ") +if (NOT SERVER_ONLY) + find_package(Freetype) + if(FREETYPE_FOUND) + include_directories(${FREETYPE_INCLUDE_DIRS}) + else() + message(FATAL_ERROR "Freetype not found. " + "Freetype is required to display characters in SuperTuxKart. ") + endif() endif() # Fribidi @@ -478,9 +480,7 @@ target_link_libraries(supertuxkart ${CURL_LIBRARIES} ${OGGVORBIS_LIBRARIES} ${OPENAL_LIBRARY} - ${FREETYPE_LIBRARIES} ${JPEG_LIBRARIES} - ${TURBOJPEG_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ) @@ -491,7 +491,7 @@ if(NOT SERVER_ONLY) target_link_libraries(supertuxkart GLESv2) endif() - target_link_libraries(supertuxkart ${SQUISH_LIBRARY} graphics_utils) + target_link_libraries(supertuxkart ${SQUISH_LIBRARY} ${FREETYPE_LIBRARIES} graphics_utils) endif() if(UNIX AND NOT APPLE) diff --git a/src/font/bold_face.cpp b/src/font/bold_face.cpp index 4f7ae33df..78a5fa7b2 100644 --- a/src/font/bold_face.cpp +++ b/src/font/bold_face.cpp @@ -59,7 +59,9 @@ void BoldFace::reset() /** Embolden the glyph to make bold font using FT_Outline_Embolden. * \return A FT_Error value. */ +#ifndef SERVER_ONLY int BoldFace::shapeOutline(FT_Outline* outline) const { return FT_Outline_Embolden(outline, getDPI() * 2); } // shapeOutline +#endif diff --git a/src/font/bold_face.hpp b/src/font/bold_face.hpp index f68030bef..dd5640555 100644 --- a/src/font/bold_face.hpp +++ b/src/font/bold_face.hpp @@ -38,7 +38,9 @@ private: // ------------------------------------------------------------------------ virtual bool isBold() const OVERRIDE { return true; } // ------------------------------------------------------------------------ +#ifndef SERVER_ONLY virtual int shapeOutline(FT_Outline* outline) const OVERRIDE; +#endif public: LEAK_CHECK() diff --git a/src/font/face_ttf.cpp b/src/font/face_ttf.cpp index fb496f590..9f577cf3e 100644 --- a/src/font/face_ttf.cpp +++ b/src/font/face_ttf.cpp @@ -27,6 +27,7 @@ */ FaceTTF::FaceTTF(const std::vector& ttf_list) { +#ifndef SERVER_ONLY for (const std::string& font : ttf_list) { FT_Face face = NULL; @@ -36,6 +37,7 @@ FaceTTF::FaceTTF(const std::vector& ttf_list) loc.c_str(), 0, &face), loc + " is loaded"); m_faces.push_back(face); } +#endif } // FaceTTF // ---------------------------------------------------------------------------- @@ -43,17 +45,10 @@ FaceTTF::FaceTTF(const std::vector& ttf_list) */ FaceTTF::~FaceTTF() { +#ifndef SERVER_ONLY for (unsigned int i = 0; i < m_faces.size(); i++) { font_manager->checkFTError(FT_Done_Face(m_faces[i]), "removing face"); } +#endif } // ~FaceTTF -// ---------------------------------------------------------------------------- -/** Return a TTF in \ref m_faces. - * \param i index of TTF file in \ref m_faces. - */ -FT_Face FaceTTF::getFace(unsigned int i) const -{ - assert(i < m_faces.size()); - return m_faces[i]; -} // getFace diff --git a/src/font/face_ttf.hpp b/src/font/face_ttf.hpp index 24ab75e22..00f615f33 100644 --- a/src/font/face_ttf.hpp +++ b/src/font/face_ttf.hpp @@ -22,11 +22,14 @@ #include "utils/leak_check.hpp" #include "utils/no_copy.hpp" +#include #include #include +#ifndef SERVER_ONLY #include #include FT_FREETYPE_H +#endif /** This class will load a list of TTF files from \ref STKConfig, and save * them inside \ref m_faces for \ref FontWithFace to load glyph. @@ -37,21 +40,31 @@ */ class FaceTTF : public NoCopy { +#ifndef SERVER_ONLY private: /** Contains all TTF files loaded. */ std::vector m_faces; - +#endif public: LEAK_CHECK() // ------------------------------------------------------------------------ FaceTTF(const std::vector& ttf_list); // ------------------------------------------------------------------------ ~FaceTTF(); +#ifndef SERVER_ONLY // ------------------------------------------------------------------------ - FT_Face getFace(unsigned int i) const; + /** Return a TTF in \ref m_faces. + * \param i index of TTF file in \ref m_faces. + */ + FT_Face getFace(unsigned int i) const + { + assert(i < m_faces.size()); + return m_faces[i]; + } // ------------------------------------------------------------------------ /** Return the total TTF files loaded. */ unsigned int getTotalFaces() const { return (unsigned int)m_faces.size(); } +#endif }; // FaceTTF diff --git a/src/font/font_manager.cpp b/src/font/font_manager.cpp index 7a20f6063..277b9f7e7 100644 --- a/src/font/font_manager.cpp +++ b/src/font/font_manager.cpp @@ -32,7 +32,9 @@ FontManager *font_manager = NULL; */ FontManager::FontManager() { +#ifndef SERVER_ONLY checkFTError(FT_Init_FreeType(&m_ft_library), "loading freetype library"); +#endif } // FontManager // ---------------------------------------------------------------------------- @@ -49,8 +51,10 @@ FontManager::~FontManager() delete m_digit_ttf; m_digit_ttf = NULL; +#ifndef SERVER_ONLY checkFTError(FT_Done_FreeType(m_ft_library), "removing freetype library"); m_ft_library = NULL; +#endif } // ~FontManager // ---------------------------------------------------------------------------- diff --git a/src/font/font_manager.hpp b/src/font/font_manager.hpp index 156cd771c..39734daeb 100644 --- a/src/font/font_manager.hpp +++ b/src/font/font_manager.hpp @@ -32,8 +32,10 @@ #include #include +#ifndef SERVER_ONLY #include #include FT_FREETYPE_H +#endif class FaceTTF; class FontWithFace; @@ -47,8 +49,10 @@ private: /** Stores all \ref FontWithFace used in STK. */ std::vector m_fonts; +#ifndef SERVER_ONLY /** A FreeType library, it holds the FT_Face internally inside freetype. */ FT_Library m_ft_library; +#endif /** TTF files used in \ref BoldFace and \ref RegularFace. */ FaceTTF* m_normal_ttf; @@ -81,6 +85,7 @@ public: return out; } // ------------------------------------------------------------------------ +#ifndef SERVER_ONLY /** Check for any error discovered in a freetype function that will return * a FT_Error value, and log into the terminal. * \param err The Freetype function. @@ -93,13 +98,15 @@ public: "code was %d.", desc.c_str(), err); } } + // ------------------------------------------------------------------------ + /** Return the \ref m_ft_library. */ + FT_Library getFTLibrary() const { return m_ft_library; } +#endif // ------------------------------------------------------------------------ void loadFonts(); // ------------------------------------------------------------------------ void unitTesting(); - // ------------------------------------------------------------------------ - /** Return the \ref m_ft_library. */ - FT_Library getFTLibrary() const { return m_ft_library; } + }; // FontManager diff --git a/src/font/font_with_face.cpp b/src/font/font_with_face.cpp index e1505e812..8b484f6d7 100644 --- a/src/font/font_with_face.cpp +++ b/src/font/font_with_face.cpp @@ -76,6 +76,7 @@ FontWithFace::~FontWithFace() void FontWithFace::init() { setDPI(); +#ifndef SERVER_ONLY // Get the max height for this face assert(m_face_ttf->getTotalFaces() > 0); FT_Face cur_face = m_face_ttf->getFace(0); @@ -94,7 +95,7 @@ void FontWithFace::init() if (height > m_glyph_max_height) m_glyph_max_height = height; } - +#endif reset(); } // init @@ -125,6 +126,7 @@ void FontWithFace::reset() */ void FontWithFace::loadGlyphInfo(wchar_t c) { +#ifndef SERVER_ONLY unsigned int font_number = 0; unsigned int glyph_index = 0; while (font_number < m_face_ttf->getTotalFaces()) @@ -134,6 +136,7 @@ void FontWithFace::loadGlyphInfo(wchar_t c) font_number++; } m_character_glyph_info_map[c] = GlyphInfo(font_number, glyph_index); +#endif } // loadGlyphInfo // ---------------------------------------------------------------------------- @@ -169,6 +172,7 @@ void FontWithFace::createNewGlyphPage() */ void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi) { +#ifndef SERVER_ONLY assert(gi.glyph_index > 0); assert(gi.font_number < m_face_ttf->getTotalFaces()); FT_Face cur_face = m_face_ttf->getFace(gi.font_number); @@ -209,7 +213,6 @@ void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi) } const unsigned int cur_tex = m_spritebank->getTextureCount() -1; -#ifndef SERVER_ONLY if (bits->buffer != NULL && !ProfileWorld::isNoGraphics()) { video::ITexture* tex = m_spritebank->getTexture(cur_tex); @@ -237,7 +240,6 @@ void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi) glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); } -#endif // Store the rectangle of current glyph gui::SGUISpriteFrame f; @@ -269,6 +271,7 @@ void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi) m_used_width += texture_size.Width; if (m_current_height < texture_size.Height) m_current_height = texture_size.Height; +#endif } // insertGlyph // ---------------------------------------------------------------------------- @@ -296,6 +299,7 @@ void FontWithFace::updateCharactersList() */ void FontWithFace::dumpGlyphPage(const std::string& name) { +#ifndef SERVER_ONLY for (unsigned int i = 0; i < m_spritebank->getTextureCount(); i++) { video::ITexture* tex = m_spritebank->getTexture(i); @@ -310,6 +314,7 @@ void FontWithFace::dumpGlyphPage(const std::string& name) (name + "_" + StringUtils::toString(i) + ".png").c_str()); image->drop(); } +#endif } // dumpGlyphPage // ---------------------------------------------------------------------------- @@ -393,6 +398,10 @@ const FontWithFace::FontArea& core::dimension2d FontWithFace::getDimension(const wchar_t* text, FontSettings* font_settings) { +#ifdef SERVER_ONLY + return core::dimension2d(1, 1); +#else + const float scale = font_settings ? font_settings->getScale() : 1.0f; // Test if lazy load char is needed insertCharacters(text); @@ -431,6 +440,7 @@ core::dimension2d FontWithFace::getDimension(const wchar_t* text, ret_dim.Height = (u32)(dim.Height + 0.9f); return ret_dim; +#endif } // getDimension // ---------------------------------------------------------------------------- diff --git a/src/font/font_with_face.hpp b/src/font/font_with_face.hpp index ca960c218..86a6541d4 100644 --- a/src/font/font_with_face.hpp +++ b/src/font/font_with_face.hpp @@ -29,9 +29,11 @@ #include #include +#ifndef SERVER_ONLY #include #include FT_FREETYPE_H #include FT_OUTLINE_H +#endif #include @@ -261,10 +263,12 @@ private: /** Override it if sub-class has bold outline. */ virtual bool isBold() const { return false; } // ------------------------------------------------------------------------ +#ifndef SERVER_ONLY /** Override it if any outline shaping is needed to be done before * rendering the glyph into bitmap. * \return A FT_Error value if needed. */ virtual int shapeOutline(FT_Outline* outline) const { return 0; } +#endif public: LEAK_CHECK() diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index e106f1038..e00edc9ba 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -87,8 +87,10 @@ void ScalableFont::draw(const core::stringw& text, bool hcenter, bool vcenter, const core::rect* clip) { +#ifndef SERVER_ONLY m_face->render(text, position, color, hcenter, vcenter, clip, m_font_settings); +#endif } // draw // ---------------------------------------------------------------------------- @@ -98,7 +100,6 @@ void ScalableFont::draw(const core::stringw& text, const core::rect* clip, bool ignoreRTL) { #ifndef SERVER_ONLY - bool previousRTL = m_font_settings->isRTL(); if (ignoreRTL) m_font_settings->setRTL(false);