Commit feb84e61 authored by Holger Kaelberer's avatar Holger Kaelberer
Browse files

core: calculate fontRatio and apply it in GCText

On some low-dpi Android devices with high res (e.g. Galaxy Tab 4) the
fonts in Text-like elements appear too small with respect to the other
graphics -- also if we are using font.pointSize.

For these cases we calculate a fontRatio in ApplicationInfo that takes
dpi information into account, as proposed on
http://doc.qt.io/qt-5/scalability.html#calculating-scaling-ratio

GCText applies this factor automatically on its new fontSize property.
parent fc09d9dc
......@@ -46,6 +46,8 @@
#include <QtCore/QLocale>
#include <QtQuick/QQuickWindow>
#include "ApplicationInfo.h"
#include <qmath.h>
#include <QDebug>
#include <QFontDatabase>
......@@ -78,6 +80,15 @@ ApplicationInfo::ApplicationInfo(QObject *parent): QObject(parent)
QRect rect = qApp->primaryScreen()->geometry();
m_ratio = m_isMobile ? qMin(qMax(rect.width(), rect.height())/800. , qMin(rect.width(), rect.height())/520.) : 1;
// calculate a factor for font-scaling, cf.
// http://doc.qt.io/qt-5/scalability.html#calculating-scaling-ratio
qreal refDpi = 216.;
qreal refHeight = 1776.;
qreal refWidth = 1080.;
qreal height = qMax(rect.width(), rect.height());
qreal width = qMin(rect.width(), rect.height());
qreal dpi = qApp->primaryScreen()->logicalDotsPerInch();
m_fontRatio = m_isMobile ? qMax(1.0, qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth))) : 1;
m_sliderHandleWidth = getSizeWithRatio(70);
m_sliderHandleHeight = getSizeWithRatio(87);
m_sliderGapWidth = getSizeWithRatio(100);
......
......@@ -61,6 +61,7 @@ class ApplicationInfo : public QObject
Q_PROPERTY(bool isMobile READ isMobile CONSTANT)
Q_PROPERTY(bool isPortraitMode READ isPortraitMode WRITE setIsPortraitMode NOTIFY portraitModeChanged)
Q_PROPERTY(qreal ratio READ ratio NOTIFY ratioChanged)
Q_PROPERTY(qreal fontRatio READ fontRatio NOTIFY fontRatioChanged)
Q_PROPERTY(qreal hMargin READ hMargin NOTIFY hMarginChanged)
Q_PROPERTY(qreal sliderHandleWidth READ sliderHandleWidth NOTIFY ratioChanged)
Q_PROPERTY(qreal sliderHandleHeight READ sliderHandleHeight NOTIFY ratioChanged)
......@@ -110,6 +111,7 @@ public:
qreal hMargin() const { return m_hMargin; }
qreal ratio() const { return m_ratio; }
qreal fontRatio() const { return m_fontRatio; }
qreal sliderHandleHeight() { return m_sliderHandleHeight; }
qreal sliderGapWidth() { return m_sliderGapWidth; }
qreal sliderHandleWidth() { return m_sliderHandleWidth; }
......@@ -143,6 +145,7 @@ signals:
void portraitModeChanged();
void hMarginChanged();
void ratioChanged();
void fontRatioChanged();
void applicationSettingsChanged();
void fullscreenChanged();
......@@ -155,6 +158,7 @@ private:
bool m_isPortraitMode;
bool m_isMobile;
qreal m_ratio;
qreal m_fontRatio;
qreal m_hMargin;
qreal m_sliderHandleHeight, m_sliderHandleWidth, m_sliderGapWidth;
......
......@@ -26,5 +26,19 @@ import GCompris 1.0
import "."
Text {
// some constants for often used fontSize-s:
readonly property int tinySize: 10.0
readonly property int smallSize: 12.0
readonly property int regularSize: 14.0
readonly property int mediumSize: 16.0
readonly property int largeSize: 24.0
readonly property int hugeSize: 32.0
// font-size should only be specified using the fontSize property, which
// wraps font.pointSize to take the DPI of the display into account.
// If font.xxxSize is used directly text might appear to small on some devices
property int fontSize: 14
font.pointSize: fontSize * ApplicationInfo.fontRatio
font.family: GCSingletonFontLoader.fontLoader.name
}
......@@ -83,6 +83,7 @@ Window {
Component.onCompleted: {
console.log("enter main.qml (run #" + ApplicationSettings.exeCount
+ ", ratio=" + ApplicationInfo.ratio
+ ", fontRatio=" + ApplicationInfo.fontRatio
+ ", dpi=" + Math.round(Screen.pixelDensity*25.4) + ")");
if (ApplicationSettings.exeCount == 1) {
// first run
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment