From 879aaa7fe886ec5c8e709d2092dafb53e6261897 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 25 May 2011 19:03:22 +0000 Subject: [PATCH] - added russian language (thanks Strannik) - updated fonts to better handle non ascii languages (russian and ukraine display much better with more native fonts) --- mk/linux/makedata-diff.sh | 2 +- source/glest_game/global/core_data.cpp | 110 +++++++++++++++--- source/shared_lib/sources/graphics/font.cpp | 4 +- .../sources/platform/unix/gl_wrap.cpp | 80 ++++++++++++- 4 files changed, 172 insertions(+), 24 deletions(-) diff --git a/mk/linux/makedata-diff.sh b/mk/linux/makedata-diff.sh index 211dcd4d..62f1441e 100755 --- a/mk/linux/makedata-diff.sh +++ b/mk/linux/makedata-diff.sh @@ -17,7 +17,7 @@ cd $CURDIR echo "Creating data package $RELEASENAME (comparing against $OLD_VERSION)" #if [ ! -e megaglest-data-$VERSION-changes.txt ]; then -diff --strip-trailing-cr --brief -r -x "*~" megaglest-data-$OLD_VERSION megaglest-data-$VERSION > megaglest-data-$VERSION-changes.txt +diff --strip-trailing-cr --brief -r -x "*~" megaglest-data-$OLD_VERSION/megaglest-$OLD_VERSION megaglest-data-$VERSION/megaglest-$VERSION > megaglest-data-$VERSION-changes.txt #fi cd megaglest-data-$VERSION diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 72f3641a..6f2d079d 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -19,6 +19,7 @@ #include "platform_util.h" #include "game_constants.h" #include "game_util.h" +#include "lang.h" #include "leak_dumper.h" using namespace Shared::Sound; @@ -123,12 +124,27 @@ void CoreData::load() { gameWinnerTexture->setForceCompressionDisabled(true); gameWinnerTexture->getPixmap()->load(dir+"/misc_textures/game_winner.png"); + Lang &lang= Lang::getInstance(); + //display font Config &config= Config::getInstance(); - string displayFontNamePrefix=config.getString("FontDisplayPrefix"); - string displayFontNamePostfix=config.getString("FontDisplayPostfix"); - int displayFontSize=computeFontSize(config.getInt("FontDisplayBaseSize")); + + string displayFontNamePrefix = config.getString("FontDisplayPrefix"); + string displayFontNamePostfix = config.getString("FontDisplayPostfix"); + int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); + + if(lang.hasString("FontDisplayPrefix") == true) { + displayFontNamePrefix = lang.get("FontDisplayPrefix"); + } + if(lang.hasString("FontDisplayPostfix") == true) { + displayFontNamePostfix = lang.get("FontDisplayPostfix"); + } + if(lang.hasString("FontDisplayBaseSize") == true) { + displayFontSize = strToInt(lang.get("FontDisplayBaseSize")); + } + string displayFontName=displayFontNamePrefix+intToStr(displayFontSize)+displayFontNamePostfix; + displayFont= renderer.newFont(rsGlobal); displayFont->setType(displayFontName); displayFont->setSize(displayFontSize); @@ -136,9 +152,20 @@ void CoreData::load() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize); //menu fonts - string displayFontNameSmallPrefix= config.getString("FontDisplayPrefix"); - string displayFontNameSmallPostfix= config.getString("FontDisplayPostfix"); - int displayFontNameSmallSize=computeFontSize(config.getInt("FontDisplaySmallBaseSize")); + string displayFontNameSmallPrefix = config.getString("FontDisplayPrefix"); + string displayFontNameSmallPostfix = config.getString("FontDisplayPostfix"); + int displayFontNameSmallSize = computeFontSize(config.getInt("FontDisplaySmallBaseSize")); + + if(lang.hasString("FontDisplayPrefix") == true) { + displayFontNameSmallPrefix = lang.get("FontDisplayPrefix"); + } + if(lang.hasString("FontDisplayPostfix") == true) { + displayFontNameSmallPostfix = lang.get("FontDisplayPostfix"); + } + if(lang.hasString("FontDisplaySmallBaseSize") == true) { + displayFontNameSmallSize = strToInt(lang.get("FontDisplaySmallBaseSize")); + } + string displayFontNameSmall=displayFontNameSmallPrefix+intToStr(displayFontNameSmallSize)+displayFontNameSmallPostfix; displayFontSmall= renderer.newFont(rsGlobal); displayFontSmall->setType(displayFontNameSmall); @@ -146,9 +173,20 @@ void CoreData::load() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize); - string menuFontNameNormalPrefix= config.getString("FontMenuNormalPrefix"); - string menuFontNameNormalPostfix= config.getString("FontMenuNormalPostfix"); - int menuFontNameNormalSize=computeFontSize(config.getInt("FontMenuNormalBaseSize")); + string menuFontNameNormalPrefix = config.getString("FontMenuNormalPrefix"); + string menuFontNameNormalPostfix = config.getString("FontMenuNormalPostfix"); + int menuFontNameNormalSize = computeFontSize(config.getInt("FontMenuNormalBaseSize")); + + if(lang.hasString("FontMenuNormalPrefix") == true) { + menuFontNameNormalPrefix = lang.get("FontMenuNormalPrefix"); + } + if(lang.hasString("FontMenuNormalPostfix") == true) { + menuFontNameNormalPostfix = lang.get("FontMenuNormalPostfix"); + } + if(lang.hasString("FontMenuNormalBaseSize") == true) { + menuFontNameNormalSize = strToInt(lang.get("FontMenuNormalBaseSize")); + } + string menuFontNameNormal= menuFontNameNormalPrefix+intToStr(menuFontNameNormalSize)+menuFontNameNormalPostfix; menuFontNormal= renderer.newFont(rsGlobal); menuFontNormal->setType(menuFontNameNormal); @@ -157,20 +195,44 @@ void CoreData::load() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize); - string menuFontNameBigPrefix= config.getString("FontMenuBigPrefix"); - string menuFontNameBigPostfix= config.getString("FontMenuBigPostfix"); - int menuFontNameBigSize=computeFontSize(config.getInt("FontMenuBigBaseSize")); + string menuFontNameBigPrefix = config.getString("FontMenuBigPrefix"); + string menuFontNameBigPostfix = config.getString("FontMenuBigPostfix"); + int menuFontNameBigSize = computeFontSize(config.getInt("FontMenuBigBaseSize")); + + if(lang.hasString("FontMenuBigPrefix") == true) { + menuFontNameBigPrefix = lang.get("FontMenuBigPrefix"); + } + if(lang.hasString("FontMenuBigPostfix") == true) { + menuFontNameBigPostfix = lang.get("FontMenuBigPostfix"); + } + if(lang.hasString("FontMenuBigBaseSize") == true) { + menuFontNameBigSize = strToInt(lang.get("FontMenuBigBaseSize")); + } + string menuFontNameBig= menuFontNameBigPrefix+intToStr(menuFontNameBigSize)+menuFontNameBigPostfix; + menuFontBig= renderer.newFont(rsGlobal); menuFontBig->setType(menuFontNameBig); menuFontBig->setSize(menuFontNameBigSize); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize); - string menuFontNameVeryBigPrefix= config.getString("FontMenuBigPrefix"); - string menuFontNameVeryBigPostfix= config.getString("FontMenuBigPostfix"); - int menuFontNameVeryBigSize=computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); + string menuFontNameVeryBigPrefix = config.getString("FontMenuBigPrefix"); + string menuFontNameVeryBigPostfix = config.getString("FontMenuBigPostfix"); + int menuFontNameVeryBigSize = computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); + + if(lang.hasString("FontMenuBigPrefix") == true) { + menuFontNameVeryBigPrefix = lang.get("FontMenuBigPrefix"); + } + if(lang.hasString("FontMenuBigPostfix") == true) { + menuFontNameVeryBigPostfix = lang.get("FontMenuBigPostfix"); + } + if(lang.hasString("FontMenuVeryBigBaseSize") == true) { + menuFontNameVeryBigSize = strToInt(lang.get("FontMenuVeryBigBaseSize")); + } + string menuFontNameVeryBig= menuFontNameVeryBigPrefix+intToStr(menuFontNameVeryBigSize)+menuFontNameVeryBigPostfix; + menuFontVeryBig= renderer.newFont(rsGlobal); menuFontVeryBig->setType(menuFontNameVeryBig); menuFontVeryBig->setSize(menuFontNameVeryBigSize); @@ -178,10 +240,22 @@ void CoreData::load() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); //console font - string consoleFontNamePrefix= config.getString("FontConsolePrefix"); - string consoleFontNamePostfix= config.getString("FontConsolePostfix"); - int consoleFontNameSize=computeFontSize(config.getInt("FontConsoleBaseSize")); + string consoleFontNamePrefix = config.getString("FontConsolePrefix"); + string consoleFontNamePostfix = config.getString("FontConsolePostfix"); + int consoleFontNameSize = computeFontSize(config.getInt("FontConsoleBaseSize")); + + if(lang.hasString("FontConsolePrefix") == true) { + consoleFontNamePrefix = lang.get("FontConsolePrefix"); + } + if(lang.hasString("FontConsolePostfix") == true) { + consoleFontNamePostfix = lang.get("FontConsolePostfix"); + } + if(lang.hasString("FontConsoleBaseSize") == true) { + consoleFontNameSize = strToInt(lang.get("FontConsoleBaseSize")); + } + string consoleFontName= consoleFontNamePrefix+intToStr(consoleFontNameSize)+consoleFontNamePostfix; + consoleFont= renderer.newFont(rsGlobal); consoleFont->setType(consoleFontName); consoleFont->setSize(consoleFontNameSize); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 893f9b0a..0bb23faf 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -49,8 +49,8 @@ float FontMetrics::getTextWidth(const string &str) const { } //Treat 2 byte characters as spaces if(str[i] < 0) { - width+= widths[87]; // This is the letter W which is a fairly wide character and good to use for spacing - i++; + width+= (widths[87]); // This is the letter W which is a fairly wide character and good to use for spacing + //i++; } else { width+= widths[str[i]]; diff --git a/source/shared_lib/sources/platform/unix/gl_wrap.cpp b/source/shared_lib/sources/platform/unix/gl_wrap.cpp index 383b5dea..91412cf7 100644 --- a/source/shared_lib/sources/platform/unix/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/unix/gl_wrap.cpp @@ -38,6 +38,8 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, if(display == 0) { throw std::runtime_error("Couldn't create font: display is 0"); } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to try font [%s]\n",type.c_str()); XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str()); if(fontInfo == NULL) { string default_font = FontGl::getDefault_fontType(); @@ -54,7 +56,78 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, // we need the height of 'a' which sould ~ be half ascent+descent metrics.setHeight(static_cast (fontInfo->ascent + fontInfo->descent) / 2); - for(unsigned int i = 0; i < static_cast (charCount); ++i) { + + + int first = (fontInfo->min_byte1 << 8) + fontInfo->min_char_or_byte2; + int last = (fontInfo->max_byte1 << 8) + fontInfo->max_char_or_byte2; + int count = last - first + 1; + + // 16-bit fonts have more than one row; indexing into + // per_char is trickier. + int rows = fontInfo->max_byte1 - fontInfo->min_byte1 + 1; + int pages = fontInfo->max_char_or_byte2 - fontInfo->min_char_or_byte2 + 1; + int byte1, byte2, index; + int charIndex = 0; + int charWidth, charHeight; + XChar2b character; + + + for (int i = first; count; i++, count--) { + bool skipToEnd = false; + int undefined = 0; + if (rows == 1) { + undefined = (fontInfo->min_char_or_byte2 > i || + fontInfo->max_char_or_byte2 < i); + } + else { + byte2 = i & 0xff; + byte1 = i >> 8; + undefined = (fontInfo->min_char_or_byte2 > byte2 || + fontInfo->max_char_or_byte2 < byte2 || + fontInfo->min_byte1 > byte1 || + fontInfo->max_byte1 < byte1); + + } + if (undefined) { + skipToEnd = true; + } + else if (fontInfo->per_char != NULL) { + if (rows == 1) { + index = i - fontInfo->min_char_or_byte2; + } + else { + byte2 = i & 0xff; + byte1 = i >> 8; + + index = + (byte1 - fontInfo->min_byte1) * pages + + (byte2 - fontInfo->min_char_or_byte2); + } + XCharStruct *charinfo = &(fontInfo->per_char[index]); + charWidth = charinfo->rbearing - charinfo->lbearing; + charHeight = charinfo->ascent + charinfo->descent; + if (charWidth == 0 || charHeight == 0) { + //if (charinfo->width != 0) { + //} + skipToEnd = true; + } + + if(skipToEnd == false) { + metrics.setWidth(charIndex, static_cast (fontInfo->per_char[index].width)); + charIndex++; + } + } + if(skipToEnd == false) { + character.byte2 = i & 255; + character.byte1 = i >> 8; + } + } + //Shared::Graphics::Font::charCount = charIndex; + + +/* + //for(unsigned int i = 0; fontInfo->per_char != NULL && i < static_cast (charCount); ++i) { + for(unsigned int i = 0; fontInfo->per_char != NULL && i < static_cast (count); ++i) { if(i < fontInfo->min_char_or_byte2 || i > fontInfo->max_char_or_byte2) { metrics.setWidth(i, static_cast(6)); @@ -63,10 +136,11 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int p = i - fontInfo->min_char_or_byte2; metrics.setWidth(i, static_cast ( fontInfo->per_char[p].width)); -// fontInfo->per_char[p].rbearing -// - fontInfo->per_char[p].lbearing)); + // fontInfo->per_char[p].rbearing + // - fontInfo->per_char[p].lbearing)); } } +*/ glXUseXFont(fontInfo->fid, 0, charCount, base); XFreeFont(display, fontInfo);