PDA

View Full Version : Qt 5.3.0 display Arabic text wrong :(



aniasen
7th August 2014, 14:07
I just used painter->drawText() to draw Arabic text(more than two lines)... but it display absolutely wrong! while i use QML to draw arabic text, it displays right....I am soooo confused, ive debuged the code, the glyph position( of course the positions are all wrong),,,, i thought it's the problem of new version harfbuzz-ng....but what confused me most that QML text and painter->drawtext() they are use the same harfbuzz ( i set a break point in harfbuzz-arabic.c) .... I am always thinking it's not hard for Qt itself to find out this bug,,,so how it happened like that? or i miss something? (i set the layout and wrapmode already,still same problem)....anyone could pls give me a hand?

anda_skoa
7th August 2014, 15:08
You could use a QTextDocument instance to do the text layouting for you and then use its drawContents() method to draw the layouted text into a QPainter.

Cheers,
_

aniasen
8th August 2014, 03:34
Thank you so much for you quick reply :) Yep, i just tried what you told me here, it works right for arabic and mix texts...but they must also share the same harfbuzz, what do you think of QPainter->drawText(), did you try the to use this one to draw text? same problem with me, right? QTextDocument may could be a good replacement, but dtawText is also widely used, i really wanna know what's wrong with it, ive debugged it(from the function "getGlyphPosition") but dont really know where the problem is...:(:(:(

anda_skoa
8th August 2014, 07:01
Thank you so much for you quick reply :) Yep, i just tried what you told me here, it works right for arabic and mix texts...but they must also share the same harfbuzz

A single QTextDocument only uses one layouting engine.


QTextDocument may could be a good replacement, but dtawText is also widely used

I assume QTextDocument uses QPainter::drawText(), but on top of that performs text layouting.
So it is not an either/or choice, more a with/without layout one.

Cheers,
_

aniasen
8th August 2014, 11:18
A single QTextDocument only uses one layouting engine.


I assume QTextDocument uses QPainter::drawText(), but on top of that performs text layouting.
So it is not an either/or choice, more a with/without layout one.

Cheers,
_

Thanks again! Acutally i dont really get what you mean :( I just wanna know if you guys had met the same problem using drawText ever, and if you guys have any idears about there the bug is?

faldzip
8th August 2014, 11:22
Please provide minimum compilable example reproducing the problem, so we can see your actual code and check if there is something wrong or not.

aniasen
8th August 2014, 11:31
Please provide minimum compilable example reproducing the problem, so we can see your actual code and check if there is something wrong or not.

Oh yeah, sorry, i should have posted it. just very simple example like here, I dont really think its the problem of my code, i used the same code in qt4.8.3, it works fine...

//just reinplement virtual function paintEvent and use QPainter instance to paint it

void MainWindow::paintEvent(QPaintEvent *)
{
QPainter painter;
painter.begin(this);

QRect rect1 = QRect(20, 20, 760, 420);
QRect rect2 = QRect(50,50,700,400);
QPen pen=QPen(Qt::red);

painter.setPen(pen);
QFont font;
font.setFamily("Droid Arabic Naskh");
font.setItalic(false);
font.setPixelSize(47);
painter.setFont(font);

QTextOption textOption;
textOption.setTextDirection(Qt::LeftToRight);

painter.drawText(rect1,QString::fromWCharArray(L"Welcome to the world of العالم في navigatio"),textOption);


painter.end();
}

aniasen
14th August 2014, 11:33
Thank god, finally i found how it happens....qt5.3.0 uses new unicode 6.3 while qt4.8.3 uses Unicode6.2... they have different ways to itemizer strings...like arabic text, in qt4.8.3,,e.g "العالم في" it will be itemizered into 3 items, second item is space button...while in qt5.3.0, it will just itemizer into 1 items...so when it counts width to draw text, it gets full width while just draw part of arabic string.......confused?! sorry im not native english speaker.....ok here is the place and they way to fix it... in file "qtextlayout.cpp" , line 2025,,, x position shouldnt be positioned by si.width as si is the item of all arabic text with space..... so should be " x += gf.width; " just hope you guys can see it and wont spend too much time on this stupid bugs by Qt....cheers, and thank you all :)

anda_skoa
14th August 2014, 12:17
just hope you guys can see it and wont spend too much time on this stupid bugs by Qt....cheers, and thank you all :)

Have you reported the problem and the fix so other won't run into the bug anymore?

Cheers,
_

aniasen
15th August 2014, 03:25
Have you reported the problem and the fix so other won't run into the bug anymore?

Cheers,
_

Yeah, I did, you could visit QTBUG-40617 (https://bugreports.qt-project.org/browse/QTBUG-40617?page=com.atlassian.jira.plugin.system.issuet abpanels:all-tabpanel) and they have confirmed it :) thank you so much btw!