Try to fix the edged font when changing resolution

I add a debug function to write the glyph page png(s) too.
This commit is contained in:
Benau 2015-10-10 01:59:29 +08:00
parent 486495d976
commit a7b2c8838f
4 changed files with 21 additions and 6 deletions

View File

@ -114,18 +114,23 @@ void getFontProperties::loadNumber(float scale)
void getFontProperties::loadBoldChar(float scale) void getFontProperties::loadBoldChar(float scale)
{ {
size = (int)(120*scale); //Set default size for Bold Text size = (int)(120*scale); //Set default size for Bold Text
for (int i = 33; i < 256; ++i) for (int i = 65; i < 640; ++i)
usedchar.insert((wchar_t)i); usedchar.insert((wchar_t)i);
setlocale(LC_ALL, "en_US.UTF8"); setlocale(LC_ALL, "en_US.UTF8");
std::set<wchar_t>::iterator it = usedchar.begin(); std::set<wchar_t>::iterator it = usedchar.begin();
while (it != usedchar.end()) while (it != usedchar.end())
{ {
if (iswlower((wchar_t)*it)) if (iswlower((wchar_t)*it) || !iswalpha((wchar_t)*it))
it = usedchar.erase(it); it = usedchar.erase(it);
else else
++it; ++it;
} }
//Final hack to make stk display title properly
usedchar.insert((wchar_t)33);
usedchar.insert((wchar_t)160);
usedchar.erase((wchar_t)304);
} }
} // end namespace gui } // end namespace gui

View File

@ -42,6 +42,11 @@ GlyphPageCreator::~GlyphPageCreator()
page = 0; page = 0;
} }
void GlyphPageCreator::dumpGlyphPage(const core::stringc fn)
{
GUIEngine::getDriver()->writeImageToFile(page, fn + ".png");
}
bool GlyphPageCreator::checkEnoughSpace(FT_Bitmap bits) bool GlyphPageCreator::checkEnoughSpace(FT_Bitmap bits)
{ {
core::dimension2du d(bits.width + 1, bits.rows + 1); core::dimension2du d(bits.width + 1, bits.rows + 1);
@ -63,10 +68,8 @@ void GlyphPageCreator::clearGlyphPage()
void GlyphPageCreator::createNewGlyphPage() void GlyphPageCreator::createNewGlyphPage()
{ {
video::IImage* blank = GUIEngine::getDriver()->createImage(video::ECF_A8R8G8B8, core::dimension2du(512, 512)); //Clean the current glyph page by filling it with transparent content
blank->copyTo(page, core::position2di(0, 0)); page->fill(video::SColor(0, 0,0,0));
blank->drop();
blank = 0;
} }
video::IImage* GlyphPageCreator::getPage() video::IImage* GlyphPageCreator::getPage()

View File

@ -31,6 +31,7 @@ public:
GlyphPageCreator(); GlyphPageCreator();
~GlyphPageCreator(); ~GlyphPageCreator();
static void dumpGlyphPage(const core::stringc);
static bool checkEnoughSpace(FT_Bitmap); static bool checkEnoughSpace(FT_Bitmap);
static void clearGlyphPage(); static void clearGlyphPage();
static void createNewGlyphPage(); static void createNewGlyphPage();

View File

@ -438,6 +438,9 @@ bool ScalableFont::loadTTF()
if (!gp_creator->checkEnoughSpace(bits)) if (!gp_creator->checkEnoughSpace(bits))
// Glyph page is full, save current one and reset the current page // Glyph page is full, save current one and reset the current page
{ {
#ifdef FONT_DEBUG
gp_creator->dumpGlyphPage(((std::to_string(m_type)) + "_" + (std::to_string(texno))).c_str());
#endif
SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage())); SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage()));
gp_creator->clearGlyphPage(); gp_creator->clearGlyphPage();
SpriteBank->addTexture(NULL); SpriteBank->addTexture(NULL);
@ -465,6 +468,9 @@ bool ScalableFont::loadTTF()
// Check for glyph page which can fit all characters // Check for glyph page which can fit all characters
if (it == --cur_prop.usedchar.end()) if (it == --cur_prop.usedchar.end())
{ {
#ifdef FONT_DEBUG
gp_creator->dumpGlyphPage(((std::to_string(m_type)) + "_" + (std::to_string(texno))).c_str());
#endif
SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage())); SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage()));
gp_creator->clearGlyphPage(); gp_creator->clearGlyphPage();
} }