diff --git a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp index 222244c22..8b1a8422a 100644 --- a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -25,6 +25,7 @@ #include "MagnumFontConverter.h" +#include #include #include #include @@ -63,12 +64,22 @@ std::vector>> MagnumFontConverter configuration.setValue("descent", font.descent()); configuration.setValue("lineHeight", font.lineHeight()); - /* Compress glyph IDs so the glyphs are in consecutive array, glyph 0 + /* Get the glyphs and sort them for predictable output */ + std::vector>> sortedGlyphs; + for(const std::pair>& glyph: cache) + sortedGlyphs.emplace_back(glyph); + std::sort(sortedGlyphs.begin(), sortedGlyphs.end(), + [](const std::pair>& a, + const std::pair>& b) { + return a.first < b.first; + }); + + /* Compress glyph IDs so the glyphs are in a consecutive array, glyph 0 should stay at position 0 */ std::unordered_map glyphIdMap; glyphIdMap.reserve(cache.glyphCount()); glyphIdMap.emplace(0, 0); - for(const std::pair>& glyph: cache) + for(const std::pair>& glyph: sortedGlyphs) glyphIdMap.emplace(glyph.first, glyphIdMap.size()); /** @todo Save only glyphs contained in @p characters */ diff --git a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp index e04c32efb..67fc0a0f6 100644 --- a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -131,7 +131,6 @@ void MagnumFontConverterTest::exportFont() { converter->exportFontToFile(font, cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave"); /* Verify font parameters */ - /** @todo This might behave differently elsewhere due to unspecified order of glyphs in cache */ CORRADE_COMPARE_AS(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf"), Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), TestSuite::Compare::File);