Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, March 2007
Converting from qt2 to qt3: font issue


Message 1 in thread

Hi all,

I have an old project written for qt2. I just recompiled it in another
machine which has qt3 and it works as is, *without the need to modify the
source code.* (of course tthe code generated by uic is different).
The only thing which differs between the 2 executables is the font used. I
use the QApplication::setFont to set the default font. If I copy the 2
executables on another PC and I run them, I can see that 2 different fonts
are used. How could that be? Is it possible that qt2 and qt3 ask X for
different fonts, even if I user setFont with the same exact string?

Message 2 in thread

Emiliano Mennucci wrote:
> Hi all,
> 
> ...
> fonts are used. How could that be? Is it possible that qt2 and qt3 ask X 
> for different fonts, even if I user setFont with the same exact string?

In theory that could indeed be: Trolltech has always changed quite some 
stuff in the font handling/rendering area of the source code between 
major versions (and also some fixes between minor versions).

So for example when you ask for an "Arial" font you could get font A 
with Qt2 whereas you would get font B with Qt3 (and font C with Qt 4).

I think on Unix in Qt3 they use the "newly" (at that time) available 
FreeType 2 library whereas Qt2 uses something else (FreeType 1 maybe or 
even the X11 font matching API which produces different results than 
FreeType 2).


Cheers, Oliver


-- 
 [ signature omitted ] 

Message 3 in thread

> So for example when you ask for an "Arial" font you could get font A
> with Qt2 whereas you would get font B with Qt3 (and font C with Qt 4).


Yes, infact I have  the font avantgarde installed. The application linked
with qt2 select  that font. qt3 application binds to DejaVu Sans instead.

I think on Unix in Qt3 they use the "newly" (at that time) available
> FreeType 2 library whereas Qt2 uses something else (FreeType 1 maybe or
> even the X11 font matching API which produces different results than
> FreeType 2).


Yes, you're right... but  I can't believe there isn't a way to  force qt3
to use the same font which qt2 would select...

Message 4 in thread

Emiliano Mennucci wrote:
> ...
> Yes, you're right... but  I can't believe there isn't a way to  force 
> qt3  to use the same font which qt2 would select...

As a matter of fact I had to dig deep into the Qt 3 sources 
(QFontDataBase_x11.cpp, QFontDatabase_win.cpp especiall) as to find the 
actual font file which was being used for a QFont ("Arial"), for example 
(I needed the path to this font file for PDF export with a 3rd party PDF 
library).

On Windows you probably don't have much choice because AFAIK the font 
matching algorithm is left to the OS and Qt does not or little influence 
the results brought up by Windows.

On Unix on the other hand you might have a chance to enforce the old "Qt 
2 font matching": mind you that when you compile Qt it needs an 
installed FreeType library - if it does not find one it falls back to 
the crude X11 font API (which is basically parsing the fonts.dir and/or 
fonts.parse and get the first matching font, given the the XLFD (X 
Logical Font Descriptor)).

Maybe there's even a Qt configure switch which lets you fall back to the 
"X11 font matching" or you can somehow enforce that the 
QT_NO_XFTFREETYPE is defined (which drops the FreeType support).

But even then it is not guaranteed that you get the same fonts for Qt 2 
and 3, because Trolltech might still have made changes in the X11 "XLFD 
matching" code. And I'm not sure, but Qt 2 already uses FreeType, but in 
an older version (1 vs. 2) than in Qt 3.

In short: it's probably hard to enforce the same font, except if you 
have a font which exactly matches your search criteria in both Qt 2 and 
3 ;) But "Arial" is certainly not one of those (you can get all sort of 
"Helvetica", "Sans-serif",... fonts for it).

Cheers, Oliver

--
 [ signature omitted ] 

Message 5 in thread

Ok, thank you very much :)
If I can manage the thing I'll let you know.