From d47d882bce89b48e5743464e160a480dcc2a6460 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 28 Feb 2007 12:38:29 +0100 Subject: [PATCH] Port the whole dpi check from mozilla --- lib/src/sugar-utils.c | 66 ++++++++++++++++++++++++++++++++++++----- tools/build-snapshot.sh | 2 +- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/lib/src/sugar-utils.c b/lib/src/sugar-utils.c index f7bf1c5a..6cc59462 100644 --- a/lib/src/sugar-utils.c +++ b/lib/src/sugar-utils.c @@ -19,19 +19,71 @@ #include #include +#include +#include #include "sugar-utils.h" +/* Ported from mozilla nsDeviceContextGTK.cpp */ + +static gint +get_gtk_settings_dpi(void) +{ + GtkSettings *settings = gtk_settings_get_default(); + GParamSpec *spec; + gint dpi = 0; + + spec = g_object_class_find_property( + G_OBJECT_GET_CLASS(G_OBJECT(settings)), "gtk-xft-dpi"); + + if (spec) { + g_object_get(G_OBJECT(settings), + "gtk-xft-dpi", &dpi, + NULL); + } + + return (int)(dpi / 1024.0 + 0.5); +} + +static gint +get_xft_dpi(void) +{ + char *val = XGetDefault(GDK_DISPLAY(), "Xft", "dpi"); + if (val) { + char *e; + double d = strtod(val, &e); + + if (e != val) + return (int)(d + 0.5); + } + + return 0; +} + +static int +get_dpi_from_physical_resolution(void) +{ + float screen_width_in; + + screen_width_in = (float)(gdk_screen_width_mm()) / 25.4f; + + return (int)((float)(gdk_screen_width()) / screen_width_in + 0.5); +} + gint sugar_get_screen_dpi(void) { - char *val = XGetDefault (GDK_DISPLAY(), "Xft", "dpi"); - if (val) { - char *e; - double d = strtod(val, &e); - if (d > 0.0) - return (int)(d+0.5); + int dpi; + + dpi = get_gtk_settings_dpi(); + + if (dpi == 0) { + dpi = get_xft_dpi(); } - return 96; + if (dpi == 0) { + dpi = get_dpi_from_physical_resolution(); + } + + return dpi; } diff --git a/tools/build-snapshot.sh b/tools/build-snapshot.sh index 1fe49888..5a937631 100755 --- a/tools/build-snapshot.sh +++ b/tools/build-snapshot.sh @@ -1,6 +1,6 @@ VERSION=0.63 DATE=`date +%Y%m%d` -RELEASE=2.23 +RELEASE=2.25 TARBALL=sugar-$VERSION-$RELEASE.${DATE}git.tar.bz2 rm sugar-$VERSION.tar.bz2