Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to fit string in rectangle in OnRender() method?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to fit string in rectangle in OnRender() method?

    Hello.

    Is there a way to render string, using max height and max width, instead of text size?


    There is a way to create TextLayout, and then measure height and width of string.
    I need to perform a reversed task: set height and width of exact string, and then get size to use it in DrawText() or DrawTextLayout();

    Is it possible?
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    You are wanting to use the width and height of a rectangle and convert this to a font size (or use this to choose a font size)?

    I'm not aware of a SharpDX method that does this.

    I think you are going to have to create some custom math / algorithm to convert this.
    You might trying try using the length x width of rectangle to get the area, and then look at the width and height of the font from the text layout and see if there is a common ration at different sizes.

    I was looking at the WPF FontSizeConverter, but I'm not certain this will suit your purposes.


    This thread will remain open for any community members that may know of a method that exists for this that I am not aware of.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Chelsea.
      I will explore FontSizeConverter class and put results here.

      My current solution that I consider as ugly is to re-create TextLayout in a loop with smaller and smaller font size until it fit my rectangle.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by elirion, Today, 01:36 AM
      2 responses
      12 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by DJ888, 04-16-2024, 06:09 PM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by samish18, Yesterday, 08:31 AM
      4 responses
      14 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by funk10101, Yesterday, 09:43 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      5 responses
      551 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X