Jump to content

Horizontally scaled type


jwhittaker

Recommended Posts

I need to horizontally scale a variable field to 90%. I am a beginner and I'm missing something really stupid. This is what I have so far and I'm getting a syntax error and it's putting the cursor on the return in the else. Can any let me know what I'm missing? Thanks

 

if (Field("name") != "")

{

return <p><setwidth newsize="7.2">Field("name")</setwidth>;

}

else

{

return "";

}

Link to comment
Share on other sites

I need to horizontally scale a variable field to 90%. I am a beginner and I'm missing something really stupid. This is what I have so far and I'm getting a syntax error and it's putting the cursor on the return in the else. Can any let me know what I'm missing? Thanks

 

if (Field("name") != "")

{

return <p><setwidth newsize="7.2">Field("name")</setwidth>;

}

else

{

return "";

}

Well, first off, some basic JavaScript: You need to put the tags in quotes to tell the JavaScript interpreter to treat them as literal strings:

if (Field("name") != "")
{
return '<p><setwidth newsize="7.2">' + Field("name") + '</setwidth>';
}
else
{
return "";
}

You can use either single- or double-quotes to denote a string literal. I'm using single quotes as an example here so that the double-quotes in the tag can be embedded. (But you don't really need those double-quotes; see below.)

 

Beyond that, I'm not sure you need the extra <p> tag in there. For that matter, I'm not sure you need to test whether the field value is empty, since if it is, you'd only be returning some tags, which, by themselves (i.e. without any text to act upon), will have no effect. So the entire rule could simply be this one line:

return "<setwidth newsize=7.2>" + NormalizeEntities(Field("name")) + "</setwidth>";

You can always use the "Suppress if empty" setting in the Paragraph Formatting dialog from the Variable Text Editor where you're using the result of this rule.

 

Also, note that I've removed the quotes around "7.2", since you don't need to put attributes in quotes if there are no spaces in them. I also highly recommend using NormalizeEntities (or if you're using FP 6.0, TaggedTextFromRaw) to avoid any potential problems with HTML control characters in the field data.

 

Furthermore, if your goal is to adjust the horizontal scaling to a specific percentage of the point size, this is a better way to go:

return '<magnify type=setwidth factor=90>' + NormalizeEntities (Field("name")) + '</magnify>';

This will adjust the setwidth to 90 percent of whatever point size is in effect, so you don't need to hard-code a specific setwidth to match a specific point size.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...