Jump to content

Replacing all text occurrences


Recommended Posts

I'm looking to create a rule that will replace all occurrences of a string of text, even when that text is not part of a rule.

 

Specifically we're having an issue where the notdef symbol is being inserted when some fonts don't have the   character. I'd like to replace the font for this character to one which does have the   glyph defined.

 

I know how to make this change when the text is returned from a rule. I'm just looking for the FusionPro way of searching through all text frames and replacing characters.

Link to comment
Share on other sites

FusionPro VDP 10.1 has a cool new text replacement feature, which does exactly what you want: globally replace all occurrences of any text in the job.

 

You can even do this without writing any JavaScript code, with the new "Global Replace Text" XML Template callback rule.

 

However, in this, case, since the text you're replacing is the "special" non-breaking space character, you do have to use JavaScript, but handling that character is easy enough with the RawTextFromTagged function.

 

So, in FusionPro 10.1, you can do this in OnJobStart, replacing the font name with whatever font you want:

FusionPro.Composition.AddTextReplacement(RawTextFromTagged(" "), '<span font="Times New Roman"> </span>');

 

That said, I suspect this is all a bit of an "XY problem," where what you're really trying to do is accomplish non-breaking text, and you're doing this by inserting   entities. But there's a better way to accomplish non-breaking text, or what we prefer to call a "horizontal keep," in FusionPro 10.1, with <hkeep> and </hkeep> tags.

 

(And really, the font shouldn't be trying to output an   character anyway; there's no glyph to draw for white space. That's part of why we have the <hkeep> tag now.)

 

It's not clear to me exactly what you're doing with the   entities, nor how you're inserting them, but you should be able to rework whatever logic you have that's relying on the   entities to use the tags instead.

 

If you have just a particular phrase that you want to never break in your job, you can use another handy XML Template callback rule, "Format Specific Word or Phrase", and simply check the "Don't break or hyphenate" box (which inserts <hkeep> and </hkeep> tags).

 

If you are doing something more complicated with programmatically inserting   tags in a rule, then you will have to modify that rule to use the tags instead. For instance, where previously you would have markup like this:

return "Never break this text";

You can now do this:

return "<hkeep>Never break this text</hkeep>";

 

The bottom line is, with FusionPro 10.1, in my opinion, the real solution is to use <hkeep> and </hkeep> tags instead of   in the first place.

Link to comment
Share on other sites

Excellent Dan, thank you. I'll keep in mind the <hkeep> tags when I need them.

 

The   character accidentally shows up sometimes in FusionPro text frames when the InDesign source document has returns with a normal space on an empty line. So ^p ^p ends up turning into ^p ^p.

 

I have a few InDesign scripts to clean things up for FusionPro but on some documents we can't run the scripts, so I was looking for an automated solution to fix the notdef character from basically ever showing up in a document with a   character.

Edited by ScottHillock
Link to comment
Share on other sites

Excellent Dan, thank you. I'll keep in mind the <hkeep> tags when I need them.

Okay. Though your signature says you're still running FusionPro 9.3. Everything I mentioned requires 10.1 or later.

The   character accidentally shows up sometimes in FusionPro text frames when the InDesign source document has returns with a normal space on an empty line. So ^p ^p ends up turning into ^p ^p.

I'd love to take a look at one of these InDesign documents.

I have a few InDesign scripts to clean things up for FusionPro but on some documents we can't run the scripts, so I was looking for an automated solution to fix the notdef character from basically ever showing up in a document with a   character.

Well, I think the code I posted with the call to FusionPro.Composition.AddTextReplacement would work. But I can't really try it without one of your InDesign files.

Link to comment
Share on other sites

Dan, sample files attached.

 

Unchecking the Limit processing to.. checkbox does make the notdef character not appear. And it's a viable solution. But, I usually leave that checked to make sure the data source doesn't contain characters that might cause issues on output. But, I should probably move that "checking" to a different workflow process.

 

We do have FusionPro 9, so the <hkeep> and AddTextReplacement aren't available to us to use yet, but we're looking at the upgrade to 10 in the near future.

Archive.zip

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