PDA

View Full Version : How to make font Smooth in QT?



janton
15th May 2011, 22:11
Hello All,

I have a simple question, or more something i need to understand i think...

I designed a application in Photoshop and though font would look simular in qt, but it doesn't ofcourse.. after some time googling i learned photoshop uses some soort of smoothing the fonts. I found this is also possible in qt or at least i found something but it wasn't really clear to me still.

In the attachment you can see the difference. In the left image you see the Photoshop text and on the right you see the same font and size in qt
SEE HERE:
6417

Is it possible i make the font more smooth, so it could look simular like the Photoshop version?

helloworld
15th May 2011, 23:48
What platform are you targeting? I have been asking myself the same question and find this problem especially prevelant when rendering fonts in smaller sizes on MS Windows.

So I just started to create some Qt-styled wrapper classes for the FreeType library. FreeType (www.freetype.org) is a font engine capable of rendering high-quality font output. It provides a low-level C API and is already used in a number of projects, but I wanted something that works without too much effort together with Qt's Painter framework.

Currently I have something like:

QFreeTypeEngine
QFreeTypeFont
QFreeTypeGlyph

...where a QFreeTypeEngine is responsible for creating and managing QFreeTypeFont objects for a specific application, and individual QFreeTypeFonts can be created from a font in the local filesystem, or from a resource.

In attached screenshot you can see the difference between FreeType (above), and Windows' default font rendering algorithm (below).

(Actually I'm not sure it's the exact same font face in both examples, but you can still see the difference in quality, especially if you open the image in PS and zoom in and look at the anti-aliasing.)

6418

janton
16th May 2011, 11:10
"helloworld" thx for your reply, i will take a look in this, but i was hoping to only use QT and not add another 3dparty library... This perhaps would bring more work if i want to build the version for Mac OS X (yes freetype is also multiplatform but i have no experience with Mac OS X)
Indeed the program running on Windows (Vista) right now.

I couldn't see the difference right away because of different size and maybe different font... ;-) (also the image has lower quality because of the qt upload/converter i guess) If you would like to show me a example with color: white; font: bold 14px; font-family: Arial; that would be great... but only if you have the time ofcourse.

i found this article: http://labs.qt.nokia.com/2008/09/01/subpixel-antialiasing-on-x11/
Where is see this settings panelhttp://labs.qt.nokia.com/wp-content/uploads/2008/09/gnome-dialog.png
But this is only in Gnome i guess. (so nothing todo with QT)

Added after 7 minutes:

Aaaaa.. i now see there is a Qt FreeType engine... that makes it much easier!

helloworld
16th May 2011, 14:02
Aaaaa.. i now see there is a Qt FreeType engine... that makes it much easier!

Where did you find this? Were you referring to my library, or something else you found? This is mainly intended for Windows, but AFAIK should work on all platforms. However I don't find this to be an issue on Mac. Anyway, I'll try to upload some more examples in a while with the settings you mentioned.

wysota
17th May 2011, 01:05
So I just started to create some Qt-styled wrapper classes for the FreeType library. FreeType (www.freetype.org) is a font engine capable of rendering high-quality font output. It provides a low-level C API and is already used in a number of projects, but I wanted something that works without too much effort together with Qt's Painter framework.
I guess you are not aware Qt already uses FreeType...

I'm not really sure what you guys are doing but font rendering in Qt is done using platform means and sometimes poor quality of fonts is caused by wrong settings of libraries responsible for font management/rendering, like FreeType, FontConfig or ClearType. Fonts in Qt apps and fonts on images in Photoshop are almost bound to look different as Photoshop provides a more fine-grained control over the rendering compared to what the system offers for applications. You can write the same text in Photoshop and on your window title bar and they will also look different.

helloworld
17th May 2011, 17:54
I guess you are not aware Qt already uses FreeType...

I am aware of this, but my understanding was that this was only supported on platforms that already provide the FreeType library; i.e., X11 and some flavors of Linux.

Perhaps I have missed something here but I can't find anything in the documentation on how to enable this for Windows/other targets. Based on my tests, using FreeType makes a huge difference on Windows when rendering text in smaller size (see attachment, FreeType on the left with default settings).

6433

Added after 32 minutes:


Photoshop provides a more fine-grained control over the rendering

Using FreeType I can have exactly the same control over anti-aliasing, kerning and various typographic properties, obtaining and modifying individual glyphs of a font. I don't see how this is currently possible with Qt. My idea was to wrap this functionality in a high-level API: For example:



QFreeTypeEngine *engine = new QFreeTypeEngine(this);
QFreeTypeFont *font = new QFreeTypeEngine("myfont.ttf", engine);

QFreeTypeImage img = QFreeTypeImage::fromString("The lorem ipsum", font);
painter.drawImage(30, 70, img);

wysota
17th May 2011, 20:30
I am aware of this, but my understanding was that this was only supported on platforms that already provide the FreeType library; i.e., X11 and some flavors of Linux.
The point is the implementation is there. No need to rewrite it.

helloworld
17th May 2011, 21:10
I am certainly not going to rewrite FreeType, but assuming I want the rendering quality that you see on the left side of my screenshot (256 gray-level anti-aliasing, rather than the normal 5-level Windows algorithm) without linking my (Qt) application against FreeType or any other third-party library. How would I achieve that on Windows?

wysota
17th May 2011, 23:11
If you want to use freetype then you will certainly need to link your application against it. My point is you don't need to manually wrap freetype calls into Qt API because it has already been done. By the way, I don't know why your default fonts look so bad on Windows. We don't experience such problems with our apps.

helloworld
17th May 2011, 23:48
What am I missing here? I can't find anything in the docs about using FreeType under Windows, only how to access the FT_Face handle from QFont (on supported platforms). All I find on Google besides this post is the following:

http://lists.trolltech.com/qt-interest/2008-03/thread00445-0.html


Almost right, freetypeFace is limited to X11 and QWS systems as those are the ones where Qt uses FreeType to render fonts. On Windows it naturally uses the native API for rendering fonts

http://developer.qt.nokia.com/forums/viewthread/1916


Features can be switchen on by configure. But freetype can only be switched on for Symbian or Qt Embedded.

Btw, quality is not THAT bad, but there is definitely a difference between native Windows font rendering and what you see in a graphics application like Photoshop.

Kostanev
21st April 2012, 08:06
I have the same "problem". In the image below you can see the differences between my android device and qt app using font "Clockopia".
http://desmond.imageshack.us/Himg851/scaled.php?server=851&filename=fontclockopiaqt.png&res=landing