From b66cf3373f3e037a4b3ddf1d891d5cbcc5656dd4 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 2 Nov 2011 03:59:04 -0200 Subject: [PATCH] fix font glyph width calculation --- modules/core/core.otmod | 1 - modules/topmenu/topmenu.otmod | 1 - src/framework/graphics/font.cpp | 9 ++++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/core/core.otmod b/modules/core/core.otmod index 02d49237..7a0a1201 100644 --- a/modules/core/core.otmod +++ b/modules/core/core.otmod @@ -3,7 +3,6 @@ Module description: Contains lua classes, functions and constants used by other modules author: OTClient team website: https://github.com/edubart/otclient - version: 0.2 autoLoad: true dependencies: - core_fonts diff --git a/modules/topmenu/topmenu.otmod b/modules/topmenu/topmenu.otmod index 6e733f38..325c6ac3 100644 --- a/modules/topmenu/topmenu.otmod +++ b/modules/topmenu/topmenu.otmod @@ -3,7 +3,6 @@ Module description: Create the top menu author: OTClient team website: https://github.com/edubart/otclient - version: 0.2 autoLoad: true dependencies: - core diff --git a/src/framework/graphics/font.cpp b/src/framework/graphics/font.cpp index 0af02879..5a59dd8a 100644 --- a/src/framework/graphics/font.cpp +++ b/src/framework/graphics/font.cpp @@ -259,17 +259,20 @@ void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize) m_glyphHeight); int width = glyphSize.width(); int lastColumnFilledPixels = 0; - for(int x = glyphCoords.left() + 1; x <= glyphCoords.right(); ++x) { + bool foundAnything = false; + for(int x = glyphCoords.left(); x <= glyphCoords.right(); ++x) { int columnFilledPixels = 0; // check if all vertical pixels are alpha for(int y = glyphCoords.top(); y <= glyphCoords.bottom(); ++y) { - if(texturePixels[(y * m_texture->getSize().width() * 4) + (x*4) + 3] != 0) + if(texturePixels[(y * m_texture->getSize().width() * 4) + (x*4) + 3] != 0) { columnFilledPixels++; + foundAnything = true; + } } // if all pixels were alpha we found the width - if(columnFilledPixels == 0) { + if(columnFilledPixels == 0 && foundAnything) { width = x - glyphCoords.left(); width += m_glyphSpacing.width(); if(m_glyphHeight >= 16 && lastColumnFilledPixels >= m_glyphHeight/3)