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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 6th, 2016, 06:01 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Question Formatting Special Characters in Email Address

I’m attempting to format the email address for a business card template and am stuck.

The database has an email address with First.Last.

My current rule is

Code:
if (Field("Individual Email") != "")
    return Field("Individual Email")+"@MyDomain.com"
    else return ""
I need assistance with the following:

1. Changing the . in the field & @MyDomain.com.com to Gotham Medium, 4.5pt with 5.4 pt leading
2. Change the @ symbol to Gotham Medium, 7pt with 8.4 pt leading

Any help with this will be much appreciated.
Reply With Quote
  #2  
Old April 6th, 2016, 03:46 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,369
Default Re: Formatting Special Characters in Email Address

I was working on an answer to your more complicated questions in this thread, but this is a lot simpler.
Code:
var s = TaggedDataField("Individual Email");
if (!s)
    return "";
//else
return s + '<span font="Gotham Medium" pointsize=7>@</span>MyDomain<span font="Gotham Medium" pointsize=4.5>.</span>com';
Regarding the leading, you shouldn't really need to do anything special in the rule for what you want. 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, remember that everything on the same baseline has, by definition, the same leading between that baseline and the previous one, so you can't really have part of the email address with different leading than the rest.

Finally, you can certainly set the dot/period character to a different font and point size than the rest of the text, but I am skeptical that any human will be able to notice either a difference in the font or a small difference in point size for that particular character, which is just a single dot, after all.
__________________
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; April 6th, 2016 at 04:12 PM.. Reason: Changed to span tags to restore the previous point size as well as the font.
Reply With Quote
  #3  
Old April 7th, 2016, 07:01 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Lightbulb Re: Formatting Special Characters in Email Address

Dan,

Thank you so much for your help on this. I was able to modify it and it works perfectly for the copy.

Code:
var s = TaggedDataField("Individual Email"); if (!s)
    return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>MyDomain</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
I'm still having issues with the . in the Email field (First.Last). Any suggestions?
Reply With Quote
  #4  
Old April 7th, 2016, 07:31 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Default Re: Formatting Special Characters in Email Address

Dan,

I don't know if I'm going about this right or not.

I created a new rule for the . in the Email field.

RuleEmail-1
Code:
return Field("Individual Email").replace(/\./gi, '<f name="Gotham Medium><new size="7">.</f>');
When I test with this rule, it works.

Can you tell me how to incorporate it into my other rule?

RuleEmail-2
Code:
var s = TaggedDataField("Individual Email"); if (!s)
    return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
Reply With Quote
  #5  
Old April 7th, 2016, 10:53 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,369
Default Re: Formatting Special Characters in Email Address

Quote:
Originally Posted by traba5058 View Post
I created a new rule for the . in the Email field.

RuleEmail-1
Code:
return Field("Individual Email").replace(/\./gi, '<f name="Gotham Medium><new size="7">.</f>');
When I test with this rule, it works.
It does? How does it work exactly? I'm confused. Because in your original post, you said:
Quote:
Originally Posted by traba5058 View Post
1. Changing the . in the field & @MyDomain.com.com to Gotham Medium, 4.5pt with 5.4 pt leading
But in the rule above, it looks like you're trying to change the dot to 7 points, not 4.5.

Also, the tagging is wrong anyway. Instead of <new size="7"> you should be using the tag <z newsize=7>. If you compose and look at the log file, there will be an error message there saying that it doesn't recognize the tag named "new."

So your rule is not actually changing the point size at all. But even if it were changing the point size of the dot to 7, that's not what your stated requirement was. So again, exactly why do you think that it's working?
Quote:
Originally Posted by traba5058 View Post
Can you tell me how to incorporate it into my other rule?

RuleEmail-2
Code:
var s = TaggedDataField("Individual Email"); if (!s)
    return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
Well, I'm not sure I understand exactly what you're trying to accomplish in that rule. When did the Telegrafico font become part of the requirements?

Frankly, I still don't understand why you want to change either the font or the point size of the dot (period) characters. How could that possibly make a difference that a person looking at the output could perceive? How would you be look at the output and know whether your dot was 4.5 points or 7, let alone whoever you're sending this output to?

That said, if you really think it will matter, I think this might do what you want:
Code:
var s = TaggedDataField("Individual Email");
if (!s)
    return "";
//else
var result = s.replace(/\./g, '<f name="Gotham Medium><z newsize=4.5>.</f>');
result += '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
return result;
Although I still am confused about the requirement. Can you post an example of the current output, and an example of the desired output, and a detailed explanation of what the differences are? Also, specify exactly what the font and point size of each character should be, including the ones that are not being modified by the rule.
__________________
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
  #6  
Old April 7th, 2016, 11:05 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Formatting Special Characters in Email Address

I agree with Dan that setting the leading on individual characters that (I'd imagine) you'd want to stay on the same line, is kind of pointless – so I excluded it from my code. Aside from that, you certainly don't need two JavaScript rules to handle your scenario. In fact, you can do it all at once like this:
Code:
var email = Field("Individual Email");

// If email is empty, return nothing
if (!email) return '';

// Else: add the domain
email += '@MyDomain.com';

// Replace . and @
return email.replace(/[\.@]/g, 
function(s) {
    var size = s == '.' ? 4.5 : 7;
    return '<span font="Gotham Medium" pointsize="' + size + '">' + s + '</span>';
});
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn

Last edited by step; April 7th, 2016 at 11:11 AM..
Reply With Quote
  #7  
Old April 8th, 2016, 08:05 AM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Default Re: Formatting Special Characters in Email Address

Dan & Stephen,

I'm sorry for my confusion. I've been using FusionPro for a while now but I haven't run into this situation before.

This customer has about 60 different business card layouts and I'm finding out that they care changing font (family, size, etc.) for specific characters within a field for more and more of them. If I get the FusionPro templates working, pre-press will not have to manually typeset each card when ordered.

The business card uses Telegrafico 9pt. This font is all caps and has no numbers or special characters. The customer uses Gotham Medium for numbers and special characters. Gotham Medium is a larger font, so the copy has to be reduced to 7pt.

Forum-BC.pdf is the PDF file from In Design.

I took your (Dan's) advice to use 7pt for all Gotham Medium including . rather than reducing it further.

When I used your original rule, it changed the font size for Telegrafico text too. So, I updated it to include the font information for the Telegrafico text. I was having trouble just changing the font size for that text, so I added the font name & it worked.

Code:
var s = TaggedDataField("Individual Email"); if (!s)
    return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>MyDomain</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
The email field is formatted as First.Last. Using the above rule, the . from that field does not match correctly. See ForumBC-Output.pdf. You can also see the font size difference in this PDF with address.

Code:
return Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f>');
The above rule changes the font size for the Telegrafico text too.

Right now, I do not have a font formatting rule for the phone & fax. I simply put the format rule in the text frame, highlighted it and selected the font & size.

I'm trying to format all of these fields:

1.) Phone & Fax Numbers with Tags
2.) . and @ for email
3.) Numbers in address

I split the above formatting into two posts (you & Stephen have responded to both) and am trying to incorporate parts from both posts as well as posts from other people to get this to work.

On another card, I have to change the email field to upper case, add @MyDomain.com in upper case and change the @ symbol to 7pt.

I have 3 rules & they aren't working together. Rule 3 is the one I have in the template and it's not changing the font size for the @.

Rule 1
Code:
var Var1 = "Individual Email";
var CaseSelection = "allcaps";

	
	
if(CaseSelection == "allcaps")
	return ToUpper(Field(Var1));
	
if(CaseSelection == "smallcaps")
	return "<smallcap>" + Field(Var1) + "</smallcap>";
	
if(CaseSelection == "propercase")
	return ToTitleCase(Field(Var1));
	
if(CaseSelection == "lowercase")
	return ToLower(Field(Var1));
Rule 2
Code:
if (Rule("RuleEmailCase") != "")
    return Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM"
    else return ""
Rule 3
Code:
return Rule("RuleEmail-1").replace(/(\@)/g, '<pointSize=7>@</pointSize>');
Thanks for all of your help!
Attached Files
File Type: pdf Forum-BC.pdf (19.1 KB, 9 views)
File Type: pdf ForumBC-Output.pdf (45.7 KB, 5 views)
Reply With Quote
  #8  
Old April 8th, 2016, 10:29 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Formatting Special Characters in Email Address

Quote:
Originally Posted by traba5058 View Post
I took your (Dan's) advice to use 7pt for all Gotham Medium including . rather than reducing it further.
Cool, that makes it even simpler:
Code:
var email = Field("Individual Email");

// If email is empty, return nothing
if (!email) return '';

// Else: add the domain
email += '@MyDomain.com';

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');
Quote:
Originally Posted by traba5058 View Post
When I used your original rule, it changed the font size for Telegrafico text too. So, I updated it to include the font information for the Telegrafico text. I was having trouble just changing the font size for that text, so I added the font name & it worked.
That's because when you set the size with "z" tags – there is no closing z tag. Meaning you'll have to set the font back to whatever it originally was instead of just closing the tag. From the looks of the code you've posted, that's what you've done. It really doesn't have anything to do with setting the font as well:
Quote:
Originally Posted by traba5058 View Post
Code:
var s = TaggedDataField("Individual Email"); if (!s)
    return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>MyDomain</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
One of the advantages to using the span tag is that it allows you to set attributes within one tag and close them without having to reset prior attributes.
Quote:
Originally Posted by traba5058 View Post
The email field is formatted as First.Last. Using the above rule, the . from that field does not match correctly. See ForumBC-Output.pdf. You can also see the font size difference in this PDF with address.

Code:
return Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f>');
The above rule changes the font size for the Telegrafico text too.
Again, that's because there is no closing z tag. You'd have to write it like this:
Code:
return '<f name="Telegrafico">' + Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f><z newsize="9">');
Or, you know, with a span tag:
Code:
return Field("Address").replace(/(\d+)/g, '<span font="Gotham Medium" pointsize="7">$1</span>');
Quote:
Originally Posted by traba5058 View Post
Right now, I do not have a font formatting rule for the phone & fax. I simply put the format rule in the text frame, highlighted it and selected the font & size.

I'm trying to format all of these fields:

1.) Phone & Fax Numbers with Tags
2.) . and @ for email
3.) Numbers in address

I split the above formatting into two posts (you & Stephen have responded to both) and am trying to incorporate parts from both posts as well as posts from other people to get this to work.

On another card, I have to change the email field to upper case, add @MyDomain.com in upper case and change the @ symbol to 7pt.

I have 3 rules & they aren't working together. Rule 3 is the one I have in the template and it's not changing the font size for the @.

Rule 1
Code:
var Var1 = "Individual Email";
var CaseSelection = "allcaps";

	
	
if(CaseSelection == "allcaps")
	return ToUpper(Field(Var1));
	
if(CaseSelection == "smallcaps")
	return "<smallcap>" + Field(Var1) + "</smallcap>";
	
if(CaseSelection == "propercase")
	return ToTitleCase(Field(Var1));
	
if(CaseSelection == "lowercase")
	return ToLower(Field(Var1));
Rule 2
Code:
if (Rule("RuleEmailCase") != "")
    return Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM"
    else return ""
Rule 3
Code:
return Rule("RuleEmail-1").replace(/(\@)/g, '<pointSize=7>@</pointSize>');
Thanks for all of your help!
Is it correct to assume that Rule1 feeds to Rule2 and Rule 2 feeds to Rule 3? Is the domain name ("@SIMPSONHOUSING.COM") supposed to be all caps regardless of the "CaseSelection" applied in Rule 1? Also note that "pointsize" is not a tag. So you'd need to re-write that to use z tags or span tags – both topics which I've beaten to death already in this post.

Have you given the code I posted a try? It seems like it would have solved a lot of your problems. But just to clarify, I'm suggesting that you condense your 3 rules into one:
Code:
var email = Field("Individual Email");
// If email is empty, return nothing
if (!email) return '';

var CaseSelection = 'allcaps';
switch(CaseSelection){
  case 'allcaps':
    email = ToUpper(email);
    break;
  case 'smallcaps':
    email = '<smallcaps>' + email + '</smallcaps>';
    break;
  case 'lowercase':
    email = ToLower(email);
    break;
  default:
    email = email;
}

// Else: add the domain
email += '@SIMPSONHOUSING.COM';

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');
Or if you want the domain of the email address to be affected by the CaseSelection:
Code:
var email = Field("Individual Email");
// If email is empty, return nothing
if (!email) return '';
email += '@SIMPSONHOUSING.COM';

var CaseSelection = 'allcaps';
switch(CaseSelection){
  case 'allcaps':
    email = ToUpper(email);
    break;
  case 'smallcaps':
    email = '<smallcaps>' + email + '</smallcaps>';
    break;
  case 'lowercase':
    email = ToLower(email);
    break;
  default:
    email = email;
}

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');
Or if you'd rather keep all of your rules as is, you could create a global function that replaces everything that isn't a letter or space (essentially replacing only special characters) and call it from your respective rules:

JavaScript Globals
Code:
function ReplaceSpecial(text, font, size) {
    var font = font || 'Gotham Medium';
    var size = size || '7';
    return text.replace(/([^a-z|<>|\s]+)(?!([^<]+)?>)/gi,
        '<span font="' + font + '" pointsize="' + size + '">$1</span>');
}
Code:
return (Rule("RuleEmailCase")) ? ReplaceSpecial(Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM") : '';
You could optionally specify a different font and pointsize for special use cases:
Code:
var twitter = '<span font="Telefico" pointsize="9">' + '@twitter';
return ReplaceSpecial(twitter, 'Arial Bold', 9); 
/*
Returns:
<span font="Telefico" pointsize="9"><span font="Arial Bold" pointsize="9">@</span>twitter

Note that numbers and special characters within tags are not replaced.
The @ sign (originally set to Telegrafico) is overridden by the function and changed to Arial Bold
*/
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn

Last edited by step; April 8th, 2016 at 11:20 AM..
Reply With Quote
  #9  
Old April 8th, 2016, 12:38 PM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Default Re: Formatting Special Characters in Email Address

Thanks so much! I think I'm getting the hang of this now.
Reply With Quote
Reply

Tags
email, font, leading, size, special characters

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 11:17 PM.


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