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 ...@@ -7,8 +7,10 @@ import org.jetbrains.skia.impl.Native
import org.jetbrains.skia.impl.Stats import org.jetbrains.skia.impl.Stats
import org.jetbrains.skia.impl.reachabilityBarrier import org.jetbrains.skia.impl.reachabilityBarrier
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
import org.jetbrains.skia.impl.InteropPointer
import org.jetbrains.skia.impl.NativePointer import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.impl.getPtr import org.jetbrains.skia.impl.getPtr
import org.jetbrains.skia.impl.withResult
class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHolder.PTR) { class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHolder.PTR) {
companion object { companion object {
...@@ -48,7 +50,10 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali ...@@ -48,7 +50,10 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali
var fontStyle: FontStyle var fontStyle: FontStyle
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
FontStyle(_nGetFontStyle(_ptr)) val fontStyleData = withResult(IntArray(3)) {
_nGetFontStyle(_ptr, it)
}
FontStyle(fontStyleData[0], fontStyleData[1], FontSlant.values()[fontStyleData[2]])
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
...@@ -195,7 +200,7 @@ private external fun _nGetFontFamilies(ptr: NativePointer): Array<String> ...@@ -195,7 +200,7 @@ private external fun _nGetFontFamilies(ptr: NativePointer): Array<String>
private external fun _nSetFontFamilies(ptr: NativePointer, families: Array<String?>?) private external fun _nSetFontFamilies(ptr: NativePointer, families: Array<String?>?)
@ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle") @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") @ExternalSymbolName("org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle")
private external fun _nSetFontStyle(ptr: NativePointer, value: Int) 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 ...@@ -42,10 +42,12 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt
instance->setFontFamilies(skStringVector(env, familiesArr)); instance->setFontFamilies(skStringVector(env, familiesArr));
} }
extern "C" JNIEXPORT jint JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nGetFontStyle extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nGetFontStyle
(JNIEnv* env, jclass jclass, jlong ptr) { (JNIEnv* env, jclass jclass, jlong ptr, jintArray fontStyleData) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>(static_cast<uintptr_t>(ptr)); 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 extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_StrutStyleKt__1nSetFontStyle
......
...@@ -14,7 +14,7 @@ static void deleteStrutStyle(StrutStyle* instance) { ...@@ -14,7 +14,7 @@ static void deleteStrutStyle(StrutStyle* instance) {
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_StrutStyle__1nGetFinalizer 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 SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_StrutStyle__1nMake
...@@ -25,8 +25,8 @@ 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 SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nEquals
(KNativePointer ptr, KNativePointer otherPtr) { (KNativePointer ptr, KNativePointer otherPtr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
StrutStyle* other = reinterpret_cast<StrutStyle*>((otherPtr)); StrutStyle* other = reinterpret_cast<StrutStyle*>(otherPtr);
return *instance == *other; return *instance == *other;
} }
...@@ -54,110 +54,96 @@ SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies ...@@ -54,110 +54,96 @@ SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies
#if 0 #if 0
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontFamilies
(KNativePointer ptr, KInteropPointerArray familiesArr) { (KNativePointer ptr, KInteropPointerArray familiesArr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setFontFamilies(skStringVector(env, familiesArr)); instance->setFontFamilies(skStringVector(env, familiesArr));
} }
#endif #endif
SKIKO_EXPORT KInt org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle
(KNativePointer ptr) { (KNativePointer ptr, KInt* fontStyleData) {
TODO("implement org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle"); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
} SkFontStyle fontStyle = instance->getFontStyle();
fontStyleData[0] = fontStyle.weight();
#if 0 fontStyleData[1] = fontStyle.width();
SKIKO_EXPORT KInt org_jetbrains_skia_paragraph_StrutStyle__1nGetFontStyle fontStyleData[2] = fontStyle.slant();
(KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr));
return skija::FontStyle::toJava(instance->getFontStyle());
} }
#endif
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontStyle
(KNativePointer ptr, KInt style) { (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 SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetFontSize
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getFontSize(); return instance->getFontSize();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontSize SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetFontSize
(KNativePointer ptr, KFloat size) { (KNativePointer ptr, KFloat size) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setFontSize(size); instance->setFontSize(size);
} }
SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetHeight SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetHeight
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getHeight(); return instance->getHeight();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeight SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeight
(KNativePointer ptr, KFloat height) { (KNativePointer ptr, KFloat height) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setHeight(height); instance->setHeight(height);
} }
SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetLeading SKIKO_EXPORT KFloat org_jetbrains_skia_paragraph_StrutStyle__1nGetLeading
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getLeading(); return instance->getLeading();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetLeading SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetLeading
(KNativePointer ptr, KFloat leading) { (KNativePointer ptr, KFloat leading) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setLeading(leading); instance->setLeading(leading);
} }
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsEnabled SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsEnabled
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getStrutEnabled(); return instance->getStrutEnabled();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetEnabled SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetEnabled
(KNativePointer ptr, KBoolean value) { (KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setStrutEnabled(value); instance->setStrutEnabled(value);
} }
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightForced SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightForced
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getForceStrutHeight(); return instance->getForceStrutHeight();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightForced SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightForced
(KNativePointer ptr, KBoolean value) { (KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setForceStrutHeight(value); instance->setForceStrutHeight(value);
} }
SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightOverridden SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_StrutStyle__1nIsHeightOverridden
(KNativePointer ptr) { (KNativePointer ptr) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
return instance->getHeightOverride(); return instance->getHeightOverride();
} }
SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightOverridden SKIKO_EXPORT void org_jetbrains_skia_paragraph_StrutStyle__1nSetHeightOverridden
(KNativePointer ptr, KBoolean value) { (KNativePointer ptr, KBoolean value) {
StrutStyle* instance = reinterpret_cast<StrutStyle*>((ptr)); StrutStyle* instance = reinterpret_cast<StrutStyle*>(ptr);
instance->setHeightOverride(value); 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