Enlightenment CVS committal Author : doursse Project : e17 Module : proto
Dir : e17/proto/epdf/src/lib Modified Files: ewl_pdf.c ewl_pdf.h poppler_page.cpp Log Message: various fixes, ewl pdf widget updated =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/epdf/src/lib/ewl_pdf.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_pdf.c 15 Feb 2006 21:45:08 -0000 1.1 +++ ewl_pdf.c 8 Mar 2006 18:25:30 -0000 1.2 @@ -1,3 +1,5 @@ +#include <math.h> + #include <Ewl.h> #include "ewl_debug.h" #include "ewl_macros.h" @@ -9,6 +11,9 @@ #define __UNUSED__ #endif + +#define round(a) ( ((a)<0.0) ? (int)(floor((a) - 0.5)) : (int)(floor((a) + 0.5)) ) + /** * @return Returns a pointer to a new pdf widget on success, NULL on failure. * @brief Load an pdf widget with specified pdf contents @@ -77,6 +82,13 @@ pdf->pdf_page = NULL; pdf->pdf_index = NULL; + pdf->search.o = NULL; + pdf->search.text = NULL; + pdf->search.list = NULL; + pdf->search.page = -1; + pdf->search.is_case_sensitive = FALSE; + pdf->search.is_circular = FALSE; + DRETURN_INT(TRUE, DLEVEL_STABLE); } @@ -105,7 +117,7 @@ * edje is used, a minimum size should be specified in the edje or the code. */ void -ewl_pdf_file_set(Ewl_Pdf *pdf, char *filename) +ewl_pdf_file_set(Ewl_Pdf *pdf, const char *filename) { Ewl_Widget *w; Ewl_Embed *emb; @@ -129,6 +141,7 @@ pdf->pdf_document = evas_poppler_document_new (filename); pdf->pdf_index = evas_poppler_index_new (pdf->pdf_document); + pdf->page = 0; /* * Load the new pdf if widget has been realized @@ -157,7 +170,8 @@ if (!pdf->pdf_document || (page >= evas_poppler_document_page_count_get (pdf->pdf_document)) || - (page == pdf->page)) return; + (page == pdf->page)) + DLEAVE_FUNCTION(DLEVEL_STABLE); pdf->page = page; @@ -207,6 +221,127 @@ } void +ewl_pdf_search_text_set (Ewl_Pdf *pdf, const char *text) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("pdf", pdf); + DCHECK_TYPE("pdf", pdf, "pdf"); + + if ((!text) || + (pdf->search.text && + strcmp (text, pdf->search.text) == 0)) + DRETURN(DLEVEL_STABLE); + + if (pdf->search.text) free (pdf->search.text); + pdf->search.text = strdup (text); + pdf->search.page = -1; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_pdf_search_first_page_set (Ewl_Pdf *pdf, int page) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("pdf", pdf); + DCHECK_TYPE("pdf", pdf, "pdf"); + + if (page != pdf->search.page) + pdf->search.page = page; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_pdf_search_is_case_sensitive (Ewl_Pdf *pdf, int is_case_sensitive) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("pdf", pdf); + DCHECK_TYPE("pdf", pdf, "pdf"); + + if (is_case_sensitive != pdf->search.is_case_sensitive) + pdf->search.is_case_sensitive = is_case_sensitive; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +int +ewl_pdf_search_next (Ewl_Pdf *pdf) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("pdf", pdf, FALSE); + DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + + if (!pdf->search.text) + DRETURN_INT(FALSE, DLEVEL_STABLE); + + if (!pdf->search.o) { + Ewl_Embed *emb; + + emb = ewl_embed_widget_find(EWL_WIDGET (pdf)); + pdf->search.o = evas_object_rectangle_add(emb->evas); + if (!pdf->search.o) + DRETURN_INT(FALSE, DLEVEL_STABLE); + evas_object_color_set(pdf->search.o, 0, 128, 0, 128); + evas_object_hide (pdf->search.o); + } + + next_page: + /* no list, we search one */ + while (!pdf->search.list && + pdf->search.page < evas_poppler_document_page_count_get (pdf->pdf_document)) { + Evas_Poppler_Page *page; + + pdf->search.page++; + printf ("page : %d\n", pdf->search.page); + page = evas_poppler_document_page_get (pdf->pdf_document, pdf->search.page); + pdf->search.list = evas_poppler_page_text_find (page, + pdf->search.text, + pdf->search.is_case_sensitive); + if (pdf->search.list) + ecore_list_goto_first (pdf->search.list); + evas_poppler_page_delete (page); + } + + /* an already existing list or a newly one */ + if (pdf->search.list) { + Rectangle *rect; + + if ((rect = (Rectangle *)ecore_list_next (pdf->search.list))) { + if (pdf->search.page != pdf->page) { + ewl_pdf_page_set (pdf, pdf->search.page); + ewl_callback_call (EWL_WIDGET (pdf), EWL_CALLBACK_REVEAL); + } + evas_object_move (pdf->search.o, + CURRENT_X(EWL_WIDGET (pdf)) + round (rect->x1 - 1), + CURRENT_Y(EWL_WIDGET (pdf)) + round (rect->y1 - 1)); + evas_object_resize (pdf->search.o, + round (rect->x2 - rect->x1 + 1), + round (rect->y2 - rect->y1)); + if (!evas_object_visible_get (pdf->search.o)) + evas_object_show (pdf->search.o); + /* we leave... */ + DRETURN_INT(TRUE, DLEVEL_STABLE); + } + else { /* no more word to find. We destroy the list */ + ecore_list_destroy (pdf->search.list); + pdf->search.list = NULL; + /* we search a new one */ + printf ("page0 : %d\n", pdf->search.page); + goto next_page; + } + } + evas_object_hide (pdf->search.o); + + if (pdf->search.is_circular) { + pdf->search.page = -1; + DRETURN_INT(TRUE, DLEVEL_STABLE); + } + else + DRETURN_INT(FALSE, DLEVEL_STABLE); +} + +void ewl_pdf_reveal_cb(Ewl_Widget *w, void *ev_data __UNUSED__, void *user_data __UNUSED__) { @@ -295,6 +430,7 @@ evas_poppler_page_delete (pdf->pdf_page); if (pdf->pdf_index) evas_poppler_index_delete (pdf->pdf_index); + if (pdf->search.text) free (pdf->search.text); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/epdf/src/lib/ewl_pdf.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_pdf.h 19 Feb 2006 13:29:17 -0000 1.2 +++ ewl_pdf.h 8 Mar 2006 18:25:30 -0000 1.3 @@ -32,16 +32,29 @@ Evas_Poppler_Document *pdf_document; Evas_Poppler_Page *pdf_page; Ecore_List *pdf_index; + + struct { + Evas_Object *o; + char *text; + Ecore_List *list; + int page; + int is_case_sensitive; + int is_circular; + }search; + }; Ewl_Widget *ewl_pdf_new(void); int ewl_pdf_init(Ewl_Pdf *pdf); -void ewl_pdf_file_set(Ewl_Pdf *pdf, char *filename); +void ewl_pdf_file_set(Ewl_Pdf *pdf, const char *filename); void ewl_pdf_page_set(Ewl_Pdf *pdf, int page); int ewl_pdf_page_get(Ewl_Pdf *pdf); Evas_Poppler_Document *ewl_pdf_pdf_document_get (Ewl_Pdf *pdf); Evas_Poppler_Page *ewl_pdf_pdf_page_get (Ewl_Pdf *pdf); Ecore_List *ewl_pdf_pdf_index_get (Ewl_Pdf *pdf); +void ewl_pdf_search_text_set (Ewl_Pdf *pdf, const char *text); +void ewl_pdf_search_is_case_sensitive (Ewl_Pdf *pdf, int is_case_sensitive); +int ewl_pdf_search_next (Ewl_Pdf *pdf); /* * Internally used callbacks, override at your own risk. =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/epdf/src/lib/poppler_page.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- poppler_page.cpp 15 Feb 2006 21:45:08 -0000 1.1 +++ poppler_page.cpp 8 Mar 2006 18:25:30 -0000 1.2 @@ -81,7 +81,7 @@ output_dev = new SplashOutputDev(splashModeRGB8, 4, gFalse, white); output_dev->startDoc(doc->pdfdoc->getXRef ()); - + printf ("PAGE : %d\n", page->index + 1); doc->pdfdoc->displayPageSlice(output_dev, page->index + 1, xres, yres, 0, false, false, false, -1, -1, -1, -1); bitmap = output_dev->getBitmap (); ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs