From 16b9b571bc3f8371416c25c4deaeeb6ab6d7454c Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 14 Aug 2024 23:42:11 +0200 Subject: [PATCH] Apply Guichan's changes from 390f8e8d8a20b7120cfbd2b9937a5f423bb05d83 (Mar 22th 2008) Patch has been applied. http://code.google.com/p/guichan/issues/detail?id=39 --- TODO | 2 +- include/guisan/imagefont.hpp | 13 +++++++++ src/imagefont.cpp | 51 ++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index b3f88c3..9a4b62f 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from df337fb783bc0f8ce1bab1bc672e301f88b9d364 +* Continue rebasing from d0400d4714bcdad2d1f00283c80e77317147ea5c * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/imagefont.hpp b/include/guisan/imagefont.hpp index eb13c53..403cffe 100644 --- a/include/guisan/imagefont.hpp +++ b/include/guisan/imagefont.hpp @@ -110,6 +110,19 @@ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode */ ImageFont(const std::string& filename, const std::string& glyphs); + /** + * Constructor. Takes an image containing the font and + * a string containing the glyphs. The glyphs in the string should + * be in the same order as they appear in the font image. + * The image will be deleted in the destructor. + * + * @param image The image with font glyphs. + * @param glyphs The glyphs found in the image. + * @throws Exception when glyph list is incorrect or the font image is + * is missing. + */ + ImageFont(Image* image, const std::string& glyphs); + /** * Constructor. Takes an image file containing the font and * two boundaries of ASCII values. The font image should include diff --git a/src/imagefont.cpp b/src/imagefont.cpp index db28cec..a61ff96 100644 --- a/src/imagefont.cpp +++ b/src/imagefont.cpp @@ -75,14 +75,14 @@ namespace gcn mImage = Image::load(filename, false); Color separator = mImage->getPixel(0, 0); - + int i = 0; for (i = 0; i < mImage->getWidth() && separator == mImage->getPixel(i, 0); ++i) { } - + if (i >= mImage->getWidth()) { throw GCN_EXCEPTION("Corrupt image."); @@ -118,6 +118,53 @@ namespace gcn mGlyphSpacing = 0; } + ImageFont::ImageFont(Image* image, const std::string& glyphs) + { + mFilename = "Image*"; + if (image == NULL) + { + throw GCN_EXCEPTION("Font image is NULL"); + } + mImage = image; + + const Color separator = mImage->getPixel(0, 0); + + int i = 0; + for (i = 0; i < mImage->getWidth() && separator == mImage->getPixel(i, 0); ++i) + {} + + if (i >= mImage->getWidth()) + { + throw GCN_EXCEPTION("Corrupt image."); + } + + int j = 0; + for (j = 0; j < mImage->getHeight(); ++j) + { + if (separator == mImage->getPixel(i, j)) + { + break; + } + } + + mHeight = j; + int x = 0, y = 0; + + for (i = 0; i < (int) glyphs.size(); ++i) + { + const unsigned char k = glyphs.at(i); + mGlyph[k] = scanForGlyph(k, x, y, separator); + // Update x and y with new coordinates. + x = mGlyph[k].x + mGlyph[k].width; + y = mGlyph[k].y; + } + + mImage->convertToDisplayFormat(); + + mRowSpacing = 0; + mGlyphSpacing = 0; + } + ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, unsigned char glyphsTo)