[PATCH 1/2] Use GDK methods to retrieve the actual screen DPI
Lubomir I. Ivanov
neolit123 at gmail.com
Tue Feb 5 15:10:40 PST 2013
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
gtk-gui.c:
+ added the method get_screen_dpi() that uses a simple
formula to retrieve the actual screen DPI
display.h:
+ use get_screen_dpi() in the SCALE_PRINT macro
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
display.h | 4 ++--
gtk-gui.c | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/display.h b/display.h
index 4fed339..83f8ada 100644
--- a/display.h
+++ b/display.h
@@ -3,12 +3,12 @@
#include <cairo.h>
-#define DPI_SCREEN 72.0
#define SCALE_SCREEN 1.0
-#define SCALE_PRINT (1.0 / DPI_SCREEN)
+#define SCALE_PRINT (1.0 / get_screen_dpi())
extern void repaint_dive(void);
extern void do_print(void);
+extern gdouble get_screen_dpi(void);
/* Plot info with smoothing, velocity indication
* and one-, two- and three-minute minimums and maximums */
diff --git a/gtk-gui.c b/gtk-gui.c
index e009f5a..20a2da8 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -2020,3 +2020,13 @@ void set_dc_nickname(struct dive *dive)
dc = dc->next;
}
}
+
+gdouble get_screen_dpi(void)
+{
+ const gdouble mm_per_inch = 25.4;
+ GdkScreen *scr = gdk_screen_get_default();
+ gdouble h_mm = gdk_screen_get_height_mm(scr);
+ gdouble h = gdk_screen_get_height(scr);
+ gdouble dpi_h = floor((h / h_mm) * mm_per_inch);
+ return dpi_h;
+}
--
1.7.11.msysgit.0
More information about the subsurface
mailing list