Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line spacing and paragraph alignment in CoreText

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

  1. The spacing underneath the first line is too big (I understand that this is because the 1st character could be a g,y,p,q etc.

  2. Lines below the first line now do not line up with corresponding lines in the next column.

Any advice on how to overcome these 2 issues would be greatly appreciated, thank you. enter image description here

like image 432
CastToInteger Avatar asked Mar 15 '11 14:03

CastToInteger


People also ask

What is the proper line spacing for paragraphs?

A space equal to 50–100% of the body text size will usually suffice. The larger the point size, the more space you'll need between paragraphs to make a visible difference. Word Right-click in the text and select Paragraph → Indents and Spacing .

What is paragraph spacing in typography?

Line spacing should be at least a space-and-a-half within paragraphs. So around 150 percent or 1.5 times the font size. Spacing following paragraphs should be at least two times the font size. Spacing between letters should be at least 0.12 times the font size.

What is font line spacing?

Line spacing, or “leading”, is the amount of space between the baselines of each line of text. Correct leading is important because it gives multiple lines of text optimum legibility.

How to change spacing between paragraphs PowerPoint?

Click anywhere in the paragraph you want to change. Go to Layout, and under Spacing, click the up or down arrows to adjust the distance before or after the paragraph. You can also type a number directly.


2 Answers

According to the documentation kCTParagraphStyleSpecifierMaximumLineHeight should have solved the problem, but unfortunately does not seem to 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 documentation says it's available in OS v10.5 and later.

kCTParagraphStyleSpecifierMaximumLineHeight:
The maximum height that any line in the frame will occupy, regardless of the font size or size of any attached graphic. Glyphs and graphics exceeding this height will overlap neighboring lines. A maximum height of 0 implies no line height limit. This value is always nonnegative.
Type: CGFloat.
Default: 0.0.
Application: CTFramesetter.
Available in Mac OS X v10.5 and later.
Declared in CTParagraphStyle.h.

like image 121
marco Avatar answered Oct 22 '22 05:10

marco


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

like image 2
CastToInteger Avatar answered Oct 22 '22 06:10

CastToInteger