PDA

View Full Version : Creating Paragraphs using CoreText in iphone/ipad




arnieterm
Jul 8, 2010, 09:40 AM
Hi all
In order to create multiple paragraph(s) using CoreText do we need to set CTFrameSetter seperately for each paragraph? I am trying to apply settings for various paragraph like alignment, paragraph spacing etc but it does not apply. Though I am successfully able to apply font to them.


CGFloat ls = height;
CTParagraphStyleSetting setting;
setting.spec = kCTParagraphStyleSpecifierParagraphSpacing;
setting.valueSize = sizeof(CGFloat);
setting.value = &ls;
CFIndex theNumberOfSettings = 1;
CTParagraphStyleSetting settings[1] = {
//{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment},
{kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &ls},
};
//CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings) / sizeof(settings[0]));
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, theNumberOfSettings);

CFStringRef keys[] = { kCTParagraphStyleAttributeName };
CFTypeRef values[] = { paragraphStyle };
CFDictionaryRef paraAttribute = CFDictionaryCreate(
NULL,
(const void **)&keys,
(const void **)&values,
sizeof(keys) / sizeof(keys[0]),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks
);
[htmlContent addAttributes:(NSDictionary*) paraAttribute range: applyToRange];
//CFRelease(paragraphStyle);
//CFRelease(attr);



here htmlContent is the NSMutableAttributedString. What is wrong with this code? Any idea?
Thanks