summaryrefslogtreecommitdiff
path: root/src/lib/font_config.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-04-19 23:57:03 +0200
committerCarl Hetherington <cth@carlh.net>2023-04-19 23:57:03 +0200
commit22aa0dd620b6db93a64e1e171fb5ddb18693e56e (patch)
treeeff4188e9877983f666b8c53b767d68d4a2ad212 /src/lib/font_config.cc
parentf6a51c4902d6c1983d58e1073f048d50ba2a50df (diff)
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.
Diffstat (limited to 'src/lib/font_config.cc')
-rw-r--r--src/lib/font_config.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lib/font_config.cc b/src/lib/font_config.cc
index d4a442fc1..8804bd6d9 100644
--- a/src/lib/font_config.cc
+++ b/src/lib/font_config.cc
@@ -56,7 +56,7 @@ FontConfig::~FontConfig()
string
FontConfig::make_font_available(shared_ptr<dcpomatic::Font> font)
{
- auto existing = _available_fonts.find(font->id());
+ auto existing = _available_fonts.find(font->content());
if (existing != _available_fonts.end()) {
return existing->second;
}
@@ -107,7 +107,10 @@ FontConfig::make_font_available(shared_ptr<dcpomatic::Font> font)
DCPOMATIC_ASSERT(font_name);
- _available_fonts[font->id()] = *font_name;
+ /* We need to use the font object as the key, as we may be passed the same shared_ptr to a modified
+ * Font object in the future and in that case we need to load the new font.
+ */
+ _available_fonts[font->content()] = *font_name;
FcConfigBuildFonts(_config);
return *font_name;