draco66 Posted January 26, 2018 Posted January 26, 2018 Is there a way to change the font in a particular text frame based on another piece of data? To keep it simple as an example: If the "Font" field = 4 then the font used for the text would be "Arial", if the "Font" field = 5 then the font used for the text would be "Times Roman" I know I can change the font color in a text box based on data but I need to change a font now as well. I know I could set up different pages with the various fonts and use the appropriate page, but that will require creating a lot of additional pages. I would like to avoid that if possible. Thank you. Quote
Dan Korn Posted January 26, 2018 Posted January 26, 2018 If the "Font" field = 4 then the font used for the text would be "Arial", if the "Font" field = 5 then the font used for the text would be "Times Roman" Please refer to the FusionPro Tags Reference Guide. The basic way to change a font is with the <f name="***"> tag. If you write a rule to return such a tag, with the appropriate font name, you can insert it (or a rule returning it) at the start of a frame. That said, simply inserting a tag such as <f name="Arial"> (or a rule returning such a tag) at the start of a text frame is that it may not affect all of the text in the frame, especially after the first paragraph, because each new paragraph resets the font. Therefore, if you want to modify the font of all of the text in a text frame (flow), you should need to use a <span> tag instead, such as <span font="Arial">. So you could write a rule like so: var fontName = ""; switch (Field("Font")) { default: case 4: fontName = "Arial"; break; case 5: fontName = "Times Roman"; break; } return '<span font="' + fontName + '">'; Or, more succintly: function FontNameFromNumber(num) { switch(num) { default: case 4: return "Arial"; case 5: return "Times Roman"; } } return '<span font="' + FontNameFromNumber(Field("Font")) + '">'; Or, even more succinctly: var FontNameFromNumber = { 4: "Arial", 5: "Times Roman", } return '<span font="' + (FontNameFromNumber(Field("Font")) || "Arial") + '">'; Then you can insert that rule at the start of any text frame whose font you want to modify. Note that you need to use FusionPro's name for the font, which may be different than the name used by the operating system. The easiest way to determine FusionPro's name for a font is to create a Formatted Text Resource with some text in that font and use the "View Source" button to see the tags representing the text in the resource. Quote
draco66 Posted January 27, 2018 Author Posted January 27, 2018 Thank you Dan. I have put this in place and it's working great. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.