Search code examples
ioslayoutcore-text

Space between the last 2 lines of a paragraph is larger?


I draw the text using CTFramesetter, I have set kCTParagraphStyleSpecifierParagraphSpacing, kCTParagraphStyleSpecifierLineSpacing, kCTParagraphStyleSpecifierParagraphSpacingBefore all to 0.0.

As you can see in the image, the space between the last 2 lines of a paragraph is much larger than others'.

There're in total 15 lines in this image, I pasted their ascent, descent, leading, origin.y in the following, we can see that the ascent and descent on the 5th and 10th line are larger than others', I couldn't find any specifier to set to avoid this weird layout.

Any ideas?

1  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 399.000000
2  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 374.000000
3  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 349.000000
4  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 324.000000
5  ascent=25.722656, desecent=13.699219, leading=0.720000, origin.y: 294.000000
6  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 258.000000
7  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 233.000000
8  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 208.000000
9  ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 183.000000
10 ascent=25.722656, descent=13.699219, leading=0.720000, origin.y: 153.000000
11 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 117.000000
12 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 92.000000
13 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 67.000000
14 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 42.000000
15 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 17.000000 

enter image description here


Solution

  • Damit, it's a bug. DTCoreText works around this by repositioning the baseline origins of those affected lines.

    see http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/