PDA

View Full Version : Changing case of special characters?


Stack
November 5th, 2008, 09:14 AM
Hi all,

I'm setting up a job that requires author names to be small caps. I created a rule which takes care of that, however, one of the letters is accented. Even though the rule changes everything to small caps, what should be "É" is returning "é". I set up the original file in InDesign, and I've verified that the font (Berkeley Bold) does include special characters in both cases.

Here's the rule in JS to convert to small caps:

Var1="Author";
CaseSelection="smallcaps";



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));

Is it possible that additional coding can be added to this rule?

Thanks!

Dan Korn
November 6th, 2008, 10:48 AM
Sorry, the <smallcap> tag doesn't properly handle extended ASCII characters outside the range of 'a' to 'z'. This is a known issue, case FP-10848.

The workaround is to let JavaScript emulate the smallcaps mode, like so:
function SmallCaps(text, ratio)
{
var factor = Int(ratio) || 80;
var result = "";
for (var i in text)
{
var c = text[I];
if (text.charCodeAt(i) == 32)
result += " ";
else if (c.toUpperCase() == c)
result += NormalizeEntities(c);
else
{
result += "<span><magnify type=text factor=" + factor + ">" +
NormalizeEntities(c.toUpperCase()) + "</magnify></span>";
}
}
return result;
}
You can add this function in your JavaScript Globals, or directly in your rule, and then call it like so:
return SmallCaps(Field(Var1));
Note that you'll need to check "Treat returned strings as tagged text," and also possibly call the NormalizeEntities function for your other returned values.