From fcf747109b6c44bc6fb6a61433f1e96e7d311ab2 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 22 May 2013 18:59:08 +0300 Subject: [PATCH] Handle exceptions in reading fonts. --- graphics/glyph_cache.cpp | 8 ++++---- graphics/glyph_cache.hpp | 2 +- graphics/glyph_cache_impl.cpp | 11 ++++++++++- platform/platform.cpp | 19 +++++++++---------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/graphics/glyph_cache.cpp b/graphics/glyph_cache.cpp index 2d5462c476..1e690e70e8 100644 --- a/graphics/glyph_cache.cpp +++ b/graphics/glyph_cache.cpp @@ -70,10 +70,10 @@ namespace graphics { } - void GlyphCache::addFont(const char *fileName) - { - m_impl->addFont(fileName); - } + //void GlyphCache::addFont(const char *fileName) + //{ + // m_impl->addFont(fileName); + //} void GlyphCache::addFonts(vector const & fontNames) { diff --git a/graphics/glyph_cache.hpp b/graphics/glyph_cache.hpp index b45ab7af57..313a0fb95c 100644 --- a/graphics/glyph_cache.hpp +++ b/graphics/glyph_cache.hpp @@ -87,7 +87,7 @@ namespace graphics GlyphCache(Params const & params); void reset(); - void addFont(char const * fileName); + //void addFont(char const * fileName); void addFonts(vector const & fontNames); pair getCharIDX(GlyphKey const & key); diff --git a/graphics/glyph_cache_impl.cpp b/graphics/glyph_cache_impl.cpp index 0fcb37606f..607a3a27f6 100644 --- a/graphics/glyph_cache_impl.cpp +++ b/graphics/glyph_cache_impl.cpp @@ -190,7 +190,16 @@ namespace graphics return; for (size_t i = 0; i < fontNames.size(); ++i) - addFont(fontNames[i].c_str()); + { + try + { + addFont(fontNames[i].c_str()); + } + catch (RootException const & ex) + { + LOG(LERROR, ("Can't load font", fontNames[i], ex.Msg())); + } + } /* LOG(LINFO, ("----------------------------")); diff --git a/platform/platform.cpp b/platform/platform.cpp index 972c42d213..671f9ceb55 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -60,19 +60,18 @@ void Platform::GetFontNames(FilesList & res) const { GetSystemFontNames(res); - string const resourcesPaths[] = { WritableDir(), ResourcesDir() }; + string const paths[] = { WritableDir(), ResourcesDir() }; - FilesList resourcesFonts; - - for (size_t i = 0; i < ARRAY_SIZE(resourcesPaths); ++i) + FilesList fonts; + for (size_t i = 0; i < ARRAY_SIZE(paths); ++i) { - LOG(LDEBUG, ("Searching for fonts in", resourcesPaths[i])); - GetFilesByExt(resourcesPaths[i], ".ttf", resourcesFonts); - }; + LOG(LDEBUG, ("Searching for fonts in", paths[i])); + GetFilesByExt(paths[i], ".ttf", fonts); + } - sort(resourcesFonts.begin(), resourcesFonts.end()); - resourcesFonts.erase(unique(resourcesFonts.begin(), resourcesFonts.end()), resourcesFonts.end()); - res.insert(res.end(), resourcesFonts.begin(), resourcesFonts.end()); + sort(fonts.begin(), fonts.end()); + fonts.erase(unique(fonts.begin(), fonts.end()), fonts.end()); + res.insert(res.end(), fonts.begin(), fonts.end()); LOG(LINFO, ("Available font files:", (res))); }