mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-04-28 12:17:57 +03:00
fix Layout.getLineStart() / Layout.getLineEnd()
These methods are supposed to return the String index and not coordinates as accidently assumed when originally implementing it.
This commit is contained in:
parent
e72c579fd4
commit
506de2b807
3 changed files with 39 additions and 2 deletions
|
@ -47,6 +47,22 @@ JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1height
|
|||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1count
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_text_Layout
|
||||
* Method: native_get_line_start
|
||||
* Signature: (JI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1start
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: android_text_Layout
|
||||
* Method: native_get_line_end
|
||||
* Signature: (JI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1end
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: android_text_Layout
|
||||
* Method: native_get_line_top
|
||||
|
|
|
@ -47,6 +47,25 @@ JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1count(JNIEnv
|
|||
return pango_layout_get_line_count(pango_layout);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1start(JNIEnv *env, jobject object, jlong layout, jint line)
|
||||
{
|
||||
PangoLayout *pango_layout = _PTR(layout);
|
||||
PangoLayoutIter *pango_iter = pango_layout_get_iter(pango_layout);
|
||||
while (line--)
|
||||
pango_layout_iter_next_line(pango_iter);
|
||||
return pango_layout_iter_get_index(pango_iter);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_text_Layout_native_1get_1line_1end(JNIEnv *env, jobject object, jlong layout, jint line)
|
||||
{
|
||||
PangoLayout *pango_layout = _PTR(layout);
|
||||
PangoLayoutIter *pango_iter = pango_layout_get_iter(pango_layout);
|
||||
while (line--)
|
||||
pango_layout_iter_next_line(pango_iter);
|
||||
pango_layout_iter_next_line(pango_iter);
|
||||
return pango_layout_iter_get_index(pango_iter);
|
||||
}
|
||||
|
||||
static void get_line_extends(PangoLayout *pango_layout, int line, PangoRectangle *logical_rect) {
|
||||
PangoRectangle ink_rect;
|
||||
PangoLayoutIter *pango_iter = pango_layout_get_iter(pango_layout);
|
||||
|
|
|
@ -155,13 +155,13 @@ public class Layout {
|
|||
public int getLineStart(int line) {
|
||||
if (line < 0 || line >= getLineCount())
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
return native_get_line_left(layout, line);
|
||||
return native_get_line_start(layout, line);
|
||||
}
|
||||
|
||||
public int getLineEnd(int line) {
|
||||
if (line < 0 || line >= getLineCount())
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
return native_get_line_right(layout, line);
|
||||
return native_get_line_end(layout, line);
|
||||
}
|
||||
|
||||
public boolean isSpanned() {
|
||||
|
@ -238,6 +238,8 @@ public class Layout {
|
|||
protected native int native_get_width(long layout);
|
||||
protected native int native_get_height(long layout);
|
||||
protected native int native_get_line_count(long layout);
|
||||
protected native int native_get_line_start(long layout, int line);
|
||||
protected native int native_get_line_end(long layout, int line);
|
||||
protected native int native_get_line_top(long layout, int line);
|
||||
protected native int native_get_line_bottom(long layout, int line);
|
||||
protected native int native_get_line_left(long layout, int line);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue