diff options
Diffstat (limited to 'dviware/dvisvgm/src/dvisvgm.cpp')
-rw-r--r-- | dviware/dvisvgm/src/dvisvgm.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/dviware/dvisvgm/src/dvisvgm.cpp b/dviware/dvisvgm/src/dvisvgm.cpp index a2c28f8a77..37584d5ddb 100644 --- a/dviware/dvisvgm/src/dvisvgm.cpp +++ b/dviware/dvisvgm/src/dvisvgm.cpp @@ -109,27 +109,36 @@ static void set_libgs (CommandLine &args) { static bool set_cache_dir (const CommandLine &args) { if (args.cacheOpt.given() && !args.cacheOpt.value().empty()) { if (args.cacheOpt.value() == "none") - PhysicalFont::CACHE_PATH = nullptr; + PhysicalFont::CACHE_PATH.clear(); else if (FileSystem::exists(args.cacheOpt.value())) - PhysicalFont::CACHE_PATH = args.cacheOpt.value().c_str(); + PhysicalFont::CACHE_PATH = args.cacheOpt.value(); else Message::wstream(true) << "cache directory '" << args.cacheOpt.value() << "' does not exist (caching disabled)\n"; } - else if (const char *userdir = FileSystem::userdir()) { + else { + string &cachepath = PhysicalFont::CACHE_PATH; + const char *cachehome = getenv("XDG_CACHE_HOME"); + if (!cachehome || util::trim(cachehome).empty()) { #ifdef _WIN32 - string cachedir = "\\.dvisvgm\\cache"; + cachehome = "~\\.cache"; #else - string cachedir = "/.dvisvgm/cache"; + cachehome = "~/.cache"; #endif - static string cachepath = userdir + cachedir; + } + cachepath = util::trim(cachehome) + FileSystem::PATHSEP + "dvisvgm"; + if (cachepath[0] == '~' && cachepath[1] == FileSystem::PATHSEP) { + if (FileSystem::userdir()) + cachepath.replace(0, 1, FileSystem::userdir()); + else + cachepath.erase(0, 2); // strip leading "~/" + } if (!FileSystem::exists(cachepath)) FileSystem::mkdir(cachepath); - PhysicalFont::CACHE_PATH = cachepath.c_str(); } if (args.cacheOpt.given() && args.cacheOpt.value().empty()) { - cout << "cache directory: " << (PhysicalFont::CACHE_PATH ? PhysicalFont::CACHE_PATH : "(none)") << '\n'; + cout << "cache directory: " << (PhysicalFont::CACHE_PATH.empty() ? "(none)" : PhysicalFont::CACHE_PATH) << '\n'; try { - if (PhysicalFont::CACHE_PATH) + if (!PhysicalFont::CACHE_PATH.empty()) FontCache::fontinfo(PhysicalFont::CACHE_PATH, cout, true); } catch (StreamReaderException &e) { |