以下のコードを使用して、TrueType フォントのパス要素を抽出しました。
問題は、 で記述された曲線が 2 つのポイントを持つelement->type
タイプkCGPathElementAddQuadCurveToPoint
(低品質) のみであることです。kCGPathElementAddCurveToPoint
どの要素も高品質のタイプ (3 ポイント) を使用しないのはなぜですか?
誰かアイデアがありますか?
int count = 0;
void applierFunction(void *info, const CGPathElement *element)
{
int point_count;
switch (element->type)
{
case kCGPathElementMoveToPoint:
point_count = 1;
break;
case kCGPathElementAddLineToPoint:
point_count = 1;
break;
case kCGPathElementAddQuadCurveToPoint:
point_count = 2;
break;
case kCGPathElementAddCurveToPoint:
point_count = 3;
break;
case kCGPathElementCloseSubpath:
point_count = 0;
break;
}
count+=point_count;
printf("%u.:\n", count);
for (int i = 0; i<point_count; i++) {
switch (element->type) {
case kCGPathElementMoveToPoint:
printf("kCGPathElementMoveToPoint\n");
break;
case kCGPathElementAddLineToPoint:
printf("kCGPathElementAddLineToPoint\n");
break;
case kCGPathElementAddQuadCurveToPoint:
printf("kCGPathElementAddQuadCurveToPoint\n");
break;
case kCGPathElementAddCurveToPoint:
printf("kCGPathElementAddCurveToPoint\n");
break;
case kCGPathElementCloseSubpath:
printf("kCGPathElementCloseSubpath\n");
break;
default:
printf("unknown path type\n");
}
}
}
void extractStringPathElements()
{
CFStringRef str = CFSTR("Q");
CFStringRef strFont = CFSTR("Arial");
CTFontRef font = CTFontCreateWithName(strFont, 500, NULL);
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, str, attr);
CFRelease(attr);
CTLineRef line = CTLineCreateWithAttributedString(attrString);
CFArrayRef runs = CTLineGetGlyphRuns(line);
long runCount = CFArrayGetCount(runs);
for (int ri = 0; ri < runCount; ri++) {
::CTRunRef run = (::CTRunRef)CFArrayGetValueAtIndex(runs, ri);
long glyphCount = CTRunGetGlyphCount(run);
const unsigned short *glyphs = CTRunGetGlyphsPtr(run);
for (int gi = 0; gi < glyphCount; gi++) {
::CGPathRef path = CTFontCreatePathForGlyph(font, glyphs[gi], NULL);
CGPathApply(path, 0, applierFunction);
printf("glyph %u has %u elements.\n", glyphs[gi], count);
CGPathRelease(path);
}
}
CFRelease(line);
CFRelease(attrString);
CFRelease(font);
}
int main (int argc, const char * argv[])
{
extractStringPathElements();
return 0;
}