diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index 467544e1f..67b97f732 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -139,6 +139,8 @@ public: Font3D *ConvertFont2DTo3D(Font2D *font); +const char* findFont(const char *firstFontToTry=NULL); + }}//end namespace #endif diff --git a/source/shared_lib/include/graphics/gl/font_textFTGL.h b/source/shared_lib/include/graphics/gl/font_textFTGL.h index a1705ba5a..cb1008deb 100644 --- a/source/shared_lib/include/graphics/gl/font_textFTGL.h +++ b/source/shared_lib/include/graphics/gl/font_textFTGL.h @@ -48,11 +48,8 @@ public: private: FTFont *ftFont; - //FTGLPixmapFont *ftFont; const char* fontFile; - const char* findFont(const char *firstFontToTry=NULL); - void cleanupFont(); }; diff --git a/source/shared_lib/include/graphics/gl/font_text_freetypegl.h b/source/shared_lib/include/graphics/gl/font_text_freetypegl.h index 6826fc201..ab2323a95 100644 --- a/source/shared_lib/include/graphics/gl/font_text_freetypegl.h +++ b/source/shared_lib/include/graphics/gl/font_text_freetypegl.h @@ -54,20 +54,16 @@ public: virtual float LineHeight(const wchar_t* = L" ", const int = -1); private: - //FTFont *ftFont; + VertexBuffer *buffer; TextureAtlas *atlas; TextureFont *font; - //TextureGlyph *glyph; FontManager *manager; - //Markup markup; int fontFaceSize; string fontName; const char* fontFile; - const char* findFont(const char *firstFontToTry=NULL); - void cleanupFont(); }; diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 97dbc7779..daac9c125 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -14,19 +14,18 @@ #include "conversion.h" #ifdef USE_FTGL - #include "font_textFTGL.h" #include #include -using namespace Shared::Util; using namespace Shared::Graphics::Gl; - #endif #ifdef USE_FREETYPEGL - #include "font_text_freetypegl.h" +#endif +#ifdef HAVE_FONTCONFIG +#include #endif #include "util.h" @@ -264,4 +263,138 @@ Font3D::Font3D(FontTextHandlerType type) : Font(type) { depth= 10.f; } +const char* findFont(const char *firstFontToTry) { + const char* font = NULL; + const char* path = NULL; + + #define CHECK_FONT_PATH(filename) \ + { \ + path = filename; \ + if( !font && path && fileExists(path) == true ) \ + font = strdup(path); \ + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found font file [%s]\n",font); \ + } + + string tryFont = ""; + if(firstFontToTry) { + tryFont = firstFontToTry; + #ifdef WIN32 + replaceAll(tryFont, "/", "\\"); + #endif + + CHECK_FONT_PATH(tryFont.c_str()) + } + + // Get user-specified font path + if(getenv("MEGAGLEST_FONT") != NULL) { + tryFont = getenv("MEGAGLEST_FONT"); + #ifdef WIN32 + replaceAll(tryFont, "/", "\\"); + #endif + + CHECK_FONT_PATH(tryFont.c_str()) + } + + string data_path = Text::DEFAULT_FONT_PATH; + string defaultFont = data_path + "data/core/fonts/LinBiolinum_RB.ttf";//LinBiolinum_Re-0.6.4.ttf + tryFont = defaultFont; + #ifdef WIN32 + replaceAll(tryFont, "/", "\\"); + #endif + CHECK_FONT_PATH(tryFont.c_str()) + +#ifdef FONT_PATH + // Get distro-specified font path + CHECK_FONT_PATH(FONT_PATH) +#endif + +#ifdef HAVE_FONTCONFIG + // Get default font via fontconfig + if( !font && FcInit() ) { + FcResult result; + FcFontSet *fs; + FcPattern* pat; + FcPattern *match; + + /* + TRANSLATORS: If using the FTGL backend, this should be the font + name of a font that contains all the Unicode characters in use in + your translation. + */ + pat = FcNameParse((FcChar8 *)"Gothic Uralic"); + FcConfigSubstitute(0, pat, FcMatchPattern); + + FcPatternDel(pat, FC_WEIGHT); + FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); + + FcDefaultSubstitute(pat); + fs = FcFontSetCreate(); + match = FcFontMatch(0, pat, &result); + + if (match) FcFontSetAdd(fs, match); + if (pat) FcPatternDestroy(pat); + if(fs) { + FcChar8* file; + if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch ) { + CHECK_FONT_PATH((const char*)file) + } + FcFontSetDestroy(fs); + } + FcFini(); + } +#endif + + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") + + // Check a couple of common paths for Gothic Uralic/bold as a last resort + // Debian + /* + TRANSLATORS: If using the FTGL backend, this should be the path of a bold + font that contains all the Unicode characters in use in your translation. + If the font is available in Debian it should be the Debian path. + */ + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") + /* + TRANSLATORS: If using the FTGL backend, this should be the path of a + font that contains all the Unicode characters in use in your translation. + If the font is available in Debian it should be the Debian path. + */ + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") + // Mandrake + /* + TRANSLATORS: If using the FTGL backend, this should be the path of a bold + font that contains all the Unicode characters in use in your translation. + If the font is available in Mandrake it should be the Mandrake path. + */ + CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") + /* + TRANSLATORS: If using the FTGL backend, this should be the path of a + font that contains all the Unicode characters in use in your translation. + If the font is available in Mandrake it should be the Mandrake path. + */ + CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") + + // Check the non-translated versions of the above + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") + CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") + CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") + + CHECK_FONT_PATH("/usr/share/fonts/truetype/linux-libertine/LinLibertine_Re.ttf") + + CHECK_FONT_PATH("/usr/share/fonts/truetype/freefont/FreeSerif.ttf") + CHECK_FONT_PATH("/usr/share/fonts/truetype/freefont/FreeSans.ttf") + CHECK_FONT_PATH("/usr/share/fonts/truetype/freefont/FreeMono.ttf") + +#ifdef _WIN32 + CHECK_FONT_PATH("c:\\windows\\fonts\\verdana.ttf") + CHECK_FONT_PATH("c:\\windows\\fonts\\tahoma.ttf") + CHECK_FONT_PATH("c:\\windows\\fonts\\arial.ttf") + CHECK_FONT_PATH("\\windows\\fonts\\arial.ttf") +#endif + + return font; +} + + }}//end namespace diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index 2b669363e..42e4798ee 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -429,126 +429,6 @@ float TextFTGL::Advance(const wchar_t* str, const int len) { return result; } -const char* TextFTGL::findFont(const char *firstFontToTry) { - const char* font = NULL; - const char* path = NULL; - - #define CHECK_FONT_PATH(filename) \ - { \ - path = filename; \ - if( !font && path && fileExists(path) == true ) \ - font = strdup(path); \ - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found font file [%s]\n",font); \ - } - - string tryFont = ""; - if(firstFontToTry) { - tryFont = firstFontToTry; - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - - CHECK_FONT_PATH(tryFont.c_str()) - } - - // Get user-specified font path - if(getenv("MEGAGLEST_FONT") != NULL) { - tryFont = getenv("MEGAGLEST_FONT"); - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - - CHECK_FONT_PATH(tryFont.c_str()) - } - - string data_path = Text::DEFAULT_FONT_PATH; - string defaultFont = data_path + "data/core/fonts/LinBiolinum_RB.ttf";//LinBiolinum_Re-0.6.4.ttf - tryFont = defaultFont; - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - CHECK_FONT_PATH(tryFont.c_str()) - -#ifdef FONT_PATH - // Get distro-specified font path - CHECK_FONT_PATH(FONT_PATH) -#endif - -#ifdef HAVE_FONTCONFIG - // Get default font via fontconfig - if( !font && FcInit() ) { - FcResult result; - FcFontSet *fs; - FcPattern* pat; - FcPattern *match; - - /* - TRANSLATORS: If using the FTGL backend, this should be the font - name of a font that contains all the Unicode characters in use in - your translation. - */ - pat = FcNameParse((FcChar8 *)"Gothic Uralic"); - FcConfigSubstitute(0, pat, FcMatchPattern); - - FcPatternDel(pat, FC_WEIGHT); - FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); - - FcDefaultSubstitute(pat); - fs = FcFontSetCreate(); - match = FcFontMatch(0, pat, &result); - - if (match) FcFontSetAdd(fs, match); - if (pat) FcPatternDestroy(pat); - if(fs) { - FcChar8* file; - if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch ) { - CHECK_FONT_PATH((const char*)file) - } - FcFontSetDestroy(fs); - } - FcFini(); - } -#endif - - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - - // Check a couple of common paths for Gothic Uralic/bold as a last resort - // Debian - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a bold - font that contains all the Unicode characters in use in your translation. - If the font is available in Debian it should be the Debian path. - */ - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a - font that contains all the Unicode characters in use in your translation. - If the font is available in Debian it should be the Debian path. - */ - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") - // Mandrake - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a bold - font that contains all the Unicode characters in use in your translation. - If the font is available in Mandrake it should be the Mandrake path. - */ - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a - font that contains all the Unicode characters in use in your translation. - If the font is available in Mandrake it should be the Mandrake path. - */ - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") - - // Check the non-translated versions of the above - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") - - return font; -} - }}}//end namespace #endif // USE_FTGL diff --git a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp index 7a78e86cd..2ed2431b5 100644 --- a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp @@ -270,126 +270,6 @@ float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) { return result; } -const char* TextFreetypeGL::findFont(const char *firstFontToTry) { - const char* font = NULL; - const char* path = NULL; - - #define CHECK_FONT_PATH(filename) \ - { \ - path = filename; \ - if( !font && path && fileExists(path) == true ) \ - font = strdup(path); \ - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found font file [%s]\n",font); \ - } - - string tryFont = ""; - if(firstFontToTry) { - tryFont = firstFontToTry; - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - - CHECK_FONT_PATH(tryFont.c_str()) - } - - // Get user-specified font path - if(getenv("MEGAGLEST_FONT") != NULL) { - tryFont = getenv("MEGAGLEST_FONT"); - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - - CHECK_FONT_PATH(tryFont.c_str()) - } - - string data_path = Text::DEFAULT_FONT_PATH; - string defaultFont = data_path + "data/core/fonts/LinBiolinum_RB.ttf";//LinBiolinum_Re-0.6.4.ttf - tryFont = defaultFont; - #ifdef WIN32 - replaceAll(tryFont, "/", "\\"); - #endif - CHECK_FONT_PATH(tryFont.c_str()) - -#ifdef FONT_PATH - // Get distro-specified font path - CHECK_FONT_PATH(FONT_PATH) -#endif - -#ifdef HAVE_FONTCONFIG - // Get default font via fontconfig - if( !font && FcInit() ) { - FcResult result; - FcFontSet *fs; - FcPattern* pat; - FcPattern *match; - - /* - TRANSLATORS: If using the FTGL backend, this should be the font - name of a font that contains all the Unicode characters in use in - your translation. - */ - pat = FcNameParse((FcChar8 *)"Gothic Uralic"); - FcConfigSubstitute(0, pat, FcMatchPattern); - - FcPatternDel(pat, FC_WEIGHT); - FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); - - FcDefaultSubstitute(pat); - fs = FcFontSetCreate(); - match = FcFontMatch(0, pat, &result); - - if (match) FcFontSetAdd(fs, match); - if (pat) FcPatternDestroy(pat); - if(fs) { - FcChar8* file; - if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch ) { - CHECK_FONT_PATH((const char*)file) - } - FcFontSetDestroy(fs); - } - FcFini(); - } -#endif - - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - - // Check a couple of common paths for Gothic Uralic/bold as a last resort - // Debian - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a bold - font that contains all the Unicode characters in use in your translation. - If the font is available in Debian it should be the Debian path. - */ - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a - font that contains all the Unicode characters in use in your translation. - If the font is available in Debian it should be the Debian path. - */ - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") - // Mandrake - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a bold - font that contains all the Unicode characters in use in your translation. - If the font is available in Mandrake it should be the Mandrake path. - */ - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") - /* - TRANSLATORS: If using the FTGL backend, this should be the path of a - font that contains all the Unicode characters in use in your translation. - If the font is available in Mandrake it should be the Mandrake path. - */ - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") - - // Check the non-translated versions of the above - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") - CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothu___.ttf") - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHUB__.TTF") - CHECK_FONT_PATH("/usr/share/fonts/TTF/uralic/GOTHU___.TTF") - - return font; -} - }}}//end namespace #endif // USE_FTGL