PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Howto convert XSize values to centimeter
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4400
Page 1 of 1

Author:  mce [ Tue Nov 01, 2022 3:40 pm ]
Post subject:  Howto convert XSize values to centimeter

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.

Author:  TH-Soft [ Wed Nov 02, 2022 7:58 am ]
Post subject:  Re: Howto convert XSize values to centimeter

Hi!

Just use the "Point" property of XUnit. That's what XSize is using: Points.

Author:  mce [ Wed Nov 02, 2022 8:44 pm ]
Post subject:  Re: Howto convert XSize values to centimeter

Thank you very much - it works very well :-)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/