Jump to content

Apply rule to variable text box


Recommended Posts

Yes, there are several ways you can do this, depending on exactly what you're trying to accomplish.

 

The simplest way is to simply set a single variable in the text frame, then create a rule with that same name to populate all the text.

 

You can also use the frame properties API in OnRecordStart to set all the text in any named frame; something like this:

FindTextFrame("YourFrameName").content = "here's some text";

If you're simply trying to modify the style of all the text in the frame, you can use a <span> tag, either in a regular rule inserted before all the other text, like so:

return '<span color="Green">';

Or you can "inject" the formatting with the frame properties API in OnRecordStart, like so:

FindTextFrame("YourFrameName").content = '<span color="Green">' + FindTextFrame("YourFrameName").content

If you could be more specific as to exactly what you're trying to apply to the text in the frame, I could offer more specific suggestions.

Link to comment
Share on other sites

Since FusionPro doesn't handle the Proportional Lining OpenType feature, I have to change the font of just the numbers. Currently I have the following rule applied to each and every field that might have numbers in it:

var numberFont = "Folio Light";
var numberWidth = "9";
var numberHeight = "8.5";
var text = Field("ADDRESS1");
return text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';});

It would be really nice if I could just have one or a couple of these rules rather than for every field.

Thanks!

Link to comment
Share on other sites

Since FusionPro doesn't handle the Proportional Lining OpenType feature, I have to change the font of just the numbers. Currently I have the following rule applied to each and every field that might have numbers in it:

var numberFont = "Folio Light";
var numberWidth = "9";
var numberHeight = "8.5";
var text = Field("ADDRESS1");
return text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';});

It would be really nice if I could just have one or a couple of these rules rather than for every field.

Thanks!

You can use "variable injection" to accomplish this, with the FusionPro.Composition.AddVariable function. Add this logic to OnRecordStart:

var numberFont = "Folio Light";
var numberWidth = "9";
var numberHeight = "8.5";

for (var f in FusionPro.Fields)
{
   var text = FusionPro.Fields[f].replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';});
   FusionPro.Composition.AddVariable(f, text, true)
}

Note that this will affect only fields called out directly in text frames or resources, not field values accessed in other rules with the Field function.

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...