Commit fc8e1f29 authored by Christoffer Ackelman's avatar Christoffer Ackelman Committed by Esteban Blanc

QT: Workaround for QFontMetrics not handling multiline text.

parent 61f2bfb0
......@@ -1165,15 +1165,21 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
painter->setFont(get_font(painter_type, FONT_SCALE * size));
QRect rect = painter->fontMetrics().boundingRect(str);
int height = rect.height();
int width = 0;
int height = 0;
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect rect = painter->fontMetrics().boundingRect(l[i]);
width = MAX(width, rect.width());
height += rect.height();
}
if (erase_rect > 0) {
painter->eraseRect(x, ROUND(y - 0.8 * height), rect.width() + 1, ROUND(height * (erase_rect / 10.0)));
painter->eraseRect(x, ROUND(y - 0.8 * height), width + 1, ROUND(height * (erase_rect / 10.0)));
}
if (erase_rect < 12) {
painter->drawText(x, ROUND(y - 0.8 * height), rect.width(), height, Qt::TextDontClip, str, &rect);
painter->drawText(x, ROUND(y - 0.8 * height), width, height, Qt::TextDontClip, str);
}
return 1;
......@@ -1598,10 +1604,14 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len,
painter->setFont(get_font(painter_type, FONT_SCALE * size));
QRect boundingRect = painter->fontMetrics().boundingRect(str);
*width = boundingRect.width();
*height = boundingRect.height();
*width = 0;
*height = 0;
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect boundingRect = painter->fontMetrics().boundingRect(l[i]);
*width = MAX(*width, boundingRect.width());
*height += boundingRect.height();
}
return 1;
}
......
......@@ -1233,6 +1233,18 @@ int GlowDrawQt::polyline_erase(
wind, glow_eDrawType_LineErase, idx, points, point_cnt);
}
static QRect getTextExtent(unique_ptr<QPainter>& painter, QString& str)
{
QRect r(0, 0, 0, 0);
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect rect = painter->fontMetrics().boundingRect(l[i]);
r.setWidth(MAX(r.width(), rect.width()));
r.setHeight(r.height() + rect.height());
}
return r;
}
int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
glow_eDrawType painter_type, glow_eDrawType color, int idx, int highlight,
int line, glow_eFont font_idx, double size, int rot)
......@@ -1266,10 +1278,10 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
painter->setPen(QPen(painter->brush(), size + 1));
}
QRect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len));
QString str = QString::fromLocal8Bit(text, len);
QRect rect = getTextExtent(painter, str);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, str);
return 1;
}
......@@ -1338,10 +1350,9 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len,
set_clip(w, painter);
}
QRect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len));
QString str = QString::fromLocal8Bit(text, len);
QRect rect = getTextExtent(painter, str);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, str);
return 1;
}
......@@ -2929,7 +2940,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
painter->setFont(get_font(font_idx, painter_type, size));
QRect rect = painter->fontMetrics().boundingRect(str);
QRect rect = getTextExtent(painter, str);
int width = rect.width();
int height = rect.height();
height = (int)(height * 0.9);
......@@ -2987,7 +2998,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
painter->setFont(get_font(font_idx, painter_type, size));
QRect rect = painter->fontMetrics().boundingRect(str);
QRect rect = getTextExtent(painter, str);
width = rect.width();
height = rect.height();
height = (int)(height * 0.9);
......@@ -3047,7 +3058,7 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len,
str = QString::fromUtf8(text);
}
QRect boundingRect = painter->fontMetrics().boundingRect(str);
QRect boundingRect = getTextExtent(painter, str);
int lwidth = boundingRect.width();
int lheight = boundingRect.height();
lheight = (int)(lheight * 0.9);
......
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