给定CFAttributedStringRef
指针,CFStringRef
以及所有属性(例如CTFont
或CTParagraphStyleRef
等等),如何找出所需的最小尺寸我的CGContextRef?
以下是一些代码:
// 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?