【发布时间】:2012-01-09 02:19:22
【问题描述】:
我正在尝试在 CTFrameRef 中仅绘制 每行 8 个字符,但我不知道如何使用 CTFrameRef .
我读过“Manual Line Breaking”,但他们使用 CTLine,我认为使用 CTFrameRef 更简单。
也许使用某种框架设置器或更改 CGPath 这可能是可能的。
这是我现在的代码(我已经删除了关于问题的测试代码的注释行):
// Prepare font
CTFontRef font = CTFontCreateWithName(CFSTR("LucidaSansUnicode"), 16, NULL);
// Create path
CGMutablePathRef gpath = CGPathCreateMutable();
CGPathAddRect(gpath, NULL, CGRectMake(0, 0, 200, 200));
// Create an attributed string
CGContextSetTextDrawingMode (newcontext, kCGTextFillStroke);
CGContextSetGrayFillColor(newcontext, 0.0, 1.0);
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
CFDictionaryRef attr = CFDictionaryCreate(NULL, (const void **)&keys,
(const void **)&values, sizeof(keys) / sizeof(keys[0]),
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef attrString = CFAttributedStringCreate(NULL,
CFSTR("Aenean lacinia bibendum nulla sed consectetur."), attr);
CTFramesetterRef framesetter =
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
CTFrameRef theFrame =
CTFramesetterCreateFrame(framesetter, CFRangeMake(0,
CFAttributedStringGetLength(attrString)), gpath, NULL);
CTFrameDraw(theFrame, newcontext);
// Clean up... CFRelease...
// Getting TIFF image
我得到以下图片:
但我想要这样的东西(有区别,因为这张图片是用 Photoshop 制作的):
感谢和抱歉我的英语。
【问题讨论】:
标签: macos cocoa drawing core-graphics core-text