tags:

views:

48

answers:

3
+1  Q: 

Font Metrics in C

I wanted to know if there is any library in C available for calculating the Font Metrics (Basically i wanted to know the width of a string of Particular Font). QT has QFontMetrics. Is there any way I can get similar data in C.

A: 

Check out FreeType: http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html

m1tk4
+1  A: 

I wouldn't say just use FreeType, unless you are on a system that uses X as the graphics display. If you are on Windows, use the Windows API to get font metrics information and on Mac use whatever Cocoa provides.

It might also help if you told us what you are trying to do.

EDIT: Since the output of your library is intended to be consumed by a particular GUI app, you will probably want to use the same GUI library to get the font metrics information as the app is using. Even better would be to have the app provide metrics information to the library, or a callback method that can provide that information. Then the library doesn't even have to know how the font metrics were derived, reducing an unnecessary dependency. This also means that you can use Qt (C++) in your GUI app, but still write your library in C and not have to figure out a way to call C++ from C, which is very difficult, especially if you are trying to make it cross-platform.

siride
Actually I have kind of report Generator Library, which provides report to an application which GUI Based (based on QT). I should provide report such that the data should not exceed the text box provided in that. So I was trying to see if its possible to truncate the report depending on the font size and font type.
hari
I updated my answer in light of your comment.
siride
Thanks for your answer. I have already implemented similar kind solution with QT QFontMetrics. But wanted to know if I can do it without support of QT.
hari