Commit 94c7e8fd authored by Pierre Ducroquet's avatar Pierre Ducroquet 🛩
Browse files

Fix underline painting

parent 984e7469
......@@ -615,19 +615,19 @@ static void drawDecorationWords(QPainter *painter, const QTextLine &line, const
}
}
static qreal computeWidth(KoCharacterStyle::LineWeight weight, qreal width, const QFont& font)
static qreal computeWidth(KoCharacterStyle::LineWeight weight, qreal width, const QFont& font, const QFontMetricsF& metrics)
{
switch (weight) {
case KoCharacterStyle::AutoLineWeight:
case KoCharacterStyle::NormalLineWeight:
case KoCharacterStyle::MediumLineWeight:
case KoCharacterStyle::DashLineWeight:
return QFontMetricsF(font).lineWidth();
return metrics.lineWidth();
case KoCharacterStyle::BoldLineWeight:
case KoCharacterStyle::ThickLineWeight:
return QFontMetricsF(font).lineWidth() * 1.5;
return metrics.lineWidth() * 1.5;
case KoCharacterStyle::ThinLineWeight:
return QFontMetricsF(font).lineWidth() * 0.7;
return metrics.lineWidth() * 0.7;
case KoCharacterStyle::PercentLineWeight:
return QFontInfo(font).pointSizeF() * width / 100;
case KoCharacterStyle::LengthLineWeight:
......@@ -850,7 +850,7 @@ void KoTextLayoutArea::decorateParagraph(QPainter *painter, QTextBlock &block, b
qreal width = computeWidth( // line thickness
(KoCharacterStyle::LineWeight) underline.intProperty(KoCharacterStyle::UnderlineWeight),
underline.doubleProperty(KoCharacterStyle::UnderlineWidth),
font);
font, metrics);
if (valign == QTextCharFormat::AlignSubScript
|| valign == QTextCharFormat::AlignSuperScript) // adjust size.
width = width * 2 / 3;
......@@ -970,7 +970,7 @@ void KoTextLayoutArea::drawStrikeOuts(QPainter *painter, const QTextCharFormat &
width = computeWidth(
(KoCharacterStyle::LineWeight) currentCharFormat.intProperty(KoCharacterStyle::StrikeOutWeight),
currentCharFormat.doubleProperty(KoCharacterStyle::StrikeOutWidth),
font);
font, metrics);
}
if (valign == QTextCharFormat::AlignSubScript
|| valign == QTextCharFormat::AlignSuperScript) // adjust size.
......@@ -1019,7 +1019,7 @@ void KoTextLayoutArea::drawOverlines(QPainter *painter, const QTextCharFormat &c
qreal width = computeWidth( // line thickness
(KoCharacterStyle::LineWeight) currentCharFormat.intProperty(KoCharacterStyle::OverlineWeight),
currentCharFormat.doubleProperty(KoCharacterStyle::OverlineWidth),
font);
font, metrics);
if (valign == QTextCharFormat::AlignSubScript
|| valign == QTextCharFormat::AlignSuperScript) // adjust size.
width = width * 2 / 3;
......@@ -1047,13 +1047,13 @@ void KoTextLayoutArea::drawUnderlines(QPainter *painter, const QTextCharFormat &
font.setPointSize(font.pointSize() * 2 / 3);
QFontMetricsF metrics(font, d->documentLayout->paintDevice());
qreal y = line.position().y();
qreal y = line.position().y() + std::ceil(metrics.underlinePos()) + 0.5;
if (valign == QTextCharFormat::AlignSubScript)
y += line.height() - metrics.descent() + metrics.underlinePos();
y += line.height() - metrics.descent();
else if (valign == QTextCharFormat::AlignSuperScript)
y += metrics.ascent() + metrics.underlinePos();
y += metrics.ascent();
else
y += line.ascent() + metrics.underlinePos();
y += line.ascent();
QColor color = currentCharFormat.underlineColor();
if (!color.isValid())
......@@ -1063,7 +1063,7 @@ void KoTextLayoutArea::drawUnderlines(QPainter *painter, const QTextCharFormat &
qreal width = computeWidth( // line thickness
(KoCharacterStyle::LineWeight) currentCharFormat.intProperty(KoCharacterStyle::UnderlineWeight),
currentCharFormat.doubleProperty(KoCharacterStyle::UnderlineWidth),
font);
font, metrics);
if (valign == QTextCharFormat::AlignSubScript
|| valign == QTextCharFormat::AlignSuperScript) // adjust size.
width = width * 2 / 3;
......@@ -1170,7 +1170,7 @@ int KoTextLayoutArea::decorateTabsAndFormatting(QPainter *painter, const QTextFr
QColor tabDecorColor = currentFragment.charFormat().foreground().color();
if (tab.leaderColor.isValid())
tabDecorColor = tab.leaderColor;
qreal width = computeWidth(tab.leaderWeight, tab.leaderWidth, painter->font());
qreal width = computeWidth(tab.leaderWeight, tab.leaderWidth, painter->font(), QFontMetricsF(painter->font()));
if (x1 < x2) {
if (tab.leaderText.isEmpty()) {
drawDecorationLine(painter, tabDecorColor, tab.leaderType, tab.leaderStyle, width, x1, x2, y);
......
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