Skip to main content
rubikluk8
Participating Frequently
April 3, 2017
Question

Assign a different Paragraph Style to text exceeding textframe

  • April 3, 2017
  • 1 reply
  • 578 views

I posted this question here: Poetry book text formatting

I'm currently working on a poetry book layout and I came up with this struggle:

I have some long lines that don't fit in a single line and (without changing paragraph) and I'd like to have all of those extra lines automatically being right justified.

I tried using nested line style, but I only manage to apply a different Character Style (not a paragraph one) on the second line.

Is there a way to achieve what I need without having to manually format every "exceeding line"?

To say it in other words I need to have all lines longer than the text box right justified.

I hope I was clear enough (if not sorry, english is not my mother tongue).

User DBLjan​ suggested me to try with a script: "Find out which paragraph exceeds the textframe. Scripters can tell you, if theres a value for this, or if you have to find out the hard way: Compare first characters baseline y with the last character baseline y. If they differs, your line exceeds the textframe – now the script could apply another paragraph style for the right alignment", but I'm totally noob in scripting and I have no idea where to start...

Can anybody help?

Edit: See picture for a reference

This topic has been closed for replies.

1 reply

Trevor:
Legend
April 3, 2017

You can't have part of a paragraph right aligned and part left even if there on separate lines so you have to either add a right tab or separate them into separate paragraphs.

The below add the tabs

HTH

Trevor

var sel, story, paragraphs, paragraph, characterStyle, n;

sel = app.selection[0];

if (!sel || !sel.properties.baseline) {

    alert('No text Selection!');

    exit();

}

// change LongLine to the name of the style you want

characterStyle = app.activeDocument.characterStyles.itemByName('LongLine');

characterStyle = characterStyle.isValid && characterStyle;

story = sel.parentStory;

paragraphs = story.paragraphs.everyItem().getElements();

n = paragraphs.length;

while(n--){

    paragraph = paragraphs;

    if (paragraph.lines.length > 1){

        paragraph.lines.itemByRange(1,-1).insertionPoints[0].contents = SpecialCharacters.RIGHT_INDENT_TAB;

        if (characterStyle) {

            paragraph.lines.itemByRange(1,-1).appliedCharacterStyle = characterStyle;

        }

    }

}

Obi-wan Kenobi
Legend
April 3, 2017

Hi Trevor,

The op wants to "right-align" the 2nd part of the poetry double-line (the para has a left-alignment).

Surely a same applied para style through the doc and I suppose in all the doc (maybe several stories …)!

(^/)