[kandinsky] Fix font test

This commit is contained in:
Léa Saviot
2019-02-28 13:50:22 +01:00
committed by Émilie Feral
parent 11b26bfa16
commit f638809ca5
3 changed files with 27 additions and 4 deletions

View File

@@ -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 <stdint.h>
@@ -147,3 +150,5 @@ uint32_t CodePoints[] = {
};
int NumberOfCodePoints = sizeof(CodePoints)/sizeof(CodePoints[0]);
#endif

View File

@@ -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

View File

@@ -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<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
1,
2,
3,
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
4,
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
5,
6,
7,
static_cast<KDFont::GlyphIndex>(defaultIndex),
};
QUIZ_CASE(kandinsky_font_index_for_code_point) {
for (int i=0; i<16; i++) {
for (int i=0; i<numberOfTests; i++) {
KDFont::GlyphIndex result = testFont.indexForCodePoint(i);
quiz_assert(result == index_for_code_point[i]);
}