You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
android.text.Layout: convert byte index to character index
This fixes a WhatsApp crash when rendering text with emojis.
This commit is contained in:
@@ -53,7 +53,8 @@ JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1start(JNIEnv
|
|||||||
PangoLayoutIter *pango_iter = pango_layout_get_iter(pango_layout);
|
PangoLayoutIter *pango_iter = pango_layout_get_iter(pango_layout);
|
||||||
while (line--)
|
while (line--)
|
||||||
pango_layout_iter_next_line(pango_iter);
|
pango_layout_iter_next_line(pango_iter);
|
||||||
return pango_layout_iter_get_index(pango_iter);
|
int byte_index = pango_layout_iter_get_index(pango_iter);
|
||||||
|
return g_utf8_strlen(pango_layout_get_text(pango_layout), byte_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1end(JNIEnv *env, jobject object, jlong layout, jint line)
|
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1end(JNIEnv *env, jobject object, jlong layout, jint line)
|
||||||
@@ -63,7 +64,8 @@ JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1end(JNIEnv *e
|
|||||||
while (line--)
|
while (line--)
|
||||||
pango_layout_iter_next_line(pango_iter);
|
pango_layout_iter_next_line(pango_iter);
|
||||||
pango_layout_iter_next_line(pango_iter);
|
pango_layout_iter_next_line(pango_iter);
|
||||||
return pango_layout_iter_get_index(pango_iter);
|
int byte_index = pango_layout_iter_get_index(pango_iter);
|
||||||
|
return g_utf8_strlen(pango_layout_get_text(pango_layout), byte_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_line_extends(PangoLayout *pango_layout, int line, PangoRectangle *logical_rect) {
|
static void get_line_extends(PangoLayout *pango_layout, int line, PangoRectangle *logical_rect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user