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…
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.
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 == "") {
...
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.
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;
}
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...
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.
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 )
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