fix font glyph width calculation

This commit is contained in:
Eduardo Bart 2011-11-02 03:59:04 -02:00
parent 5ab0e6f2ac
commit b66cf3373f
3 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)