LyX needs help: Broken font metrics computation

Chris January chris at atomice.net
Wed Jan 5 10:29:55 CET 2005


> Dear Ralf, Christian, and all others,
> 
> as you have already noticed, the LyX team is working on a 
> native Win32 port of their text processor, using your GPL'd 
> QT/Win32. Things have progressed nicely in the last couple of 
> weeks and Qt/Win32 seems to work quite well.
> 
> However, we have a serious problem with the computation of 
> font metrics. I have generated a small test case that 
> illustrates the problem:
> 
> #include <qapplication.h>
> 
> int main(int argc, char **argv) {
>   QApplication app(argc, argv);
>   QFont f("times",18,QFont::Bold);
>   QFontMetrics fm(f);
>   QRect r = fm.boundingRect('x');
>   printf( "top: %d   bottom: %d", r.top(), r.bottom());
>   return 0;
> }
> 
> If you compile and run this program with GPL'd Qt/Win32, it outputs
> 
>    top: 16  bottom:36
> 
> However, if you run exactly the same program with Qt/X11 on 
> cygwin (or on Linux), you get the following output:
> 
>   top: -9  bottom: -1
> 
> Quite clear the numbers do not have to be identical but the 
> fact that they are once negative and once positive breaks our neck.
> 
> So... do you have any idea what is wrong?

At a guess, Qt/X11 uses the bottom left of the character cell (or perhaps
baseline) as the origin and Qt/Win32 Free uses the top left of the character
cell. To find the height of the character, the procedure would be the same
on both platforms (bottom - top).
If you want the same pixel height on each platform be sure to use
Qfont.setPixelSize instead of Qfont.setPointSize.

Chris



More information about the kde-cygwin mailing list