Scoop API

scoop:scoop.graphics.text:0.1.0

src/native/layout.scoop

Selected production source · src/native/layout.scoop

1package scoop.graphics.text.native
3import scoop.graphics.Point
4import scoop.graphics.Rect
5import scoop.graphics.text.TextLayout
6import scoop.graphics.text.TextRange
8/** Native query status: 1 success, 0 unavailable, -1 invalid argument, -2 native failure. */
9@CLayout
10public struct NativeTextPosition(val byteOffset: Long, val affinity: Int, val status: Int)
12@CLayout
13public struct NativeTextRect(val rect: Rect, val status: Int)
15@CLayout
16public 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@CLayout
24public 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>) -> Int
32 >,
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>
39/** Borrows retainable native queries; ordinary TextLayout methods remain owner-thread-only. */
40@Unsafe
41public 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 }
50@Extern(name = "scoop_graphics_text_export_layout")
51private fun textNativeLayout(layout: Ptr<Unit>): NativeTextLayout