From d01d99481d1f630cbb91cfe50a607e03effa8e51 Mon Sep 17 00:00:00 2001 From: Hombre57 Date: Thu, 11 Apr 2019 22:23:07 +0200 Subject: [PATCH 1/4] Suppress baseDPI and baseHiDPI hardcoded values Should fix the issue reported here : https://discuss.pixls.us/t/test-rawtherapee-5-6-rc1/12073/13 --- rtgui/cursormanager.cc | 2 +- rtgui/editwindow.cc | 10 +++++----- rtgui/rtscalable.cc | 2 +- rtgui/rtscalable.h | 8 ++++---- rtgui/rtwindow.cc | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rtgui/cursormanager.cc b/rtgui/cursormanager.cc index 9a28eb061..3181d288e 100644 --- a/rtgui/cursormanager.cc +++ b/rtgui/cursormanager.cc @@ -56,7 +56,7 @@ void CursorManager::init (Glib::RefPtr mainWindow) Glib::RefPtr rotate = RTImage::createPixbufFromFile("rotate-aroundnode-hicontrast.png"); Glib::RefPtr wait = RTImage::createPixbufFromFile("gears.png"); // Currently unused, create *-hicontrast once used. - double s = RTScalable::getTweakedDPI() / 96.; // RTScalable::getDPI() might be preferable, however it imply a lot of work to support this option + double s = RTScalable::getTweakedDPI() / RTScalable::baseDPI; // RTScalable::getDPI() might be preferable, however it imply a lot of work to support this option cAdd = add ? Gdk::Cursor::create(display, add, (int)(8.*s), (int)(8.*s)) : Gdk::Cursor::create(display, Gdk::PLUS); cAddPicker = colPickAdd ? Gdk::Cursor::create(display, colPickAdd, (int)(4.*s), (int)(21.*s)) : Gdk::Cursor::create(display, Gdk::PLUS); diff --git a/rtgui/editwindow.cc b/rtgui/editwindow.cc index 8ba829b26..ec7201f84 100644 --- a/rtgui/editwindow.cc +++ b/rtgui/editwindow.cc @@ -51,7 +51,7 @@ EditWindow* EditWindow::getInstance(RTWindow* p, bool restore) return &instance_.editWnd; } -EditWindow::EditWindow (RTWindow* p) : resolution(96.), parent(p) , isFullscreen(false), isClosed(true) +EditWindow::EditWindow (RTWindow* p) : resolution(RTScalable::baseDPI), parent(p) , isFullscreen(false), isClosed(true) { updateResolution(); @@ -128,7 +128,7 @@ bool EditWindow::updateResolution() double res = get_screen()->get_resolution(); if (scale == 2) { // from Windows' behavior : if scale==2, resolution = 192. (Gtk shows 96 dpi !?), there's no higher value - res = 192.; + res = RTScalable::baseHiDPI; } bool retVal = res != resolution; resolution = res; @@ -141,11 +141,11 @@ void EditWindow::setAppIcon() bool downsize = false; // findIconAbsolutePath won't be able to select the image based on resolution with the // storage of the images, we're doing the selection here - if (resolution == 96.) { + if (resolution == RTScalable::baseDPI) { fName = "rawtherapee-logo-24.png"; } else { fName = "rawtherapee-logo-48.png"; - if (resolution < 192.) { + if (resolution < RTScalable::baseHiDPI) { downsize = true; } } @@ -155,7 +155,7 @@ void EditWindow::setAppIcon() return; } if (downsize) { - int size = int((48. * resolution) / 192.); + int size = int((48. * resolution) / RTScalable::baseHiDPI); pixbuf->scale_simple(size, size, Gdk::InterpType::INTERP_BILINEAR); } diff --git a/rtgui/rtscalable.cc b/rtgui/rtscalable.cc index 7aa3c82c8..e497e3f08 100644 --- a/rtgui/rtscalable.cc +++ b/rtgui/rtscalable.cc @@ -225,7 +225,7 @@ Cairo::RefPtr RTScalable::loadImage(const Glib::ustring &fn RsvgDimensionData dim; rsvg_handle_get_dimensions(handle, &dim); - double r = dpi / 96.; + double r = dpi / baseDPI; Cairo::RefPtr surf = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, (int)(dim.width * r + 0.499), (int)(dim.height * r + 0.499)); Cairo::RefPtr c = Cairo::Context::create(surf); c->set_source_rgba (0., 0., 0., 0.); diff --git a/rtgui/rtscalable.h b/rtgui/rtscalable.h index c3ff19e60..a182dd2e0 100644 --- a/rtgui/rtscalable.h +++ b/rtgui/rtscalable.h @@ -40,11 +40,11 @@ protected: public: #ifdef __APPLE__ - static constexpr double baseDPI = 72; - static constexpr double baseHiDPI = 144; + static constexpr double baseDPI = 72.; + static constexpr double baseHiDPI = 144.; #else - static constexpr double baseDPI = 96; - static constexpr double baseHiDPI = 192; + static constexpr double baseDPI = 96.; + static constexpr double baseHiDPI = 192.; #endif static void init(Gtk::Window *window); diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 0d9017fbd..ce1d5151a 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -109,7 +109,7 @@ RTWindow::RTWindow () #if defined(__APPLE__) // This will force screen resolution regarding font, but I don't think it's compliant with Gtk guidelines... // Do not confuse with screen scaling, where everything is scaled up ! - screen->set_resolution (96.); + screen->set_resolution (RTScalable::baseDPI); #endif Glib::RefPtr regex = Glib::Regex::create (THEMEREGEXSTR, Glib::RegexCompileFlags::REGEX_CASELESS); @@ -184,15 +184,15 @@ RTWindow::RTWindow () int resolution = (int)style->get_screen()->get_resolution(); if (isPix) { // HOMBRE: guessing here... - // if resolution is lower than 192ppi, we're supposing that it's already expressed in a scale==1 scenario + // if resolution is lower than baseHiDPI, we're supposing that it's already expressed in a scale==1 scenario if (resolution >= int(RTScalable::baseHiDPI)) { // converting the resolution to a scale==1 scenario resolution /= 2; } // 1pt = 1/72in @ 96 ppi // HOMBRE: If the font unit is px, is it already scaled up to match the resolution ? - // px >inch >pt >"scaled pt" - pt = (int)(double(fontSize) / RTScalable::baseDPI * 72. * (RTScalable::baseHiDPI / resolution) + 0.49); + // px >inch >pt >"scaled pt" + pt = (int)(double(fontSize) / RTScalable::baseDPI * 72. * (RTScalable::baseDPI / resolution) + 0.49); } else { pt = fontSize / Pango::SCALE; } From ace5a011369f60928f8c975155dd93c19a911d9f Mon Sep 17 00:00:00 2001 From: Hombre57 Date: Sun, 14 Apr 2019 11:10:01 +0200 Subject: [PATCH 2/4] Setting 12pt as base font size for MacOS (see issue #5282) --- rtgui/rtscalable.h | 2 ++ rtgui/rtwindow.cc | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rtgui/rtscalable.h b/rtgui/rtscalable.h index a182dd2e0..e6180eaa1 100644 --- a/rtgui/rtscalable.h +++ b/rtgui/rtscalable.h @@ -42,9 +42,11 @@ public: #ifdef __APPLE__ static constexpr double baseDPI = 72.; static constexpr double baseHiDPI = 144.; + static constexpr int baseFontSize = 12; #else static constexpr double baseDPI = 96.; static constexpr double baseHiDPI = 192.; + static constexpr int baseFontSize = 9; #endif static void init(Gtk::Window *window); diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index ce1d5151a..4e5c6f753 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -170,7 +170,7 @@ RTWindow::RTWindow () css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}", options.fontFamily, options.fontSize * (int)initialGdkScale); #endif //GTK318 - fontScale = options.fontSize / 9.f; + fontScale = options.fontSize / (float)RTScalable::baseFontSize; if (options.rtSettings.verbose) { printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, fontScale); } @@ -192,12 +192,12 @@ RTWindow::RTWindow () // 1pt = 1/72in @ 96 ppi // HOMBRE: If the font unit is px, is it already scaled up to match the resolution ? // px >inch >pt >"scaled pt" - pt = (int)(double(fontSize) / RTScalable::baseDPI * 72. * (RTScalable::baseDPI / resolution) + 0.49); + pt = (int)(double(fontSize) / RTScalable::baseDPI * 72. * (96. / (double)resolution) + 0.49); } else { pt = fontSize / Pango::SCALE; } - fontScale = (float)pt / 9.f; - if ((int)initialGdkScale > 1 || pt != 9) { + fontScale = (float)pt / (float)RTScalable::baseFontSize; + if ((int)initialGdkScale > 1 || pt != RTScalable::baseFontSize) { css = Glib::ustring::compose ("* { font-size: %1pt}", pt * (int)initialGdkScale); if (options.rtSettings.verbose) { printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, fontScale); From 89e63639be155bb22ee4b4bf0bbe9ec4f0565424 Mon Sep 17 00:00:00 2001 From: Hombre57 Date: Sun, 14 Apr 2019 16:58:11 +0200 Subject: [PATCH 3/4] Making pseudo-HiDPI tweaks optional, disabled by default (see issue #5276) --- rtdata/languages/Francais | 1 + rtdata/languages/default | 1 + rtgui/main.cc | 18 ++++++++++-------- rtgui/options.cc | 6 ++++++ rtgui/options.h | 1 + rtgui/preferences.cc | 8 ++++++++ rtgui/preferences.h | 2 ++ rtgui/rtscalable.cc | 6 ++++++ rtgui/rtwindow.cc | 16 ++++++---------- 9 files changed, 41 insertions(+), 18 deletions(-) diff --git a/rtdata/languages/Francais b/rtdata/languages/Francais index 36ffa2afa..2036a2ce3 100644 --- a/rtdata/languages/Francais +++ b/rtdata/languages/Francais @@ -1036,6 +1036,7 @@ PREFERENCES_APPEARANCE_COLORPICKERFONT;Police des ancres de vérification couleu PREFERENCES_APPEARANCE_CROPMASKCOLOR;Couleur du masque de recadrage PREFERENCES_APPEARANCE_MAINFONT;Police principale PREFERENCES_APPEARANCE_NAVGUIDECOLOR;Couleur du cadre dans le Navigateur +PREFERENCES_APPEARANCE_PSEUDOHIDPI;Mode pseudo-HiDPI PREFERENCES_APPEARANCE_THEME;Thème PREFERENCES_APPLNEXTSTARTUP;appliqué au prochain lancement PREFERENCES_AUTOMONPROFILE;Utiliser automatiquement le profil de l'écran principal diff --git a/rtdata/languages/default b/rtdata/languages/default index 91535be42..81b4eeaa4 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -1039,6 +1039,7 @@ PREFERENCES_APPEARANCE_COLORPICKERFONT;Color picker font PREFERENCES_APPEARANCE_CROPMASKCOLOR;Crop mask color PREFERENCES_APPEARANCE_MAINFONT;Main font PREFERENCES_APPEARANCE_NAVGUIDECOLOR;Navigator guide color +PREFERENCES_APPEARANCE_PSEUDOHIDPI;Pseudo-HiDPI mode PREFERENCES_APPEARANCE_THEME;Theme PREFERENCES_APPLNEXTSTARTUP;restart required PREFERENCES_AUTOMONPROFILE;Use operating system's main monitor color profile diff --git a/rtgui/main.cc b/rtgui/main.cc index 322081b69..5cfe93718 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -375,14 +375,6 @@ int main (int argc, char **argv) Glib::init(); // called by Gtk::Main, but this may be important for thread handling, so we call it ourselves now Gio::init (); - // Reading/updating GDK_SCALE early if it exists - const gchar *gscale = g_getenv("GDK_SCALE"); - if (gscale && gscale[0] == '2') { - initialGdkScale = 2; - } - // HOMBRE: On Windows, if resolution is set to 200%, Gtk internal variables are SCALE=2 and DPI=96 - g_setenv("GDK_SCALE", "1", true); - #ifdef WIN32 if (GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)) == 0x0003) { // started from msys2 console => do not buffer stdout @@ -536,6 +528,16 @@ int main (int argc, char **argv) int ret = 0; + if (options.pseudoHiDPISupport) { + // Reading/updating GDK_SCALE early if it exists + const gchar *gscale = g_getenv("GDK_SCALE"); + if (gscale && gscale[0] == '2') { + initialGdkScale = 2; + } + // HOMBRE: On Windows, if resolution is set to 200%, Gtk internal variables are SCALE=2 and DPI=96 + g_setenv("GDK_SCALE", "1", true); + } + gdk_threads_set_lock_functions (G_CALLBACK (myGdkLockEnter), (G_CALLBACK (myGdkLockLeave))); gdk_threads_init(); gtk_init (&argc, &argv); // use the "--g-fatal-warnings" command line flag to make warnings fatal diff --git a/rtgui/options.cc b/rtgui/options.cc index 0df70a4fd..4ba6ee5fc 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -345,6 +345,7 @@ void Options::setDefaults() fontSize = 10; CPFontFamily = "default"; CPFontSize = 8; + pseudoHiDPISupport = false; lastScale = 5; lastShowAllExif = false; panAccelFactor = 5; @@ -1252,6 +1253,10 @@ void Options::readFromFile(Glib::ustring fname) CPFontSize = keyFile.get_integer("GUI", "CPFontSize"); } + if (keyFile.has_key("GUI", "ScaledIcons")) { + pseudoHiDPISupport = keyFile.get_boolean("GUI", "PseudoHiDPISupport"); + } + if (keyFile.has_key("GUI", "LastPreviewScale")) { lastScale = keyFile.get_integer("GUI", "LastPreviewScale"); } @@ -2062,6 +2067,7 @@ void Options::saveToFile(Glib::ustring fname) keyFile.set_integer("GUI", "FontSize", fontSize); keyFile.set_string("GUI", "CPFontFamily", CPFontFamily); keyFile.set_integer("GUI", "CPFontSize", CPFontSize); + keyFile.set_boolean("GUI", "PseudoHiDPISupport", pseudoHiDPISupport); keyFile.set_integer("GUI", "LastPreviewScale", lastScale); keyFile.set_boolean("GUI", "LastShowAllExif", lastShowAllExif); keyFile.set_integer("GUI", "PanAccelFactor", panAccelFactor); diff --git a/rtgui/options.h b/rtgui/options.h index c06d9df30..304a1e220 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -212,6 +212,7 @@ public: int fontSize; // RT's main font size (units: pt) Glib::ustring CPFontFamily; // ColorPicker font family int CPFontSize; // ColorPicker font size (units: pt) + bool pseudoHiDPISupport; bool fbOnlyRaw; bool fbShowDateTime; bool fbShowBasicExif; diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index cc517d4e0..42cb9a607 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -1048,6 +1048,9 @@ Gtk::Widget* Preferences::getGeneralPanel () navGuideColorCB = Gtk::manage(new Gtk::ColorButton()); navGuideColorCB->set_use_alpha(true); + pseudoHiDPI = Gtk::manage(new Gtk::CheckButton(M("PREFERENCES_APPEARANCE_PSEUDOHIDPI") + Glib::ustring (" (") + M ("PREFERENCES_APPLNEXTSTARTUP") + ")")); + setExpandAlignProperties(pseudoHiDPI, false, false, Gtk::ALIGN_START, Gtk::ALIGN_BASELINE); + Gtk::VSeparator *vSep = Gtk::manage(new Gtk::VSeparator()); appearanceGrid->attach(*themeLbl, 0, 0, 1, 1); @@ -1062,6 +1065,7 @@ Gtk::Widget* Preferences::getGeneralPanel () appearanceGrid->attach(*colorPickerFontFB, 1, 2, 1, 1); appearanceGrid->attach(*navGuideColorLbl, 3, 2, 1, 1); appearanceGrid->attach(*navGuideColorCB, 4, 2, 1, 1); + appearanceGrid->attach(*pseudoHiDPI, 0, 3, 5, 1); appearanceFrame->add(*appearanceGrid); vbGeneral->attach_next_to(*appearanceFrame, *flang, Gtk::POS_BOTTOM, 2, 1); @@ -1642,6 +1646,8 @@ void Preferences::storePreferences () moptions.CPFontSize = cpfd.get_size() / Pango::SCALE; } + moptions.pseudoHiDPISupport = pseudoHiDPI->get_active(); + #ifdef WIN32 moptions.gimpDir = gimpDir->get_filename (); moptions.psDir = psDir->get_filename (); @@ -1906,6 +1912,8 @@ void Preferences::fillPreferences () colorPickerFontFB->set_font_name (Glib::ustring::compose ("%1 %2", options.CPFontFamily, options.CPFontSize)); } + pseudoHiDPI->set_active(options.pseudoHiDPISupport); + showDateTime->set_active (moptions.fbShowDateTime); showBasicExif->set_active (moptions.fbShowBasicExif); showExpComp->set_active (moptions.fbShowExpComp); diff --git a/rtgui/preferences.h b/rtgui/preferences.h index 6f434c477..4f92e9e22 100644 --- a/rtgui/preferences.h +++ b/rtgui/preferences.h @@ -145,6 +145,8 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener Gtk::FontButton* colorPickerFontFB; Gtk::ColorButton* cropMaskColorCB; Gtk::ColorButton* navGuideColorCB; + Gtk::CheckButton* pseudoHiDPI; + Gtk::SpinButton* maxRecentFolders; Gtk::SpinButton* maxThumbHeightSB; diff --git a/rtgui/rtscalable.cc b/rtgui/rtscalable.cc index e497e3f08..aaa10bd21 100644 --- a/rtgui/rtscalable.cc +++ b/rtgui/rtscalable.cc @@ -36,6 +36,12 @@ Gtk::TextDirection RTScalable::direction = Gtk::TextDirection::TEXT_DIR_NONE; void RTScalable::setDPInScale (const double newDPI, const int newScale) { + if (!options.pseudoHiDPISupport) { + scale = 1; + dpi = baseDPI; + return; + } + if (scale != newScale || (scale == 1 && dpi != newDPI)) { // reload all images scale = newScale; diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 4e5c6f753..3d7f01e84 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -106,12 +106,6 @@ RTWindow::RTWindow () Gtk::Settings::get_for_screen (screen)->property_gtk_theme_name() = "Adwaita"; Gtk::Settings::get_for_screen (screen)->property_gtk_application_prefer_dark_theme() = true; -#if defined(__APPLE__) - // This will force screen resolution regarding font, but I don't think it's compliant with Gtk guidelines... - // Do not confuse with screen scaling, where everything is scaled up ! - screen->set_resolution (RTScalable::baseDPI); -#endif - Glib::RefPtr regex = Glib::Regex::create (THEMEREGEXSTR, Glib::RegexCompileFlags::REGEX_CASELESS); Glib::ustring filename; Glib::MatchInfo mInfo; @@ -170,7 +164,9 @@ RTWindow::RTWindow () css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}", options.fontFamily, options.fontSize * (int)initialGdkScale); #endif //GTK318 - fontScale = options.fontSize / (float)RTScalable::baseFontSize; + if (options.pseudoHiDPISupport) { + fontScale = options.fontSize / (float)RTScalable::baseFontSize; + } if (options.rtSettings.verbose) { printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, fontScale); } @@ -196,15 +192,15 @@ RTWindow::RTWindow () } else { pt = fontSize / Pango::SCALE; } - fontScale = (float)pt / (float)RTScalable::baseFontSize; + if (options.pseudoHiDPISupport) { + fontScale = (float)pt / (float)RTScalable::baseFontSize; + } if ((int)initialGdkScale > 1 || pt != RTScalable::baseFontSize) { css = Glib::ustring::compose ("* { font-size: %1pt}", pt * (int)initialGdkScale); if (options.rtSettings.verbose) { printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, fontScale); } } - } else { - fontScale = 1.f; } } if (!css.empty()) { From feb122553e5ddfa81b8054ee6cc62c5e7e02d73a Mon Sep 17 00:00:00 2001 From: Hombre57 Date: Sun, 14 Apr 2019 17:19:48 +0200 Subject: [PATCH 4/4] Minor bugfix --- rtgui/options.cc | 2 +- rtgui/preferences.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rtgui/options.cc b/rtgui/options.cc index 4ba6ee5fc..8f601b764 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -1253,7 +1253,7 @@ void Options::readFromFile(Glib::ustring fname) CPFontSize = keyFile.get_integer("GUI", "CPFontSize"); } - if (keyFile.has_key("GUI", "ScaledIcons")) { + if (keyFile.has_key("GUI", "PseudoHiDPISupport")) { pseudoHiDPISupport = keyFile.get_boolean("GUI", "PseudoHiDPISupport"); } diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index 42cb9a607..b37fc537a 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -1056,7 +1056,7 @@ Gtk::Widget* Preferences::getGeneralPanel () appearanceGrid->attach(*themeLbl, 0, 0, 1, 1); appearanceGrid->attach(*themeCBT, 1, 0, 1, 1); appearanceGrid->attach(*themeRestartLbl, 2, 0, 2, 1); - appearanceGrid->attach(*vSep, 2, 1, 1, 3); + appearanceGrid->attach(*vSep, 2, 1, 1, 2); appearanceGrid->attach(*mainFontLbl, 0, 1, 1, 1); appearanceGrid->attach(*mainFontFB, 1, 1, 1, 1); appearanceGrid->attach(*cropMaskColorLbl, 3, 1, 1, 1);