- cleanup of font work:
- removed uneeded code - set default scale font value to 0.8 to fit nicely on screen - added two new optional settings for ini or lng files to control scale and y centering: FONT_SCALE_SIZE=0.8 FONT_SCALE_CENTERH_FACTOR=3.0
This commit is contained in:
parent
32950a168c
commit
50347b0a66
|
@ -152,12 +152,12 @@ void CoreData::load() {
|
|||
displayFont= renderer.newFont(rsGlobal);
|
||||
displayFont->setType(displayFontName,config.getString("FontDisplay",""));
|
||||
displayFont->setSize(displayFontSize);
|
||||
displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
displayFont3D= renderer.newFont3D(rsGlobal);
|
||||
displayFont3D->setType(displayFontName,config.getString("FontDisplay",""));
|
||||
displayFont3D->setSize(displayFontSize);
|
||||
displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
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);
|
||||
|
||||
|
@ -181,12 +181,12 @@ void CoreData::load() {
|
|||
displayFontSmall= renderer.newFont(rsGlobal);
|
||||
displayFontSmall->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
||||
displayFontSmall->setSize(displayFontNameSmallSize);
|
||||
displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
displayFontSmall3D= renderer.newFont3D(rsGlobal);
|
||||
displayFontSmall3D->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
||||
displayFontSmall3D->setSize(displayFontNameSmallSize);
|
||||
displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
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);
|
||||
|
||||
|
@ -210,13 +210,13 @@ void CoreData::load() {
|
|||
menuFontNormal->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
||||
menuFontNormal->setSize(menuFontNameNormalSize);
|
||||
menuFontNormal->setWidth(Font::wBold);
|
||||
menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
menuFontNormal3D= renderer.newFont3D(rsGlobal);
|
||||
menuFontNormal3D->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
||||
menuFontNormal3D->setSize(menuFontNameNormalSize);
|
||||
menuFontNormal3D->setWidth(Font::wBold);
|
||||
menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
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);
|
||||
|
||||
|
@ -239,12 +239,12 @@ void CoreData::load() {
|
|||
menuFontBig= renderer.newFont(rsGlobal);
|
||||
menuFontBig->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
||||
menuFontBig->setSize(menuFontNameBigSize);
|
||||
menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
menuFontBig3D= renderer.newFont3D(rsGlobal);
|
||||
menuFontBig3D->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
||||
menuFontBig3D->setSize(menuFontNameBigSize);
|
||||
menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
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);
|
||||
|
||||
|
@ -267,12 +267,12 @@ void CoreData::load() {
|
|||
menuFontVeryBig= renderer.newFont(rsGlobal);
|
||||
menuFontVeryBig->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
||||
menuFontVeryBig->setSize(menuFontNameVeryBigSize);
|
||||
menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
menuFontVeryBig3D= renderer.newFont3D(rsGlobal);
|
||||
menuFontVeryBig3D->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
||||
menuFontVeryBig3D->setSize(menuFontNameVeryBigSize);
|
||||
menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
//printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D);
|
||||
|
||||
|
@ -298,12 +298,12 @@ void CoreData::load() {
|
|||
consoleFont= renderer.newFont(rsGlobal);
|
||||
consoleFont->setType(consoleFontName,config.getString("FontConsole",""));
|
||||
consoleFont->setSize(consoleFontNameSize);
|
||||
consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
consoleFont3D= renderer.newFont3D(rsGlobal);
|
||||
consoleFont3D->setType(consoleFontName,config.getString("FontConsole",""));
|
||||
consoleFont3D->setSize(consoleFontNameSize);
|
||||
consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
//consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize);
|
||||
|
||||
|
|
|
@ -1390,15 +1390,15 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) {
|
|||
return textPos;
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centered) {
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
|
||||
|
||||
Vec2f pos= Vec2f(x, y);
|
||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||
if(centered == true) {
|
||||
getCentered3DPos(text, font, pos, w, h);
|
||||
if(centeredW == true || centeredH == true) {
|
||||
getCentered3DPos(text, font, pos, w, h, centeredW, centeredH);
|
||||
}
|
||||
|
||||
textRenderer3D->begin(font);
|
||||
|
@ -1439,32 +1439,48 @@ void Renderer::renderText(const string &text, Font2D *font, float alpha, int x,
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h) {
|
||||
float lineWidth = (font->getTextHandler()->Advance(text.c_str()) * Font::scaleFontValue);
|
||||
if(lineWidth < w) {
|
||||
pos.x += ((w / 2.f) - (lineWidth / 2.f));
|
||||
Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h,bool centeredW, bool centeredH) {
|
||||
if(centeredW == true) {
|
||||
float lineWidth = (font->getTextHandler()->Advance(text.c_str()) * Font::scaleFontValue);
|
||||
if(lineWidth < w) {
|
||||
pos.x += ((w / 2.f) - (lineWidth / 2.f));
|
||||
}
|
||||
}
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
//float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||
float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||
//lineHeight=metrics.toVirtualY(lineHeight);
|
||||
//lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR);
|
||||
//pos.y += (h / 2.f) - (lineHeight / 2.f);
|
||||
//pos.y += (h / 2.f) - (lineHeight);
|
||||
pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height
|
||||
|
||||
if(centeredH) {
|
||||
//const Metrics &metrics= Metrics::getInstance();
|
||||
//float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||
float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||
//lineHeight=metrics.toVirtualY(lineHeight);
|
||||
//lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR);
|
||||
//pos.y += (h / 2.f) - (lineHeight / 2.f);
|
||||
//pos.y += (h / 2.f) - (lineHeight);
|
||||
//pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height
|
||||
|
||||
if(lineHeight < h) {
|
||||
//int realHeight = lineHeight + (h - lineHeight);
|
||||
// First go to top of bounding box
|
||||
pos.y += (h - lineHeight);
|
||||
|
||||
pos.y -= ((h - lineHeight) / Font::scaleFontValueCenterHFactor);
|
||||
|
||||
// Now calculate till we get text to middle
|
||||
//pos.y -= (realHeight / 2);
|
||||
//pos.y += (lineHeight / 2);
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centered) {
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
glPushAttrib(GL_CURRENT_BIT);
|
||||
glColor3fv(color.ptr());
|
||||
|
||||
Vec2f pos= Vec2f(x, y);
|
||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||
|
||||
if(centered == true) {
|
||||
getCentered3DPos(text, font, pos, w, h);
|
||||
if(centeredW == true || centeredH == true) {
|
||||
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||
}
|
||||
|
||||
textRenderer3D->begin(font);
|
||||
|
@ -1501,7 +1517,7 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec3f &color,
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centered) {
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
glColor4fv(color.ptr());
|
||||
|
@ -1509,8 +1525,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
|
|||
Vec2f pos= Vec2f(x, y);
|
||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||
|
||||
if(centered == true) {
|
||||
getCentered3DPos(text, font, pos, w, h);
|
||||
if(centeredW == true || centeredH == true) {
|
||||
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||
}
|
||||
|
||||
textRenderer3D->begin(font);
|
||||
|
@ -1652,7 +1668,7 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||
//renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
|
||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color), x, y, w, h, label->getCentered());
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color), x, y, w, h, label->getCentered(),label->getCentered());
|
||||
}
|
||||
else {
|
||||
renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered());
|
||||
|
@ -1663,7 +1679,7 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||
//renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), x, y, w, h, label->getCentered());
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), x, y, w, h, label->getCentered(),label->getCentered());
|
||||
}
|
||||
else {
|
||||
renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
||||
|
@ -1784,7 +1800,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||
if(button->getEditable()) {
|
||||
if(renderText3DEnabled == true) {
|
||||
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(), color, x, y, w, h, true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(), color, x, y, w, h, true, true);
|
||||
}
|
||||
else {
|
||||
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
|
||||
|
@ -1795,7 +1811,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||
// x + (w / 2), y + (h / 2), true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||
x, y, w, h, true);
|
||||
x, y, w, h, true, true);
|
||||
}
|
||||
else {
|
||||
renderText(button->getText(), button->getFont(),disabledTextColor,
|
||||
|
@ -5147,7 +5163,7 @@ void Renderer::renderProgressBar3D(int size, int x, int y, Font3D *font, int cus
|
|||
//glColor3fv(defColor.ptr());
|
||||
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
|
||||
|
||||
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize, progressbarHeight, true);
|
||||
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize, progressbarHeight, true, true);
|
||||
}
|
||||
|
||||
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
|
||||
|
|
|
@ -368,10 +368,10 @@ public:
|
|||
void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered=false);
|
||||
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
|
||||
|
||||
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centered);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centered);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centered);
|
||||
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
|
||||
void beginRenderToTexture(Texture2D **renderToTexture);
|
||||
void endRenderToTexture(Texture2D **renderToTexture);
|
||||
|
|
|
@ -2560,6 +2560,8 @@ int glestMain(int argc, char** argv) {
|
|||
Font::fontIsMultibyte = config.getBool("FONT_MULTIBYTE",intToStr(Font::fontIsMultibyte).c_str());
|
||||
Font::fontIsRightToLeft = config.getBool("FONT_RIGHTTOLEFT",intToStr(Font::fontIsRightToLeft).c_str());
|
||||
Font::baseSize = config.getInt("FONT_BASE_SIZE",intToStr(Font::baseSize).c_str());
|
||||
Font::scaleFontValue = config.getFloat("FONT_SCALE_SIZE",floatToStr(Font::scaleFontValue).c_str());
|
||||
Font::scaleFontValueCenterHFactor = config.getFloat("FONT_SCALE_CENTERH_FACTOR",floatToStr(Font::scaleFontValueCenterHFactor).c_str());
|
||||
|
||||
// Example values:
|
||||
// DEFAULT_CHARSET (English) = 1
|
||||
|
@ -2650,10 +2652,18 @@ int glestMain(int argc, char** argv) {
|
|||
|
||||
lang.loadStrings(language);
|
||||
if( lang.hasString("FONT_BASE_SIZE")) {
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE"));
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE"));
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_SCALE_SIZE")) {
|
||||
Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE"));
|
||||
}
|
||||
if( lang.hasString("FONT_SCALE_CENTERH_FACTOR")) {
|
||||
Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR"));
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_CHARCOUNT")) {
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
|
@ -2686,12 +2696,26 @@ int glestMain(int argc, char** argv) {
|
|||
#endif
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_YOFFSET_FACTOR")) {
|
||||
FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR"));
|
||||
}
|
||||
// if( lang.hasString("FONT_YOFFSET_FACTOR")) {
|
||||
// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR"));
|
||||
// }
|
||||
|
||||
#if defined(WIN32)
|
||||
// Win32 overrides for fonts (just in case they must be different)
|
||||
|
||||
if( lang.hasString("FONT_BASE_SIZE_WINDOWS")) {
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE_WINDOWS"));
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_SCALE_SIZE_WINDOWS")) {
|
||||
Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE_WINDOWS"));
|
||||
}
|
||||
if( lang.hasString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) {
|
||||
Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR_WINDOWS"));
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) {
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
|
@ -2719,9 +2743,9 @@ int glestMain(int argc, char** argv) {
|
|||
_putenv(newEnvValue.c_str());
|
||||
}
|
||||
|
||||
if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) {
|
||||
FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS"));
|
||||
}
|
||||
// if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) {
|
||||
// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS"));
|
||||
// }
|
||||
|
||||
// end win32
|
||||
#endif
|
||||
|
|
|
@ -32,17 +32,17 @@ private:
|
|||
float *widths;
|
||||
float height;
|
||||
|
||||
float yOffsetFactor;
|
||||
//float yOffsetFactor;
|
||||
Text *textHandler;
|
||||
|
||||
public:
|
||||
static float DEFAULT_Y_OFFSET_FACTOR;
|
||||
//static float DEFAULT_Y_OFFSET_FACTOR;
|
||||
|
||||
FontMetrics(Text *textHandler=NULL);
|
||||
~FontMetrics();
|
||||
|
||||
void setYOffsetFactor(float yOffsetFactor);
|
||||
float getYOffsetFactor() const;
|
||||
//void setYOffsetFactor(float yOffsetFactor);
|
||||
//float getYOffsetFactor() const;
|
||||
|
||||
void setTextHandler(Text *textHandler);
|
||||
Text * getTextHandler();
|
||||
|
@ -66,9 +66,9 @@ public:
|
|||
static bool forceLegacyFonts;
|
||||
static bool fontIsRightToLeft;
|
||||
static float scaleFontValue;
|
||||
static float scaleFontValueCenterHFactor;
|
||||
static int baseSize;
|
||||
static int faceResolution;
|
||||
//static int scaleFontYOffset;
|
||||
|
||||
public:
|
||||
enum Width {
|
||||
|
@ -93,15 +93,12 @@ public:
|
|||
virtual void end()=0;
|
||||
|
||||
//get
|
||||
//string getType() const {return type;}
|
||||
int getWidth() const;
|
||||
FontMetrics *getMetrics() {return &metrics;}
|
||||
Text * getTextHandler() {return textHandler;}
|
||||
float getYOffsetFactor() const;
|
||||
string getType() const;
|
||||
|
||||
//set
|
||||
void setYOffsetFactor(float yOffsetFactor);
|
||||
void setType(string typeX11, string typeGeneric);
|
||||
void setWidth(int width);
|
||||
|
||||
|
@ -114,8 +111,6 @@ public:
|
|||
// =====================================================
|
||||
|
||||
class Font2D: public Font {
|
||||
protected:
|
||||
//int size;
|
||||
|
||||
public:
|
||||
Font2D(FontTextHandlerType type=ftht_2D);
|
||||
|
|
|
@ -36,12 +36,18 @@ int Font::charCount = 256;
|
|||
std::string Font::fontTypeName = "Times New Roman";
|
||||
bool Font::fontIsMultibyte = false;
|
||||
bool Font::forceLegacyFonts = false;
|
||||
float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 2.0f;
|
||||
bool Font::fontIsRightToLeft = false;
|
||||
float Font::scaleFontValue = 1.0;
|
||||
|
||||
// This value is used to scale the font text rendering
|
||||
// in 3D render mode
|
||||
float Font::scaleFontValue = 0.80;
|
||||
// This value is used for centering font text vertically (height)
|
||||
float Font::scaleFontValueCenterHFactor = 3.0;
|
||||
//float Font::scaleFontValue = 1.0;
|
||||
//float Font::scaleFontValueCenterHFactor = 4.0;
|
||||
|
||||
int Font::baseSize = 0;
|
||||
int Font::faceResolution = 72;
|
||||
//int Font::scaleFontYOffset = 0;
|
||||
//
|
||||
|
||||
// =====================================================
|
||||
|
@ -52,7 +58,6 @@ FontMetrics::FontMetrics(Text *textHandler) {
|
|||
this->textHandler = textHandler;
|
||||
this->widths = new float[Font::charCount];
|
||||
this->height = 0;
|
||||
this->yOffsetFactor = FontMetrics::DEFAULT_Y_OFFSET_FACTOR;
|
||||
|
||||
for(int i=0; i < Font::charCount; ++i) {
|
||||
widths[i]= 0;
|
||||
|
@ -64,14 +69,6 @@ FontMetrics::~FontMetrics() {
|
|||
widths = NULL;
|
||||
}
|
||||
|
||||
void FontMetrics::setYOffsetFactor(float yOffsetFactor) {
|
||||
this->yOffsetFactor = yOffsetFactor;
|
||||
}
|
||||
|
||||
float FontMetrics::getYOffsetFactor() const {
|
||||
return this->yOffsetFactor;
|
||||
}
|
||||
|
||||
void FontMetrics::setTextHandler(Text *textHandler) {
|
||||
this->textHandler = textHandler;
|
||||
}
|
||||
|
@ -94,7 +91,6 @@ float FontMetrics::getTextWidth(const string &str) {
|
|||
//Treat 2 byte characters as spaces
|
||||
if(str[i] < 0) {
|
||||
width+= (widths[97]); // This is the letter a which is a normal wide character and good to use for spacing
|
||||
//i++;
|
||||
}
|
||||
else {
|
||||
width+= widths[str[i]];
|
||||
|
@ -149,14 +145,6 @@ Font::~Font() {
|
|||
textHandler = NULL;
|
||||
}
|
||||
|
||||
void Font::setYOffsetFactor(float yOffsetFactor) {
|
||||
metrics.setYOffsetFactor(yOffsetFactor);
|
||||
}
|
||||
|
||||
float Font::getYOffsetFactor() const {
|
||||
return metrics.getYOffsetFactor();
|
||||
}
|
||||
|
||||
string Font::getType() const {
|
||||
return this->type;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ Font3D * ConvertFont2DTo3D(Font2D *font) {
|
|||
Font3D *result = new Font3DGl();
|
||||
result->setSize(font->getSize());
|
||||
result->setType("",font->getType());
|
||||
result->setYOffsetFactor(font->getYOffsetFactor());
|
||||
result->setWidth(font->getWidth());
|
||||
result->init();
|
||||
return result;
|
||||
|
|
|
@ -73,11 +73,11 @@ void TextRenderer2DGl::render(const string &text, float x, float y, bool centere
|
|||
|
||||
if(centered) {
|
||||
rasterPos.x= x - font->getTextHandler()->Advance(renderText.c_str()) / 2.f;
|
||||
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str()) / font->getYOffsetFactor();
|
||||
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str()) / 2;
|
||||
}
|
||||
else {
|
||||
rasterPos= Vec2f(static_cast<float>(x), static_cast<float>(y));
|
||||
rasterPos.y= y + (font->getTextHandler()->LineHeight(renderText.c_str()) / font->getYOffsetFactor());
|
||||
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue