Added code in sf::Font to handle bitmap glyphs rendered in monochrome mode

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1479 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-03-26 19:45:06 +00:00
parent 09a0d11668
commit 87f712e0c6

View File

@ -375,6 +375,23 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
// Extract the glyph's pixels from the bitmap
myPixelBuffer.resize(width * height * 4, 255);
const Uint8* pixels = bitmap.buffer;
if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
{
// Pixels are 1 bit monochrome values
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
// The color channels remain white, just fill the alpha channel
std::size_t index = (x + y * width) * 4 + 3;
myPixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
}
pixels += bitmap.pitch;
}
}
else
{
// Pixels are 8 bits gray levels
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
@ -382,12 +399,10 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
// The color channels remain white, just fill the alpha channel
std::size_t index = (x + y * width) * 4 + 3;
myPixelBuffer[index] = pixels[x];
// Formula for FT_RENDER_MODE_MONO
//myPixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
}
pixels += bitmap.pitch;
}
}
// Write the pixels to the texture
IntRect subrect = glyph.SubRect;