示例#1
0
static void
_generate_thumb(Ethumb *e)
{
    Epdf_Document *document;
    Epdf_Page *page;
    Evas_Object *o;
    const char *src_path;
    int w, h, ww, hh;
    int fx, fy, fw, fh;
    unsigned int npages, pagenum;

    ethumb_file_get(e, &src_path, NULL);
    document = epdf_document_new(src_path);
    if (!document)
    {
        fprintf(stderr, "ERROR: could not read document: %s\n", src_path);
        ethumb_finished_callback_call(e, 0);
        return;
    }

    page = epdf_page_new(document);
    if (!page)
    {
        fprintf(stderr, "ERROR: could not read document: %s\n", src_path);
        epdf_document_delete(document);
        ethumb_finished_callback_call(e, 0);
        return;
    }

    npages = epdf_document_page_count_get(document);
    pagenum = ethumb_document_page_get(e);
    if (pagenum < npages)
        epdf_page_page_set(page, pagenum);
    epdf_page_size_get(page, &w, &h);
    ethumb_calculate_aspect(e, w, h, &ww, &hh);
    ethumb_plugin_image_resize(e, ww, hh);

    o = evas_object_image_add(ethumb_evas_get(e));
    epdf_page_render(page, o);
    evas_object_resize(o, ww, hh);
    evas_object_move(o, 0, 0);

    ethumb_calculate_fill(e, w, h, &fx, &fy, &fw, &fh);
    evas_object_image_fill_set(o, fx, fy, fw, fh);

    evas_object_show(o);
    ethumb_image_save(e);

    evas_object_del(o);
    epdf_page_delete(page);
    epdf_document_delete(document);

    ethumb_finished_callback_call(e, 1);
}
示例#2
0
/**
 * @param pdf the pdf to set the page of
 * @param page:  the page number
 * @return Returns no value.
 * @brief Set the page of the document
 *
 * Sets the page of the document @p pdf to @p page
 */
void
ewl_pdf_page_set(Ewl_Pdf *pdf, int page)
{
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR(pdf);
        DCHECK_TYPE(pdf, EWL_PDF_TYPE);

        if (!pdf->pdf_document ||
            !pdf->pdf_page ||
            (page < 0) ||
            (page >= epdf_document_page_count_get(pdf->pdf_document)) ||
            (page == epdf_page_page_get(pdf->pdf_page)))
                DRETURN(DLEVEL_STABLE);

        pdf->dirty = 1;
        epdf_page_page_set(pdf->pdf_page, page);
        ewl_widget_configure(EWL_WIDGET(pdf));

        DLEAVE_FUNCTION(DLEVEL_STABLE);
}
示例#3
0
int
main (int argc, char *argv[])
{
  Ecore_Evas    *ee;
  Evas          *evas;
  Evas_Object   *o;
  Epdf_Document *document;
  Epdf_Page     *page;
  int            page_number;
  int            width;
  int            height;

  if (argc < 3) {
    printf ("\nUsage: %s filename page_number\n\n", argv[0]);
    return EXIT_FAILURE;
  }

  if (!epdf_init ()) {
    printf ("Epdf can't be initialized\n");
    return EXIT_FAILURE;
  }

  document = epdf_document_new (argv[1]);
  if (!document) {
    printf ("Bad pdf file\n");
    goto epdf_shutdown;
  }

  sscanf (argv[2], "%d", &page_number);
  if (page_number >= epdf_document_page_count_get (document)) {
    printf ("Page number exceeds the page count of the PDF document\n");
    goto document_delete;
  }

  page = epdf_page_new (document);
  if (!page) {
    printf ("Bad page\n");
    goto document_delete;
  }
  epdf_page_page_set (page, page_number);
  epdf_page_size_get (page, &width, &height);

  document_info_print (document, page);

  if (!ecore_evas_init())
    goto page_delete;

  ee = ecore_evas_new ("software_x11",  0, 0, width, height, NULL);
  /* these tests can be improved... */
  if (!ee) {
    printf ("Can not find Software X11 engine. Trying DirectDraw engine...\n");
    ee = ecore_evas_software_ddraw_new (NULL,  0, 0, width, height);
    if (!ee) {
      printf ("Can not find DirectDraw engine...\n");
      printf ("Exiting...\n");
      goto ecore_evas_shutdown;
    }
  }
  ecore_event_handler_add (ECORE_EVENT_SIGNAL_EXIT, app_signal_exit, NULL);
  ecore_evas_callback_delete_request_set (ee, app_delete_request);
  ecore_evas_title_set (ee, "Evas Pdf Test");
  ecore_evas_name_class_set (ee, "evas_pdf_test", "test_evas_pdf");
  ecore_evas_callback_resize_set (ee, app_resize);
  ecore_evas_show (ee);

  evas = ecore_evas_get (ee);

  o = evas_object_image_add (evas);
  evas_object_move (o, 0, 0);
  epdf_page_render (page, o);
  evas_object_show (o);

  ecore_main_loop_begin ();

  epdf_page_delete (page);
  epdf_document_delete (document);

  ecore_evas_shutdown ();
  epdf_shutdown ();

  return EXIT_SUCCESS;

 ecore_evas_shutdown:
  ecore_evas_shutdown ();
 page_delete:
  epdf_page_delete (page);
 document_delete:
  epdf_document_delete (document);
 epdf_shutdown:
  epdf_shutdown ();

  return EXIT_FAILURE;
}
示例#4
0
/**
 * @param pdf: the pdf to change the scale
 * @return 1 if the text is found, 0 otherwise.
 * @brief Set the case of the search
 *
 * Start the search of text in the @p pdf document. The
 * text to search should have been set by ewl_pdf_search_text_set().
 * It is @c NULL by default. The first page from which the search
 * starts is set by ewl_pdf_search_first_page_set(). It is 0 by default.
 * The search can be case sensitive or not. It is set by
 * ewl_pdf_search_is_case_sensitive() and it is case insensitive by
 * default.
 *
 * Several call of that function can be done to search several occurences
 * of the text in the document. When a text is found,
 * epdf_page_page_set() is called.
 */
int
ewl_pdf_search_next(Ewl_Pdf *pdf)
{
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR_RET(pdf, FALSE);
        DCHECK_TYPE_RET(pdf, EWL_PDF_TYPE, FALSE);

        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->canvas);
                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 < epdf_document_page_count_get(pdf->pdf_document)) {
                Epdf_Page *page;

                pdf->search.page++;
                printf("page : %d\n", pdf->search.page);
                epdf_page_page_set(pdf->pdf_page, pdf->search.page);
                pdf->search.list = epdf_page_text_find(page,
                                                       pdf->search.text,
                                                       pdf->search.is_case_sensitive);
                if (pdf->search.list)
                        ecore_list_first_goto(pdf->search.list);
                epdf_page_delete(page);
        }

        /* an already existing list or a newly one */
        if (pdf->search.list) {
                Epdf_Rectangle *rect;

                if ((rect = (Epdf_Rectangle *)ecore_list_next(pdf->search.list))) {
                  if (pdf->search.page != epdf_page_page_get(pdf->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);
}