Jump to content

Non breaking phrase word spacing


Recommended Posts

In this rule, I have a function for the non breaking phrase:

 

//here are the 2 functions

 

function NoBreak(s)

{

return NormalizeEntities(s).replace(/ /g, " ");

}

 

var NoBreakPhrases =

[

"Very Happy New Year",

"Happy New Year",

"Holiday Season",

"New Year",

// add as many as you like

];

 

function SetNoBreakPhrases(str)

{

for (var p in NoBreakPhrases)

{

var re = new RegExp("(" + NoBreakPhrases[p] + ")", "gi")

str = str.replace(re, function(w){return NoBreak(w);});

}

 

return str;

}

 

 

var myPointSize = Left(Field("mainfontsize"), 2); //grabs the leftmost 2 digits from the field to get the point size

var myFontFace = Field("MainFontFace");

var myFontColor = Field("MainFontColor");

 

if (Field("ChooseMainGreeting") == "Custom Greeting")

{

return greeting = '<z newsize="'+myPointSize+'"><f Name="'+myFontFace+'"><color Name="'+myFontColor+'">'+ Field("CustomGreeting");

}

 

else if (Field("ChooseMainGreeting") == "No Greeting")

{

return "";

}

else return '<z newsize="'+myPointSize+'"><f Name="'+myFontFace+'"><color Name="'+myFontColor+'">'+SetNoBreakPhrases(Field("ChooseMainGreeting"));

 

It correctly validates as:

<z newsize="14"><f Name="Scala"><color Name="Black">Wishing You All the Joys of the Season and a Very Happy New Year

 

Problem is the spacing between words in the phrase increases to larger than it should be. Example attached showing the difference in spacing without the non-breaking phrase function and using the function.

 

What is causing the increase in spacing?

non-breaking phrase.pdf

Link to comment
Share on other sites

Please remember to use "code" tags when posting code in your thread. It makes it difficult to follow along with your question when you have sentences and code co-mingling without anything obvious to differentiate between the two. If you're unfamiliar with how to format code in the context of this forum, check out this post.

 

Anyway, I'd bet the differing spacing is coming from Scala's (the font) interpretation of the non-breaking space entity ( ). So, if you temporarily switched the font to Helvetica, for example, you'd see even spacing between your examples. With that in mind, you could change the font that the non-breaking spaces display in to Helvetica and get the results you're looking for:

function SetNoBreakPhrases(str) {
   var NoBreakPhrases = [ 
       "Very Happy New Year",
       "Happy New Year",
       "Holiday Season",
       "New Year",
       // add as many as you like
   ];

   for (var p in NoBreakPhrases) {
       var re = new RegExp("(" + NoBreakPhrases[p] + ")", "gi");
       str = str.replace(re, function(w){return NormalizeEntities(w).replace(/ /g, " ");});
   }

   return str;
}

var myPointSize = Field("mainfontsize"), 2); //grabs the leftmost 2 digits from the field to get the point size
var myFontFace = Field("MainFontFace");
var myFontColor = Field("MainFontColor");
var greeting = (Field("ChooseMainGreeting") == 'Custom Greeting') ? Field("CustomGreeting") : SetNoBreakPhrases(Field("ChooseMainGreeting"));
var tags = '<z newsize="'+myPointSize+'"><f Name="'+myFontFace+'"><color Name="'+myFontColor+'">'

if (greeting == 'No Greeting')
   return '';

return tags + greeting.replace(/ /g,'<f name=Helvetica> <f Name="' + myFontFace + '">');

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