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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 24th, 2012, 09:12 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Question Changing Fonts for Numbers

I've been using Marcomm Central & Fusion Pro since Feb, so I am still fairly new at javascript.

I am setting up a new business card template for Marcomm Central using FusionPro and need help. This client uses one font for text and one font for numbers. This means the number font needs to be used for phone & mobile numbers as well as the zip code & numbers in the address 1 & address 2 fields. FusionPro makes it very easy to assign a font to a field, so I can easily assign the font to the phone & mobile numbers as well as the zip code field. I'm having problems with address1 & address2 fields.

Is there javascript or a setting that will look for numbers in a field and use a font? Please help.
Reply With Quote
  #2  
Old October 24th, 2012, 09:46 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Changing Fonts for Numbers

Create the following text rule:
Code:
var address = your address field;
address = address.replace(/(\d+)/g,"<f name='number_font'>$1</f>");
return address;
(Alternatively, you could build your entire address block (street, city, state, zip, etc) for your variable.)

Place the rule in a text frame and apply the text font you want. The code will replace all number sequences in your variable string with a tagged version of same string(s) using the number font you add to the code. Be sure to check 'Treat returned strings as tagged text' in the rule.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #3  
Old October 24th, 2012, 10:03 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Question Re: Changing Fonts for Numbers

Thanks Eric!
I updated your rule to read
Code:
var address = Field("Street 1");
address = address.replace(/(\d+)/g,"<f name='Sebastion Light UCF'>$1</f>");
return address;
and

Code:
var address = Field("Street 2");
address = address.replace(/(\d+)/g,"<f name='Sebastion Light UCF'>$1</f>");
return address;
I also checked the treat tagged text box.

The preview is returning a different font for the numbers in the field but it looks like a default font or something. It doesn't match the font in the phone & mobile number fields or the zip code field. I entered the name of the font as it appears in the drop down in FusionPro. Is there a different way it needs to be entered?
Reply With Quote
  #4  
Old October 24th, 2012, 10:08 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,381
Default Re: Changing Fonts for Numbers

You need double-quotes in the markup tags. Try this instead:
Code:
return Field("Street 2").replace(/(\d+)/g,'<f name="Sebastion Light UCF">$1</f>');
Also, you might not have the correct font name. Do a regular composition (not a Preview) and look in the composition log (.msg) file for any font warnings.

You can always determine the correct font name to use in an <f> tag by creating a Formatted Text resource, entering some text in the desired font, then exiting the Text Editor and clicking "View Source." That will show you the correct <f name=***> tag.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

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)});
Reply With Quote
  #5  
Old October 24th, 2012, 10:13 AM
dreimer dreimer is offline
Senior Contributor
 
Join Date: Oct 2010
Location: Shakopee, MN
Posts: 473
Default Re: Changing Fonts for Numbers

Both rules work for me but I have a problem when the street name is a number. For example 123 86th Ave is returned 12386th Ave.
__________________
Don Reimer - JavaScript Novice

MAC OS 10.13.6 Acrobat DC FP Creator 10.1.11
Windows 7 Acrobat X 10.1.4 FP Creator 9.3.9
Reply With Quote
  #6  
Old October 24th, 2012, 10:13 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Changing Fonts for Numbers

Your updates look correct to me. When I google the font you are using it "corrects" the name to be "Sebastian Light UCF" -- are you sure the name isn't misspelled?

If that is not the issue, you may want to temporarily try another (more common) font in the tag to see if the problem is with the specific font or something broader. Also, if you reverse the font assignments (for testing only) does "Sebastion Light UCF" preview correctly for the alpha characters?
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #7  
Old October 24th, 2012, 10:23 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Changing Fonts for Numbers

Quote:
Originally Posted by dreimer View Post
Both rules work for me but I have a problem when the street name is a number. For example 123 86th Ave is returned 12386th Ave.
Good catch dreimer! The code vallidates correctly with a space in that scenario but does not appear to format it correctly in the preview. I tweaked my original code and changed the single/double quotes that Dan suggested (which I was unaware of):

Code:
var address = '123 21South Main Street, Suite 24A 3 SW 1342A5692';
address = address.replace(/\s/g,"&nbsp;").replace(/(\d+)/g,'<f name="FolioSS-Bold">$1</f>');
return address;
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #8  
Old October 24th, 2012, 10:28 AM
dreimer dreimer is offline
Senior Contributor
 
Join Date: Oct 2010
Location: Shakopee, MN
Posts: 473
Default Re: Changing Fonts for Numbers

Perfect, the new code worked correctly.

Getting great stuff off this forum of late, thank you everyone!!!
__________________
Don Reimer - JavaScript Novice

MAC OS 10.13.6 Acrobat DC FP Creator 10.1.11
Windows 7 Acrobat X 10.1.4 FP Creator 9.3.9
Reply With Quote
  #9  
Old October 24th, 2012, 10:39 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,381
Default Re: Changing Fonts for Numbers

Quote:
Originally Posted by esmith View Post
Good catch dreimer! The code vallidates correctly with a space in that scenario but does not appear to format it correctly in the preview. I tweaked my original code and changed the single/double quotes that Dan suggested (which I was unaware of):

Code:
var address = '123 21South Main Street, Suite 24A 3 SW 1342A5692';
address = address.replace(/\s/g,"&nbsp;").replace(/(\d+)/g,'<f name="FolioSS-Bold">$1</f>');
return address;
That will work, except that you're replacing every space with a non-breaking space, which will prevent the address from wrapping to multiple lines properly. If that's not an issue in your job, then it's fine. If, however, you do want to maintain the breaking spaces, then you need to do something like this instead:
Code:
function replace_helper(match, digits, spaces)
{
    return '<f name="Courier New">' + digits + '</f>' +
        Array(spaces.length + 1).join("&#32;");
}

return Field("Address").replace(/(\d+)(\s*)/g, replace_helper);
More info: https://developer.mozilla.org/en-US/...as_a_parameter
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

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; October 24th, 2012 at 10:40 AM.. Reason: typo
Reply With Quote
  #10  
Old October 24th, 2012, 11:09 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Question Re: Changing Fonts for Numbers

Thanks to All! It was the quotes & spelling of Sebastian. I'm using:
Code:
var address = Field("Street 1");
address = address.replace(/\s/g,"&nbsp;").replace(/(\d+)/g,'<f name="Sebastian Light UCF">$1</f>');
return address;
and
var address = Field("Street 2");
address = address.replace(/\s/g,"&nbsp;").replace(/(\d+)/g,'<f name="Sebastian Light UCF">$1</f>');
return address;

Can you tell me what you mean by breaking? I have copyfit on and hyphenation off & do not break on copyfit on. I do not want address 1 to move to the next line & I do not want address 2 to move to the next line. I want copy to shrink to fit in address block. Do I have to worry about breaking?
Reply With Quote
Reply

Tags
font, javascript, numbers

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 04:26 AM.


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