Given a CFAttributedStringRef
pointer, the CFStringRef
and all the attributes such as the CTFont
or CTParagraphStyleRef
and what not, how do I find out the minimum dimension required for my CGContextRef?
Here's some code:
// create one attribute
CFArrayRef fontDescriptors = CTFontManagerCreateFontDescriptorsFromURL((__bridge CFURLRef)urlToFontFile);
CTFontRef font = CTFontCreateWithFontDescriptor(CFArrayGetValueAtIndex(fontDescriptors, 0), 40, NULL);
// create a dictionary for the attributes
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
CFDictionaryRef attributes = CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
(const void**)&values, sizeof(keys) / sizeof(keys[0]),
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// create my string
CFStringRef textString = CFSTR("Hello World!");
// finally, create my attributed string
CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, textString, attributes);
// now how do I get the width and height of my attributed string?