scoop:scoop.graphics.text:0.1.0
src/native/layout.scoop
Selected production source · src/native/layout.scoop
1
package scoop.graphics.text.native3
import scoop.graphics.Point4
import scoop.graphics.Rect5
import scoop.graphics.text.TextLayout6
import scoop.graphics.text.TextRange8
/** Native query status: 1 success, 0 unavailable, -1 invalid argument, -2 native failure. */9
@CLayout10
public struct NativeTextPosition(val byteOffset: Long, val affinity: Int, val status: Int)12
@CLayout13
public struct NativeTextRect(val rect: Rect, val status: Int)15
@CLayout16
public struct NativeTextRange(val range: TextRange, val status: Int)18
/**19
* Paired native queries over the same shaped layout. Retain before saving this borrowed value.20
* Affinity is 0 upstream or 1 downstream; range units are grapheme, word, visual line, logical line.21
* Native functions and the boxes visitor must not enter Scoop or throw across the ABI.22
*/23
@CLayout24
public struct NativeTextLayout(25
val context: Ptr<Unit>,26
val retain: FunPtr<(Ptr<Unit>) -> Unit>,27
val release: FunPtr<(Ptr<Unit>) -> Unit>,28
val hit: FunPtr<(Ptr<Unit>, Point) -> NativeTextPosition>,29
val caret: FunPtr<(Ptr<Unit>, Long, Int, Double) -> NativeTextRect>,30
val boxes: FunPtr<31
(Ptr<Unit>, Long, Long, Ptr<Unit>, FunPtr<(Ptr<Unit>, Rect, Int) -> Unit>) -> Int32
>,33
val range: FunPtr<(Ptr<Unit>, Long, Int, Int) -> NativeTextRange>,34
val lineRange: FunPtr<(Ptr<Unit>, Long) -> NativeTextRange>,35
/** Nonnegative line index; -1 unavailable, -2 invalid argument, -3 native failure. */36
val lineIndex: FunPtr<(Ptr<Unit>, Long, Int) -> Long>37
)39
/** Borrows retainable native queries; ordinary TextLayout methods remain owner-thread-only. */40
@Unsafe41
public fun <T> TextLayout.withNativeLayout(block: (NativeTextLayout) -> T): T {42
val value = textNativeLayout(resource.get())43
try {44
return block(value)45
} finally {46
value.release(value.context)47
}48
}50
@Extern(name = "scoop_graphics_text_export_layout")51
private fun textNativeLayout(layout: Ptr<Unit>): NativeTextLayout