diff --git a/skiko/gradle.properties b/skiko/gradle.properties index 5bdc63811..135b7c5c9 100644 --- a/skiko/gradle.properties +++ b/skiko/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official deploy.version=0.0.0 -dependencies.skia=m126-1d69d9b-2 +dependencies.skia=m126-d2aaacc35d-1 # you can override general skia dependencies by passing platform-specific property: # dependencies.skia.android-arm64 diff --git a/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/StrutStyle.kt b/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/StrutStyle.kt index bd225718f..6b2ab7dbd 100644 --- a/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/StrutStyle.kt +++ b/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/StrutStyle.kt @@ -211,6 +211,7 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali return this } + @Deprecated("Replaced by topRatio") var isHalfLeading: Boolean get() = try { Stats.onNativeCall() @@ -222,6 +223,8 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali setHalfLeading(value) } + // Same as topRatio = halfLeading ? 0.5f : -1.0f + @Deprecated("Replaced by topRatio") fun setHalfLeading(value: Boolean): StrutStyle { try { Stats.onNativeCall() @@ -232,6 +235,29 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali return this } + // [0..1]: the ratio of ascent to ascent+descent + // -1: proportional to the ascent/descent + var topRatio: Float + get() = try { + Stats.onNativeCall() + StrutStyle_nGetTopRatio(_ptr) + } finally { + reachabilityBarrier(this) + } + set(value) { + setTopRatio(value) + } + + fun setTopRatio(topRatio: Float): StrutStyle { + try { + Stats.onNativeCall() + StrutStyle_nSetTopRatio(_ptr, topRatio) + } finally { + reachabilityBarrier(this) + } + return this + } + private object _FinalizerHolder { val PTR = StrutStyle_nGetFinalizer() } @@ -321,3 +347,11 @@ private external fun _nIsHalfLeading(ptr: NativePointer): Boolean @ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nSetHalfLeading") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_StrutStyle__1nSetHalfLeading") private external fun _nSetHalfLeading(ptr: NativePointer, value: Boolean) + +@ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nGetTopRatio") +@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_StrutStyle__1nGetTopRatio") +private external fun StrutStyle_nGetTopRatio(ptr: NativePointer): Float + +@ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nSetTopRatio") +@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_StrutStyle__1nSetTopRatio") +private external fun StrutStyle_nSetTopRatio(ptr: NativePointer, value: Float) diff --git a/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/TextStyle.kt b/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/TextStyle.kt index 7182d4b86..bebd835e0 100644 --- a/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/TextStyle.kt +++ b/skiko/src/commonMain/kotlin/org/jetbrains/skia/paragraph/TextStyle.kt @@ -323,6 +323,7 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz return this } + @Deprecated("Replaced by topRatio") var isHalfLeading: Boolean get() = try { Stats.onNativeCall() @@ -334,6 +335,8 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz setHalfLeading(value) } + // Same as topRatio = halfLeading ? 0.5f : -1.0f + @Deprecated("Replaced by topRatio") fun setHalfLeading(value: Boolean): TextStyle { try { Stats.onNativeCall() @@ -344,6 +347,29 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz return this } + // [0..1]: the ratio of ascent to ascent+descent + // -1: proportional to the ascent/descent + var topRatio: Float + get() = try { + Stats.onNativeCall() + TextStyle_nGetTopRatio(_ptr) + } finally { + reachabilityBarrier(this) + } + set(value) { + setTopRatio(value) + } + + fun setTopRatio(topRatio: Float): TextStyle { + try { + Stats.onNativeCall() + TextStyle_nSetTopRatio(_ptr, topRatio) + } finally { + reachabilityBarrier(this) + } + return this + } + var letterSpacing: Float get() = try { Stats.onNativeCall() @@ -560,6 +586,14 @@ private external fun TextStyle_nGetHalfLeading(ptr: NativePointer): Boolean @ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_TextStyle__1nSetHalfLeading") private external fun TextStyle_nSetHalfLeading(ptr: NativePointer, value: Boolean) +@ExternalSymbolName("org_jetbrains_skia_paragraph_TextStyle__1nGetTopRatio") +@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_TextStyle__1nGetTopRatio") +private external fun TextStyle_nGetTopRatio(ptr: NativePointer): Float + +@ExternalSymbolName("org_jetbrains_skia_paragraph_TextStyle__1nSetTopRatio") +@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_TextStyle__1nSetTopRatio") +private external fun TextStyle_nSetTopRatio(ptr: NativePointer, value: Float) + @ExternalSymbolName("org_jetbrains_skia_paragraph_TextStyle__1nGetBaselineShift") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_TextStyle__1nGetBaselineShift") private external fun TextStyle_nGetBaselineShift(ptr: NativePointer): Float diff --git a/skiko/src/commonTest/kotlin/org/jetbrains/skiko/paragraph/TextStyleTest.kt b/skiko/src/commonTest/kotlin/org/jetbrains/skiko/paragraph/TextStyleTest.kt index 1e78f205f..81729e56a 100644 --- a/skiko/src/commonTest/kotlin/org/jetbrains/skiko/paragraph/TextStyleTest.kt +++ b/skiko/src/commonTest/kotlin/org/jetbrains/skiko/paragraph/TextStyleTest.kt @@ -143,6 +143,15 @@ class TextStyleTest { } } + @Test + fun textStyleTopRatioTest() { + TextStyle().use { textStyle -> + assertEquals(-1f, textStyle.topRatio) + textStyle.topRatio = 0.42f + assertEquals(0.42f, textStyle.topRatio, 0.001f) + } + } + @Test fun textStyleMetricsContainsMeaningfulValues() = runTest { val jbMono = Typeface.makeFromResource(jbMonoPath) diff --git a/skiko/src/jvmMain/cpp/common/paragraph/StrutStyle.cc b/skiko/src/jvmMain/cpp/common/paragraph/StrutStyle.cc index 8b85c1f36..43670a25b 100644 --- a/skiko/src/jvmMain/cpp/common/paragraph/StrutStyle.cc +++ b/skiko/src/jvmMain/cpp/common/paragraph/StrutStyle.cc @@ -145,3 +145,15 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt StrutStyle* instance = reinterpret_cast(static_cast(ptr)); instance->setHalfLeading(value); } + +extern "C" JNIEXPORT jfloat JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nGetTopRatio + (JNIEnv* env, jclass jclass, jlong ptr) { + StrutStyle* instance = reinterpret_cast(static_cast(ptr)); + return instance->getTopRatio(); +} + +extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nSetTopRatio + (JNIEnv* env, jclass jclass, jlong ptr, jfloat value) { + StrutStyle* instance = reinterpret_cast(static_cast(ptr)); + instance->setTopRatio(value); +} diff --git a/skiko/src/jvmMain/cpp/common/paragraph/TextStyle.cc b/skiko/src/jvmMain/cpp/common/paragraph/TextStyle.cc index 791126593..222e3e0d0 100644 --- a/skiko/src/jvmMain/cpp/common/paragraph/TextStyle.cc +++ b/skiko/src/jvmMain/cpp/common/paragraph/TextStyle.cc @@ -257,6 +257,18 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_TextStyleKt_ instance->setHalfLeading(value); } +extern "C" JNIEXPORT jfloat JNICALL Java_org_jetbrains_skia_paragraph_TextStyleKt_TextStyle_1nGetTopRatio + (JNIEnv* env, jclass jclass, jlong ptr) { + TextStyle* instance = reinterpret_cast(static_cast(ptr)); + return instance->getTopRatio(); +} + +extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_TextStyleKt_TextStyle_1nSetTopRatio + (JNIEnv* env, jclass jclass, jlong ptr, jfloat value) { + TextStyle* instance = reinterpret_cast(static_cast(ptr)); + instance->setTopRatio(value); +} + extern "C" JNIEXPORT jfloat JNICALL Java_org_jetbrains_skia_paragraph_TextStyleKt_TextStyle_1nGetBaselineShift (JNIEnv* env, jclass jclass, jlong ptr) { TextStyle* instance = reinterpret_cast(static_cast(ptr)); diff --git a/skiko/src/nativeJsMain/cpp/paragraph/StrutStyle.cc b/skiko/src/nativeJsMain/cpp/paragraph/StrutStyle.cc index 7776521b7..17389d2f0 100644 --- a/skiko/src/nativeJsMain/cpp/paragraph/StrutStyle.cc +++ b/skiko/src/nativeJsMain/cpp/paragraph/StrutStyle.cc @@ -145,3 +145,15 @@ SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHalfLeading StrutStyle* instance = reinterpret_cast(ptr); instance->setHalfLeading(value); } + +SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetTopRatio + (KNativePointer ptr) { + StrutStyle* instance = reinterpret_cast(ptr); + return instance->getTopRatio(); +} + +SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetTopRatio + (KNativePointer ptr, KFloat topRatio) { + StrutStyle* instance = reinterpret_cast(ptr); + instance->setTopRatio(topRatio); +} diff --git a/skiko/src/nativeJsMain/cpp/paragraph/TextStyle.cc b/skiko/src/nativeJsMain/cpp/paragraph/TextStyle.cc index 4f396e9bd..52969ac1f 100644 --- a/skiko/src/nativeJsMain/cpp/paragraph/TextStyle.cc +++ b/skiko/src/nativeJsMain/cpp/paragraph/TextStyle.cc @@ -255,6 +255,18 @@ SKIKO_EXPORT void org_jetbrains_skia_paragraph_TextStyle__1nSetHalfLeading instance->setHalfLeading(halfLeading); } +SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_TextStyle__1nGetTopRatio + (KNativePointer ptr) { + TextStyle* instance = reinterpret_cast(ptr); + return instance->getTopRatio(); +} + +SKIKO_EXPORT void org_jetbrains_skia_paragraph_TextStyle__1nSetTopRatio + (KNativePointer ptr, KFloat topRatio) { + TextStyle* instance = reinterpret_cast(ptr); + instance->setTopRatio(topRatio); +} + SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_TextStyle__1nGetBaselineShift (KNativePointer ptr) { TextStyle* instance = reinterpret_cast(ptr);