Exemplo n.º 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);
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/**
 * @param pdf the pdf widget to change the displayed pdf
 * @param filename: the path to the new pdf to be displayed by @a pdf
 * @return 0 on failure, 1 otherwise.
 * @brief Change the pdf file displayed by an pdf widget
 *
 * Set the pdf displayed by @a pdf to the one found at the filename @a filename. If an
 * edje is used, a minimum size should be specified in the edje or the code.
 */
int
ewl_pdf_file_set(Ewl_Pdf *pdf, const char *filename)
{
        Ewl_Widget *w;

        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR_RET(pdf, FALSE);
        DCHECK_TYPE(pdf, EWL_PDF_TYPE);

        w = EWL_WIDGET(pdf);

        if (!filename || (filename[0] == '\0'))
                DRETURN_INT(FALSE, DLEVEL_STABLE);

        if (pdf->filename != filename) {
                IF_FREE(pdf->filename);
        }

        if (pdf->pdf_index) {
                epdf_index_delete(pdf->pdf_index);
                pdf->pdf_index = NULL;
        }

        if (pdf->pdf_page) {
                epdf_page_delete(pdf->pdf_page);
                pdf->pdf_page = NULL;
        }

        if (pdf->pdf_document) {
                epdf_document_delete(pdf->pdf_document);
                pdf->pdf_document = NULL;
        }

        pdf->filename = strdup(filename);

        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;

        /*
         * Load the new PDF document
         */

        pdf->pdf_document = epdf_document_new(pdf->filename);
        if (!pdf->pdf_document)
                DRETURN_INT(FALSE, DLEVEL_STABLE);

        pdf->pdf_page = epdf_page_new(pdf->pdf_document);
        if (!pdf->pdf_page) {
                epdf_document_delete(pdf->pdf_document);
                pdf->pdf_document = NULL;
                DRETURN_INT(FALSE, DLEVEL_STABLE);
        }

        pdf->pdf_index = epdf_index_new(pdf->pdf_document);

        if (REALIZED(w)) {
                ewl_widget_obscure(w);
                ewl_widget_reveal(w);
        }

        DRETURN_INT(TRUE, DLEVEL_STABLE);
}