diff options
author | Joerg Bornemann <joerg.bornemann@nokia.com> | 2009-10-22 10:28:27 (GMT) |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@nokia.com> | 2009-10-23 14:08:58 (GMT) |
commit | 04d18b38c38c5ff623b30366ea08d56128b9b7d0 (patch) | |
tree | 01a551d66ddfc77084bf55ed9f6942661d528f45 /src/gui/styles | |
parent | 37dc859e7e2e0f135e4c40bc7f6f824fcdb21e86 (diff) | |
download | Qt-04d18b38c38c5ff623b30366ea08d56128b9b7d0.zip Qt-04d18b38c38c5ff623b30366ea08d56128b9b7d0.tar.gz Qt-04d18b38c38c5ff623b30366ea08d56128b9b7d0.tar.bz2 |
Line spacing fixes
QTextEdit (via QTextLayout) and QPlainTextEdit in Qt used to ignore
any font leading but added one extra pixel in QFontMetrics. With many
freetype fonts, this resulted in a "spacy" text layout.
The necessary fixes on X11 and Windows were to take (positive) leading
into account, to make the font database convert point sizes to pixel
sizes without rounding to plain integer values, and to subtract the
extra pixel from QFontMetrics from the font engines' descent value.
The change also fixes several places in styles and widgets, where
QFontMetrics::lineSpacing() was wrongly used instead of
QFontMetrics::height().
Ideally we should also handle negative leading, which would require
additional and bigger code changes in QTextLayout and QPlainTextEdit.
In addition, all other editors we have tested seem to ignore leading on
X11. If we choose to believe the values provided by freetype, our text
layout would be one pixel smaller than everybody else's.
On the Mac, this change does nothing. There our layout is still too spacy,
and for smaller fonts quite ugly compared to native Mac applications.
Done with mae.
Reviewed-by: mae
Diffstat (limited to 'src/gui/styles')
-rw-r--r-- | src/gui/styles/qcleanlooksstyle.cpp | 2 | ||||
-rw-r--r-- | src/gui/styles/qcommonstyle.cpp | 6 | ||||
-rw-r--r-- | src/gui/styles/qmotifstyle.cpp | 4 | ||||
-rw-r--r-- | src/gui/styles/qplastiquestyle.cpp | 8 | ||||
-rw-r--r-- | src/gui/styles/qstylesheetstyle.cpp | 2 |
5 files changed, 11 insertions, 11 deletions
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp index fabd7ca..fc12cfe 100644 --- a/src/gui/styles/qcleanlooksstyle.cpp +++ b/src/gui/styles/qcleanlooksstyle.cpp @@ -3866,7 +3866,7 @@ QSize QCleanlooksStyle::sizeFromContents(ContentsType type, const QStyleOption * if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { if (!menuItem->text.isEmpty()) { - newSize.setHeight(menuItem->fontMetrics.lineSpacing()); + newSize.setHeight(menuItem->fontMetrics.height()); } } #ifndef QT_NO_COMBOBOX diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 5886512..70d130a 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -4396,13 +4396,13 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid case PM_TitleBarHeight: { if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool) { - ret = qMax(widget ? widget->fontMetrics().lineSpacing() : opt->fontMetrics.lineSpacing(), 16); + ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 16); #ifndef QT_NO_DOCKWIDGET } else if (qobject_cast<const QDockWidget*>(widget)) { - ret = qMax(widget->fontMetrics().lineSpacing(), int(QStyleHelper::dpiScaled(13))); + ret = qMax(widget->fontMetrics().height(), int(QStyleHelper::dpiScaled(13))); #endif } else { - ret = qMax(widget ? widget->fontMetrics().lineSpacing() : opt->fontMetrics.lineSpacing(), 18); + ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 18); } } else { ret = int(QStyleHelper::dpiScaled(18.)); diff --git a/src/gui/styles/qmotifstyle.cpp b/src/gui/styles/qmotifstyle.cpp index e6c60cf..b65d45c 100644 --- a/src/gui/styles/qmotifstyle.cpp +++ b/src/gui/styles/qmotifstyle.cpp @@ -1154,7 +1154,7 @@ void QMotifStyle::drawControl(ControlElement element, const QStyleOption *opt, Q menuitem->palette, menuitem->state & State_Enabled, menuitem->text, QPalette::Text); textWidth = menuitem->fontMetrics.width(menuitem->text) + 10; - y += menuitem->fontMetrics.lineSpacing() / 2; + y += menuitem->fontMetrics.height() / 2; p->setFont(oldFont); } p->setPen(opt->palette.dark().color()); @@ -2056,7 +2056,7 @@ QMotifStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, if (mi->menuItemType == QStyleOptionMenuItem::Separator) { w = 10; - h = (mi->text.isEmpty()) ? motifSepHeight : mi->fontMetrics.lineSpacing(); + h = (mi->text.isEmpty()) ? motifSepHeight : mi->fontMetrics.height(); } // a little bit of border can never harm diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index ce2109a..09f5d36 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -5027,7 +5027,7 @@ QSize QPlastiqueStyle::sizeFromContents(ContentsType type, const QStyleOption *o case CT_MenuItem: if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) - newSize.setHeight(menuItem->text.isEmpty() ? 2 : menuItem->fontMetrics.lineSpacing()); + newSize.setHeight(menuItem->text.isEmpty() ? 2 : menuItem->fontMetrics.height()); } break; case CT_MenuBarItem: @@ -5607,11 +5607,11 @@ int QPlastiqueStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, #ifdef QT3_SUPPORT if (widget && widget->inherits("Q3DockWindowTitleBar")) { // Q3DockWindow has smaller title bars than QDockWidget - ret = qMax(widget->fontMetrics().lineSpacing(), 20); + ret = qMax(widget->fontMetrics().height(), 20); } else #endif - ret = qMax(widget ? widget->fontMetrics().lineSpacing() : - (option ? option->fontMetrics.lineSpacing() : 0), 30); + ret = qMax(widget ? widget->fontMetrics().height() : + (option ? option->fontMetrics.height() : 0), 30); break; case PM_MaximumDragDistance: return -1; diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 707b05e..2d90aa1 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -4722,7 +4722,7 @@ int QStyleSheetStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const return subRule.size().height(); else if (subRule.hasBox() || subRule.hasBorder()) { QFontMetrics fm = opt ? opt->fontMetrics : w->fontMetrics(); - return subRule.size(QSize(0, fm.lineSpacing())).height(); + return subRule.size(QSize(0, fm.height())).height(); } break; } |