Line spacing and alignment of positions in CoreText

I am using CoreText to render multiple columns of text. However, when I set the first letter of the 1st paragraph in boldface larger than the rest of the text, I have 2 problems (both visible in the attached image):

  • The interval between the first line is too long (I understand that this is because the 1st character can be g, y, p, q, etc.

  • Rows below the first row no longer match the corresponding rows in the next column.

Any advice on how to overcome these 2 problems would be greatly appreciated, thanks. enter image description here

+5
source share
2 answers

It seems the only way to fix this is with a workaround that should create 3 frames for the first column, 1 for W, 1 for the rest of the first sentence and 1 for the rest of the first column.

+2
source

According to the documentation, kCTParagraphStyleSpecifierMaximumLineHeight was supposed to solve this problem, but, unfortunately, does not work, at least on iOS 4.3.

CTParagraphStyleSetting theSettings[5] = { { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &spaceBetweenParaghraphs }, { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), &topSpacing }, { kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &spaceBetweenLines }, { kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &lineHeight}, { kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &lineHeight} }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, 5); 

To be fair, this suggests that it is available in OS v10.5 and later.

kCTParagraphStyleSpecifierMaximumLineHeight :
The maximum height that any line in the frame occupies, regardless of the size or font size of any attached graphics. Glyphs and graphics that exceed this height will overlap adjacent lines. Maximum height 0 means no line height limit. This value is always non-negative.
Type: CGFloat.
Default: 0.0.
Application: CTFramesetter.
Available on Mac OS X version 10.5 and later. Declared in CTParagraphStyle.h.

+3
source

Source: https://habr.com/ru/post/885938/


All Articles