Unverified Commit fa2f2af4 authored by Shagen Ogandzhanian's avatar Shagen Ogandzhanian Committed by GitHub

Commonize setting fontStyle in StrutStyle (#359)

* Remove rednundant braces

* Introduce StruStyleTests

* StrutStyle.fontStyle commonized

* Setting fontStyle in StrutStyle
parent 8dee13dc
......@@ -7,8 +7,10 @@ import org.jetbrains.skia.impl.Native
import org.jetbrains.skia.impl.Stats
import org.jetbrains.skia.impl.reachabilityBarrier
import org.jetbrains.skia.ExternalSymbolName
import org.jetbrains.skia.impl.InteropPointer
import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.impl.getPtr
import org.jetbrains.skia.impl.withResult
class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHolder.PTR) {
companion object {
......@@ -48,7 +50,10 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali
var fontStyle: FontStyle
get() = try {
Stats.onNativeCall()
FontStyle(_nGetFontStyle(_ptr))
val fontStyleData = withResult(IntArray(3)) {
_nGetFontStyle(_ptr, it)
}
FontStyle(fontStyleData[0], fontStyleData[1], FontSlant.values()[fontStyleData[2]])
} finally {
reachabilityBarrier(this)
}
......@@ -195,7 +200,7 @@ private external fun _nGetFontFamilies(ptr: NativePointer): Array<String>
private external fun _nSetFontFamilies(ptr: NativePointer, families: Array<String?>?)
@ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle")
private external fun _nGetFontStyle(ptr: NativePointer): Int
private external fun _nGetFontStyle(ptr: NativePointer, fontStyleData: InteropPointer): Int
@ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle")
private external fun _nSetFontStyle(ptr: NativePointer, value: Int)
......
package org.jetbrains.skia
import org.jetbrains.skia.impl.use
import org.jetbrains.skia.paragraph.StrutStyle
import kotlin.test.Test
import kotlin.test.assertEquals
class StrutStyleTests {
@Test
fun strutStyleTest() {
StrutStyle().use { strutStyle ->
assertEquals(FontStyle(400, 5, FontSlant.UPRIGHT), strutStyle.fontStyle)
strutStyle.fontStyle = FontStyle(300, 4, FontSlant.ITALIC)
assertEquals(FontStyle(300, 4, FontSlant.ITALIC), strutStyle.fontStyle)
}
}
}
\ No newline at end of file
......@@ -42,10 +42,12 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt
instance->setFontFamilies(skStringVector(env, familiesArr));
}
extern "C" JNIEXPORT jint JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nGetFontStyle
(JNIEnv* env, jclass jclass, jlong ptr) {
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nGetFontStyle
(JNIEnv* env, jclass jclass, jlong ptr, jintArray fontStyleData) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>(static_cast<uintptr_t>(ptr));
return skija::FontStyle::toJava(instance->getFontStyle());
SkFontStyle fontStyle = instance->getFontStyle();
jint res[3] = { fontStyle.weight(), fontStyle.width(), fontStyle.slant() };
env->SetIntArrayRegion(fontStyleData, 0, 3, res);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nSetFontStyle
......
......@@ -14,7 +14,7 @@ static void deleteStrutStyle(StrutStyle* instance) {
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_StrutStyle__1nGetFinalizer
() {
return reinterpret_cast<KNativePointer>((&deleteStrutStyle));
return reinterpret_cast<KNativePointer>(&deleteStrutStyle);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_StrutStyle__1nMake
......@@ -25,8 +25,8 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_StrutStyle__1nMake
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nEquals
(KNativePointer ptr, KNativePointer otherPtr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* other = reinterpret_cast<StrutStyle*>((otherPtr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
StrutStyle* other = reinterpret_cast<StrutStyle*>(otherPtr);
return *instance == *other;
}
......@@ -54,110 +54,96 @@ SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies
#if 0
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies
(KNativePointer ptr, KInteropPointerArray familiesArr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setFontFamilies(skStringVector(env, familiesArr));
}
#endif
SKIKO_EXPORT KInt org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle
(KNativePointer ptr) {
TODO("implement org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle");
}
#if 0
SKIKO_EXPORT KInt org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
return skija::FontStyle::toJava(instance->getFontStyle());
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle
(KNativePointer ptr, KInt* fontStyleData) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
SkFontStyle fontStyle = instance->getFontStyle();
fontStyleData[0] = fontStyle.weight();
fontStyleData[1] = fontStyle.width();
fontStyleData[2] = fontStyle.slant();
}
#endif
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle
(KNativePointer ptr, KInt style) {
TODO("implement org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle");
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setFontStyle(skija::FontStyle::fromKotlin(style));
}
#if 0
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle
(KNativePointer ptr, KInt style) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
instance->setFontStyle(skija::FontStyle::fromJava(style));
}
#endif
SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetFontSize
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getFontSize();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontSize
(KNativePointer ptr, KFloat size) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setFontSize(size);
}
SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetHeight
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getHeight();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeight
(KNativePointer ptr, KFloat height) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setHeight(height);
}
SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetLeading
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getLeading();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetLeading
(KNativePointer ptr, KFloat leading) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setLeading(leading);
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsEnabled
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getStrutEnabled();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetEnabled
(KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setStrutEnabled(value);
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightForced
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getForceStrutHeight();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightForced
(KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setForceStrutHeight(value);
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightOverridden
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getHeightOverride();
}
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightOverridden
(KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setHeightOverride(value);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment