locked
How to calculate height & width of string with particular font family & font size? RRS feed

  • Question

  • I want to achieve this in WinRT app.

    I know I can use SharpDX to render the text, you can check out my CodeProject articleI've found how to create white image. But how can I calculate the size of the long string (like 2000+ characters), which is going to be render on white image ?

    I've checked how to calculate the textbock height and width in on load if i create textblock from code?, but I am getting incorrect value. I don't know what to pass as arguments in Arrange(...) &Measure(...) methods. I am passing Window.Current.Bounds as parameter. I also passed the highest possible limit of my app but it's not giving correct value. I want something like this.

    private double GetHeight(string Text, string fontFamily, double fontSize)
    {
        //TODO:
    }






    • Edited by Xyroid Tuesday, September 17, 2013 1:59 PM
    Sunday, September 15, 2013 4:16 PM

All replies

  • Hi Xyroid,

    Currently for Win8 we do no have such feature, but we do have RenderTargetBitmap class by Win8.1, I think you could achieve your idea by the help of this API.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 16, 2013 6:25 AM
    Moderator
  • Please check my question, I've updated it.
    Monday, September 16, 2013 12:42 PM