Results 1 to 7 of 7

Thread: Mirror Font

  1. #1
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Mirror Font

    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:

    Qt Code:
    1. QFontDatabase fontbase;
    2. fontbase.addApplicationFont("c:\Resources\Backrg__.ttf");
    3. painter.setFont(fontbase.font(QString("backwards"),QString("Regular"),10));
    4. painter.drawText(posx, posy,text);
    To copy to clipboard, switch view to plain text mode 

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

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mirror Font

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    _Jack_ (15th May 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mirror Font

    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.
    Last edited by _Jack_; 15th May 2010 at 15:54. Reason: updated contents

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mirror Font

    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().

  6. The following user says thank you to Lykurg for this useful post:

    _Jack_ (15th May 2010)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mirror Font

    QPainter's scale(-1,1) will do the trick.

    Edit: and translate() of course...

    Qt Code:
    1. QPainter p(this);
    2. p.scale(-1,1);
    3. p.translate(-width(), 0);
    4. p.drawText(...);
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 15th May 2010 at 16:43.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    _Jack_ (15th May 2010)

  9. #6
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mirror Font

    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?

    Qt Code:
    1. QPainter p(this)
    2. p.scale(-1,1);
    3. p.drawText(...);
    4. p.scale(-1,1); //reset the trasform whith another contrary trasform
    To copy to clipboard, switch view to plain text mode 

  10. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mirror Font

    That's possible but you also can use QPainter::save() and QPainter::restore():
    Qt Code:
    1. QPainter p(this);
    2. // use p
    3. p.save();
    4. p.scale(-1,1);
    5. p.drawText(...);
    6. p.restore();
    7. // now p is like before "save()".
    To copy to clipboard, switch view to plain text mode 
    This approach is much easier if you do more complex transformations.

  11. The following user says thank you to Lykurg for this useful post:

    _Jack_ (15th May 2010)

Similar Threads

  1. Change Font of QListWidget to Monospace Font
    By pospiech in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 19:23
  2. font incorrectly show - font break.
    By sgh in forum Qt Programming
    Replies: 9
    Last Post: 30th May 2008, 03:35
  3. How to mirror-image text?
    By WinchellChung in forum Newbie
    Replies: 11
    Last Post: 31st July 2007, 18:13
  4. 4.3.0 installer and MinGW mirror problem
    By ucomesdag in forum Installation and Deployment
    Replies: 2
    Last Post: 8th July 2007, 04:17
  5. mirror for QGraphicsItem
    By jobrandt in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2007, 10:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.