commit 1a969fa4a6130506ab52e72098ae0edce48d3231
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Thu Jan 25 22:06:03 2018 +0100
New method zoomedPixel to compute pixel amount also in HiDpi
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 | 20 ++++++++++++++++++--
src/BufferView.h | 5 +++++
src/TextMetrics.cpp | 2 +-
src/mathed/InsetMathHull.cpp | 4 ++--
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 3832982..18f9725 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -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;
diff --git a/src/BufferView.h b/src/BufferView.h
index 2851066..fd4ae4c 100644
--- a/src/BufferView.h
+++ b/src/BufferView.h
@@ -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;
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index fedb773..5877e0f 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -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
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 7ab51da..287c169 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -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);