msink
04/26/2019, 10:27 AMmsink
04/26/2019, 10:27 AM/** Provides a complete description of a font where one is needed. */
open class Font(
family: String? = null,
size: Double = 0.0,
weight: uiTextWeight = uiTextWeightNormal,
italic: uiTextItalic = uiTextItalicNormal,
stretch: uiTextStretch = uiTextStretchNormal
) : Disposable<uiFontDescriptor>(
alloc = nativeHeap.alloc<uiFontDescriptor>().ptr
) {
init {
with(ptr.pointed) {
Family = family?.cstr.rawPtr //.getPointer(nativeHeap)
Size = size
Weight = weight
Italic = italic
Stretch = stretch
}
}
override fun clear() {
ptr.pointed.Family?.let { nativeHeap.free(it) }
}
override fun free() {
clear()
nativeHeap.free(ptr)
}
}
msink
04/26/2019, 10:28 AMFamily
is C string = so how to initialize it in Kotlin wrapper?JoakimForslund
04/26/2019, 10:35 AMmsink
04/26/2019, 10:37 AMval cString = kotlinString.cstr.getPointer(nativeHeap)
Error: type mismatch Required: AutofreeScope Found: nativeHeapolonho
04/26/2019, 11:22 AMfun mycstring(s: String) = s.cstr.place(nativeHeap.allocArray(s.length * 4))
svyatoslav.scherbina
04/26/2019, 2:43 PMArena
the most idiomatic approach for this case.
You can create one along with object instance and dispose in clear
.
See also https://github.com/JetBrains/kotlin-native/blob/master/samples/videoplayer/src/videoPlayerMain/kotlin/Disposable.kt
The arena object can be used in getPointer
.