@@ -9,10 +9,14 @@ extern "C" {
99
1010#include < android/native_window.h>
1111#include < android/native_window_jni.h>
12+ #include < android/bitmap.h>
1213#include < utils/Mutex.h>
1314using namespace android ;
1415
16+
1517#include < fpdfview.h>
18+ #include < fpdfdoc.h>
19+ #include < fpdftext.h>
1620
1721
1822static Mutex sLibraryLock ;
@@ -255,4 +259,135 @@ JNI_FUNC(void, PdfiumCore, nativeRenderPage)(JNI_ARGS, jlong pagePtr, jobject ob
255259 ANativeWindow_release (nativeWindow);
256260}
257261
262+
263+ // Text Module API
264+
265+ JNI_FUNC (jint*, PdfiumCore, textLoadPage)(JNI_ARGS, jlong pagePtr){
266+ FPDF_PAGE page = reinterpret_cast <FPDF_PAGE>(pagePtr);
267+ return (jint*)FPDFText_LoadPage (page);
268+ }
269+
270+ JNI_FUNC (void , PdfiumCore, textClosePage)(JNI_ARGS, jint textpage){
271+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textpage);
272+ FPDFText_ClosePage (pTextPage);
273+ }
274+
275+ JNI_FUNC (jint*, PdfiumCore, textFindStart)(JNI_ARGS, jint textpage, jstring findwhat, jlong flag, jint startindex){
276+
277+ int length = env->GetStringLength (findwhat);
278+ const FPDF_WCHAR* wcFind = env->GetStringChars (findwhat, 0 );
279+
280+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textpage);
281+ FPDF_SCHHANDLE searchHandle = NULL ;
282+ LOGI (" wcFind is %x %x %x %x" ,wcFind[0 ],wcFind[1 ],wcFind[2 ],wcFind[3 ]);
283+
284+ searchHandle = FPDFText_FindStart (pTextPage,(FPDF_WCHAR*)wcFind, flag, startindex);
285+
286+ if (searchHandle == NULL ){
287+ LOGE (" FPDFTextFindStart: FPDFTextFindStart did not return success" );
288+ }
289+
290+ return (jint*)searchHandle;
291+ }
292+
293+ JNI_FUNC (jint, PdfiumCore, textFindNext)(JNI_ARGS, jint searchHandle){
294+
295+ FPDF_SCHHANDLE pSearchHandle = reinterpret_cast <FPDF_SCHHANDLE>(searchHandle);
296+ FPDF_BOOL isMatch = 0 ;
297+ isMatch = FPDFText_FindNext (pSearchHandle);
298+ LOGD (" FPDFText_FindNext Match is %x" ,isMatch);
299+ return isMatch;
300+ }
301+
302+ // TODO: incomplete
303+ JNI_FUNC (jstring, PdfiumCore, textGetText)(JNI_ARGS, jint textpage, jint nStart, jint nCount){
304+
305+ FPDF_DWORD bufflen = 0 ;
306+
307+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textpage);
308+
309+ // TODO: How to fix this ????
310+ FPDF_WCHAR* pBuff = new FPDF_WCHAR[bufflen+1 ];
311+ pBuff[bufflen] = 0 ;
312+
313+ int ret = FPDFText_GetText (pTextPage, nStart, nCount, pBuff);
314+
315+ if (ret == 0 ){
316+ LOGE (" FPDFTextGetText: FPDFTextGetText did not return success" );
317+ }
318+
319+ return env->NewString (pBuff, bufflen);
320+ }
321+
322+ JNI_FUNC (jint, PdfiumCore, textCountChars)(JNI_ARGS, jint textPage){
323+
324+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textPage);
325+ int count = 0 ;
326+ count = FPDFText_CountChars (pTextPage);
327+ return count;
328+ }
329+
330+ JNI_FUNC (jint, PdfiumCore, textCountRects)(JNI_ARGS, jint textPage, jint start, jint count){
331+
332+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textPage);
333+ int rectCount = 0 ;
334+ rectCount = FPDFText_CountRects (pTextPage, start, count);
335+ return rectCount;
336+ }
337+
338+
339+ JNI_FUNC (jobject, PdfiumCore, textGetRect)(JNI_ARGS, jint textpage, jint index){
340+
341+ jclass cls_r;
342+ double rectLeft, rectTop, rectRight, rectBottom;
343+ FPDF_TEXTPAGE pTextPage = reinterpret_cast <FPDF_TEXTPAGE>(textpage);
344+
345+ FPDFText_GetRect (pTextPage, index, &rectLeft, &rectTop, &rectRight, &rectBottom);
346+
347+ // get android RectF
348+ cls_r = env->FindClass ((const char *)" android/graphics/RectF" );
349+ if (cls_r == NULL ){
350+ return NULL ;
351+ }
352+
353+ jobject obj = env->AllocObject (cls_r);
354+ jfieldID left = env->GetFieldID ( cls_r, (const char *)" left" , " F" );
355+ jfieldID right = env->GetFieldID (cls_r, (const char *)" right" , " F" );
356+ jfieldID top = env->GetFieldID (cls_r, (const char *)" top" , " F" );
357+ jfieldID bottom = env->GetFieldID ( cls_r, (const char *)" bottom" , " F" );
358+
359+ env->SetFloatField ( obj, left, rectLeft);
360+ env->SetFloatField ( obj, right, rectRight);
361+ env->SetFloatField ( obj, top, rectTop);
362+ env->SetFloatField ( obj, bottom, rectBottom);
363+ return obj;
364+ }
365+
366+ JNI_FUNC (jint, PdfiumCore, textGetSchResultIndex)(JNI_ARGS, jint searchHandle){
367+ FPDF_SCHHANDLE pSearchHandle = reinterpret_cast <FPDF_SCHHANDLE>(searchHandle);
368+ int index = -1 ;
369+ index = FPDFText_GetSchResultIndex (pSearchHandle);
370+ if (index == -1 ){
371+ LOGE (" FPDFTextGetSchResultIndex: FPDFTextGetSchResultIndex did not return success" );
372+ }
373+ return index;
374+ }
375+
376+ JNI_FUNC (jint, PdfiumCore, textGetSchCount)(JNI_ARGS, jint searchHandle){
377+ FPDF_SCHHANDLE pSearchHandle = reinterpret_cast <FPDF_SCHHANDLE>(searchHandle);
378+ int count = -1 ;
379+ count = FPDFText_GetSchCount (pSearchHandle);
380+ if (count == -1 ){
381+ LOGE (" FPDFTextGetSchCount: FPDFTextGetSchCount did not return success" );
382+ }
383+ return count;
384+ }
385+
386+ JNI_FUNC (void , PdfiumCore, textFindClose)(JNI_ARGS, jint searchHandle){
387+ FPDF_SCHHANDLE pSearchHandle = reinterpret_cast <FPDF_SCHHANDLE>(searchHandle);
388+ FPDFText_FindClose (pSearchHandle);
389+ }
390+
391+
392+
258393}// extern C
0 commit comments