Core Text

Core Textは、Mac OS X v10.4で初めて導入され、Mac OS X v10.5で公開されたmacOSのCore Foundation風のAPIで、古くからmacOSにあり非推�…

Core Text

Core Textは、Mac OS X v10.4で初めて導入され、Mac OS X v10.5で公開されたmacOSCore Foundation風のAPIで、古くからmacOSにあり非推奨となったQuickDrawATSUIに代わってテキストレンダリングの機能を担うものである。Appleによると、Core Textは高いパフォーマンスと利用の容易さを意識して設計され、このレイアウトAPIはシンプルで安定しており、Core FoundationやCore GraphicsCocoaと密接に関連している。[1]

特徴

Core Textは次のような不透過型を提供している。

  • CTFramesetter - CTTypesetterを使って、与えられた属性付き文字列とCGPathからCTFrameオブジェクトを生成する。
  • CTTypesetter - 改行などの行のレイアウトを行う。
  • CTFrame - 行(CTLineオブジェクト)の配列を表す。
  • CTLine - 同じ属性を持つグリフの並びの配列を表す。
  • CTFont - フォントを表す。

使用例

次のコードは与えられたグラフィックコンテクストに「Hello, World!」と表示する。

// フォントの準備
CTFontRef font = CTFontCreateWithName(CFSTR("Times"), 48, 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, CFSTR("Hello, World!"), attr);
CFRelease(attr);

// 文字列の描画
CTLineRef line = CTLineCreateWithAttributedString(attrString);
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextSetTextPosition(context, 10, 20);
CTLineDraw(line, context);

// 後片付け
CFRelease(line);
CFRelease(attrString);
CFRelease(font);

参照

外部リンク

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.