diff --git a/kandinsky/fonts/code_points.h b/kandinsky/fonts/code_points.h index aa5d997df..50e3630f0 100644 --- a/kandinsky/fonts/code_points.h +++ b/kandinsky/fonts/code_points.h @@ -1,3 +1,6 @@ +#ifndef KANDINSKY_FONTS_CODE_POINTS_H +#define KANDINSKY_FONTS_CODE_POINTS_H + // [0x30a].map{|i| "0x" + i.to_s(16) +", // " + [i].pack("U") + " // " + Unicode::Name.of([i].pack("U"))}.join("|") #include @@ -147,3 +150,5 @@ uint32_t CodePoints[] = { }; int NumberOfCodePoints = sizeof(CodePoints)/sizeof(CodePoints[0]); + +#endif diff --git a/kandinsky/src/font.cpp b/kandinsky/src/font.cpp index b13ace8ac..80d3b9896 100644 --- a/kandinsky/src/font.cpp +++ b/kandinsky/src/font.cpp @@ -82,6 +82,7 @@ void KDFont::colorizeGlyphBuffer(const RenderPalette * renderPalette, GlyphBuffe KDFont::GlyphIndex KDFont::indexForCodePoint(CodePoint c) const { int defaultIndex = NumberOfCodePoints - 2; + assert(defaultIndex == 132); // If not, change kandinsky/test/font.cpp assert(CodePoints[defaultIndex] == 0xFFFD); #define USE_BINARY_SEARCH 0 #if USE_BINARY_SEARCH diff --git a/kandinsky/test/font.cpp b/kandinsky/test/font.cpp index 4c29c68d4..422df5c75 100644 --- a/kandinsky/test/font.cpp +++ b/kandinsky/test/font.cpp @@ -11,13 +11,30 @@ static constexpr KDFont::CodePointIndexPair table[] = { constexpr KDFont testFont(4, table, 10, 10, nullptr, nullptr); -const KDFont::GlyphIndex index_for_code_point[] = { -/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 */ - 0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 0, 0, 5, 6, 7, 0 +constexpr int defaultIndex = 132; // Taken from KDFont::indexForCodePoint + +constexpr int numberOfTests = 16; +const KDFont::GlyphIndex index_for_code_point[numberOfTests] = { + static_cast(defaultIndex), + static_cast(defaultIndex), + static_cast(defaultIndex), + 1, + 2, + 3, + static_cast(defaultIndex), + static_cast(defaultIndex), + static_cast(defaultIndex), + 4, + static_cast(defaultIndex), + static_cast(defaultIndex), + 5, + 6, + 7, + static_cast(defaultIndex), }; QUIZ_CASE(kandinsky_font_index_for_code_point) { - for (int i=0; i<16; i++) { + for (int i=0; i