2 Replies Latest reply on Jan 23, 2012 9:44 PM by ErichWetzel

    Automating font size



      Automating font size


      Is there a way to automaticly set the font size in a field so the text will all fit? What I would like to have happen is the default size would be 10, but if the text was longer, then the size would decrease to fit, say down to minium of 6.

        • 1. Re: Automating font size

          You can approximate this, but given the variablity of today's proportional fonts, it's difficult to impossible to accurately determine whether text entered in a field "fits" or not.

          Use a conditional format with expressions stacked up like a large case function such as:

          Length ( yourTable::YourTextField ) > 10
          length (YourTable::yourTextfield ) > 15

          and so forth.

          For each such formula, specify smaller and smaller font sizes as the number of characters in the field increase. This is not perfect as WWWWW is much wider than iiiii.

          • 2. Re: Automating font size

            Another way to do this is with a script which is triggered on leaving the field in question.  I got this here in the past but I cannot remember who to attribute it to.


            Write a script which looks at the static height of the field you are using, then enters the field and gets the active height of the field.  If you overrun the set size of the field it will run over to a next line by default.  If active is longer than static, reduce the font size.  If they are the same end the script.  The following only works if the field has the ability to open longer when selected showing all contained text if needed.  That is, it cannot be against the bottom margin of the layout.  It must be able to open by a minimum of 1 pixel more than the static field length so that your active field can be longer than the static one.  Do not freeze the window during the script otherwise the active field is the same as static because it is frozen.  Not pretty if the window is flickering a bit but it does work.


            Example : 

            Set Variable [$FontStartSize; Value:14] (your default font size for the field)

            Set Variable [$StaticHeight; Value:GetLayoutObjectAttribute ("Layoutitem" ; "height")] (where "Layoutitem" is the object name of the field you want to work on)

            Set Variable [$LoopCount; Value:0]


            Go to Field [Select/perform; Database::Field]

            Set Variable [$ActiveHeight ; Value:GetLayoutObjectAttribute ("Layoutitem" ; "height")] (gets the active height of the field when it is selected)

            Exit Loop If [$StaticHeight    =   $ActiveHeight] (stop if heights are the same, ie: all text fits)

            Set Variable [$LoopCount; Value:LoopCount+1]


            Set Field [Database::Field; TextSize (Database::Field ; $StartSize - $LoopCount)] (replace the field content with same content but with reduced text size by 1pt)

            Commit Records/Requests [] (commit change in size)

            End Loop (repeat until Exit Loop step is met)


            Hope this helps.  I use it frequently to make sure content fits on pages properly without cutoff / overrun.