Change Font Dynamically with Code

Sometimes, you may need to change fonts at runtime. While it is potentially easier to have 2 Text I/Os in 2 cards of a Deck (1 of each font), there is also a way to change a font via code.

If you want to change fonts via code, you can use altiaSetFont (then send the UNIX font string) in this manner:

/* Set object ID of the text object to update */
altiaSendEvent("altiaSetObj", <object_id_number>); //the obj ID is in parenthesis in the Altia Design navigator

/* Set font type */

altiaSendText("altiaSetFont", <UNIX_X11_font_string>);

You can find a UNIX font string as shown in the image below:


Link to image as well: https://altia.zendesk.com/attachments/token/gGQ5He8PknDc5C1m0Y4eLKuwP/?name=inline641943226837.png

UNIX Font String location in AD

NOTE: For the builtin animation "altiaSetFont" make sure to follow all the rules (refer to the Altia User's Guide for details on Built-In Animations, and sections 3.9.3 and 3.9.4 for these special animations).

Specifically, the font must exist in your design in order for it to be accessible on the target hardware. In addition the "Dynamic Built-in Animations" option must be checked at code generation time in the Code Generation Options dialog.

NOTE: As an alternative, you can use the Skin object instead to change fonts at runtime. Please see the KB linked below to explore that option:

https://altia.zendesk.com/entries/23581826--Video-5-min-Apply-a-GUI-Skin-or-Theme

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.