Free Support Forum - aspose.com

Determine the exact size of a portion

How can I determine the exact height and width of a portion? I am using MeasureString, but it returns values that are larger than what PowerPoint reports for the same string.

Here's my code:

using (Bitmap bmp = new Bitmap(1, 1))

{

Graphics g = Graphics.FromImage(bmp);

Font stringFont = new Font(_pres.Fonts[port.SymbolFontIndex].FontName, port.FontHeight);

SizeF stringSize = new SizeF();

stringSize = g.MeasureString(port.Text, stringFont);

_Log.Write(string.Format(" stringSize H[{0}] W[{1}]", stringSize.Height.ToString(), stringSize.Width.ToString())); // = " ";

}

Thanks

Hello bthrasher.



PowerPoint uses another font-em-size to height-in-pixels conversion than the GDI+ engine, which used in .NET. If you will change font in PowerPoint, you’ll see that line spacing depends on font’s em-size only, while MeasureString() and font.GetHeight() methods will return different heights for diffirent font families. To get correct line-spacing ftom the em-size you should find coefficient for target resolution.

But you can trust width, returned by MeasureString if you thansmit to it a correct StringFormat object.