From 83662ebf70e5aa4410895d9b986c686aa88e7b63 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Sat, 6 Oct 2018 22:15:10 +0200 Subject: [PATCH] [kandinsky] Remove warning, add missing file --- .gitignore | 2 -- kandinsky/src/font.cpp | 1 - kandinsky/src/font.h | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 kandinsky/src/font.h diff --git a/.gitignore b/.gitignore index 13abdc284..332ec6666 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,6 @@ poincare/src/simplification/demo_ruleset.h # Font related generated files. kandinsky/fonts/rasterizer -kandinsky/src/font.c -kandinsky/src/font.h # No i18n headers apps/i18n.h diff --git a/kandinsky/src/font.cpp b/kandinsky/src/font.cpp index f2b284b4e..642aa85ba 100644 --- a/kandinsky/src/font.cpp +++ b/kandinsky/src/font.cpp @@ -23,7 +23,6 @@ void KDFont::fetchGlyphForChar(char c, const KDFont::RenderPalette & renderPalet uint8_t * greyscaleBuffer = reinterpret_cast(pixelBuffer); fetchGreyscaleGlyphForChar(c, greyscaleBuffer); - int numberOfPixels = m_glyphWidth*m_glyphHeight; uint8_t mask = (0xFF >> (8-k_bitsPerPixel)); int pixelIndex = m_glyphWidth * m_glyphHeight; int greyscaleByteIndex = pixelIndex / k_bitsPerPixel; diff --git a/kandinsky/src/font.h b/kandinsky/src/font.h new file mode 100644 index 000000000..76ec07cff --- /dev/null +++ b/kandinsky/src/font.h @@ -0,0 +1,45 @@ +#ifndef KANDINSKY_FONT_H +#define KANDINSKY_FONT_H + +#include +#include +#include "palette.h" + +class KDFont { +private: + static constexpr int k_bitsPerPixel = 4; +public: + static const KDFont * LargeFont; + static const KDFont * SmallFont; + + using RenderPalette = KDPalette; + void fetchGlyphForChar(char c, const RenderPalette & renderPalette, KDColor * pixelBuffer) const; + RenderPalette renderPalette(KDColor textColor, KDColor backgroundColor) const { + return RenderPalette::Gradient(textColor, backgroundColor); + } + KDCoordinate glyphWidth() const { return m_glyphWidth; } + KDCoordinate glyphHeight() const { return m_glyphWidth; } + + constexpr KDFont(KDCoordinate glyphWidth, KDCoordinate glyphHeight, const uint16_t * glyphDataOffset, const uint8_t * data) : + m_glyphWidth(glyphWidth), m_glyphHeight(glyphHeight), m_glyphDataOffset(glyphDataOffset), m_data(data) { } +private: + void fetchGreyscaleGlyphForChar(char c, uint8_t * greyscaleBuffer) const; + + const uint8_t * compressedGlyphData(char c) const { + return m_data + m_glyphDataOffset[charAsIndex(c)]; + } + uint16_t compressedGlyphDataSize(char c) const { + return m_glyphDataOffset[charAsIndex(c)+1] - m_glyphDataOffset[charAsIndex(c)]; + } + uint8_t charAsIndex(char c) const { + // FIXME: This is most likely false for chars greater than 127 + return static_cast(c); + } + + KDCoordinate m_glyphWidth; + KDCoordinate m_glyphHeight; + const uint16_t * m_glyphDataOffset; + const uint8_t * m_data; +}; + +#endif