Skip to content

Commit 188f940

Browse files
redstratetronical
authored andcommitted
Qt: Fix outline rendering with Parley
This fixes a regression seen with 0910024 where text outlines no longer rendered with Qt and the text color was wrong in general. It turns out drawGlyphRun doesn't work when drawing outlines. It only uses the current QPen color and that's it - so not a built-in way to draw the outlines separately. There was also another bug where we weren't setting the correct QPen color, which regressed any dark themes. (Presumably because no one expected it to fill text with the QPen!) We can fix this by only using drawGlyphRun for filling in glyphs. For drawing the glyph outlines, we can skip the built-in QPainter functions altogether and use QRawFont's ability to create QPainterPaths for us. This restores the text to its previous appearance while keeping the nicer text layouting!
1 parent 5450ce8 commit 188f940

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

internal/backends/qt/qt_window.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,27 +1087,40 @@ impl GlyphRenderer for QtItemRenderer<'_> {
10871087
let glyph_indices_ptr = glyph_indices.as_ptr();
10881088
let glyph_positions_ptr = positions.as_ptr();
10891089
let size: u32 = glyph_indices.len() as u32;
1090-
1091-
let mut qt_pen = qttypes::QPen::default();
1092-
let mut qt_brush = qttypes::QBrush::default();
1090+
if size == 0 {
1091+
return;
1092+
}
10931093

10941094
let painter: &mut QPainterPtr = &mut self.painter;
10951095

10961096
match brush {
1097-
GlyphBrush::Fill(qbrush) => qt_brush = qbrush,
1098-
GlyphBrush::Stroke(qpen) => qt_pen = qpen,
1097+
GlyphBrush::Fill(qt_brush) => {
1098+
cpp! { unsafe [painter as "QPainterPtr*", glyph_indices_ptr as "const quint32 *", glyph_positions_ptr as "const QPointF *", size as "int", raw_font as "QRawFont", qt_brush as "QBrush"] {
1099+
// drawGlyphRun uses QPen to fill glyphs
1100+
(*painter)->setPen(QPen(qt_brush, 1));
1101+
(*painter)->setBrush(Qt::NoBrush);
1102+
1103+
QGlyphRun glyphRun;
1104+
glyphRun.setRawFont(raw_font);
1105+
glyphRun.setRawData(glyph_indices_ptr, glyph_positions_ptr, size);
1106+
(*painter)->drawGlyphRun(QPointF(0, 0), glyphRun);
1107+
}}
1108+
}
1109+
GlyphBrush::Stroke(qt_pen) => {
1110+
cpp! { unsafe [painter as "QPainterPtr*", glyph_indices_ptr as "const quint32 *", glyph_positions_ptr as "const QPointF *", size as "int", raw_font as "QRawFont", qt_pen as "QPen"] {
1111+
(*painter)->setPen(qt_pen);
1112+
(*painter)->setBrush(Qt::NoBrush);
1113+
1114+
QPainterPath path;
1115+
for (int i = 0; i < size; i++) {
1116+
QPainterPath glyphPath = raw_font.pathForGlyph(glyph_indices_ptr[i]);
1117+
glyphPath.translate(glyph_positions_ptr[i]);
1118+
path.addPath(glyphPath);
1119+
}
1120+
(*painter)->drawPath(path);
1121+
}}
1122+
}
10991123
}
1100-
1101-
cpp! { unsafe [painter as "QPainterPtr*", glyph_indices_ptr as "const quint32 *", glyph_positions_ptr as "const QPointF *", size as "int", qt_pen as "QPen", qt_brush as "QBrush", raw_font as "QRawFont"] {
1102-
if (size == 0)
1103-
return;
1104-
(*painter)->setPen(qt_pen);
1105-
(*painter)->setBrush(qt_brush);
1106-
QGlyphRun glyphRun;
1107-
glyphRun.setRawFont(raw_font);
1108-
glyphRun.setRawData(glyph_indices_ptr, glyph_positions_ptr, size);
1109-
(*painter)->drawGlyphRun(QPointF(0, 0), glyphRun);
1110-
}}
11111124
}
11121125

11131126
fn fill_rectangle(

0 commit comments

Comments
 (0)