Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text


Thread Tools Search this Thread Display Modes
Old April 5th, 2016, 10:11 AM
traba5058 traba5058 is offline
Regular Contributor
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Unhappy Changing Fonts for Characters

I currently have 3 rules to change the numbers in the specific field to a different font. These rules work.

return Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium">$1</f>');
return Rule("RuleFaxFormat").replace(/(\d+)/g,'<f name="Gotham Medium">$1</f>');
return Rule("RulePhoneFormat").replace(/(\d+)/g,'<f name="Gotham Medium">$1</f>');
I need assistance with the following:

1. Including change in font size & leading for the numbers: Font size with Gotham Medium should be 7pt with 8.4pt leading

2. Including ( ) and - characters in the phone & fax rules

If someone can use the phone or fax rule above to show me how to do this, I can then apply it to the others.

All help will be much appreciated.

Last edited by traba5058; April 6th, 2016 at 04:55 AM.. Reason: To clarify & simplify and hopefully get a response
Reply With Quote
Old April 6th, 2016, 03:24 PM
step's Avatar
step step is offline
Senior Contributor
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 957
Default Re: Changing Fonts for Characters

Right now, you're capturing all numbers and assigning them to the '$1' variable which you then wrap in your font tag. If you want to expand that regexp to include parentheses and hyphens, I think this would work for you:

return Field("Address").replace(/([\(\)\-\d]+)/g, '<span font="Gotham Medium">$1</span>');
Here's a more in depth break-down of how it works:
var find = new RegExp(
  '(' +   // Parenthesis CAPTURE matched patterns and assign them to $1
  '[' +   // Square brackets denote a character set that the RegExp should match
  '\\(' + // First character to match: ( <-- Open parenthesis
          // Note that we escape so we don't start another capture group
  '\\)' + // Second character to match: ) <-- Close parenthesis
  '\\-' + // Third character to match: - <-- hyphen
  '\\d' + // All digits 0-9
  ']' +   // Close the square brackets because we only want to match what's inside
  '+' +   // Plus sign means we want to match 1 or more of the characters in the []
  ')'     // Close parenthesis to end capturing
 ,'g');   // g means "Match globally"

// Each captured match is assigned to $1 so we can wrap it in font tags 
var replace = '<span font="Gotham Medium">$1</span>';

return Field("Address").replace(find,replace);
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

Reply With Quote
Old April 6th, 2016, 03:48 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,647
Default Re: Changing Fonts for Characters

Step's solution seems fine, other than not addressing the point size change, although I think this will work as well:
return Field("Address").replace(/([\d\W]+)/g, '<span font="Gotham Medium" pointsize=7>$1</span>');
The \W means "any non-word character", basically anything that's not a letter or digit, and \d means a digit, and the square brackets mean "match anything in here", so [\d\W] means basically anything that's not a letter. For reference:

As I noted in the other thread, you shouldn't really need to do anything special in the rule for leading. By default, you're automatically going to get 8.4 point leading for a line where the largest text is 7 point. If you need to adjust this, you can change the auto-leading factor in the Paragraph Formatting dialog.

Also, if you want, you can put this logic into a function in the JavaScript Globals like so:
function FormatAddressOrPhone(text)
    return String(text).replace(/([\d\W]+)/g, '<span font="Gotham Medium" pointsize=7>$1</f>');
Or name it whatever you want. Then instead of every rule needing to have all that special code in it, you can just have each rule call the function, like so:
return FormatAddressOrPhone(Field("Address"));
return FormatAddressOrPhone(Rule("RuleFaxFormat"));
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; April 6th, 2016 at 03:58 PM.. Reason: corrected ending span tag
Reply With Quote

change, family, font, size

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 12:00 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.