Highlighted

Automatically change line spacing depending on total line count in text frame

New Here ,
Jul 15, 2020

Copy link to clipboard

Copied

I need to fill a text frame with a fixed height with text that needs to be vertically centered and, depending on the amount of text (lines), automatically have a different line spacing (leading).

Let’s say the text frame height is 100mm, font size is 12pt, leading 20pt and we only have text for 1 line. Then the line spacing is not important, it will just align vertically centered. Then we add more text so it fill’s to 2 lines. Now the leading need’s to down to 18pt. We add more text so it fill’s to 3 lines, now the leading need’s to go down to 14pt. etc.

 

I think it could be done with GREP…

Most Valuable Participant
Correct answer by Jongware | Most Valuable Participant

GREP is probably totally out of the question, it does not handle "x number of lines".

It sounds you just need Vertical Justification for that text frame.

TOPICS
How to, Scripting

Views

90

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Automatically change line spacing depending on total line count in text frame

New Here ,
Jul 15, 2020

Copy link to clipboard

Copied

I need to fill a text frame with a fixed height with text that needs to be vertically centered and, depending on the amount of text (lines), automatically have a different line spacing (leading).

Let’s say the text frame height is 100mm, font size is 12pt, leading 20pt and we only have text for 1 line. Then the line spacing is not important, it will just align vertically centered. Then we add more text so it fill’s to 2 lines. Now the leading need’s to down to 18pt. We add more text so it fill’s to 3 lines, now the leading need’s to go down to 14pt. etc.

 

I think it could be done with GREP…

Most Valuable Participant
Correct answer by Jongware | Most Valuable Participant

GREP is probably totally out of the question, it does not handle "x number of lines".

It sounds you just need Vertical Justification for that text frame.

TOPICS
How to, Scripting

Views

91

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 15, 2020 0
Most Valuable Participant ,
Jul 15, 2020

Copy link to clipboard

Copied

GREP is probably totally out of the question, it does not handle "x number of lines".

It sounds you just need Vertical Justification for that text frame.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 2
Enthusiast ,
Jul 15, 2020

Copy link to clipboard

Copied

How the text will be entered? Do you want this as a live behaviour?

Or just want to enter text using script and then change the leading based on the text?

 

To enter text using javascript and change the leading, you can use something like:

var doc = app.activeDocument;
var sel = app.selection[0];
var st = sel.parentStory;

sel.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
st.justification = Justification.CENTER_ALIGN;

st.pointSize = 12;

if (st.contents == "") {
	st.contents = "One line of text.";
	st.leading = 20;
	}
else {
	st.contents += "\rAnother line of text.";
	st.leading -= 2;
	}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 0
New Here ,
Jul 17, 2020

Copy link to clipboard

Copied

I wan't to have it as a "live" behaviour. So as you start typing (our copy paste) into the text-frame it will change the leading if it jumps to the next line, and the next etc... Mabye I want somthing that isn't possible in InDesign. I think the problem is that InDesign can't give feedback on how many line's a text-frame contains (apart from line breaks '\r'). Any ideas...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 17, 2020 0
Adobe Community Professional ,
Jul 17, 2020

Copy link to clipboard

Copied

Do as Jongware said: set the text frame's vertical justification to justify and you get exactly the behaviour that you want.

P.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 17, 2020 0
Adobe Community Professional ,
Jul 17, 2020

Copy link to clipboard

Copied

Hi martv26823449,

I still can't see the whole picture. At some point, very soon, the lines of text will overlap.

When exactly this would happen will depend on the typeface and the contents of the text.

Can you do a screenshot what you do expect when?

 

FWIW: What's the purpose decreasing the leading?

Is there an overall maximum height of text that should not or never be met?

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 17, 2020 0
Adobe Employee ,
Jul 25, 2020

Copy link to clipboard

Copied

Hi there,

 

Thanks for reaching out. I hope your issue is resolved now. We'd appreciate if you can mark the appropriate answer correct.

If you used any other method, please share it here. It'll help other users having similar concern.

If you still have issues, let us know. We'll be happy to help.

 

Regards,

Ashutosh

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 25, 2020 0