LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Font size to pixel size

I'm working in dynamically increasing/decreasing the size of elements in an array based on window size (vi below) My main hang up now is on figuring out how to increase/decrease font size as a function of pixels allocated to the string indicator.

 

0 Kudos
Message 1 of 16
(5,103 Views)

Graphics and Sound >>> Picture Functions >>> Get Text Rect.vi will return the size in pixel for the text you specify and the font you specify.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 16
(5,096 Views)

Ok, is there a reverse of this, where I give it the desired height in pixels and it will give me the best font size? I guess I could start high use a while loop to increment down if this is the only way though.

0 Kudos
Message 3 of 16
(5,084 Views)

@ATE-EGNE wrote:

Ok, is there a reverse of this, ...


Not that I know.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 16
(5,081 Views)

Can you try a few different sizes?  I'm thinking there is a direct formula that would take you from font size to pixel size.  Like Font size * X + Y = pixel size.

 

Where X is a "scaling factor" and Y might be some constant add-on such as for borders in string or numeric control.

 

Quick experiment on a Modern Numeric.  I'm getting font size + 25 for any font size 5 or larger.  For a Modern string, it seems to be the same.

0 Kudos
Message 5 of 16
(5,064 Views)

@RavensFan wrote:

Can you try a few different sizes?  I'm thinking there is a direct formula that would take you from font size to pixel size.  Like Font size * X + Y = pixel size.

 

Where X is a "scaling factor" and Y might be some constant add-on such as for borders in string or numeric control.

 

Quick experiment on a Modern Numeric.  I'm getting font size + 25 for any font size 5 or larger.  For a Modern string, it seems to be the same.


Hide the label?

Will the math change for different system settings and fonts?

Strings of fixed width fonts will be linear but non-fixed width fonts?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 16
(5,053 Views)

Some good points Ben.

 

Hiding the label made it only + 10.

I'm not sure if changing the font actually changed anything.   It didn't seem to for the couple of fonts I tried.

Width shouldn't matter whether fixed width or not.

 

At least not for height which was how I interpreted the original question based on another post by the user on the topic. Change size of an object in an array

 

For width, then certainly the amount of characters in a string will be important whether they are fixed width or not.

Assuming it is only height, the OP shouldn't rely on my numbers, but run similar tests on his own.

0 Kudos
Message 7 of 16
(5,049 Views)

Ok, Here's my solution so far, but the pid isn't settling any suggestions team?

 

Sizepid.png

0 Kudos
Message 8 of 16
(5,046 Views)

 For width, then certainly the amount of characters in a string will be important whether they are fixed width or not.

Assuming it is only height, the OP shouldn't rely on my numbers, but run similar tests on his own.


I was hoping that I can get this to work as a general case so I'd really like to get LabVIEW to solve for the font size as it could vary greatly depending on the number of elements I'm working with at a given time.

 

Also, I will need to be worried about the width as well as multiple lines, so using the get text rect.vi is a good catch all.

0 Kudos
Message 9 of 16
(5,040 Views)

I threw this together, so it's not perfectly tailored to solve your whole problem, but if you can follow what I'm doing, it may get you an answer you can work with. It's a little hackish, definitely. Hope it helps you find the right path, though!

 

The line down the middle just separates the first part from the second part. This doesn't actually run without problems; you'd have to enforce data flow and you'd probably want to find the longest element of your array first and test against that, but then you'd have your worst case scenario so you could safely use that for your font size and know that your other elements would fit nicely.

______________________________________________________________________
The avatar is for the best weapon in any game ever. But nobody goes there anymore.

CLAD, LV2013, LV2015
0 Kudos
Message 10 of 16
(5,022 Views)