pageiterator.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2011, Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stdio.h>
  17. #include "common.h"
  18. #include "pageiterator.h"
  19. #include "allheaders.h"
  20. #include "helpers.h"
  21. #include "pageres.h"
  22. #include "tesseractclass.h"
  23. using namespace tesseract;
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /* __cplusplus */
  27. void Java_com_googlecode_tesseract_android_PageIterator_nativeBegin(JNIEnv *env, jclass clazz,
  28. jlong nativePageIterator) {
  29. ((PageIterator *) nativePageIterator)->Begin();
  30. }
  31. jboolean Java_com_googlecode_tesseract_android_PageIterator_nativeNext(JNIEnv *env, jclass clazz,
  32. jlong nativePageIterator, jint level) {
  33. PageIterator *pageIterator = (PageIterator *) nativePageIterator;
  34. PageIteratorLevel enumLevel = (PageIteratorLevel) level;
  35. return pageIterator->Next(enumLevel) ? JNI_TRUE : JNI_FALSE;
  36. }
  37. jintArray Java_com_googlecode_tesseract_android_PageIterator_nativeBoundingBox(JNIEnv *env, jclass clazz,
  38. jlong nativePageIterator, jint level) {
  39. int size = 4;
  40. jintArray result = env->NewIntArray(size);
  41. LOG_ASSERT((result != NULL), "Could not create Java bounding box array!");
  42. PageIterator *pageIterator = (PageIterator *) nativePageIterator;
  43. PageIteratorLevel enumLevel = (PageIteratorLevel) level;
  44. int x1, y1, x2, y2;
  45. pageIterator->BoundingBox(enumLevel, &x1, &y1, &x2, &y2);
  46. // fill a temp structure to use to populate the java int array
  47. jint fill[4];
  48. fill[0] = x1;
  49. fill[1] = y1;
  50. fill[2] = x2;
  51. fill[3] = y2;
  52. env->SetIntArrayRegion(result, 0, size, fill);
  53. return result;
  54. }
  55. #ifdef __cplusplus
  56. }
  57. #endif /* __cplusplus */