Jump to content

Replace font globally for one record


psmosser

Recommended Posts

Is it possible with an OnRecordStart rule to replace a font throughout the template (including on repeatable components) based on a field?

 

What I have is a person who's name starts with "IL" and in Avante Garde that prints as "ll". What I would like to do is by using her client Id field have any occurrence of Avante Garde Change to "Mercury Text G1" anywhere Avante Garde is used in the template.

 

I don't want to search for her name and replace just that because this may come up again later at which point I would add a field for "alternate font" to my data.

 

Any ideas would be appreciated.

Link to comment
Share on other sites

How about creating a formatted text resource with "Il" using Mercury Text, then create a rule to pull that resource when [Name] = "Il"?

 

I've done something similar when I needed special characters that didn't look good in the main body font.

 

Appreciate the feedback but that won't work for what we're doing. Inevitably I will end up with more people who want to change the font and I would just have to keep chasing rules.

 

I also don't want to make an alternate template page with another font because the client can choose from many templates each month and may change from month to month so I would need doubles of each.

Link to comment
Share on other sites

Well, it's a bit hard to say without seeing the template. Also, it depends on how the Avante Garde font is being specified in the first place. Is it via tagging in the data, or is it being set in the GUI (in the Variable Text Editor dialog)? Also, are you trying to apply the change for just one particular data field, or are you really trying to do it globally for the template?

 

If the font is being specified in the data, then you can do something similar to what's discussed in this thread:

http://forums.pti.com/showthread.php?t=3133

Something like this in OnRecordStart:

for (var i in FusionPro.Fields)
    FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "Avante Garde", "Mercury Text G1", true));

If the font is being specified in the GUI, then it depends on whether you want to replace the font in one field, or in just one or a few particular text frames.

 

If it's really just one field, you can do something like this in OnRecordStart:

FusionPro.Composition.AddVariable("client Id", '<f name="Mercury Text G1">' + Field("client Id") + '</font>', true));

 

If it's more than one field, then you might need to do the above multiple times. Again, it's hard to say without more specific information.

 

If you really only want to make the change for a particular record, then the logic above (whichever you choose) can be put into a conditional "if" block, although I don't know what that condition is.

 

Of course, this is all kind of playing tricks to work around an issue with the font. So I think what would be better is to find another font which looks similar to the one you're using now, but with a different representation of the capital "L".

 

Finally, I'll reiterate that this would be easier for others to analyze and make more specific suggestions if you could post the job, or at least a stripped-down version that shows what you're trying to do.

Link to comment
Share on other sites

Thanks for the input Dan.

 

I was actually trying to use some variation of your first suggestion but to no avail.

 

The font is specified in the GUI. The fields are being called out directly not through rules. I do need to affect multiple fields however.

 

I tried your second suggestion.

 

if (Field("ClientID") == "1467708")

FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury Text G1">' + Field("AlternateName") + '</f>', true);
FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") + '</f>', true);

The result of this is that the AlternateName field font changes for the record where the if statement is satisfied and then goes back to AvantGarde. The second AddVariable line however changes the font on all records.

 

What would be preferable is to switch the AvanteGarde font in every field where it's used rather than listing these out. Is that possible with some variation of your first code?

Link to comment
Share on other sites

Thanks for the input Dan.

 

I was actually trying to use some variation of your first suggestion but to no avail.

 

The font is specified in the GUI. The fields are being called out directly not through rules. I do need to affect multiple fields however.

 

I tried your second suggestion.

 

if (Field("ClientID") == "1467708")

FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury Text G1">' + Field("AlternateName") + '</f>', true);
FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") + '</f>', true);

The result of this is that the AlternateName field font changes for the record where the if statement is satisfied and then goes back to AvantGarde. The second AddVariable line however changes the font on all records.

Well, of course. If you don't put a statement block, with curly brackets {} after an "if" statement, then only the next statement (line) immediately after the "if" statement is conditional upon the "if" statement, and any subsequent lines are executed unconditionally. So if you want to have both of those lines to be executed based upon the condition, then you need the curly brackets, like so:

if (Field("ClientID") == "1467708")
{
   FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury  Text G1">' + Field("AlternateName") + '</f>', true);
   FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") +  '</f>', true);
}

(White space, such as indentation and blank lines, doesn't affect the execution of the code in JavaScript, although it can make it easier for humans to read. The curly brackets are what matter here. When in doubt, just use the brackets.)

What would be preferable is to switch the AvanteGarde font in every field where it's used rather than listing these out. Is that possible with some variation of your first code?

I'm still a bit confused as to exactly what you're trying to accomplish, but I think this might be what you want:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<f name="Mercury Text G1">' + Field(i) + '</font>', true);
}

Although, to properly handle certain characters which may be present in the data, as well as to handle other markup which may be present, you probably want this slight variation:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<span font="Mercury Text G1">' + TaggedDataField(i) + '</span>', true);
}

Edited by Dan Korn
slightly better answer to handle special characters and other markup
Link to comment
Share on other sites

Well, of course. If you don't put a statement block, with curly brackets {} after an "if" statement, then only the next statement (line) immediately after the "if" statement is conditional upon the "if" statement, and any subsequent lines are executed unconditionally. So if you want to have both of those lines to be executed based upon the condition, then you need the curly brackets, like so:

if (Field("ClientID") == "1467708")
{
   FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury  Text G1">' + Field("AlternateName") + '</f>', true);
   FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") +  '</f>', true);
}

(White space, such as indentation and blank lines, doesn't affect the execution of the code in JavaScript, although it can make it easier for humans to read. The curly brackets are what matter here. When in doubt, just use the brackets.)

 

I'm still a bit confused as to exactly what you're trying to accomplish, but I think this might be what you want:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<f name="Mercury Text G1">' + Field(i) + '</font>', true);
}

Although, to properly handle certain characters which may be present in the data, as well as to handle other markup which may be present, you probably want this slight variation:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<span font="Mercury Text G1">' + TaggedDataField(i) + '</span>', true);
}

 

Ah the { brackets. I know better than that. Sorry for that.

 

That technically would work for what I'm doing but I wonder still if there is a cleaner way to do this. I have quite a few fields that use this font so I would have to list maybe a dozen in that rule.

 

Would there be a way to modify this to look in "i" for "Avante Garde Bold" and replace only that with Mercury Text?

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<span font="Mercury  Text G1">' + TaggedDataField(i) + '</span>', true);
}

I don't want to change every field in the layout with Mercury Text just those styled "Avante Garde Bold".

 

Again, I appreciate the assistance.

Link to comment
Share on other sites

That technically would work for what I'm doing but I wonder still if there is a cleaner way to do this. I have quite a few fields that use this font so I would have to list maybe a dozen in that rule.

Why would you need to list anything else to get more fields? The "for (var i in FusionPro.Fields)" loop will pick up every field in the job.

Would there be a way to modify this to look in "i" for "Avante Garde Bold" and replace only that with Mercury Text?

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<span font="Mercury  Text G1">' + TaggedDataField(i) + '</span>', true);
}

I don't want to change every field in the layout with Mercury Text just those styled "Avante Garde Bold".

That's what this code from my previous post does:

for (var i in FusionPro.Fields)
    FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "Avante Garde", "Mercury Text G1", true));

Just put that logic inside the "if" statement:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, ReplaceSubstring(TaggedDataField(i), "Avante Garde", "Mercury Text G1", true));
}

Does that not do what you want?

Link to comment
Share on other sites

Why would you need to list anything else to get more fields? The "for (var i in FusionPro.Fields)" loop will pick up every field in the job.

 

This was in response to this option.

 

 
if (Field("ClientID") == "1467708") {     FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury  Text G1">' + Field("AlternateName") + '</f>', true);
FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") +  '</f>', true); }

That's what this code from my previous post does:

for (var i in FusionPro.Fields)      FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "Avante Garde", "Mercury Text G1", true)); 

I understood you to mean that this would only work if the font was tagged in the data which it is not.

 

Originally Posted by psmosser http://forums.printable.com/images/buttons/viewpost.gif

Thanks for the input Dan.

 

I was actually trying to use some variation of your first suggestion but to no avail.

 

The font is specified in the GUI. The fields are being called out directly not through rules. I do need to affect multiple fields however.

 

I tried your second suggestion.

 

Code:

if (Field("ClientID") == "1467708") FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury Text G1">' + Field("AlternateName") + '</f>', true); FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") + '</f>', true);

The result of this is that the AlternateName field font changes for the record where the if statement is satisfied and then goes back to AvantGarde. The second AddVariable line however changes the font on all records.

[/Quote]

Just put that logic inside the "if" statement:

Quote:

Originally Posted by Dan Korn http://forums.printable.com/images/buttons/viewpost.gif

Code:

if (Field("ClientID") == "1467708") { for (var i in FusionPro.Fields) FusionPro.Composition.AddVariable(i, ReplaceSubstring(TaggedDataField(i), "Avante Garde", "Mercury Text G1", true)); }

 

Does that not do what you want?

That actually does nothing in my scenario. I believe this to be because the fonts are specified in the GUI.

 

I've attached a sample data and the template so that you can better understand what I'm looking to achieve.

 

Specifically the "AlternateName" field on Template page "FIC IC001" in teh FIC right column rule will show you what font I'm after. It's the AvantGarde Bold font that I'd like to replace. It is used throughout the template if you look around a bit.

 

Any questions please let me know.

 

Thanks!

FusionProTemplates_FlammFont.zip

Link to comment
Share on other sites

This was in response to this option.

 
if (Field("ClientID") == "1467708") {     FusionPro.Composition.AddVariable("AlternateName", '<f name="Mercury  Text G1">' + Field("AlternateName") + '</f>', true);
FusionPro.Composition.AddVariable("ReturnAddressSenderLabel1", '<f name="Mercury Text G1">' + Field("ReturnAddressSenderLabel1") +  '</f>', true); }

I understood you to mean that this would only work if the font was tagged in the data which it is not.

 

That actually does nothing in my scenario. I believe this to be because the fonts are specified in the GUI.

Okay, sorry, there's been a lot of stuff thrown around in this thread. This will change the font for every data field, regardless of what's specified in the GUI:

if (Field("ClientID") == "1467708")
{
   for (var i in FusionPro.Fields)
       FusionPro.Composition.AddVariable(i, '<span font="Mercury  Text G1">' + TaggedDataField(i) + '</span>', true);
}

But I understand that you don't want to change every data field like this.

 

If you have a specific set of fields to which you want to apply the change, then yes, you will need to list each field. But you don't need to have a dozen lines of code with similar AddVariable calls; you can reduce the code like this instead:

var FieldsToChangeFont =
[
   "AlternateName",
   "ReturnAddressSenderLabel1",
   // etc.
]

if (Field("ClientID") == "1467708")
{
   for (var i in FieldsToChangeFont)
   {
       var fieldName = FieldsToChangeFont[i];
       FusionPro.Composition.AddVariable(fieldName, ReplaceSubstring(TaggedDataField(fieldName), "Avante Garde", "Mercury Text G1"), true);
   }
}

I've attached a sample data and the template so that you can better understand what I'm looking to achieve.

Yes, thanks for attaching the template. Unfortunately, though, while having the template to look at is usually quite helpful, and it is still somewhat useful here, in this particular case, I can't really see what you're seeing, because I don't have all of your fonts installed, and the fonts are quite relevant to the issue at hand. That said, please do not post the fonts here to this public forum.

Specifically the "AlternateName" field on Template page "FIC IC001" in teh FIC right column rule will show you what font I'm after. It's the AvantGarde Bold font that I'd like to replace. It is used throughout the template if you look around a bit.

Okay, but it's not just that one field "AlternateName" that you want to change, right?

 

Anyway, there are a few other ways you could approach this. Since you already have copyfitting applied to that "FIC-Right Column" frame, one way you could handle this in the OnCopyfit rule, like so, at the start of the rule:

FusionPro.Composition.CurrentFlow.content = ReplaceSubstring(FusionPro.Composition.CurrentFlow.content, "Avante Garde", "Mercury Text G1");

Although, this will replace all instances of that font in the entire frame/flow, not just in that one field. I'm not sure if that's what you want. And again, while I think this will work to replace the font, I can't really be sure, because I don't have your fonts installed, and therefore can't really test this on my end.

 

Also, I'm not sure what else you're trying to do there in the OnCopyfit rule, but I don't think it will work to call CopyfitLine, since you're obviously trying to copyfit a frame with multiple lines in it, and besides, using "return" in a callback rule like that doesn't have any effect anyway, as the box notes when you click Validate.

Link to comment
Share on other sites

I am trying to do something similar and thought the code in this post would be a good starting point. However, I can't seem to get it to work.

 

I made a blank pdf, and a dummy data file with three fields. I added a text box, placed the fields in it, and then set the font to Whitney Book using the GUI. Then I added the following OnRecordStart rule:

 

for (var i in FusionPro.Fields)

    FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "Whitney Book", "Wingdings", true));

This rule validates fine, but doesn't actually change the text at all; neither in preview or on output.

 

Am I missing something? I want to get this working before I start trying to change the code for what I need.

 

Thanks.

Link to comment
Share on other sites

I made a blank pdf, and a dummy data file with three fields. I added a text box, placed the fields in it, and then set the font to Whitney Book using the GUI. Then I added the following OnRecordStart rule:

 

for (var i in FusionPro.Fields)

    FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "Whitney Book", "Wingdings", true));

This rule validates fine, but doesn't actually change the text at all; neither in preview or on output.

 

Am I missing something?

Yes. As we've been discussing in this thread, that only works if the data field values contain <f name="***"> markup tags, in the data file. If you want to apply a font to all the fields in the job, to override the fonts selected in the Text Editor, then you need to do this:

for (var i in FusionPro.Fields)
   FusionPro.Composition.AddVariable(i, '<f name="Wingdings">' + TaggedDataField(i) + '</font>', true);

But that will put every data field value in the Wingdings font, in every text frame, not just the ones which were already in Whitney Book.

 

Exactly what you need to do depends on the job. So I can't tell you more without seeing more specifically what you're trying to do.

Link to comment
Share on other sites

Thanks. Yes, it looks like I missed the last couple of messages in the thread where that was explained.

 

Here is what I am trying to do. I have a client that uses the font Whitney almost exclusively. But, wherever there is a number, they want to use the smallcap version of the current face.

 

So, I made a global function:

 

function SMALLCAPS(incoming_text, font_name) {

   incoming_text = incoming_text.replace(/([0-9])/g, "<f name = \"" + font_name + " SC\">$1<f name = \"" + font_name + "\">");

   return incoming_text;
}

and then I have to make a rule to call it for each field:

 

var font_name = "Whitney Book";

return SMALLCAPS(TaggedDataField("street_address"),font_name);

Esentially I am creating a rule for every field they have in their file. I would love to have a way to globally change the fonts for the numbers.

 

Possible?

Link to comment
Share on other sites

Dan, thanks for all of your help in this one.

 

In the end this one worked for us.

 

if (Field("Contact Id") == "529672")
{
    FusionPro.Composition.CurrentFlow.content = ReplaceSubstring(FusionPro.Composition.CurrentFlow.content, "AvantGarde Bold", "Verdana Bold");
} 

We had to add copyfitting to one frame that wasn't using it but otherwise this does the trick neatly.

Link to comment
Share on other sites

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...