LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Text to size for indicator

Solved!
Go to solution

I am trying to make text font size modifiable in a fixed width and height indicator. Can anyone give me some advice on this?
Thanks.

Vu_Anh_1-1611288769449.png

 

 

0 Kudos
Message 1 of 12
(2,871 Views)

Hi Vu,

 


@Vu_Anh wrote:

I am trying to make text font size modifiable in a fixed width and height indicator. Can anyone give me some advice on this?


Use property nodes of the string indicator to set the font/font size…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(2,849 Views)

Hi GerdW,

Thanks for the quick reply. I tried your way but it's the manual way. I want to do it programatically, but I can't find the common characteristic of text size and indicator size.

0 Kudos
Message 3 of 12
(2,846 Views)

Hi Vu,

 


@Vu_Anh wrote:

I tried your way but it's the manual way. I want to do it programatically


You didn't say so in your first message…

 


@Vu_Anh wrote:

I want to do it programatically, but I can't find the common characteristic of text size and indicator size.


Can you describe with words what the expected result should look like?

What "common characteristic" are you talking about?

 

The usual recommendation is to use a PictureIndicator and 2d image drawing functions: this way you can easily determine the bounding box for text and use different font parameters to fit your text into a given rectangle…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 12
(2,844 Views)

Hi GerdW,

My string input is constantly updated. As my picture below, when I write one more character, it will jump one more line then I cannot see all of my data.

Vu_Anh_1-1611300477167.png

I know there is a way to Size to Text to show all the results, but I want my indicator string to be fixed so I have to resize the font text to see all the results and I want it to be done automatically.
Sorry for not fully expressing my thoughts on the post.
Thanks

0 Kudos
Message 5 of 12
(2,842 Views)

Hi Vu,

 


@Vu_Anh wrote:

I want my indicator string to be fixed so I have to resize the font text to see all the results and I want it to be done automatically.


See my previous message…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 12
(2,840 Views)

Hi GerdW,

You mean using the get text rect.vi function, I've done it before and I don't find its commonality (comment # 3). As shown below, I use the get text rect function to give the result right = 60 corresponding to 1 character with length equal to 6. I use the property node to give the width of the indicator string, the result is 228. I don't know how to find a relationship between them.
If you don't mind you can help me with this problem with 1 vi.
Thank you very much.

Vu_Anh_0-1611302829377.png

0 Kudos
Message 7 of 12
(2,832 Views)

Hi Vu,

 


@Vu_Anh wrote:

I use the get text rect function to give the result right = 60 corresponding to 1 character with length equal to 6. I use the property node to give the width of the indicator string, the result is 228. I don't know how to find a relationship between them.


You call the GetTextRect function with that string input: as you didn't specify a font here (!) it gives you a width of 60 pixels (right-left) and a height of 15 pixels (bottom-top).

The string indicator is set to 228 pixels width, but is using a different font/fontsize as was used by GetTextRect.

 

The relationship between both is as follows:

  • Using the same font/fontsize for GetTextRect you can calculate the needed width/height of the string indicator.
  • By changing fontsize in a loop you can iterate until you found a suitable fontsize using GetTextRect.
  • Then set the string indicator to use the fontsize you just determined before! (Or replace the string indicator by a 2DPictureIndicator and draw your text into this indicator…)

It certainly involves a little bit more work than just placing two property nodes in a block diagram!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 12
(2,830 Views)

Hi GerdW,

I have written a program to resize text but it is not very efficient, it is only true in some cases. Size tex

text to size.png

Can you give me some suggestions so that it can work correctly?

Thank

0 Kudos
Message 9 of 12
(2,808 Views)
Solution
Accepted by topic author Vu_Anh

I once tried to solve the inverse problem, how to resize a String (or Path) Indicator to fit an arbitrary String whose properties (Size and Boldness, don't think I added Italics) were presented at Run Time (it was made for one-line String/Path displays, but would grow/shrink the indicator as needed).  The Picture Control trick didn't work (at least at the time I did this, maybe 4-5 years ago), as the "measurements" from the Pictures were not accurate, particularly as Font size changed.

 

Your situation is easier, as you will change the Font size to make the text fit.  You can do this with a String Control/Indicator, whose width I presume you have fixed.  The Algorithm is basically to write the String to the Indicator (or Control), with the Enable Wrap property turned on.  Now use the Get Nth Line Method to get Line 1 (present if the String is too long and "wraps"), and return its "Start" position.  If it is 0, then there is no Line 1, and your String fits (hooray).  Otherwise, reset the Text.FontSize property of the String (make it smaller) and try again.  Depending on how fast you want this to go and how "exact" you want the fit, you can try various algorithms to adjust how you make the size adjustment.  Another trick you can use to speed up the computation is to turn the "Visible" Property of the Indicator off while you are doing this, saving writing to the screen.

 

Bob Schor

0 Kudos
Message 10 of 12
(2,778 Views)