Text wrap in Text layer

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
payal1711
Posts: 12
Joined: August 3rd, 2004, 7:43 pm

November 17th, 2004, 11:47 am

Hi,

Is there any way to specify the height of the text layer in terms of number of rows using Javascript. Currently when I add the text through javascript, it does not wrap and is cut at the edge of the frame, it does not wrap to the next line. Can I do this somehow?

Thanks,
Payal
teedoubleyou
Posts: 6
Joined: December 12th, 2005, 5:29 am

December 13th, 2005, 6:54 am

As far as I know it isn't possible to do so.

The method I use is using the substring command in javascript. You have to set a cut off point for the line to break at. I.e. if you want it to wrap at the 45th character, you need to set this.

Code: Select all

if (text.length > 45)
{
       Line1 = text.substring(0, 45)
       Line2 = text.substring(45, text.length)
}
From this point, save the remaining part of the string after character 45 in a different variable.

Use the "\r" (return character) to concatenate the 2 strings:

Code: Select all

var wrappedText = line1+"\r"+line2;
--

If you want to wrap the text without splitting the word, you need to scan from character 45, until you encounter a space.

Do this by using the substring method and scanning 2 characters at a time until you encounter a " " (a space).

Code: Select all

var i = 45
while (substring((i-1), i) != " ")
{
      i++;
}

Line1 = text.substring(0, i);
Line2 = text.substring(i, text.length);
Then concatenate the two variables as above.

--

I hope that was of some help, even if its about a month late.
payal1711
Posts: 12
Joined: August 3rd, 2004, 7:43 pm

December 13th, 2005, 11:36 am

Thanks TW for your reply.

Actually its a year and a month since I posted it :).

I have found out a way on how to do that. I insert a Text Layer with the Height and Width that I want. Then I modify the SourceText property of the layer to insert the Text. It auto wraps as it hits the width. But it will truncate when it reaches the maximum height. Below is the code I use to insert SourceText.


var myFolder = app.project.item(i);
var sourcetext = myFolder.layer(1).sourceText;
var newstring = "Test string with loooonnnnnnnnnggg text";
sourcetext.setValue(newstring);


This serves the necessary purpose for me.

Thanks for your posting anyways.
Payal
Post Reply