Model::Page* Model::DjVuDocument::page(int index) const { QMutexLocker mutexLocker(&m_mutex); ddjvu_status_t status; ddjvu_pageinfo_t pageinfo; while(true) { status = ddjvu_document_get_pageinfo(m_document, index, &pageinfo); if(status < DDJVU_JOB_OK) { clearMessageQueue(m_context, true); } else { break; } } if(status >= DDJVU_JOB_FAILED) { return 0; } return new DjVuPage(this, index, pageinfo); }
static int openPage(lua_State *L) { ddjvu_status_t r; DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); int pageno = luaL_checkint(L, 2); if (pageno < 1 || pageno > ddjvu_document_get_pagenum(doc->doc_ref)) { return luaL_error(L, "cannot open page #%d, out of range (1-%d)", pageno, ddjvu_document_get_pagenum(doc->doc_ref)); } DjvuPage *page = (DjvuPage*) lua_newuserdata(L, sizeof(DjvuPage)); luaL_getmetatable(L, "djvupage"); lua_setmetatable(L, -2); /* djvulibre counts page starts from 0 */ page->page_ref = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1); if (! page->page_ref) return luaL_error(L, "cannot open page #%d", pageno); while (! ddjvu_page_decoding_done(page->page_ref)) handle(L, doc->context, TRUE); page->doc = doc; page->num = pageno; /* djvulibre counts page starts from 0 */ while((r=ddjvu_document_get_pageinfo(doc->doc_ref, pageno - 1, &(page->info)))<DDJVU_JOB_OK) handle(L, doc->context, TRUE); if (r>=DDJVU_JOB_FAILED) return luaL_error(L, "cannot get page #%d information", pageno); return 1; }
extern "C" jint Java_org_ebookdroid_droids_djvu_codec_DjvuDocument_getPageInfo(JNIEnv *env, jclass cls, jlong docHandle, jint pageNumber, jlong contextHandle, jobject cpi) { ddjvu_status_t r; ddjvu_pageinfo_t info; jclass clazz; jfieldID fid; while ((r = ddjvu_document_get_pageinfo((ddjvu_document_t*) docHandle, pageNumber, &info)) < DDJVU_JOB_OK) { waitAndHandleMessages(env, contextHandle); } CodecPageInfoHelper h(env); if (!h.valid) { return -1; } h.setSize(cpi, info.width, info.height); h.setDpi(cpi, info.dpi); h.setRotation(cpi, info.rotation); h.setVersion(cpi, info.version); return 0; }
JNIEXPORT void JNICALL Java_universe_constellation_orion_viewer_djvu_DjvuDocument_getPageInfo(JNIEnv *env, jobject thiz, int pageNum, jobject info) { clock_t start, end; start = clock(); /* ddjvu_page_t * mypage = ddjvu_page_create_by_pageno(doc, pageNum); int pageWidth = ddjvu_page_get_width(mypage); int pageHeight = ddjvu_page_get_height(mypage); //LOGI("mypage: %x", mypage); ddjvu_page_release(mypage); */ ddjvu_pageinfo_t dinfo; ddjvu_document_get_pageinfo(doc, pageNum, &dinfo); jclass cls = (*env)->GetObjectClass(env, info); jfieldID width = (*env)->GetFieldID(env, cls, "width", "I"); jfieldID height = (*env)->GetFieldID(env, cls, "height", "I"); (*env)->SetIntField(env, info, width, dinfo.width); (*env)->SetIntField(env, info, height, dinfo.height); end = clock(); LOGI("Page info get %lf s; page size = %ix%i", ((double) (end - start)) / CLOCKS_PER_SEC, dinfo.width, dinfo.height); }
zathura_error_t djvu_page_init(zathura_page_t* page, void* UNUSED(data)) { if (page == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } zathura_document_t* document = zathura_page_get_document(page); djvu_document_t* djvu_document = zathura_document_get_data(document); ddjvu_status_t status; ddjvu_pageinfo_t page_info; unsigned int index = zathura_page_get_index(page); while ((status = ddjvu_document_get_pageinfo(djvu_document->document, index, &page_info)) < DDJVU_JOB_OK) { handle_messages(djvu_document, true); } if (status >= DDJVU_JOB_FAILED) { handle_messages(djvu_document, true); return ZATHURA_ERROR_UNKNOWN; } zathura_page_set_width(page, ZATHURA_DJVU_SCALE * page_info.width); zathura_page_set_height(page, ZATHURA_DJVU_SCALE * page_info.height); return ZATHURA_ERROR_OK; }
jobject djvu_links_get_links(JNIEnv *jenv, ddjvu_document_t* djvu_document, int page) { DEBUG("djvu_links_get_links %d", page); miniexp_t page_annotations = miniexp_nil; miniexp_t *hyperlinks = NULL, *iter = NULL; ddjvu_pageinfo_t page_info; jobject arrayList = NULL; page_annotations = ddjvu_document_get_pageanno(djvu_document, page); ddjvu_document_get_pageinfo(djvu_document, page, &page_info); if (page_annotations) { hyperlinks = ddjvu_anno_get_hyperlinks(page_annotations); if (hyperlinks) { jclass arrayListClass = jenv->FindClass("java/util/ArrayList"); if (!arrayListClass) return arrayList; jmethodID alInitMethodId = jenv->GetMethodID(arrayListClass, "<init>", "()V"); if (!alInitMethodId) return arrayList; jmethodID alAddMethodId = jenv->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); if (!alAddMethodId) return arrayList; arrayList = jenv->NewObject(arrayListClass, alInitMethodId); if (!arrayList) return arrayList; for (iter = hyperlinks; *iter; ++iter) { jobject hl = get_djvu_hyperlink_mapping(jenv, djvu_document, &page_info, *iter); if (hl) jenv->CallBooleanMethod(arrayList, alAddMethodId, hl); //jenv->DeleteLocalRef(hl); } free(hyperlinks); } ddjvu_miniexp_release(djvu_document, page_annotations); } return arrayList; }
static int getOriginalPageSize(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); int pageno = luaL_checkint(L, 2); ddjvu_status_t r; ddjvu_pageinfo_t info; while ((r=ddjvu_document_get_pageinfo( doc->doc_ref, pageno-1, &info))<DDJVU_JOB_OK) { handle(L, doc->context, TRUE); } lua_pushnumber(L, info.width); lua_pushnumber(L, info.height); return 2; }
JNIEXPORT jstring JNICALL Java_universe_constellation_orion_viewer_djvu_DjvuDocument_getText(JNIEnv *env, jobject thiz, int pageNumber, int startX, int startY, int width, int height) { LOGI("==================Start Text Extraction=============="); miniexp_t pagetext; while ((pagetext=ddjvu_document_get_pagetext(doc,pageNumber,0))==miniexp_dummy) { //handle_ddjvu_messages(ctx, TRUE); } if (miniexp_nil == pagetext) { return NULL; } // ddjvu_status_t status; ddjvu_pageinfo_t info; while ((status = ddjvu_document_get_pageinfo(doc, pageNumber, &info)) < DDJVU_JOB_OK) { //nothing } LOGI("Extraction rectangle=[%d,%d,%d,%d]", startX, startY, width, height); Arraylist values = arraylist_create(); int w = info.width; int h = info.height; fz_bbox target = {startX, h - startY - height, startX + width, h - startY}; LOGI("Extraction irectangle=[%d,%d,%d,%d]", target.x0, target.y0, target.x1, target.y1); extractText(pagetext, values, &target); arraylist_add(values, 0); LOGI("Data: %s", arraylist_getData(values)); jstring result = (*env)->NewStringUTF(env, arraylist_getData(values)); arraylist_free(values); return result; }
JNIEXPORT jboolean JNICALL Java_universe_constellation_orion_viewer_djvu_DjvuDocument_getPageText(JNIEnv *env, jobject thiz, jint pageNumber, jobject stringBuilder, jobject positionList) { LOGI("Start Page Text Extraction %i", pageNumber); miniexp_t pagetext; while ((pagetext=ddjvu_document_get_pagetext(doc, pageNumber, "word"))==miniexp_dummy) { //handle_ddjvu_messages(ctx, TRUE); } if (pagetext == NULL) { LOGI("no text on page %i", pageNumber); return 0; } jclass listClass; jmethodID addToList; listClass = (*env)->FindClass(env, "java/util/ArrayList"); if (listClass == NULL) return 0; addToList = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z"); if (addToList == NULL) return 0; jclass rectFClass; jmethodID ctor; rectFClass = (*env)->FindClass(env, "android/graphics/RectF"); if (rectFClass == NULL) return 0; ctor = (*env)->GetMethodID(env, rectFClass, "<init>", "(FFFF)V"); if (ctor == NULL) return 0; int state = -1; ddjvu_pageinfo_t dinfo; ddjvu_document_get_pageinfo(doc, pageNumber, &dinfo); return miniexp_get_text(env, pagetext, stringBuilder, positionList, &state, rectFClass, ctor, addToList, dinfo.height); }
EvMappingList * djvu_links_get_links (EvDocumentLinks *document_links, gint page, double scale_factor) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document_links); GList *retval = NULL; miniexp_t page_annotations = miniexp_nil; miniexp_t *hyperlinks = NULL, *iter = NULL; EvMapping *ev_link_mapping; ddjvu_pageinfo_t page_info; while ((page_annotations = ddjvu_document_get_pageanno (djvu_document->d_document, page)) == miniexp_dummy) djvu_handle_events (djvu_document, TRUE, NULL); while (ddjvu_document_get_pageinfo (djvu_document->d_document, page, &page_info) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE, NULL); if (page_annotations) { hyperlinks = ddjvu_anno_get_hyperlinks (page_annotations); if (hyperlinks) { for (iter = hyperlinks; *iter; ++iter) { ev_link_mapping = get_djvu_hyperlink_mapping (djvu_document, page, &page_info, *iter); if (ev_link_mapping) { ev_link_mapping->area.x1 *= scale_factor; ev_link_mapping->area.x2 *= scale_factor; ev_link_mapping->area.y1 *= scale_factor; ev_link_mapping->area.y2 *= scale_factor; retval = g_list_prepend (retval, ev_link_mapping); } } free (hyperlinks); } ddjvu_miniexp_release (djvu_document->d_document, page_annotations); } return ev_mapping_list_new (page, retval, (GDestroyNotify)g_object_unref); }
/* * Return a table like following: * { * -- a line entry * 1 = { * 1 = {word="This", x0=377, y0=4857, x1=2427, y1=5089}, * 2 = {word="is", x0=377, y0=4857, x1=2427, y1=5089}, * 3 = {word="Word", x0=377, y0=4857, x1=2427, y1=5089}, * 4 = {word="List", x0=377, y0=4857, x1=2427, y1=5089}, * x0 = 377, y0 = 4857, x1 = 2427, y1 = 5089, * }, * * -- an other line entry * 2 = { * 1 = {word="This", x0=377, y0=4857, x1=2427, y1=5089}, * 2 = {word="is", x0=377, y0=4857, x1=2427, y1=5089}, * x0 = 377, y0 = 4857, x1 = 2427, y1 = 5089, * }, * } */ static int getPageText(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); int pageno = luaL_checkint(L, 2); /* get page height for coordinates transform */ ddjvu_pageinfo_t info; ddjvu_status_t r; while ((r=ddjvu_document_get_pageinfo( doc->doc_ref, pageno-1, &info))<DDJVU_JOB_OK) { handle(L, doc->context, TRUE); } if (r>=DDJVU_JOB_FAILED) return luaL_error(L, "cannot get page #%d information", pageno); /* start retrieving page text */ miniexp_t sexp, se_line, se_word; int i = 1, j = 1, counter_l = 1, counter_w=1, nr_line = 0, nr_word = 0; const char *word = NULL; while ((sexp = ddjvu_document_get_pagetext(doc->doc_ref, pageno-1, "word")) == miniexp_dummy) { handle(L, doc->context, True); } /* throuw page info and obtain lines info, after this, sexp's entries * are lines. */ sexp = miniexp_cdr(sexp); /* get number of lines in a page */ nr_line = miniexp_length(sexp); /* table that contains all the lines */ lua_newtable(L); counter_l = 1; for(i = 1; i <= nr_line; i++) { /* retrive one line entry */ se_line = miniexp_nth(i, sexp); nr_word = miniexp_length(se_line); if (nr_word == 0) { continue; } /* subtable that contains words in a line */ lua_pushnumber(L, counter_l); lua_newtable(L); counter_l++; /* set line position */ lua_pushstring(L, "x0"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_line))); lua_settable(L, -3); lua_pushstring(L, "y1"); lua_pushnumber(L, info.height - miniexp_to_int(miniexp_nth(2, se_line))); lua_settable(L, -3); lua_pushstring(L, "x1"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_line))); lua_settable(L, -3); lua_pushstring(L, "y0"); lua_pushnumber(L, info.height - miniexp_to_int(miniexp_nth(4, se_line))); lua_settable(L, -3); /* now loop through each word in the line */ counter_w = 1; for(j = 1; j <= nr_word; j++) { /* retrive one word entry */ se_word = miniexp_nth(j, se_line); /* check to see whether the entry is empty */ word = miniexp_to_str(miniexp_nth(5, se_word)); if (!word) { continue; } /* create table that contains info for a word */ lua_pushnumber(L, counter_w); lua_newtable(L); counter_w++; /* set word info */ lua_pushstring(L, "x0"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_word))); lua_settable(L, -3); lua_pushstring(L, "y1"); lua_pushnumber(L, info.height - miniexp_to_int(miniexp_nth(2, se_word))); lua_settable(L, -3); lua_pushstring(L, "x1"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_word))); lua_settable(L, -3); lua_pushstring(L, "y0"); lua_pushnumber(L, info.height - miniexp_to_int(miniexp_nth(4, se_word))); lua_settable(L, -3); lua_pushstring(L, "word"); lua_pushstring(L, word); lua_settable(L, -3); /* set word entry to line subtable */ lua_settable(L, -3); } /* end of for (j) */ /* set line entry to page text table */ lua_settable(L, -3); } /* end of for (i) */ return 1; }