I have the following routine to calculate the fitted width of a string.
Code:
public string GetFittedStringToPrint(XGraphics gfx, XFont font, XUnit width, string input)
{
string output = input;
XSize stringMeasurement = gfx.MeasureString(input, font);
if (stringMeasurement.Width > width)
{
string inputMinusOneChar = input;
do
{
inputMinusOneChar = inputMinusOneChar.Substring(0, inputMinusOneChar.Length - 1).Trim();
stringMeasurement = gfx.MeasureString(inputMinusOneChar + '…', font);
} while (stringMeasurement.Width > width);
output = inputMinusOneChar + '…';
}
return output;
}
But I have a conversion problem from XUnit to XSize. So how can I compare a XUnit value (as centimeter) with a XSize value and check the width in centimeter?
Its because I have all inputs in centimeter - but MeasureString returns XSize...
Thanks in advance.