Remove freetype in server only build

This commit is contained in:
Benau 2018-07-07 02:06:49 +08:00
parent 00db1f8405
commit a60b2d3761
10 changed files with 65 additions and 27 deletions

View File

@ -303,12 +303,14 @@ find_package(OggVorbis REQUIRED)
include_directories(${OGGVORBIS_INCLUDE_DIRS})
# Freetype
find_package(Freetype)
if(FREETYPE_FOUND)
if (NOT SERVER_ONLY)
find_package(Freetype)
if(FREETYPE_FOUND)
include_directories(${FREETYPE_INCLUDE_DIRS})
else()
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)

View File

@ -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

View File

@ -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()

View File

@ -27,6 +27,7 @@
*/
FaceTTF::FaceTTF(const std::vector<std::string>& 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<std::string>& 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<std::string>& 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

View File

@ -22,11 +22,14 @@
#include "utils/leak_check.hpp"
#include "utils/no_copy.hpp"
#include <cassert>
#include <string>
#include <vector>
#ifndef SERVER_ONLY
#include <ft2build.h>
#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<FT_Face> m_faces;
#endif
public:
LEAK_CHECK()
// ------------------------------------------------------------------------
FaceTTF(const std::vector<std::string>& 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

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -32,8 +32,10 @@
#include <unordered_map>
#include <vector>
#ifndef SERVER_ONLY
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
class FaceTTF;
class FontWithFace;
@ -47,8 +49,10 @@ private:
/** Stores all \ref FontWithFace used in STK. */
std::vector<FontWithFace*> 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

View File

@ -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<u32> FontWithFace::getDimension(const wchar_t* text,
FontSettings* font_settings)
{
#ifdef SERVER_ONLY
return core::dimension2d<u32>(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<u32> FontWithFace::getDimension(const wchar_t* text,
ret_dim.Height = (u32)(dim.Height + 0.9f);
return ret_dim;
#endif
} // getDimension
// ----------------------------------------------------------------------------

View File

@ -29,9 +29,11 @@
#include <set>
#include <string>
#ifndef SERVER_ONLY
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#endif
#include <irrlicht.h>
@ -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()

View File

@ -87,8 +87,10 @@ void ScalableFont::draw(const core::stringw& text,
bool hcenter, bool vcenter,
const core::rect<s32>* 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<s32>* clip, bool ignoreRTL)
{
#ifndef SERVER_ONLY
bool previousRTL = m_font_settings->isRTL();
if (ignoreRTL)
m_font_settings->setRTL(false);