views:

33

answers:

4

How can we calculate x-height of a font (typeface) without needing .NET 3.0 or later (for example I would like to avoid System.Windows.Media namespace).

A: 

Are you looking for this: Font.Height or Perhaps this: How to: Obtain Font Metrics

Josh
I am looking for specifically [x-height](http://en.wikipedia.org/wiki/X-height). `System.Windows.Media` includes the required value [Typeface.XHeight](http://msdn.microsoft.com/en-us/library/system.windows.media.typeface.xheight%28v=VS.100%29.aspx)
Marius
A: 

Or are you looking for a way to calculate the height of a text rendered with a font? In that case you can use the TextRenderer class with the MeasureText function. This is available from .NET 2.0.

Patrick
A: 

If you may use the System.Drawing namespace, you might want to use the Graphics.MeasureString() method. Otherwise, do as Josh says, perhaps.

Your question might not be detailed enough for further assistance.

EDIT #1

The Graphics.MeasureString() method's return type is a System.Drawing.SizeF. This SizeF class provides three properties which among them you have these two:

  1. Height;
  2. Width.

If this is not what you want, them I don't get your point. If it is so, I'm sorry.

I hope this helps anyway! =)

Will Marcouiller
Or use the TextRenderer class. In that case you don't need an instance of a Graphics object.
Patrick
@Patrick: Or using the TextRenderer class works as well. I always forget about this class. I personally don't really have to work with neither of these, but have worked with a .NET PDF library which works in graphical mode, so I kept this in mind with the `MeasureString` method. Thanks for the info! =)
Will Marcouiller
I will have access to Graphics object. In the worst case I will have to calculate height of 'x' using either `MeasureString` or `MeasureCharacterRanges`.
Marius
A: 

Although your question clearly states x-height, all the answers talk about height, which is not at all the same thing. MeasureString and MeasureCharacterRanges don't provide x-height.

Anyway, my answer would be: no, x-height is not available (in any way) in .Net 2.0.

egrunin