Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Dynamically change font size based on length of data


This topic is 3300 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I would like to have the font size of a text field grow or shrink, based upon the number of characters or overall length of text, in order to "always completely fill" a text field to its boundaries. We've seen this happen here-and-there in OSX. I have one idea on how to accomplish it, but it seems "clunky". I am wondering if there's a better way.

My idea: use Conditional Formatting to change font size, based on Length(Self). I'd need many, many of those "steps", say, 30 of them, if I wanted to account for every possible font size between 12 point and 42 point, for example. That seems tedious to set up, and not truly "dynamic". Is there a better way?

 

Example.png

Posted

Well you could set it up with a case statement in the calculation or use the choose function.  But keep in mind it wont work perfectly.  Each letter takes up a different amount of space

WWWWWWWWWW - 10 w's

llllllllll-10 lower case l's

Posted
On 11/5/2015, 10:47:45, Grundly said:

I would like to have the font size of a text field grow or shrink

Why?

I've seen others attempt something like this, and I can't remember one that I thought would look nice in the interface, nor any that do what you describe.

Steve pointed out one of the things  you need to be concern about. 

Why not just use a vertical bar on the field instead?

I did a Google search using this URL site: fmforums.com Font size

Here are a couple I remember. 

 

Posted

I was bored...here's on way to create the font.size used in the TextSize() function.

It'll give you a whole number between the max.size and min.size. field.size represents the number of characters that you want and still have the max.size font.

Let( [
field.size = 50 ;
max.font = 36 ;
min.font = 6 ;

text = table::field ;
text.length = Max ( Length ( text ) ; 1 ) ;

size.diff = max.font - min.font ;
adj = ( field.size / text.length ) * max.font ;

font.size = Min ( adj ; max.font ) ;
font.size = Max ( min.font ; font.size ) ;
font.size = Round ( font.size ; 0 )
];

font.size
)

Posted (edited)

I've used a method similar to this in the past for creating Name badges for people attending meetings, where the purpose is to make a person's name as large as possible to read at some distance.  (People with short names like Tom have an advantage).  I've reworked some of what I remembered into a demo (see attachment)... 

There are two versions.  

Because of a difference in behaviour between fp7 and fmp12 files, it was found that doing a conversion of the fp7 file was problematic.  

I therefore revised the script, and the fmp12 version (as provided here) now works correctly.  In fact it's a bit more "visually interesting" because the rendering time is a bit longer.

I haven't tested using Filemaker 13 or 14, only Filemaker 11 and 12.

To run it, click the "Fill all " button.   Initialise using the "Reset all" button.

The way it works makes it completely independent of the font family or variant used.  It works by using a "suck it and see" approach - where the script begins with a small size (I used 10 but it could be less).  It then fills a THIN version of the final field, the purpose being to deliberately swell the field's vertical dimension with each pass of a loop.

Each loop pass uses an incrementing font size.  This consequently pumps up the text box, so we measure the text-box's vertical height at each pass.  The increased dimension is then compared with the previous result.  The technique uses a calculation:

$CurrentHeight = GetLayoutObjectAttribute ( "TextBoxSlim" ; "Height" )

This continues, until suddenly the active text box suddenly increases its height by a factor of around 2, and this moment is obviously the moment the text decides to overflow onto a fresh new line.

We capture this event and exit the loop.  Knowing we have exceeded the point-size by "1" we simply render the final "Presentation" text-box using a font size 1 point less than that which caused the overflow.

Getting this to work means initially allowing a bit of time for text box expansion and contraction.  It's worth noting that you can inflate a text box and it stays that way but if you then replace your text selection with a small font-size, the box stays expanded.  You need to exit  the field and re-enter it before it shrinks down.  (Again I don't know if this behaviour changes with v13 or v14).

Ralph

 

DynamicFontSize.zip

 

 

Edited by Ralph Learmont
  • Like 2

This topic is 3300 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.