如何根据字符串和属性获取CFAttributedStringRef的维度?

时间:2015-02-21 23:33:31

标签: objective-c c cocoa core-text core-foundation

给定CFAttributedStringRef指针,CFStringRef以及所有属性(例如CTFontCTParagraphStyleRef等等),如何找出所需的最小尺寸我的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?

0 个答案:

没有答案