diff --git a/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp b/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp index 73358ca29..a0b45c9bd 100644 --- a/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp +++ b/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp @@ -84,6 +84,23 @@ jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetSymbo return ret; } +jboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtBeginningOf(JNIEnv *env, + jclass clazz, jlong nativeResultIterator, jint level) { + ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; + PageIteratorLevel enumLevel = (PageIteratorLevel) level; + + return (jboolean) (resultIterator->IsAtBeginningOf(enumLevel) ? JNI_TRUE : JNI_FALSE); +} + +jboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtFinalElement(JNIEnv *env, + jclass clazz, jlong nativeResultIterator, jint level, jint element) { + ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; + PageIteratorLevel enumLevel = (PageIteratorLevel) level; + PageIteratorLevel enumElement = (PageIteratorLevel) element; + + return (jboolean) (resultIterator->IsAtFinalElement(enumLevel, enumElement) ? JNI_TRUE : JNI_FALSE); +} + void Java_com_googlecode_tesseract_android_ResultIterator_nativeDelete(JNIEnv *env, jclass clazz, jlong nativeResultIterator) { ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; diff --git a/tess-two/src/com/googlecode/tesseract/android/ResultIterator.java b/tess-two/src/com/googlecode/tesseract/android/ResultIterator.java index b44d2b002..3ffcedac7 100644 --- a/tess-two/src/com/googlecode/tesseract/android/ResultIterator.java +++ b/tess-two/src/com/googlecode/tesseract/android/ResultIterator.java @@ -69,6 +69,30 @@ public float confidence(int level) { return nativeConfidence(mNativeResultIterator, level); } + /** + * Returns true if the iterator is at the start of an object at the given + * level. Possible uses include determining if a call to Next(RIL_WORD) + * moved to the start of a RIL_PARA. + * + * @param level the page iterator level. See {@link PageIteratorLevel}. + * @return {@code true} if iterator points to the start of an object at the given level. + */ + public boolean isAtBeginningOf(int level) { + return nativeIsAtBeginningOf(mNativeResultIterator, level); + } + + /** + * Returns whether the iterator is positioned at the last element in a + * given level. (e.g. the last word in a line, the last line in a block) + * + * @param level the page iterator level. See {@link PageIteratorLevel}. + * @param element the page iterator level. See {@link PageIteratorLevel}. + * @return {@code true} if iterator points to the last element in a given level. + */ + public boolean isAtFinalElement(int level, int element) { + return nativeIsAtFinalElement(mNativeResultIterator, level, element); + } + /** * Returns all possible matching text strings and their confidence level * for the current object at the given level. @@ -124,5 +148,7 @@ public void delete() { private static native String nativeGetUTF8Text(long nativeResultIterator, int level); private static native float nativeConfidence(long nativeResultIterator, int level); + private static native boolean nativeIsAtBeginningOf(long nativeResultIterator, int level); + private static native boolean nativeIsAtFinalElement(long nativeResultIterator, int level, int element); private static native void nativeDelete(long nativeIterator); }