]> git.lyx.org Git - lyx.git/commitdiff
#9130 Text in main work area isn't rendered with high resolution
authorStephan Witt <switt@lyx.org>
Sat, 18 Oct 2014 13:19:47 +0000 (15:19 +0200)
committerStephan Witt <switt@lyx.org>
Sat, 18 Oct 2014 13:19:47 +0000 (15:19 +0200)
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
src/frontends/qt4/qt_helpers.h
src/support/filetools.cpp
src/support/filetools.h

index 05c9c3d7cb31f477aeebd8c046db7f14864f70fb..bf869a3eeb06bcb19d130dfe63263f78634504da 100644 (file)
@@ -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;
 }
index 0f7fd63137ece5ec6a3d6082230f9bfe524183ff..defd1a827fd47a46b4e61194baf22f3507e392b5 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "Length.h"
 #include "support/qstring_helpers.h"
+#include "support/filetools.h"
 #include "qt_i18n.h"
 
 #include <QHeaderView>
@@ -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.
index d167d6a94cb1a52ddd7b5401c6a2c17a513ee3f8..8e1be90731606a4991d06ef7c67811d32e871c9f 100644 (file)
@@ -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);
 }
 
 
index 9d91f334de2ba9bf09b1a30ed2a09622b16c0418..dc3bddab23e57c69e94496e4d341901c121e125c 100644 (file)
@@ -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 {