From 22aa0dd620b6db93a64e1e171fb5ddb18693e56e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 19 Apr 2023 23:57:03 +0200 Subject: In 1c73379ed8483dcf71c5ccfc459c2c22516a9aef I changed FontConfig::_available_fonts to use the font ID as a key, but that's totally wrong because the same Font object with the same ID can have its font filename/data changed, and in that case we don't want to use the cached font. Here we use the actual TTF/OTF font data as the key. We could have just hashed the data (whether it comes from a disk file or is held in memory) but this is slower in the case where we have the filename, as then the file must be loaded from disk for each comparison. This fixes #2518. --- test/font_comparator_test.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/font_comparator_test.cc (limited to 'test/font_comparator_test.cc') diff --git a/test/font_comparator_test.cc b/test/font_comparator_test.cc new file mode 100644 index 000000000..dad058a74 --- /dev/null +++ b/test/font_comparator_test.cc @@ -0,0 +1,27 @@ +#include "lib/font.h" +#include "lib/font_comparator.h" +#include +#include + + +using std::make_shared; +using std::map; +using std::shared_ptr; +using std::string; + + +BOOST_AUTO_TEST_CASE(font_comparator_test) +{ + map cache; + + auto font = make_shared("foo"); + + BOOST_CHECK(cache.find(font->content()) == cache.end()); + cache[font->content()] = "foo"; + BOOST_CHECK(cache.find(font->content()) != cache.end()); + + font->set_file("test/data/Inconsolata-VF.ttf"); + BOOST_CHECK(cache.find(font->content()) == cache.end()); +} + + -- cgit v1.2.3