LoginSignup
5
9

More than 5 years have passed since last update.

Core Text の CTLine と 行の折り返し位置を取得する

Last updated at Posted at 2017-02-05

CTLine を作る

CTLine
public func CTLineCreateWithAttributedString(_ attrString: CFAttributedString) -> CTLine

public func CTLineCreateTruncatedLine(_ line: CTLine, _ width: Double, _ truncationType: CTLineTruncationType, _ truncationToken: CTLine?) -> CTLine?

public func CTLineCreateJustifiedLine(_ line: CTLine, _ justificationFactor: CGFloat, _ justificationWidth: Double) -> CTLine?
CTTypesetter
public func CTTypesetterCreateLineWithOffset(_ typesetter: CTTypesetter, _ stringRange: CFRange, _ offset: Double) -> CTLine

public func CTTypesetterCreateLine(_ typesetter: CTTypesetter, _ stringRange: CFRange) -> CTLine

CTLineCreateWithAttributedString()

属性付き文字列 CFAttributedString から CTLine を作る。

CTLineCreateTruncatedLine()

CTLine からトランケーション(省略)を適用した CTLine を新たに作る。

CTLineCreateJustifiedLine()

CTLine から均等割付を適用した CTLine を新たに作る。

CTTypesetterCreateLineWithOffset()

テキストの指定範囲内から CTLine を作る。

CTTypesetterCreateLine()

CTTypesetterCreateLineWithOffset()offset=0 版。

改行位置を得る

CTTypesetter
public func CTTypesetterSuggestLineBreakWithOffset(_ typesetter: CTTypesetter, _ startIndex: CFIndex, _ width: Double, _ offset: Double) -> CFIndex

public func CTTypesetterSuggestLineBreak(_ typesetter: CTTypesetter, _ startIndex: CFIndex, _ width: Double) -> CFIndex

public func CTTypesetterSuggestClusterBreakWithOffset(_ typesetter: CTTypesetter, _ startIndex: CFIndex, _ width: Double, _ offset: Double) -> CFIndex

public func CTTypesetterSuggestClusterBreak(_ typesetter: CTTypesetter, _ startIndex: CFIndex, _ width: Double) -> CFIndex

引数

  • typesetter: CTTypesetter
  • startIndex: typesetter における処理を開始する文字位置
  • width: 描画コンテクストにおける行の長さ(pt)
  • offset: 描画コンテクストにおける行の開始位置(pt)

CTTypesetterSuggestLineBreakWithOffset()

改行はテキストストリーム内のハードブレーク文字または指定された幅に文字を埋め込むことによってトリガされます。

つまりは Word break(単語単位の折り返し)のように振る舞います。欧文ではスペースで区切られた単語単位を維持しようとします。和文では行頭/行末禁止文字などを考慮した簡単な禁則処理が適用されるようです。

CTTypesetterSuggestLineBreak()

CTTypesetterSuggestLineBreakWithOffset()offset=0 版。

CTTypesetterSuggestClusterBreakWithOffset()

指定された幅 width に基づいて、タイポグラフィクラスタの改行位置を返却します。このクラスター改行は文字改行に似ていますが、言語クラスターを分割することはありません。他のコンテキスト分析は行われません。これは、ハイフネーションなどの異なる禁則処理を実装するために呼び出し元によって使用されます。タイポグラフィクラスタ改行は、テキストストリーム内のハードブレーク文字によってトリガされることにも注意してください。

つまりは Character break(文字単位の折り返し)のように振る舞います。欧文ではスペースで区切られた単語単位を無視して改行位置を返します。和文では禁則処理は施されません。

CTTypesetterSuggestClusterBreak()

CTTypesetterSuggestClusterBreakWithOffset()offset=0 版。

5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9