fix font glyph width calculation

master
Eduardo Bart 13 years ago
parent 5ab0e6f2ac
commit b66cf3373f

@ -3,7 +3,6 @@ Module
description: Contains lua classes, functions and constants used by other modules description: Contains lua classes, functions and constants used by other modules
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
version: 0.2
autoLoad: true autoLoad: true
dependencies: dependencies:
- core_fonts - core_fonts

@ -3,7 +3,6 @@ Module
description: Create the top menu description: Create the top menu
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
version: 0.2
autoLoad: true autoLoad: true
dependencies: dependencies:
- core - core

@ -259,17 +259,20 @@ void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize)
m_glyphHeight); m_glyphHeight);
int width = glyphSize.width(); int width = glyphSize.width();
int lastColumnFilledPixels = 0; 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; int columnFilledPixels = 0;
// check if all vertical pixels are alpha // check if all vertical pixels are alpha
for(int y = glyphCoords.top(); y <= glyphCoords.bottom(); ++y) { 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++; columnFilledPixels++;
foundAnything = true;
}
} }
// if all pixels were alpha we found the width // if all pixels were alpha we found the width
if(columnFilledPixels == 0) { if(columnFilledPixels == 0 && foundAnything) {
width = x - glyphCoords.left(); width = x - glyphCoords.left();
width += m_glyphSpacing.width(); width += m_glyphSpacing.width();
if(m_glyphHeight >= 16 && lastColumnFilledPixels >= m_glyphHeight/3) if(m_glyphHeight >= 16 && lastColumnFilledPixels >= m_glyphHeight/3)

Loading…
Cancel
Save