commit 82904d46030947352e5dccffeb85ede3ae0a81ca
Author: Stephan Witt <[email protected]>
Date:   Sat Oct 18 15:26:49 2014 +0200

    #9130 Text in main work area isn't rendered with high resolution
    Add pixel_ratio to graphics params to use it for displays with high 
resolution.
    It holds the ratio between physical pixels and device-independent pixels of 
the graphics.

diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp
index ade29f1..23ebb62 100644
--- a/src/graphics/GraphicsLoader.cpp
+++ b/src/graphics/GraphicsLoader.cpp
@@ -191,6 +191,15 @@ public:
        /// The connection of the signal StatusChanged  
        boost::signals::connection sc_;
 
+       double displayPixelRatio() const
+       {
+               return params_.pixel_ratio;
+       }
+       void setDisplayPixelRatio(double scale)
+       {
+               params_.pixel_ratio = scale;
+       }
+
 private:
        ///
        void statusChanged();
@@ -326,6 +335,18 @@ ImageStatus Loader::status() const
 }
 
 
+double Loader::displayPixelRatio() const
+{
+       return pimpl_->displayPixelRatio();
+}
+
+
+void Loader::setDisplayPixelRatio(double scale)
+{
+       pimpl_->setDisplayPixelRatio(scale);
+}
+
+
 boost::signals::connection Loader::connect(slot_type const & slot) const
 {
        return pimpl_->signal_.connect(slot);
@@ -433,6 +454,16 @@ void Loader::Impl::createPixmap()
 
        image_.reset(cached_item_->image()->clone());
 
+       if (params_.pixel_ratio == 1.0) {
+               string filename = cached_item_->filename().absFileName();
+               size_t idx = filename.find_last_of('.');
+               if (idx != string::npos && idx > 3) {
+                       if (filename.substr(idx - 3, 3) == "@2x") {
+                               params_.pixel_ratio = 2.0;
+                       }
+               }
+       }
+
        bool const success = image_->setPixmap(params_);
 
        if (success) {
diff --git a/src/graphics/GraphicsLoader.h b/src/graphics/GraphicsLoader.h
index 6521850..5732810 100644
--- a/src/graphics/GraphicsLoader.h
+++ b/src/graphics/GraphicsLoader.h
@@ -101,6 +101,9 @@ public:
         */
        Image const * image() const;
 
+       double displayPixelRatio() const;
+       void setDisplayPixelRatio(double scale);
+
 private:
        /// Use the Pimpl idiom to hide the internals.
        class Impl;
diff --git a/src/graphics/GraphicsParams.cpp b/src/graphics/GraphicsParams.cpp
index a53d2c5..c1c32a0 100644
--- a/src/graphics/GraphicsParams.cpp
+++ b/src/graphics/GraphicsParams.cpp
@@ -25,6 +25,7 @@ namespace graphics {
 Params::Params()
        : display(true),
          scale(100),
+         pixel_ratio(1.0),
          angle(0)
 {}
 
@@ -35,6 +36,7 @@ bool operator==(Params const & a, Params const & b)
                a.display == b.display &&
                a.bb == b.bb &&
                a.scale == b.scale &&
+               a.pixel_ratio == b.pixel_ratio &&
                a.angle == b.angle);
 }
 
diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h
index b1eb1a0..86cc9dc 100644
--- a/src/graphics/GraphicsParams.h
+++ b/src/graphics/GraphicsParams.h
@@ -55,6 +55,7 @@ public:
 
        bool display;
        unsigned int scale;
+       double pixel_ratio;
 
        /// The image filename.
        support::FileName filename;

Reply via email to