Skip to content

Commit

Permalink
turn off flutter hack by default, implement methods to control it
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeevPavel committed Oct 28, 2024
1 parent bbfaf62 commit 576ae8f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
reachabilityBarrier(this)
}

var isApplyRoundingHackEnabled: Boolean
get() = try {
Stats.onNativeCall()
_nGetApplyRoundingHack(_ptr)
} finally {
reachabilityBarrier(this)
}
set(value) = try {
Stats.onNativeCall()
_nSetApplyRoundingHack(_ptr, value)
} finally {
reachabilityBarrier(this)
}

var textIndent: TextIndent
get() = try {
Expand Down Expand Up @@ -322,6 +335,14 @@ private external fun _nGetHinting(ptr: NativePointer): Int
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_ParagraphStyle__1nGetSubpixel")
private external fun _nGetSubpixel(ptr: NativePointer): Boolean

@ExternalSymbolName("org_jetbrains_skia_paragraph_ParagraphStyle__1nGetApplyRoundingHack")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_ParagraphStyle__1nGetApplyRoundingHack")
private external fun _nGetApplyRoundingHack(ptr: NativePointer): Boolean

@ExternalSymbolName("org_jetbrains_skia_paragraph_ParagraphStyle__1nSetApplyRoundingHack")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_ParagraphStyle__1nSetApplyRoundingHack")
private external fun _nSetApplyRoundingHack(ptr: NativePointer, value: Boolean)

@ExternalSymbolName("org_jetbrains_skia_paragraph_ParagraphStyle__1nSetTextIndent")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_paragraph_ParagraphStyle__1nSetTextIndent")
private external fun _nSetTextIndent(ptr: NativePointer, firstLine: Float, restLine: Float)
Expand Down
19 changes: 11 additions & 8 deletions skiko/src/commonTest/kotlin/org/jetbrains/skia/ParagraphTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,40 @@ class ParagraphTest {
val lineMetricsEpsilon = 0.0001f

assertCloseEnough(
singleLineMetrics("aa"), LineMetrics(
actual = singleLineMetrics("aa"),
expected = LineMetrics(
startIndex = 0,
endIndex = 2,
endExcludingWhitespaces = 2,
endIncludingNewline = 2,
isHardBreak = true,
ascent = 13.5625,
descent = 3.3806817531585693,
descent = 3.380584716796875,
unscaledAscent = 13.5625,
height = 17.0,
width = 15.789999961853027,
width = 15.789764404296875,
left = 0.0,
baseline = 13.619318008422852,
baseline = 13.619415283203125,
lineNumber = 0
), epsilon = lineMetricsEpsilon
)


assertCloseEnough(
singleLineMetrics("яя"), LineMetrics(
actual = singleLineMetrics("яя"),
expected = LineMetrics(
startIndex = 0,
endIndex = 2,
endExcludingWhitespaces = 2,
endIncludingNewline = 2,
isHardBreak = true,
ascent = 13.5625,
descent = 3.3806817531585693,
descent = 3.380584716796875,
unscaledAscent = 13.5625,
height = 17.0,
width = 15.710000038146973,
width = 15.710235595703125,
left = 0.0,
baseline = 13.619318008422852,
baseline = 13.619415283203125,
lineNumber = 0
), epsilon = lineMetricsEpsilon
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ class ParagraphStyleTests {
assertEquals(gloriousRasterSettings, paragraphStyle.fontRastrSettings)
}
}

@Test
fun paragraphStyleRoundingHackTests() {
ParagraphStyle().use { paragraphStyle ->
assertEquals(false, paragraphStyle.isApplyRoundingHackEnabled)
paragraphStyle.isApplyRoundingHackEnabled = true
assertEquals(true, paragraphStyle.isApplyRoundingHackEnabled)
}
}
}
13 changes: 13 additions & 0 deletions skiko/src/jvmMain/cpp/common/paragraph/ParagraphStyle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_ParagraphSt
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_ParagraphStyleKt_ParagraphStyle_1nMake
(JNIEnv* env, jclass jclass) {
ParagraphStyle* instance = new ParagraphStyle();
instance->setApplyRoundingHack(false);
return reinterpret_cast<jlong>(instance);
}

Expand Down Expand Up @@ -180,6 +181,18 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_ParagraphSty
instance->turnHintingOff();
}

extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_paragraph_ParagraphStyleKt__1nGetApplyRoundingHack
(JNIEnv* env, jclass jclass, jlong ptr) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>(static_cast<uintptr_t>(ptr));
return instance->getApplyRoundingHack();
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_ParagraphStyleKt__1nSetApplyRoundingHack
(JNIEnv* env, jclass jclass, jlong ptr, jboolean val) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>(static_cast<uintptr_t>(ptr));
instance->setApplyRoundingHack(val);
}

extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_ParagraphStyleKt__1nSetTextIndent
(JNIEnv* env, jclass jclass, jlong ptr, jfloat firstLine, jfloat restLine) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>(static_cast<uintptr_t>(ptr));
Expand Down
13 changes: 13 additions & 0 deletions skiko/src/nativeJsMain/cpp/paragraph/ParagraphStyle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_ParagraphStyle__1nGetFi
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_ParagraphStyle__1nMake
() {
ParagraphStyle* instance = new ParagraphStyle();
instance->setApplyRoundingHack(false);
return reinterpret_cast<KNativePointer>(instance);
}

Expand Down Expand Up @@ -177,6 +178,18 @@ SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_ParagraphStyle__1nGetSubpixel
return fontRastrSettings.fSubpixel;
}

SKIKO_EXPORT KBoolean org_jetbrains_skia_paragraph_ParagraphStyle__1nGetApplyRoundingHack
(KNativePointer ptr) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>(ptr);
return instance->getApplyRoundingHack();
}

SKIKO_EXPORT void org_jetbrains_skia_paragraph_ParagraphStyle__1nSetApplyRoundingHack
(KNativePointer ptr, KBoolean val) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>(ptr);
instance->setApplyRoundingHack(val);
}

SKIKO_EXPORT void org_jetbrains_skia_paragraph_ParagraphStyle__1nSetTextIndent
(KNativePointer ptr, KFloat firstLine, KFloat restLine) {
ParagraphStyle* instance = reinterpret_cast<ParagraphStyle*>((ptr));
Expand Down

0 comments on commit 576ae8f

Please sign in to comment.