Welcome Ethumb, it's ready to get out of PROTO.
[framework/uifw/ethumb.git] / src / plugins / epdf / epdf.c
1 #include "Ethumb.h"
2 #include "Ethumb_Plugin.h"
3 #include "config.h"
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <Eina.h>
8 #include <Evas.h>
9 #include <Epdf.h>
10
11 static void
12 _generate_thumb(Ethumb *e)
13 {
14    Epdf_Document *document;
15    Epdf_Page *page;
16    Evas_Object *o;
17    const char *src_path;
18    int w, h, ww, hh;
19    int fx, fy, fw, fh;
20    int npages;
21    int pagenum;
22
23    ethumb_file_get(e, &src_path, NULL);
24    document = epdf_document_new(src_path);
25    if (!document)
26      {
27         fprintf(stderr, "ERROR: could not read document: %s\n", src_path);
28         ethumb_finished_callback_call(e, 0);
29         return;
30      }
31
32    page = epdf_page_new(document);
33    if (!page)
34      {
35         fprintf(stderr, "ERROR: could not read document: %s\n", src_path);
36         epdf_document_delete(document);
37         ethumb_finished_callback_call(e, 0);
38         return;
39      }
40
41    npages = epdf_document_page_count_get(document);
42    pagenum = ethumb_document_page_get(e);
43    if (pagenum < npages)
44      epdf_page_page_set(page, pagenum);
45    epdf_page_size_get(page, &w, &h);
46    ethumb_calculate_aspect(e, w, h, &ww, &hh);
47    ethumb_plugin_image_resize(e, ww, hh);
48
49    o = evas_object_image_add(ethumb_evas_get(e));
50    epdf_page_render(page, o);
51    evas_object_resize(o, ww, hh);
52    evas_object_move(o, 0, 0);
53
54    ethumb_calculate_fill(e, w, h, &fx, &fy, &fw, &fh);
55    evas_object_image_fill_set(o, fx, fy, fw, fh);
56
57    evas_object_show(o);
58    ethumb_image_save(e);
59
60    evas_object_del(o);
61    epdf_page_delete(page);
62    epdf_document_delete(document);
63
64    ethumb_finished_callback_call(e, 1);
65 }
66
67 EAPI Ethumb_Plugin *
68 ethumb_plugin_get(void)
69 {
70    static const char *extensions[] = { "pdf", NULL };
71    static Ethumb_Plugin plugin =
72      {
73         extensions,
74         _generate_thumb,
75      };
76
77    return &plugin;
78 }
79
80 static Eina_Bool
81 _module_init(void)
82 {
83    epdf_init();
84
85    return EINA_TRUE;
86 }
87
88 static void
89 _module_shutdown(void)
90 {
91    epdf_shutdown();
92 }
93
94 EINA_MODULE_INIT(_module_init);
95 EINA_MODULE_SHUTDOWN(_module_shutdown);