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

Sizing text - separate from what the text is.


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

Recommended Posts

Posted

We allow users to increase and decrease font size by clicking a + or - sign. Each sign is a button and the button is a "set field" with the field specified and the calculated result:

textSizeChg (field ; "UP" ), where textSizeChg is a custom function written by someone long ago:

***********************************************************************************

// fontSizeChg ( text ; upordown )

Let ( [

sizenow = Filter ( LeftWords ( GetAsCSS( text ) ; 5 ) ; "1234567890" ) ;

sizenow = Case ( IsEmpty ( sizenow ) ; 12 ; sizenow ) ] ;

TextSize ( text ; Case ( PatternCount ( upordown ; "up" ) ; sizenow + 1 ; Max ( 1 ; sizenow - 1 ) ) )

)

*************************************************************************************

however when we have a number in the field to be sized, it grabs that number and things it's the sizenow.

So if we have the field with a default of 12, and it has a Save $49 Today! in it, clicking + takes it to a 50 font size and clicking - takes it to a 48 font size. That's not nearly as bad as when the number 50000 appears!

This happens on Win.

How can I have button sizing when the text includes a number (which is not its font?)

Thanks for any all insights!!

Posted

Whoever wrote that custom function made an unwarranted assumption that the text in the field (or more precisely, the first character of the text) has a font-size attribute. When this assumption fails, the function is "lost" and misinterprets any digits in the first 3 words of the text as the font size.

To determine the current size of the text, try =

Let ( [

CSS = GetAsCSS ( Textfield ) ;

pos = Position ( CSS ; "font-size: " ; 1 ; 1 ) ;

start = pos + 11 ;

end = Position ( CSS ; "px;" ; start ; 1 )

] ;

Case ( pos ; Middle ( CSS ; start ; end - start ) ; 12 )

)

Note that this returns the font-size of the first portion of text that has a font-size attribute. If no character in the entire text has a font-size attribute, the default result of 12 is returned.

  • Like 1
Posted

You're awesome! I rewrote the custom function, and it's such a relief to have it work as expected! Thank you so much for your wisdom and help.


// determine font size:

Let ( [

CSS = GetAsCSS ( text ) ;

pos = Position ( CSS ; "font-size: " ; 1 ; 1 ) ;

start = pos + 11 ;

end = Position ( CSS ; "px;" ; start ; 1 ) ;

sizenow = Case ( pos ; Middle ( CSS ; start ; end - start ) ; 12 )

] ;



// resize up or down

TextSize ( text ; Case ( PatternCount ( upordown ; "up" ) ; sizenow + 1 ; Max ( 1 ; sizenow - 1 ) ) )

)

Posted

Do you really need the custom function? You could let the script handle the entire logic by setting your field to =

Let ( [

CSS = GetAsCSS ( YourTable::Textfield ) ;

pos = Position ( CSS ; "font-size: " ; 1 ; 1 ) ;

start = pos + 11 ;

end = Position ( CSS ; "px;" ; start ; 1 ) ;

sizeNow = Case ( pos ; Middle ( CSS ; start ; end - start ) ; 12 )

] ;

TextSize ( YourTable::Textfield ; sizeNow + Get ( ScriptParameter ) )

) 

with the script parameter being either 1 (increase) or -1 (decrease).

This topic is 4454 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.