Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Guichan's changes from 390f8e8d8a20b7120cfbd2b9937a5f423bb05d83… #45

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 13 additions & 0 deletions include/guisan/imagefont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 49 additions & 2 deletions src/imagefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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)
Expand Down