Same Font family ,size. different width
when I use same font family ,size and weight. QFontInfo also is same. but the text width is different in different OS.(windows,ubuntu,solaris). so how to do it ? when I draw a rectangle around the text, running in different OS, because different width, text sometimes goes out. or the text is in center, but in other OS, it’s left or right, not center.
The width of text heavily depends on the used rendering engine.
The font rendering depends on the OS, so it might be that on windows, the system font rendering is used, on Linux freetype, which might lead to different widths.
[quote author="dxwang" date="1303804332"]when I use same font family ,size and weight. QFontInfo also is same. but the text width is different in different OS.(windows,ubuntu,solaris). so how to do it ?[/quote]
How to do what exactly? You can query the width using QFontMetrics. Is there anything else you need?
If you disable hinting, the same TTF fonts should deliver same widths. There was an article about it recently on "labs":http://labs.qt.nokia.com/2011/03/14/hint-hint-nudge-nudge-say-no-more/ .
There is also a way to ship your own fonts with your Qt app.
my question is when I draw a rectangle around the text, running in different OS, because different width, text sometimes goes out. or the text is in center, but in other OS, it’s left or right, not center.
if disable hinting, maybe font is not clear, has aliasing when the font size is only 7. so I use QPainter::Antialiasing、QPainter::TextAntialiasing and QFont::PreferAntialias(QFont is set to QPainter, and use QPainter to draw text).
by the way, what’s the meaning of shiping your own fonts with your Qt app. I have tried wenquanyi 、heiti and other fonts. ony lishu(隶书) is equal width，but it’s width is double of others, and it is serif font. I want to use sansserif font to Reduce the deformation when Zooming in and out by QMatrix.
now I have tried to modify the /etc/fonts/conf.d, delete all 10-*.conf files and add 10-unhinted.conf to this directory under ubuntu, solaris x86 and sparc. but the width is still differnt . need I to set setGraphicsSystem() to Raster ? Thanks
Why need the size be 100% equal on the different systems. You can query it during runtime, so you can define the rectangle size during runtime.
Edit: and please, if you reply to two replys in the forum, you can do this in one post. Thanks
@dxwang: You can package the fonts you need with your application and call "QFontDatabase::addApplicationFont()":http://doc.qt.nokia.com/4.7/qfontdatabase.html#addApplicationFont.
In my cross-platform app. I use QFontDialog to choose fonts. indeed I need to filter the font family, for example, Arial, Courier, wenquanyi and Microsoft YaHei. I don't want to see and choose others in combo box., how I can do that? does QFontDatabase::addApplicationFont() can do it?
by the way, my app is cross-platform(windows xp , windows7, ubuntu, solaris x86 and sparc), but QFontDatabase::addApplicationFont() needs fontconfig to support, so it is no use for windows.