[kandinsky/font] Define IndexForReplacementCharacterCodePoint

This commit is contained in:
Ruben Dashyan
2020-01-29 14:54:30 +01:00
committed by Léa Saviot
parent dd92450115
commit 7cfdadd394
3 changed files with 12 additions and 15 deletions

View File

@@ -59,6 +59,7 @@ public:
CodePoint m_codePoint;
GlyphIndex m_glyphIndex;
};
static constexpr GlyphIndex IndexForReplacementCharacterCodePoint = 132;
GlyphIndex indexForCodePoint(CodePoint c) const;
void setGlyphGreyscalesForCodePoint(CodePoint codePoint, GlyphBuffer * glyphBuffer) const;

View File

@@ -83,9 +83,6 @@ 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
int lowerBound = 0;
@@ -157,6 +154,7 @@ KDFont::GlyphIndex KDFont::indexForCodePoint(CodePoint c) const {
return endPair->glyphIndex();
}
NoMatchingGlyph:
return defaultIndex;
assert(CodePoints[IndexForReplacementCharacterCodePoint] == 0xFFFD);
return IndexForReplacementCharacterCodePoint;
#endif
}

View File

@@ -11,26 +11,24 @@ static constexpr KDFont::CodePointIndexPair table[] = {
constexpr KDFont testFont(4, table, 10, 10, nullptr, nullptr);
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),
KDFont::IndexForReplacementCharacterCodePoint,
KDFont::IndexForReplacementCharacterCodePoint,
KDFont::IndexForReplacementCharacterCodePoint,
1,
2,
3,
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
KDFont::IndexForReplacementCharacterCodePoint,
KDFont::IndexForReplacementCharacterCodePoint,
KDFont::IndexForReplacementCharacterCodePoint,
4,
static_cast<KDFont::GlyphIndex>(defaultIndex),
static_cast<KDFont::GlyphIndex>(defaultIndex),
KDFont::IndexForReplacementCharacterCodePoint,
KDFont::IndexForReplacementCharacterCodePoint,
5,
6,
7,
static_cast<KDFont::GlyphIndex>(defaultIndex),
KDFont::IndexForReplacementCharacterCodePoint,
};
QUIZ_CASE(kandinsky_font_index_for_code_point) {