[Development] Possible bug in Qt Text Engine

Konstantin Ritt ritt.ks at gmail.com
Tue Mar 15 20:57:02 CET 2016


Hi,

Did you file a bug report? ML is not really the right place for reporting
bugs.

Briefly, the CJK characters in your text are covered by some fallback font
for which the font metrics are slightly different, so that the line height
is the sum of a max ascent, max descent, and max leading (see
QTextEngine::shapeText).


Regards,
Konstantin

2016-03-15 17:41 GMT+04:00 Ziming Song <s.ziming at hotmail.com>:

> Hi everyone,
>
>
> I have been fighting with this bug for over a year, but till now I can't
> find a satisfying solution, so I came here.
>
>
> I use QPlainTextEdit  to implement my own code editor widget, much like
> the tutorial does. The widget works fine, except it displays CJK characters
> with a different line height.
>
>
> If a line contains only English and Latin characters, QPlainTextEdit would
> displays them just fine. But if a line contains CJK characters, that line
> height will be a little larger than other lines.
>
>
>
>
> In the above picture, I put two widget next to each other, and both
> entered 17 lines. Only the left one has lines with Chinese characters.
>
>
> I browsed through the qt source code, and I think the problem might in the
> Qt text engine. Since QTextLine gives different height for english and
> chinese characters.
>
>
> void test(QString s) {
>     QFont f("Courier 10 Pitch", 12);    // this font doesn't contain CJK
> characters
>     QTextLayout textLayout(s, f);
>     textLayout.setCacheEnabled(true);
>     textLayout.beginLayout();
>     while (1) {
>         QTextLine line = textLayout.createLine();
>         if (!line.isValid()) { break; }
>         line.setLineWidth(1000);    // long enough
>         qDebug() << line.height();
>     }
>     textLayout.endLayout();
> }
>
> // in main
> test("english");    // output 19
> test("中文");        // output 20
>
> I've tried reimplementing QPlainTextEdit::paintEvent or inherits from
> QPlainTextDocumentLayout, but those classes are heavily coupled.
>
>
> So is this really a bug in Qt text engine. How can I make lines have same
> line height?
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160315/06c7d247/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ed.png
Type: image/png
Size: 20321 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160315/06c7d247/attachment.png>


More information about the Development mailing list