#9130 Text in main work area isn't rendered with high resolution

Add search mode check_hidpi to ease the lookup for images with double size to use for displays with high resolution.
This commit is contained in:
Stephan Witt 2014-10-18 15:19:47 +02:00
parent 9135dcee07
commit e7163a0999
4 changed files with 34 additions and 18 deletions

View File

@ -27,7 +27,6 @@
#include "support/convert.h" #include "support/convert.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/filetools.h"
#include "support/foreach.h" #include "support/foreach.h"
#include "support/gettext.h" #include "support/gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -60,17 +59,17 @@ using namespace lyx::support;
namespace lyx { namespace lyx {
FileName libFileSearch(QString const & dir, QString const & name, 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, FileName imageLibFileSearch(QString & dir, QString const & name,
QString const & ext) QString const & ext, search_mode mode)
{ {
string tmp = fromqstr(dir); 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); dir = toqstr(tmp);
return fn; return fn;
} }

View File

@ -15,6 +15,7 @@
#include "Length.h" #include "Length.h"
#include "support/qstring_helpers.h" #include "support/qstring_helpers.h"
#include "support/filetools.h"
#include "qt_i18n.h" #include "qt_i18n.h"
#include <QHeaderView> #include <QHeaderView>
@ -91,11 +92,13 @@ QString const qt_(QString const & qstr);
/// ///
support::FileName libFileSearch(QString const & dir, QString const & name, 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, 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 /** Wrappers around browseFile which try to provide a filename
relative to relpath. relative to relpath.

View File

@ -300,8 +300,14 @@ FileName const fileSearch(string const & path, string const & name,
return mode == may_not_exist ? fullname : FileName(); return mode == may_not_exist ? fullname : FileName();
// Only add the extension if it is not already the extension of // Only add the extension if it is not already the extension of
// fullname. // 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)); fullname = FileName(addExtension(fullname.absFileName(), ext));
}
if (fullname.isReadableFile() || mode == may_not_exist) if (fullname.isReadableFile() || mode == may_not_exist)
return fullname; return fullname;
return FileName(); return FileName();
@ -313,20 +319,21 @@ FileName const fileSearch(string const & path, string const & name,
// 2) build_lyxdir (if not empty) // 2) build_lyxdir (if not empty)
// 3) system_lyxdir // 3) system_lyxdir
FileName const libFileSearch(string const & dir, string const & name, 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), FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
name, ext); name, ext, mode);
if (!fullname.empty()) if (!fullname.empty())
return fullname; return fullname;
if (!package().build_support().empty()) if (!package().build_support().empty())
fullname = fileSearch(addPath(package().build_support().absFileName(), dir), fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
name, ext); name, ext, mode);
if (!fullname.empty()) if (!fullname.empty())
return fullname; return fullname;
return fileSearch(addPath(package().system_support().absFileName(), dir), name, ext); return fileSearch(addPath(package().system_support().absFileName(), dir),
name, ext, mode);
} }
@ -381,17 +388,17 @@ FileName const i18nLibFileSearch(string const & dir, string const & name,
FileName const imageLibFileSearch(string & dir, string const & name, FileName const imageLibFileSearch(string & dir, string const & name,
string const & ext) string const & ext, search_mode mode)
{ {
if (!lyx::lyxrc.icon_set.empty()) { if (!lyx::lyxrc.icon_set.empty()) {
string const imagedir = addPath(dir, lyx::lyxrc.icon_set); 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()) { if (fn.exists()) {
dir = imagedir; dir = imagedir;
return fn; return fn;
} }
} }
return libFileSearch(dir, name, ext); return libFileSearch(dir, name, ext, mode);
} }

View File

@ -50,7 +50,12 @@ enum search_mode {
must_exist, must_exist,
/// Only do file name expansion, return the complete name even if /// Only do file name expansion, return the complete name even if
/// the file does not exist /// 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 /** Returns the real name of file name in directory path, with optional
@ -90,7 +95,8 @@ bool isBinaryFile(FileName const & filename);
*/ */
FileName const libFileSearch(std::string const & dir, FileName const libFileSearch(std::string const & dir,
std::string const & name, 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 /** Same as libFileSearch(), but tries first to find an
internationalized version of the file by prepending $LANG_ to the internationalized version of the file by prepending $LANG_ to the
@ -106,7 +112,8 @@ i18nLibFileSearch(std::string const & dir,
*/ */
FileName const FileName const
imageLibFileSearch(std::string & dir, std::string const & name, 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 /// How to quote a filename
enum quote_style { enum quote_style {