]> git.lyx.org Git - lyx.git/commitdiff
New method zoomedPixel to compute pixel amount also in HiDpi
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 25 Jan 2018 21:06:03 +0000 (22:06 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 25 Jan 2018 21:08:35 +0000 (22:08 +0100)
The function does not use for now any information from the BufferView
(only lyxrc), but this should eventually change if we want to honor
multi monitor setups properly.

src/BufferView.cpp
src/BufferView.h
src/TextMetrics.cpp
src/mathed/InsetMathHull.cpp

index 3832982395d6a2d40dd252d2422de4efdea5edc8..18f972527dcf21485c84a98694cb4a28500d202e 100644 (file)
@@ -81,6 +81,7 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/lyxlib.h"
 #include "support/Package.h"
 #include "support/types.h"
 
@@ -361,8 +362,8 @@ BufferView::~BufferView()
 
 int BufferView::rightMargin() const
 {
-       // The value used to be hardcoded to 10, which is 0.1in at 100dpi
-       int const default_margin = Length(0.1, Length::IN).inPixels(0);
+       // The value used to be hardcoded to 10
+       int const default_margin = zoomedPixels(10);
        // The additional test for the case the outliner is opened.
        if (!full_screen_ || !lyxrc.full_screen_limit
            || width_ < lyxrc.full_screen_width + 2 * default_margin)
@@ -385,6 +386,21 @@ int BufferView::inPixels(Length const & len) const
 }
 
 
+int BufferView::zoomedPixels(int pix) const
+{
+       // FIXME: the dpi setting should really depend on the BufferView
+       // (think different monitors).
+
+       // Zoom factor specified by user in percent
+       double const zoom = lyxrc.currentZoom / 100.0; // [percent]
+
+       // DPI setting for monitor: pixels/inch
+       double const dpi = lyxrc.dpi; // screen resolution [pixels/inch]
+
+       return support::iround(pix * zoom * dpi);
+}
+
+
 bool BufferView::isTopScreen() const
 {
        return 0 == d->scrollbarParameters_.min;
index 285106699eb053be53dbb81c56284edddcfab41f..fd4ae4c33eb5448849e6dfba070be4c9a0392987 100644 (file)
@@ -114,6 +114,11 @@ public:
         */
        int inPixels(Length const & len) const;
 
+       /** Return the number of pixels equivalent to \c pix pixels at
+        * 100dpi and 100% zoom.
+        */
+       int zoomedPixels(int pix) const;
+
        /// \return true if the BufferView is at the top of the document.
        bool isTopScreen() const;
 
index fedb7730850aaf6693178536ffafc7ef51d3745e..5877e0f124b563d6b724fc3d5bf149b3c85bcbca 100644 (file)
@@ -501,7 +501,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        // Top and bottom margin of the document (only at top-level)
        if (text_->isMainText()) {
                // original value was 20px, which is 0.2in at 100dpi
-               int const margin = Length(0.2, Length::IN).inPixels(0);
+               int const margin = bv_->zoomedPixels(20);
                if (pit == 0) {
                        pm.rows().front().dimension().asc += margin;
                        /* coverity thinks that we should update pm.dim().asc
index 7ab51daab093e2153767be9b01bf7476c0410fba..287c169f0cffa18d4b50bad1652640dc4ed218dc 100644 (file)
@@ -565,7 +565,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 
                if (l)
                        // Value was hardcoded to 30 pixels
-                       dim.wid += mi.base.inPixels(Length(0.3, Length::IN)) + l;
+                       dim.wid += mi.base.bv->zoomedPixels(30) + l;
        }
 
        // reserve some space for marker.
@@ -674,7 +674,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 
                if (l)
                        // Value was hardcoded to 30 pixels
-                       xmath += pi.base.inPixels(Length(0.3, Length::IN)) + l;
+                       xmath += pi.base.bv->zoomedPixels(30) + l;
        }
 
        InsetMathGrid::draw(pi, xmath + 1, y);