Welcome to DirectSmile

Vertically align text to center- I have an idea how it MIGHT be done?

link this post written on 02/10/2015
  • To top

Has anybody found a way to center text vertically? I know wsc has posted about a way to align things to the bottom of a text frame, but the product I'm working on now needs the text aligned to the center of a space between two other objects, no matter how many lines it is.

The text between "Kudos to You" and "Ray Cook" is what I need centered, but since it can be several lines long, I can't just place the field in the center and forget about it.

 

I was thinking about if there might be a javascript solution, but I'm not terribly skilled in js yet. Does anybody know if there's a way for javascript to detect the line height of text, and to detect how many lines of text there are? And to position the text?

I'm thinking:

start position - [(# of lines) x (1/2 line height)] = final position

so if

start position = 5in
# of lines = 3
line height = .5in

then

5in - 3(.5/2) = 4.25

And the text is placed at 4.25 inches down the page instead of 5 inches, which would keep it centered.

If anybody knows how to use javascript to detect/use line height and number of lines, please reply!

The author has edited this post (on 02/10/2015)
link this post written on 07/10/2015
  • To top

I contacted support about it and they said it was impossible to center the text, I hope someone has an answer!

link this post written on 07/10/2015
  • To top

I've been thinking about this more. Since you set the line height when you place the text field in InDesign, you don't need js to tell you what it is, which hopefully eliminates one of the fiddly problems (assuming line height carries over).

The remaining fiddly bits that js needs to take care of:

  • get # of lines
  • change text position

Getting the number of lines may be very simple, or not so simple. It may require getting the element IDs, which means I may have to plug javascript that will get element IDs into a variable data field and run a merge/preview through DirectSmiel in InDesign. With luck, the javascript will return element IDs I can work with.

Changing the text position could also be very simple, or very difficult. Now that I've ruminated some, I think it may be easier to perform a baseline shift than actually repositioning the text.

Links to look into when I have a chance...

Get # of lines

Get element IDs

Baseline Shift (NOT positioning)

Positioning Text (NOT baseline shift)

link this post written on 07/10/2015
  • To top

Hi Sheri,

Unfortunately there is no feedback given to the script how much space/lines are needed for a text in a DS frame.
As well as there is no element ID like in the web.
Also it is not InDesign what is working behind, it is a DS solution.

So, as far as I know, it will lead into a terrible script looking like recreating a word processor, counting characters of words and text to calculate an approximately value for the lines a text would need.
But each text is different and a lot iiiiiiiiiiiii in a text are needing a different space like the same count of wwwwwwwwwwwww using a proportional font, so counting how many "n"s are fitting into a line is not always satisfying.
I am not sure if this can be it worth for recreating such a simple functionality like vertical alignment, even if I am pretty sure you would be able to write such a script (saw your help for Ken! Great job! ).

In case you have linefeeds at each end of a line and the lines don't wrap into the next line, it is not too hard.
You can use the 'VAR.Size("Value")' or 'VAR.Tag("TagName", "Value")' with the (DS supported) InDesign "cl" tag to shrink a line height to the half. But unfortunately this ends with the document default value after the <cl:> tag, so you have to revert to the needed size before inserting new text.

Here a list I got of the few features which are currently supported by the DS engine:
- Fontsize
- Auto-Leading, Leading
- Character Spacing
- Baseline shift
- RGB Color
- CMYK color
- Fillcolor (No Outline!)
- Left, Center, Right, Justified Text
- Left Indent, FirstlineIndent
- Compress (horizontal scaling)
- Textflow (frame to frame)
- Shrink / Shrink & Grow (also for Textflows)

What not can be reached via the predefined VAR commands can be done using the InDesign tag with the former mentioned VAR.Tag() command in a JS.

Perhaps there is a silver lining at the horizon or some hope, I heard the developers are willing to include some simpler solution in the not so far future – when ever this will mean – to avoid this scripting stuff.

The author has edited this post (on 07/10/2015)
link this post written on 07/10/2015
  • To top

Thanks for all the good info, WSC! It should prove very useful on this little... experiment.

Unfortunately for me, my options are either to spend a ton of time and energy up front to find a javascript solution to this problem, or to manually correct the positioning of that one element on hundreds of these Kudos every time an order is placed, for all the forseeable future. For obvious reasons, I'm choosing to pursue a solution through script, even if it does turn out to be eyebleedingly unwieldy.

I'm still very much a javascript noob, though, so there's a decent chance I won't find a solution. Fingers crossed!

link this post written yesterday
  • To top

Just a thought I had that I'm putting here so I don't forget it-

maybe it's possible to use textflow to count lines, if I correctly understand what you mean by textflow? If I make three text boxes that are one line tall, stack them one above the other, and then link them together so the text will flow from frame to frame- maybe it's possible to write a script where if one text box is used, then move x amount, if 2 are used, move y amount... It would eliminate the need to measure the length and quantity of characters.

Not sure. I'll look into it later. I haven't tried applying javascript to text areas with flowing content before.

link this post written 5 hours ago
  • To top

As I mentioned somewhere before, there is no feedback given to the script, so it is the same like using one single frame.

  • Statistics: 7 Posts | 14 Visits
created by mixxt
  • v1.1.1
  • (highfive)