PDA

View Full Version : Mirror Font



_Jack_
15th May 2010, 11:33
Hi Users,
I need to write a mirrored (reversed) text in a QT application.
I'm triing to install a mirrored font (Windows environment) with this code but without success:


QFontDatabase fontbase;
fontbase.addApplicationFont("c:\Resources\Backrg__.ttf");
painter.setFont(fontbase.font(QString("backwards"),QString("Regular"),10));
painter.drawText(posx, posy,text);

Someone have an idea or is there another approach to obtain a reverse text printing?

Thanks in advance

wysota
15th May 2010, 12:03
Is each character separately to be reversed or is the whole text to be reversed? In other words do you wish to have the natural order of letters preserved or not? Oh... and which way you want it mirrored, horizontally or vertically?

_Jack_
15th May 2010, 14:52
Hi Wysota,thanks for your reply,
I want to print reversed words because I need to print in a transparent paper, in witch some text need to be read right from the other side of the transparent paper.
Basically I think to use the fond you can find here:
http://www.fontspace.com/wa2ise/backwards
because I do not know it is possible to modify, and how eventually to modify, a system font.
If you have some suggestion you are welcome.
Only orizzontally text.
Thank you in advance.

Lykurg
15th May 2010, 15:12
For that purpose you can use any font you like and "just" flip the text. Since you use QPainter that is no big deal! See QPainter::setTransform().

wysota
15th May 2010, 15:39
QPainter's scale(-1,1) will do the trick.

Edit: and translate() of course...


QPainter p(this);
p.scale(-1,1);
p.translate(-width(), 0);
p.drawText(...);

_Jack_
15th May 2010, 17:32
Excellent!!! thank you Wysota and Lykurg for the precious help.

Last consideration to close the topic: considering this code is part of a large painter block of code and there is also others global painter trasformation I not want to loose or change
( painter.setWorldTransform(QTransform,true);

Is correct to write the follow code to restore painter state, without resetting al the painter trasformation matri,x doing another trasform after the text drawing?


QPainter p(this)
p.scale(-1,1);
p.drawText(...);
p.scale(-1,1); //reset the trasform whith another contrary trasform

Lykurg
15th May 2010, 17:49
That's possible but you also can use QPainter::save() and QPainter::restore():

QPainter p(this);
// use p
p.save();
p.scale(-1,1);
p.drawText(...);
p.restore();
// now p is like before "save()".

This approach is much easier if you do more complex transformations.