3 #include <poppler/cpp/poppler-document.h>
4 #include <poppler/cpp/poppler-image.h>
5 #include <poppler/cpp/poppler-page.h>
6 #include <poppler/cpp/poppler-page-renderer.h>
8 #define MIN(a, b) ((a) < (b) ? (a) : (b))
16 poppler::document
*doc
;
19 static poppler::rotation_enum
rotation(int times
)
22 return poppler::rotate_90
;
24 return poppler::rotate_180
;
26 return poppler::rotate_270
;
27 return poppler::rotate_0
;
30 void *doc_draw(struct doc
*doc
, int p
, int zoom
, int rotate
, int *rows
, int *cols
)
32 poppler::page
*page
= doc
->doc
->create_page(p
- 1);
33 poppler::page_renderer pr
;
38 pr
.set_render_hint(poppler::page_renderer::antialiasing
, true);
39 pr
.set_render_hint(poppler::page_renderer::text_antialiasing
, true);
40 poppler::image img
= pr
.render_page(page
,
41 (float) 72 * zoom
/ 100, (float) 72 * zoom
/ 100,
42 -1, -1, -1, -1, rotation((rotate
+ 89) / 90));
45 dat
= (unsigned char *) img
.data();
46 if (!(pbuf
= (fbval_t
*) malloc(h
* w
* sizeof(pbuf
[0])))) {
50 for (y
= 0; y
< h
; y
++) {
51 unsigned char *s
= dat
+ img
.bytes_per_row() * y
;
52 for (x
= 0; x
< w
; x
++)
53 pbuf
[y
* w
+ x
] = FB_VAL(s
[x
* 4 + 2],
54 s
[x
* 4 + 1], s
[x
* 4 + 0]);
62 int doc_pages(struct doc
*doc
)
64 return doc
->doc
->pages();
67 struct doc
*doc_open(char *path
)
69 struct doc
*doc
= (struct doc
*) malloc(sizeof(*doc
));
72 doc
->doc
= poppler::document::load_from_file(path
);
80 void doc_close(struct doc
*doc
)