1

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?
JackyJohnson
  • 3,106
  • 3
  • 28
  • 35
  • See [CoreText. How Do I Calculate the Bounding Box of an Attributed String?](http://stackoverflow.com/questions/6988498/coretext-how-do-i-calculate-the-bounding-box-of-an-attributed-string) – CRD Feb 22 '15 at 04:56

0 Answers0