Disable freetype in no graphics

This commit is contained in:
Benau 2018-09-13 01:11:17 +08:00
parent 930115a449
commit 7d561de3fb
3 changed files with 35 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include "font/font_manager.hpp"
#include "io/file_manager.hpp"
#include "modes/profile_world.hpp"
// ----------------------------------------------------------------------------
/** Constructor. Load all TTFs from a list.
@ -28,6 +29,9 @@
FaceTTF::FaceTTF(const std::vector<std::string>& ttf_list)
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
for (const std::string& font : ttf_list)
{
FT_Face face = NULL;
@ -46,6 +50,9 @@ FaceTTF::FaceTTF(const std::vector<std::string>& ttf_list)
FaceTTF::~FaceTTF()
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
for (unsigned int i = 0; i < m_faces.size(); i++)
{
font_manager->checkFTError(FT_Done_Face(m_faces[i]), "removing face");

View File

@ -23,6 +23,7 @@
#include "font/digit_face.hpp"
#include "font/face_ttf.hpp"
#include "font/regular_face.hpp"
#include "modes/profile_world.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
@ -33,6 +34,10 @@ FontManager *font_manager = NULL;
FontManager::FontManager()
{
#ifndef SERVER_ONLY
m_ft_library = NULL;
if (ProfileWorld::isNoGraphics())
return;
checkFTError(FT_Init_FreeType(&m_ft_library), "loading freetype library");
#endif
} // FontManager
@ -52,8 +57,10 @@ FontManager::~FontManager()
m_digit_ttf = NULL;
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
checkFTError(FT_Done_FreeType(m_ft_library), "removing freetype library");
m_ft_library = NULL;
#endif
} // ~FontManager

View File

@ -77,6 +77,12 @@ void FontWithFace::init()
{
setDPI();
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
{
reset();
return;
}
// Get the max height for this face
assert(m_face_ttf->getTotalFaces() > 0);
FT_Face cur_face = m_face_ttf->getFace(0);
@ -127,6 +133,9 @@ void FontWithFace::reset()
void FontWithFace::loadGlyphInfo(wchar_t c)
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
unsigned int font_number = 0;
unsigned int glyph_index = 0;
while (font_number < m_face_ttf->getTotalFaces())
@ -145,6 +154,9 @@ void FontWithFace::loadGlyphInfo(wchar_t c)
void FontWithFace::createNewGlyphPage()
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
uint8_t* data = new uint8_t[getGlyphPageSize() * getGlyphPageSize() *
(CVS->isARBTextureSwizzleUsable() ? 1 : 4)]();
#else
@ -173,6 +185,9 @@ void FontWithFace::createNewGlyphPage()
void FontWithFace::insertGlyph(wchar_t c, const GlyphInfo& gi)
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
assert(gi.glyph_index > 0);
assert(gi.font_number < m_face_ttf->getTotalFaces());
FT_Face cur_face = m_face_ttf->getFace(gi.font_number);
@ -401,6 +416,8 @@ core::dimension2d<u32> FontWithFace::getDimension(const wchar_t* text,
#ifdef SERVER_ONLY
return core::dimension2d<u32>(1, 1);
#else
if (ProfileWorld::isNoGraphics())
return core::dimension2d<u32>(1, 1);
const float scale = font_settings ? font_settings->getScale() : 1.0f;
// Test if lazy load char is needed
@ -494,6 +511,9 @@ void FontWithFace::render(const core::stringw& text,
FontCharCollector* char_collector)
{
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics())
return;
const bool black_border = font_settings ?
font_settings->useBlackBorder() : false;
const bool rtl = font_settings ? font_settings->isRTL() : false;