[kandinsky/font] fetchGlyphForChar handles chars that do not have glyphs

This commit is contained in:
Léa Saviot
2018-11-22 13:40:08 +01:00
committed by Émilie Feral
parent 5deef3176e
commit eda07922ab
2 changed files with 16 additions and 3 deletions

View File

@@ -37,13 +37,17 @@ private:
}
uint8_t charAsIndex(char c) const {
// FIXME: This is most likely false for chars greater than 127
return static_cast<uint8_t>(c) - 0x20;
// FIXME: 0x20 is a magic value...
return static_cast<uint8_t>(c) - k_magicCharOffsetValue;
}
int signedCharAsIndex(char c) const {
return static_cast<int>(c) - k_magicCharOffsetValue;
}
KDSize m_glyphSize;
const uint16_t * m_glyphDataOffset;
const uint8_t * m_data;
static constexpr uint8_t k_magicCharOffsetValue = 0x20; // FIXME: Value from kandinsky/fonts/rasterizer.c (CHARACTER_RANGE_START). 0x20 because we do not want have a glyph for the first 20 ASCII characters
static constexpr uint8_t k_numberOfGlyphs = 120; // FIXME: Value from kandinsky/fonts/rasterizer.c (GLYPH_COUNT)
};
#endif

View File

@@ -33,6 +33,15 @@ void KDFont::fetchGreyscaleGlyphForChar(char c, uint8_t * greyscaleBuffer) const
}
void KDFont::fetchGlyphForChar(char c, const KDFont::RenderPalette * renderPalette, KDColor * pixelBuffer) const {
int pixelCount = m_glyphSize.width() * m_glyphSize.height() - 1;
int charIndex = signedCharAsIndex(c);
if (charIndex < 0 || charIndex >= k_numberOfGlyphs) {
// There is no data for this glyph
for (int i = 0; i < pixelCount; i++) {
pixelBuffer[i] = KDColorBlack;
}
return;
}
/* Since a greyscale value is smaller than a color value (see assertion), we
* can store the temporary greyscale values in the output pixel buffer.
* What's great is that now, if we fill the pixel buffer right-to-left with
@@ -44,7 +53,7 @@ void KDFont::fetchGlyphForChar(char c, const KDFont::RenderPalette * renderPalet
fetchGreyscaleGlyphForChar(c, greyscaleBuffer);
uint8_t mask = (0xFF >> (8-k_bitsPerPixel));
int pixelIndex = m_glyphSize.width() * m_glyphSize.height() - 1; // Let's start at the final pixel
int pixelIndex = pixelCount; // Let's start at the final pixel
int greyscaleByteIndex = pixelIndex * k_bitsPerPixel / 8;
while (pixelIndex >= 0) {
assert(greyscaleByteIndex == pixelIndex * k_bitsPerPixel / 8);