Initial commit for real hidpi support

Note: This commit has only been tested on MacOS

Changes:
- Icons now use the native hidpi support from Gtk (through Icon Theme)
- Icons are now directly generated from scalable file (i.e. SVG file)
- Widget sizes are scaled based on DPI and scale factor
- Font size is scaled based on DPI and scale factor
This commit is contained in:
Pandagrapher
2022-08-19 16:47:28 +02:00
parent 1e2dc30738
commit 89d2bdce5b
108 changed files with 1949 additions and 2032 deletions

View File

@@ -2,6 +2,7 @@
* This file is part of RawTherapee.
*
* Copyright (c) 2018 Jean-Christophe FRISCH <natureh.510@gmail.com>
* Copyright (c) 2022 Pierre CABRERA <pierre.cab@gmail.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,39 +20,52 @@
#pragma once
#include <gtkmm/image.h>
#include <gtkmm.h>
/**
* @brief A master class for derived class of Gtk::Image in order to handle theme-related icon sets.
* A static class in order to handle Hi-DPI.
*
* About Cairo size convention (for surface):
* Cairo size is expressed in "px" with a 96 DPI (i.e. px per inch) default resolution
*
* About Pango size convention (for font):
* Pango size can be expressed in two different units:
* - Absolute size (i.e. "px"): If size is int type, absolute size is given in "Pango unit"
* shall be divided by Pango::SCALE (i.e. 1024) to get "px". If size is double, absolute
* is already given in "px".
* - Non-absolute size (i.e. "pt"): The default resolution is 72 DPI (i.e. pt per inch). To
* convert the size to "px", use the following formula:
* "size in px" = "size in pt" * ("device resolution" / 72) * "device scale"
*
* Hi-DPI implementation according to the OS (source: GDK code):
* - Windows: A default DPI of 96 is considered. Current DPI parameter is provided by the OS.
* Scale is calculated by (int)("current DPI" / 96). If Scale is greater than 1, DPI is
* forced to 96.
* - MacOS: Scale is calculated from OS parameters (= "Retina screen width" / "Virtual width").
* DPI is forced to 72.
* - Linux: DPI is calculated from OS parameter (= 96 * "text-scaling-factor").
*/
class RTScalable
{
private:
static double dpi;
static int scale;
static Gtk::TextDirection direction; // cached value for text-direction
static void deleteDir(const Glib::ustring& path);
static void updateDPInScale(const Gtk::Window* window, double &newDPI, int &newScale);
protected:
static void setDPInScale (const double newDPI, const int newScale);
static Cairo::RefPtr<Cairo::ImageSurface> loadImage(const Glib::ustring &fname, double dpi);
static Gtk::TextDirection getDirection();
static Cairo::RefPtr<Cairo::ImageSurface> loadSurfaceFromIcon(const Glib::ustring &icon_name, const Gtk::IconSize iconSize = Gtk::ICON_SIZE_SMALL_TOOLBAR);
static Cairo::RefPtr<Cairo::ImageSurface> loadSurfaceFromPNG(const Glib::ustring &fname, const bool is_path = false);
static Cairo::RefPtr<Cairo::ImageSurface> loadSurfaceFromSVG(const Glib::ustring &fname, const int width = -1, const int height = -1, const bool is_path = false);
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);
static void cleanup(bool all = false);
static double getDPI ();
static double getTweakedDPI (); // The returned value is tweaked DPI to adapt to main the font size. Maybe not an ideal solution.
static int getScale ();
static constexpr double pangoDPI = 72.; // Pango default DPI for "pt" size
static constexpr double baseDPI = 96.; // Cairo default DPI
static void init(const Gtk::Window* window);
static void setDPInScale(const Gtk::Window* window);
static void setDPInScale(const double newDPI, const int newScale);
static double getDPI();
static int getScale();
static double getGlobalScale();
static int scalePixelSize(const int pixel_size);
static double scalePixelSize(const double pixel_size);
};