PDA

View Full Version : Wrap copy if over so many letters


Tattoued
November 17th, 2014, 08:59 AM
I tried to search forums but cannot find my answer so apologies if it's out there and I didn't see it!

I have a variable data field where the name or company name is sometimes very short or sometimes pretty long. I'd like to be able to have the size adjust accordingly (without going TOO large), or wrap on two lines if necessary. Say I have a field called "vdata". I imagine I'd do something like if vdata is more than 50 characters, then wrap, else leave on one line, along with some other copyfit command that will adjust the size of the type so it looks decent without going too large on the short names? Thanks!

WMajor
November 24th, 2014, 10:32 PM
Although probably not going to give you the best result and I am a novice when it comes to code, here is a suggestion. It just breaks your text into lines of about 50 characters. Also, don't forget to click on the "Treat ... as tagged text" checkbox.:

var vdata = "Say I have a field called 'vdata'. I imagine I'd do something like if vdata is more than 50 characters, then wrap, else leave on one line, along with some other copyfit command that will adjust the size of the type so it looks decent without going too large on the short names?";
var newstring="";
var characters=50;
textstart=0;
textend=characters;
if(Len(vdata)>characters)
{
for (aloop=1;aloop<vdata.length/characters;aloop++)
{
breakpos = vdata.indexOf(" ",textend);
textamount = breakpos-textstart;
newstring = newstring + vdata.substr(textstart, textamount)+"<br />";
textstart=breakpos+1;
textend=(aloop+1)*characters;
}
newstring = newstring + vdata.substr(textstart, vdata.length-breakpos);
}
return newstring;

Now wait while someone amazingly converts this into a single line of regex :)

The reducing and enlarging of text is up to the settings in FusionPro. You can accept the default or override and there are plenty of examples in the forum.

Dan Korn
November 25th, 2014, 09:17 AM
You want to use the CopyfitLine function, or this variation thereof:
http://forums.pti.com/showthread.php?t=84