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 GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,227 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      7 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      440 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      12 views
      0 likes
      Last Post FAQtrader  
      Working...
      X