7 #define MIN_(a, b) ((a) < (b) ? (a) : (b))
14 int doc_draw(struct doc
*doc
, int p
, int zoom
, int rotate
,
15 fbval_t
*bitmap
, int *rows
, int *cols
)
26 if (!(page
= fz_load_page(doc
->pdf
, p
- 1)))
28 ctm
= fz_scale((float) zoom
/ 10, (float) -zoom
/ 10);
29 ctm
= fz_concat(ctm
, fz_translate(0, -100));
31 ctm
= fz_concat(ctm
, fz_rotate(rotate
));
32 rect
= fz_bound_page(doc
->pdf
, page
);
33 rect
= fz_transform_rect(ctm
, rect
);
34 bbox
= fz_round_rect(rect
);
35 w
= MIN_(*cols
, rect
.x1
- rect
.x0
);
36 h
= MIN_(*rows
, rect
.y1
- rect
.y0
);
38 pix
= fz_new_pixmap_with_bbox(doc
->ctx
, fz_device_rgb
, bbox
);
39 fz_clear_pixmap_with_value(doc
->ctx
, pix
, 0xff);
41 dev
= fz_new_draw_device(doc
->ctx
, pix
);
42 fz_run_page(doc
->pdf
, page
, dev
, ctm
, NULL
);
45 for (y
= 0; y
< h
; y
++) {
46 int xs
= (h
- y
- 1) * *cols
+ (*cols
- w
) / 2;
47 for (x
= 0; x
< w
; x
++) {
48 unsigned char *s
= fz_pixmap_samples(doc
->ctx
, pix
) +
49 y
* fz_pixmap_width(doc
->ctx
, pix
) * 4 + x
* 4;
50 bitmap
[xs
+ x
] = FB_VAL(s
[0], s
[1], s
[2]);
54 fz_drop_pixmap(doc
->ctx
, pix
);
55 fz_free_page(doc
->pdf
, page
);
61 int doc_pages(struct doc
*doc
)
63 return fz_count_pages(doc
->pdf
);
66 struct doc
*doc_open(char *path
)
68 struct doc
*doc
= malloc(sizeof(*doc
));
69 doc
->ctx
= fz_new_context(NULL
, NULL
, FZ_STORE_DEFAULT
);
70 doc
->pdf
= fz_open_document(doc
->ctx
, path
);
71 if (!doc
->pdf
|| !fz_count_pages(doc
->pdf
)) {
78 void doc_close(struct doc
*doc
)
80 fz_close_document(doc
->pdf
);
81 fz_free_context(doc
->ctx
);