Forum Replies Created

Page 2 of 2
  • Hmm, no this wouldn’t work as it wouldn’t divide the text evenly over the lines. So you might be left with a single word on the last line.

    So far we have this which is working great for shorter texts where we only want two lines.
    But for longer text, we need it to divide into 3 lines.

    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(” “, mid);
    var after = myString.indexOf(” “, mid + 1);

    if (before == -1 || (after != -1 && mid – before >= after – mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + “\n” + myString.substring(mid + 1);
    }

    if (text.sourceText.indexOf(“\n”) != -1 || text.sourceText.indexOf(“\r”) != -1 || text.sourceText.length<18) {
    value;
    } else {
    val = breakInTwo(text.sourceText);

    style.setFont(comp(“00 Color Control”).layer(“Headline Text Font Style”).text.sourceText).setText(val);
    }

  • Sorry, no I meant this part is not working:

    style.setFont(comp(“00 Color Control”).layer(“Headline Text Font Style”).text.sourceText.style.font).setText(val);

  • Works great but unfortunately now the font style is not working…

  • That works a charm!

    Would it be easy to put in another statement that if the text length is less than say 20 characters no line break is added?

  • So sorry, I’m completely new to this.
    That seems to still add the line break when there is already a linebreak present…

  • I can’t thank you enough!

    Sorry to ask again… instead of removing any existing line breaks instead could it be that if there is an existing line break not to run the expression?

  • Also, would it by any chance be possible to remove any existing line breaks first?

  • Wow, this is absolutely brilliant!!!

    I’m also running another expression to pull in the font style but I’m not sure if/how I can have them both running:

    style.setFont(comp(“00 Color Control”).layer(“Headline Text Font Style”).text.sourceText);

Page 2 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy