20 #include <QFontMetricsF>
26 , m_fontMetrics(m_font)
27 , m_initialFontMetrics(m_fontMetrics)
28 , m_scalingFactor(1.0)
39 if (m_font.pixelSize() == -1)
42 m_font.setPixelSize(qRound(m_font.pixelSize() *
scalingFactor));
43 m_fontMetrics = QFontMetricsF(m_font);
44 m_initialFontMetrics = m_fontMetrics;
50 m_scalingFactor *= factor;
52 if (m_font.pixelSize() == -1) {
53 if (factor > 0.99 && factor < 1.000)
54 m_font.setPointSizeF(m_font.pointSizeF() - 0.1);
56 m_font.setPointSizeF(m_font.pointSizeF() * factor);
58 if (m_font.pixelSize() > 2 && factor > 0.99 && factor < 1.000)
59 m_font.setPixelSize(m_font.pixelSize() - 1);
61 m_font.setPixelSize(
int(m_font.pixelSize() * factor));
64 qDebug() <<
" applyAdditionalScalingFactor" << factor <<
"combined factor:" << m_scalingFactor <<
"pointSize:" << m_font.pointSizeF() <<
"pixelSize:" << m_font.pixelSize();
66 m_fontMetrics = QFontMetricsF(m_font);
71 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 return fm.width(text);
74 return fm.size(Qt::TextSingleLine, text).width();
86 qDebug() <<
" FontScaler::setFactorForHeight" << wantedHeight;
88 Q_ASSERT(wantedHeight > 0);
89 qreal height = m_fontMetrics.height();
92 while (height > wantedHeight && height > 3.0 ) {
93 const qreal factor = wantedHeight / height;
95 qreal prevHeight = height;
96 height = m_fontMetrics.height();
98 qDebug() <<
" FontScaler: height=" << height << factor << m_scalingFactor;
100 if (++iterations > 10 && height == prevHeight) {
105 if (m_font.pixelSize() == 1) {
114 qDebug() <<
" FontScaler::setFactorForWidth" << wantedFactor;
120 const qreal wantedWidth = initialWidth * wantedFactor;
123 qDebug() <<
" FontScaler: sampleText with initialFontMetrics:" << initialWidth <<
"with current fontMetrics:" << width <<
"wanted:" << wantedWidth;
128 while (width > wantedWidth) {
129 qreal factor = wantedWidth / width;
131 qreal prevWidth = width;
134 qDebug() <<
" FontScaler: width=" << width <<
"factor=" << factor <<
"m_scalingFactor=" << m_scalingFactor;
136 if (++iterations > 10 && width == prevWidth) {