我正在使用一种 QR 码生成器,它是一个 Mac 应用程序。我知道如何绘制文本,但我不知道如何设置行距。
我的代码:
// Prepare font
CTFontRef font = CTFontCreateWithName(CFSTR("LucidaSansUnicode"), 16, NULL);
// Create Path
CGMutablePathRef gpath = CGPathCreateMutable();
CGPathAddRect(gpath, NULL, CGRectMake(10, 0, pixelsWidth, pixelsHigh));
CGContextSetTextDrawingMode (newcontext, kCGTextFill);
CGContextSetGrayFillColor(newcontext, 0.0, 1.0);
// Create an attributed string
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, stringCode, attr);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, CFAttributedStringGetLength(attrString)), gpath, NULL);
// Draw the string
CTFrameDraw(theFrame, newcontext);
我一直在寻找,但我什么也没找到。也许我必须使用 CTLine?
更新:
好的,我找到了这个,但它不能解决我的问题,我想要小于 0.0 点的行距。
CTTextAlignment paragraphAlignment = kCTLeftTextAlignment;
CGFloat maxLine = 0.0;
CTParagraphStyleSetting setting[2] = {
{kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), ¶graphAlignment},
{kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof(CGFloat), &maxLine}
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, 2);