Beispiel #1
0
static void page_size_get(int *width, int *height)
{
    epdf_page_size_get(EWL_PDF(pdfwidget)->pdf_page, width, height);
    switch(epdf_page_orientation_get(EWL_PDF(pdfwidget)->pdf_page)) {
            case EPDF_PAGE_ORIENTATION_LANDSCAPE:
            case EPDF_PAGE_ORIENTATION_SEASCAPE:
                SWAP(int, width, height);
    }
}
Beispiel #2
0
void calculate_margins()
{
    int docwidth,docheight;
    double hscale,vscale;
    epdf_page_size_get (EWL_PDF(pdfwidget)->pdf_page,&docwidth,&docheight);
    ewl_pdf_scale_get(EWL_PDF(pdfwidget),&hscale,&vscale);
    leftmarge=((double)get_left_margin())/floor(((double)docwidth)*hscale);
    rightmarge=((double)get_right_margin())/floor(((double)docwidth)*hscale);
    fprintf(stderr,"%f %f",leftmarge,rightmarge);
}
Beispiel #3
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);
}
Beispiel #4
0
void resize_and_rescale(double scale)
{
    int docwidth,docheight;
    double docscale;
    int sp_inner;
    double ltrimpct=0.0,rtrimpct=0.0;
    
    //ewl_object_maximum_h_set(EWL_OBJECT(pdfwidget),99999);
    //ewl_object_minimum_h_set(EWL_OBJECT(pdfwidget),0);
    sp_inner=CURRENT_W(scrollpane)-INSET_HORIZONTAL(scrollpane)-PADDING_HORIZONTAL(scrollpane);
    //if(EWL_SCROLLPANE(scrollpane)->vflag)
    //    sp_inner-=CURRENT_W(EWL_OBJECT(EWL_SCROLLPANE(scrollpane)->vscrollbar));
        
    //ewl_pdf_size_get(EWL_PDF(pdfwidget),&docwidth,&docheight);
    epdf_page_size_get (EWL_PDF(pdfwidget)->pdf_page,&docwidth,&docheight);
    if(fitmode==0)
        docscale=((double)sp_inner)/((double)docwidth)*scale;
    else if(fitmode==1)
    {
        ltrimpct=((double)get_settings()->ltrimpad)/((double)docwidth);
        rtrimpct=((double)get_settings()->rtrimpad)/((double)docwidth);
        docscale=((double)sp_inner)/((1.0-leftmarge+ltrimpct-rightmarge+rtrimpct)*((double)docwidth))*scale;
        
    }
    ewl_pdf_scale_set(EWL_PDF(pdfwidget),docscale,docscale);
    //ewl_object_custom_w_set(EWL_OBJECT(pdfwidget),floor(((double)sp_inner)*scale));
    
    //ewl_object_custom_w_set(EWL_OBJECT(pdfwidget),floor(((double)sp_inner)*scale));
    //ewl_object_custom_h_set(EWL_OBJECT(pdfwidget),floor(((double)docheight)/((double)docwidth)*((double)sp_inner)*scale));
    ewl_object_custom_w_set(EWL_OBJECT(pdfwidget),floor(((double)docwidth)*docscale));
    ewl_object_custom_h_set(EWL_OBJECT(pdfwidget),floor(((double)docheight)*docscale));
    //ewl_object_position_request(EWL_OBJECT(pdfwidget),0,0);
    ewl_widget_configure(pdfwidget);
    
    //ewl_object_custom_w_set(EWL_OBJECT(trimpane),floor(((double)docwidth)*docscale));
    //ewl_object_custom_h_set(EWL_OBJECT(trimpane),floor(((double)docheight)*docscale));
    ewl_object_custom_w_set(EWL_OBJECT(trimpane),floor(((double)sp_inner)*scale));
    ewl_object_custom_h_set(EWL_OBJECT(trimpane),floor(((double)docheight)*docscale));
    ewl_object_position_request(EWL_OBJECT(trimpane),0,0);
    

    //ewl_object_place(EWL_OBJECT(pdfwidget),0,0,floor(((double)docwidth)*docscale),floor(((double)docheight)*docscale));
    ewl_widget_configure(trimpane);
    ewl_widget_configure(scrollpane);
    if(fitmode==0)
        ewl_scrollpane_hscrollbar_value_set(EWL_SCROLLPANE(trimpane),0.0);
    else if(fitmode==1)
        ewl_scrollpane_hscrollbar_value_set(EWL_SCROLLPANE(trimpane),(leftmarge-ltrimpct)/(leftmarge-ltrimpct+rightmarge-rtrimpct));
}
Beispiel #5
0
/**
 * @param pdf the pdf widget to get the size of
 * @param width width of the current page
 * @param height height of the current page
 * @brief get the size of the pdf @p pdf. If @p pdf is NULL,
 * return a width equal to 0 and a height equal to 0
 */
void
ewl_pdf_pdf_size_get(Ewl_Pdf *pdf, int *width, int *height)
{
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR(pdf);
        DCHECK_TYPE(pdf, EWL_PDF_TYPE);

        if (!pdf->pdf_page) {
                if (width) *width = 0;
                if (height) *height = 0;
                DRETURN(DLEVEL_STABLE);
        }

        epdf_page_size_get(pdf->pdf_page, width, height);

        DLEAVE_FUNCTION(DLEVEL_STABLE);
}
Beispiel #6
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;
}
Eina_List *
epdf_page_text_find (const Epdf_Page *page,
                     const char      *text,
                     unsigned char    is_case_sensitive)
{
    Epdf_Rectangle *match;
    TextOutputDev  *output_dev;
    Eina_List      *matches = NULL;
    double          xMin, yMin, xMax, yMax;
    int             length;
    int             height;


    if (!page || !text)
        return NULL;

    GooString tmp (text);
    Unicode *s;

    {
        length = tmp.getLength();
        s = (Unicode *)gmallocn(length, sizeof(Unicode));
        bool anyNonEncoded = false;
        for (int j = 0; j < length && !anyNonEncoded; ++j) {
            s[j] = pdfDocEncoding[tmp.getChar(j) & 0xff];
            if (!s[j]) anyNonEncoded = true;
        }
        if ( anyNonEncoded )
        {
            for (int j = 0; j < length; ++j) {
                s[j] = tmp.getChar(j);
            }
        }
    }

    length = strlen (text);

    output_dev = new TextOutputDev (NULL, 1, 0, 0);

    epdf_page_size_get (page, NULL, &height);
    page->page->display (output_dev, 72, 72, 0, false,
                         true, false,
                         page->doc->pdfdoc->getCatalog());

    xMin = 0;
    yMin = 0;
#warning you probably want to add backwards as parameters
    while (output_dev->findText (s, tmp.getLength (),
                                 0, 1, // startAtTop, stopAtBottom
                                 1, 0, // startAtLast, stopAtLast
                                 is_case_sensitive, 0, // caseSensitive, backwards
                                 &xMin, &yMin, &xMax, &yMax)) {
        match = (Epdf_Rectangle *)malloc (sizeof (Epdf_Rectangle));
        match->x1 = xMin;
        match->y1 = yMin;//height - yMax;
        match->x2 = xMax;
        match->y2 = yMax;//height - yMin;
        matches = eina_list_append (matches, match);
    }

    delete output_dev;

    return matches;
}