1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 18:14:50 +02:00

Make DpiScaler entirely dependent on absolute font height in px :C

This commit is contained in:
Teo Mrnjavac
2013-07-30 20:28:23 +02:00
parent 95c8d53b96
commit 00cb5fafe2
2 changed files with 14 additions and 14 deletions

View File

@@ -92,44 +92,44 @@ DpiScaler::scaledY( const QPaintDevice* pd, int y )
qreal qreal
DpiScaler::ratioX( const QPaintDevice* pd ) DpiScaler::ratioX( const QPaintDevice* pd )
{ {
qreal basePpp = s_baseDpi / 72.; //72*(1.333)=96 dpi qreal ratioFromFH = ratioFromFontHeight();
qreal ratioFromPpp = getPpp() / basePpp;
qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height
//if the error is less than 1%, we trust that the logical DPI setting has the best value //if the error is less than 1%, we trust that the logical DPI setting has the best value
if ( qAbs( ratioFromPpp / ratioYFromDpi - 1 ) < 0.01 ) if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 )
return pd->logicalDpiX() / s_baseDpi; return pd->logicalDpiX() / s_baseDpi;
else else
return ratioFromPpp; return ratioFromFH;
} }
qreal qreal
DpiScaler::ratioY( const QPaintDevice* pd ) DpiScaler::ratioY( const QPaintDevice* pd )
{ {
qreal basePpp = s_baseDpi / 72.; //72*(1.333)=96 dpi qreal ratioFromFH = ratioFromFontHeight();
qreal ratioFromPpp = getPpp() / basePpp;
qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height
//if the error is less than 1%, we trust that the logical DPI setting has the best value //if the error is less than 1%, we trust that the logical DPI setting has the best value
if ( qAbs( ratioFromPpp / ratioYFromDpi - 1 ) < 0.01 ) if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 )
return ratioYFromDpi; return ratioYFromDpi;
else else
return ratioFromPpp; return ratioFromFH;
} }
qreal qreal
DpiScaler::getPpp() DpiScaler::ratioFromFontHeight()
{ {
int fS = TomahawkUtils::defaultFontSize(); int fS = TomahawkUtils::defaultFontSize();
QFont f; QFont f;
f.setPointSize( fS ); f.setPointSize( fS );
int fH = QFontMetrics( f ).ascent() + 1; //a font's em-height should be ascent + 1px (baseline) int fH = QFontMetrics( f ).ascent() + 1; //a font's em-height should be ascent + 1px (baseline)
qreal ppp = fH / (qreal)fS; //pixels per point
return ppp; qreal basePpp = s_baseDpi / 72.; //72*(1.333)=96 dpi
qreal baseFontHeight = 7 * basePpp; //we assume a minimum font size of 7pt
qreal ratioFromFontHeights = qMax( fH / baseFontHeight, 1. );
return ratioFromFontHeights;
} }

View File

@@ -52,7 +52,7 @@ public:
private: private:
inline static qreal ratioX( const QPaintDevice* pd ); inline static qreal ratioX( const QPaintDevice* pd );
inline static qreal ratioY( const QPaintDevice* pd ); inline static qreal ratioY( const QPaintDevice* pd );
inline static qreal getPpp(); inline static qreal ratioFromFontHeight();
qreal m_ratioX; qreal m_ratioX;
qreal m_ratioY; qreal m_ratioY;