Unverified Commit bfc11b6a authored by Igor Demin's avatar Igor Demin Committed by GitHub

The previous fix was wrong, we don't fill all indices of the array (#412)

Fixes https://github.com/JetBrains/compose-jb/issues/1308#issuecomment-981139635
parent cb5c72a7
...@@ -115,7 +115,13 @@ class ParagraphTest { ...@@ -115,7 +115,13 @@ class ParagraphTest {
it.build() it.build()
}.layout(Float.POSITIVE_INFINITY) }.layout(Float.POSITIVE_INFINITY)
para.getRectsForRange(2, 8, RectHeightMode.MAX, RectWidthMode.MAX) val rects = para.getRectsForRange(2, 8, RectHeightMode.MAX, RectWidthMode.MAX)
for (rect in rects) {
rect.rect.left
rect.rect.right
rect.rect.top
rect.rect.bottom
}
} }
} }
} }
\ No newline at end of file
...@@ -82,15 +82,20 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_ParagraphKt_ ...@@ -82,15 +82,20 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_paragraph_ParagraphKt_
extern "C" JNIEXPORT jobjectArray JNICALL Java_org_jetbrains_skia_paragraph_ParagraphKt__1nGetRectsForRange extern "C" JNIEXPORT jobjectArray JNICALL Java_org_jetbrains_skia_paragraph_ParagraphKt__1nGetRectsForRange
(JNIEnv* env, jclass jclass, jlong ptr, jint start, jint end, jint rectHeightStyle, jint rectWidthStyle) { (JNIEnv* env, jclass jclass, jlong ptr, jint start, jint end, jint rectHeightStyle, jint rectWidthStyle) {
Paragraph* instance = reinterpret_cast<Paragraph*>(static_cast<uintptr_t>(ptr)); Paragraph* instance = reinterpret_cast<Paragraph*>(static_cast<uintptr_t>(ptr));
std::vector<TextBox> rects = instance->getRectsForRange(start, end, static_cast<RectHeightStyle>(rectHeightStyle), static_cast<RectWidthStyle>(rectWidthStyle)); std::vector<TextBox> originalRects = instance->getRectsForRange(start, end, static_cast<RectHeightStyle>(rectHeightStyle), static_cast<RectWidthStyle>(rectWidthStyle));
jobjectArray rectsArray = env->NewObjectArray((jsize) rects.size(), skija::paragraph::TextBox::cls, nullptr); std::vector<TextBox> rects;
for (int i = 0; i < rects.size(); ++i) { for (TextBox& box : originalRects) {
TextBox box = rects[i];
// TODO fix https://github.com/JetBrains/compose-jb/issues/1308 another way, we just masking the issue // TODO fix https://github.com/JetBrains/compose-jb/issues/1308 another way, we just masking the issue
// (but experiments show, that the result of GetRectsForRange is correct after that) // (but experiments show, that the result of GetRectsForRange is correct after that)
if (isnan(box.rect.fLeft) || isnan(box.rect.fTop) || isnan(box.rect.fRight) || isnan(box.rect.fBottom)) { if (isnan(box.rect.fLeft) || isnan(box.rect.fTop) || isnan(box.rect.fRight) || isnan(box.rect.fBottom)) {
continue; continue;
} }
rects.push_back(box);
}
jobjectArray rectsArray = env->NewObjectArray((jsize) rects.size(), skija::paragraph::TextBox::cls, nullptr);
for (int i = 0; i < rects.size(); ++i) {
TextBox box = rects[i];
jobject boxObj = env->NewObject(skija::paragraph::TextBox::cls, skija::paragraph::TextBox::ctor, box.rect.fLeft, box.rect.fTop, box.rect.fRight, box.rect.fBottom, static_cast<jint>(box.direction)); jobject boxObj = env->NewObject(skija::paragraph::TextBox::cls, skija::paragraph::TextBox::ctor, box.rect.fLeft, box.rect.fTop, box.rect.fRight, box.rect.fBottom, static_cast<jint>(box.direction));
env->SetObjectArrayElement(rectsArray, i, boxObj); env->SetObjectArrayElement(rectsArray, i, boxObj);
env->DeleteLocalRef(boxObj); env->DeleteLocalRef(boxObj);
......
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