Add search mode check_hidpi to ease the lookup for images with double size to use for displays with high resolution.
#include "support/convert.h"
#include "support/debug.h"
-#include "support/filetools.h"
#include "support/foreach.h"
#include "support/gettext.h"
#include "support/lstrings.h"
namespace lyx {
FileName libFileSearch(QString const & dir, QString const & name,
- QString const & ext)
+ QString const & ext, search_mode mode)
{
- return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
+ return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext), mode);
}
FileName imageLibFileSearch(QString & dir, QString const & name,
- QString const & ext)
+ QString const & ext, search_mode mode)
{
string tmp = fromqstr(dir);
- FileName fn = support::imageLibFileSearch(tmp, fromqstr(name), fromqstr(ext));
+ FileName fn = support::imageLibFileSearch(tmp, fromqstr(name), fromqstr(ext), mode);
dir = toqstr(tmp);
return fn;
}
#include "Length.h"
#include "support/qstring_helpers.h"
+#include "support/filetools.h"
#include "qt_i18n.h"
#include <QHeaderView>
///
support::FileName libFileSearch(QString const & dir, QString const & name,
- QString const & ext = QString());
+ QString const & ext = QString(),
+ support::search_mode mode = support::must_exist);
///
support::FileName imageLibFileSearch(QString & dir, QString const & name,
- QString const & ext = QString());
+ QString const & ext = QString(),
+ support::search_mode mode = support::must_exist);
/** Wrappers around browseFile which try to provide a filename
relative to relpath.
return mode == may_not_exist ? fullname : FileName();
// Only add the extension if it is not already the extension of
// fullname.
- if (getExtension(fullname.absFileName()) != ext)
+ if (getExtension(fullname.absFileName()) != ext) {
+ if (mode == check_hidpi) {
+ FileName fullname2x = FileName(addExtension(fullname.absFileName() + "@2x", ext));
+ if (fullname2x.isReadableFile())
+ return fullname2x;
+ }
fullname = FileName(addExtension(fullname.absFileName(), ext));
+ }
if (fullname.isReadableFile() || mode == may_not_exist)
return fullname;
return FileName();
// 2) build_lyxdir (if not empty)
// 3) system_lyxdir
FileName const libFileSearch(string const & dir, string const & name,
- string const & ext)
+ string const & ext, search_mode mode)
{
FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
- name, ext);
+ name, ext, mode);
if (!fullname.empty())
return fullname;
if (!package().build_support().empty())
fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
- name, ext);
+ name, ext, mode);
if (!fullname.empty())
return fullname;
- return fileSearch(addPath(package().system_support().absFileName(), dir), name, ext);
+ return fileSearch(addPath(package().system_support().absFileName(), dir),
+ name, ext, mode);
}
FileName const imageLibFileSearch(string & dir, string const & name,
- string const & ext)
+ string const & ext, search_mode mode)
{
if (!lyx::lyxrc.icon_set.empty()) {
string const imagedir = addPath(dir, lyx::lyxrc.icon_set);
- FileName const fn = libFileSearch(imagedir, name, ext);
+ FileName const fn = libFileSearch(imagedir, name, ext, mode);
if (fn.exists()) {
dir = imagedir;
return fn;
}
}
- return libFileSearch(dir, name, ext);
+ return libFileSearch(dir, name, ext, mode);
}
must_exist,
/// Only do file name expansion, return the complete name even if
/// the file does not exist
- may_not_exist
+ may_not_exist,
+ /// The (image) file may be present with hi-dpi resolution -
+ /// the lookup checks for a file named "image" + "@2x" + ".ext" first.
+ /// If found it will return e.g. "image@2x.png" instead of "image.png".
+ /// Otherwise it will work as must_exist.
+ check_hidpi
};
/** Returns the real name of file name in directory path, with optional
*/
FileName const libFileSearch(std::string const & dir,
std::string const & name,
- std::string const & ext = std::string());
+ std::string const & ext = std::string(),
+ search_mode mode = must_exist);
/** Same as libFileSearch(), but tries first to find an
internationalized version of the file by prepending $LANG_ to the
*/
FileName const
imageLibFileSearch(std::string & dir, std::string const & name,
- std::string const & ext = std::string());
+ std::string const & ext = std::string(),
+ search_mode mode = must_exist);
/// How to quote a filename
enum quote_style {