Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
ResultIterator: Add IsAtBeginningOf and IsAtFinalElement methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Robyer committed May 11, 2017
1 parent 506d004 commit 56203ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions tess-two/src/com/googlecode/tesseract/android/ResultIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

0 comments on commit 56203ad

Please sign in to comment.