From e7163a0999c08ae3e0448b0d4a7c956d78f98954 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sat, 18 Oct 2014 15:19:47 +0200 Subject: [PATCH] #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. --- src/frontends/qt4/qt_helpers.cpp | 9 ++++----- src/frontends/qt4/qt_helpers.h | 7 +++++-- src/support/filetools.cpp | 23 +++++++++++++++-------- src/support/filetools.h | 13 ++++++++++--- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 05c9c3d7cb..bf869a3eeb 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -27,7 +27,6 @@ #include "support/convert.h" #include "support/debug.h" -#include "support/filetools.h" #include "support/foreach.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -60,17 +59,17 @@ using namespace lyx::support; 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; } diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 0f7fd63137..defd1a827f 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -15,6 +15,7 @@ #include "Length.h" #include "support/qstring_helpers.h" +#include "support/filetools.h" #include "qt_i18n.h" #include @@ -91,11 +92,13 @@ QString const qt_(QString const & qstr); /// 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. diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index d167d6a94c..8e1be90731 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -300,8 +300,14 @@ FileName const fileSearch(string const & path, string const & name, 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(); @@ -313,20 +319,21 @@ FileName const fileSearch(string const & path, string const & name, // 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); } @@ -381,17 +388,17 @@ FileName const i18nLibFileSearch(string const & 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()) { 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); } diff --git a/src/support/filetools.h b/src/support/filetools.h index 9d91f334de..dc3bddab23 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -50,7 +50,12 @@ enum search_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 @@ -90,7 +95,8 @@ bool isBinaryFile(FileName const & filename); */ 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 @@ -106,7 +112,8 @@ i18nLibFileSearch(std::string const & dir, */ 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 { -- 2.39.5