私は一種の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);