From 87f712e0c673f248f7a55d2efb60c1545b4bfaee Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 26 Mar 2010 19:45:06 +0000 Subject: [PATCH] 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 --- src/SFML/Graphics/Font.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 0d0df0304..124c29cbd 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -48,7 +48,7 @@ myCurrentSize(0) //////////////////////////////////////////////////////////// -Font::Font(const Font& copy) : +Font::Font(const Font& copy) : Resource(), myLibrary (copy.myLibrary), myFace (copy.myFace), @@ -375,18 +375,33 @@ 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; - for (int y = 0; y < height; ++y) + if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { - for (int x = 0; x < width; ++x) + // Pixels are 1 bit monochrome values + for (int y = 0; y < height; ++y) { - // 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; + 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) + { + // The color channels remain white, just fill the alpha channel + std::size_t index = (x + y * width) * 4 + 3; + myPixelBuffer[index] = pixels[x]; + } + pixels += bitmap.pitch; } - pixels += bitmap.pitch; } // Write the pixels to the texture