How to get pixel dimensions of a string using GTK&Pango?



I am translating a bunch of Windows programs that critically need to work out pixel dimensions of a string (with no newlines in it).
On Windows I first call getfont:

void getfont ( char * fontfacename , int sizeinpts , int weight , HFONT * hfret )
   {
   LOGFONT lf = usewindowsapifunctions ( fontfacename , sizeinpts , weight );
   *hfret = CreateFontIndirect ( &lf ) ;
   }

and then for all strings to be measured call this:

int getpixeldims ( HFONT hf , char * stringtomeasure ,
                   int * widthret , int * heightret )
   {
   HDC hdc = GetDC ( 0 );      // device context of screen
   HGIOBJ prev = SelectObject ( hdc , hf );  // add font to context
   SIZE s;
   int len = strlen ( stringtomeasure );
   GetTextExtentPoint ( hdc , stringtomeasure , len , &s );  // measures
   SelectObject ( hdc , prev );
   ReleaseDC ( 0 , hdc );

   *widthret = s.cx;
   *heightret = s.cy;
   }

I think I need Pango for this, but I have no idea how to use it. I have the Pango reference manual and have read the tutorials by Tony Graham, but have not found any examples to learn from.

Help would be most appreciated.



New Email addresses available on Yahoo!
Get the Email name you've always wanted on the new @ymail and @rocketmail.
Hurry before someone else does!

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]