Skip to main content
Inspiring
February 19, 2010
Answered

How can I control the line spacing in TLF

  • February 19, 2010
  • 2 replies
  • 7272 views

Hello,

Is it possible to control the line spacing in TLF?

For example I might have text lines with font size of 12 (i.e. constant text height) but I would like to be able to change the space between the lines programatically.

Playing with the lineHeight property is not the best approach because in case there are images embedded in the text once lineHeight is set then the image is cut if it is higher than the line height. I really need to control the space between lines but not the lines' height.

Thanks

This topic has been closed for replies.
Correct answer

I would like to achieve the following behavior: the gap between all text lines to be always X pixels.

My understanding how TLF handles this (please correct me if I am wrong) is that there is no gap between TextLines but one could achieve similar behavior by playing with lineHeigh. You could set it to a percentage and then this would introduce visual gap between text lines however in cases when a text line contains elements with different height (like the case with images or spans with different fontSize) then the gap will differ because it is calculated as a percentage of the overall fontSize. I don't want to have different gaps in these cases. I would like to have always (let's say) 10 pixels between each text line.

What I need is very similar to the "verticalGap" style available in the VBox container. I would like to specify the exact gap between each text line in exactly the same way.

Using "lineHeight" is not good because it depends on the height of the text/images and this leads to different gaps when I have mixture of elements with different heights. The way I set the gap should not be dependent on the height of the elements.


You can specify lineHeight in pixels instead of percentages - lineHeight="12" versus lineHeight="120%"

If you want each line to be exactly the same height - as if the lines were falling on a grid, you can specify a pixel lineHeight with the default leadingModel. In this case we set each line's baseline that many pixels from the last line's baseline. In this case larger type or larger inlines may not fit, so you have to specify a pixel height that's appropriate for the content.

Or if you want lines with larger content to automatically be larger, but the gap between the lines to be constant, then you can choose the ASCENT_DESCENT_UP leadingModel and a pixel lineHeight. In this case lineHeight is the distance between one line's descenders and the next line's ascenders. I think that's what you're asking for.

2 replies

Participant
October 27, 2011

hi, all, i see this prolem in my project now. when set leadingModel ASCENT_DESCENT_UP,  and a constant pixel lineHeight, if insert a image, the text will be mixed up.

i want to know if the newest textlayout framework have fixed this problem? or any solution? thanks.

Adobe Employee
October 28, 2011

Box leading model was introduced to solve this particular use case.

Adobe Employee
February 19, 2010

LineHeight an be set as a percentage of fontSize, for example, lineHeight="120%".  The height of an InlineGraphicElement is treated as its fontSize.

Richard

Inspiring
February 19, 2010

Thanks for the information.

In my case using percentage to control the spacing between lines doesn't help.

I'll give an example ... I have three lines of text (fontSize = 10, lineHeight=120%). In the middle text line I have an image 30 pixels high. This would lead to uneven spacing between the lines. Line #2 height will be 36 pixels i.e. we have 6 pixels gap between line #1 and line #2. Line #3 will be 12 pixels i.e. we have 2 pixels spacing between line #2 and line #3.

I would like to have even spacing between the lines even when there are images in them.

If there is no other way to control the line spacing then this looks like a good feature request.

Is it possible to achieve in a way different than using lineHeight? ... and is there a feature request submitted for similar feature because if not I could write one.

Thanks

Adobe Employee
February 20, 2010

The lineHeight is the maximum of all the lineHeights of the LeafElements on the line.  So you could set your lineHeights for each span to be 12 point and the lineHeight of the InlineGraphicElements to the first multiple of 12 greater than the height.

Is that the effect you are trying to achieve?

Richard