#ifndef CORE_LIBS_TESTS_FONTFIXTURE_HPP #define CORE_LIBS_TESTS_FONTFIXTURE_HPP #include #include #include #include #include #include namespace FontFixture { inline void Put16(std::vector& out, int value) { out.push_back(static_cast((value >> 8) & 0xFF)); out.push_back(static_cast(value & 0xFF)); } inline std::vector Words(std::initializer_list values) { std::vector out; for (const int value : values) Put16(out, value); return out; } inline std::vector BitmapFont() { const std::string_view font = "STARTFONT 2.1\n" "FONT -anyps5-fixture-medium-r-normal--1-10-75-75-c-10-iso10646-1\n" "SIZE 1 75 75\n" "FONTBOUNDINGBOX 1 1 0 0\n" "STARTPROPERTIES 4\n" "FONT_ASCENT 1\n" "FONT_DESCENT 0\n" "CHARSET_REGISTRY \"ISO10646\"\n" "CHARSET_ENCODING \"1\"\n" "ENDPROPERTIES\n" "CHARS 1\n" "STARTCHAR A\n" "ENCODING 65\n" "SWIDTH 1000 0\n" "DWIDTH 1 0\n" "BBX 1 1 0 0\n" "BITMAP\n" "80\n" "ENDCHAR\n" "ENDFONT\n"; return {font.begin(), font.end()}; } inline std::vector BuildFont(int glyphCount, std::map> tables) { tables["glyf"] = Words({0, 0}); tables["head"] = Words({1, 0, 1, 0, 0, 0, 0x5F0F, 0x3CF5, 0, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 2, 0, 0}); tables["hhea"] = Words({1, 0, 800, -200, 0, 500, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}); tables["hmtx"] = Words({500}); tables["hmtx"].resize(2 + 2 * static_cast(glyphCount)); tables["loca"].assign(2 * (static_cast(glyphCount) + 1), 0); tables["maxp"] = Words({1, 0, glyphCount, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0}); const int tableCount = static_cast(tables.size()); int entrySelector = 0; while ((2 << entrySelector) <= tableCount) ++entrySelector; std::vector font = Words({1, 0, tableCount, 16 << entrySelector, entrySelector, 16 * tableCount - (16 << entrySelector)}); int offset = 12 + 16 * tableCount; for (const auto& table : tables) { font.insert(font.end(), table.first.begin(), table.first.end()); for (const int value : {0, 0, offset >> 16, offset & 0xFFFF, 0, static_cast(table.second.size())}) Put16(font, value); offset += static_cast((table.second.size() + 3) & ~std::size_t{3}); } for (const auto& table : tables) { font.insert(font.end(), table.second.begin(), table.second.end()); font.resize((font.size() + 3) & ~std::size_t{3}); } return font; } } #endif