From 1fa82ad6b7ebf04e127cf9f771cbee2df50e46ae Mon Sep 17 00:00:00 2001 From: andrew-korolev-omp Date: Fri, 18 Feb 2022 22:11:14 +0300 Subject: [PATCH] [sailfish-components-webview] updated DPR calculating mechanism to achieve the same DPR values as in Firefox for Android --- lib/webenginesettings.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/webenginesettings.cpp b/lib/webenginesettings.cpp index 2bb6262..8fb9666 100644 --- a/lib/webenginesettings.cpp +++ b/lib/webenginesettings.cpp @@ -127,24 +127,31 @@ void SailfishOS::WebEngineSettings::initialize() Silica::Theme *silicaTheme = Silica::Theme::instance(); - qreal pixelRatio = SAILFISH_WEBENGINE_DEFAULT_PIXEL_RATIO * silicaTheme->pixelRatio(); - // Round to nearest even rounding factor - pixelRatio = qRound(pixelRatio / 0.5) * 0.5; - - int screenWidth = QGuiApplication::primaryScreen()->size().width(); - - // Do not floor the pixel ratio if the pixel ratio less than 2.0 (1.5 is minimum). - if (pixelRatio >= 2.0 && !testScreenDimensions(pixelRatio)) { - qreal tempPixelRatio = qFloor(pixelRatio); - if (testScreenDimensions(tempPixelRatio)) { - pixelRatio = tempPixelRatio; - } - } else if (screenWidth >= 1080) { - pixelRatio = qRound(pixelRatio); + qreal pixelRatio; + //DPI ranges and DPRs are taken from Android (lpdi, mdpi, hdpi etc.) + qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); + if(dpi < 140) { + pixelRatio = 0.75; + } else if(dpi < 200) { + pixelRatio = 1.0; + } else if(dpi < 280) { + pixelRatio = 1.5; + } else if(dpi < 400) { + pixelRatio = 2.0; + } else if(dpi < 560) { + pixelRatio = 3.0; + } else { + pixelRatio = 4.0; } - + + //reduce pR until screen dimensions can be divivded by it, but not lower than 1.0. + while (!testScreenDimensions(pixelRatio) && pixelRatio > 1.0) { + pixelRatio -= 0.5; + } + engineSettings->setPixelRatio(pixelRatio); + int screenWidth = QGuiApplication::primaryScreen()->size().width(); int tileSize = screenWidth; // With bigger than FullHD screen fill with two tiles in row (portrait).