diff options
author | Vincent Sanders <vince@kyllikki.org> | 2018-01-29 00:02:37 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2018-01-29 00:02:37 +0000 |
commit | 6b16f2446bb381be3de54d9edfe9088a8363df70 (patch) | |
tree | 3d13fbd5d0053b720b56256027d2c8a4aa13129e | |
parent | 887175cabfbf3cea833583834937eadf9654e07a (diff) | |
download | libnspdf-6b16f2446bb381be3de54d9edfe9088a8363df70.tar.gz libnspdf-6b16f2446bb381be3de54d9edfe9088a8363df70.tar.bz2 |
extend page interface with render context
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | include/nspdf/page.h | 55 | ||||
-rw-r--r-- | src/cos_parse.c | 2 | ||||
-rw-r--r-- | src/page.c | 11 | ||||
-rw-r--r-- | test/parsepdf.c | 38 |
5 files changed, 93 insertions, 14 deletions
@@ -57,5 +57,6 @@ I := /$(INCLUDEDIR)/nspdf INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nspdf/document.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nspdf/meta.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nspdf/errors.h +INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nspdf/page.h INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT) diff --git a/include/nspdf/page.h b/include/nspdf/page.h index 8c1d7fc..f8c280e 100644 --- a/include/nspdf/page.h +++ b/include/nspdf/page.h @@ -19,8 +19,61 @@ struct nspdf_doc; +/** + * Type of plot operation + */ +enum nspdf_style_operation { + NSPDF_OP_TYPE_NONE = 0, /**< No operation */ + NSPDF_OP_TYPE_SOLID, /**< Solid colour */ + NSPDF_OP_TYPE_DOT, /**< Dotted plot */ + NSPDF_OP_TYPE_DASH, /**< Dashed plot */ +}; + + +/** + * Plot style for stroke/fill plotters + */ +typedef struct nspdf_style { + enum nspdf_style_operation stroke_type; /**< Stroke plot type */ + int stroke_width; /**< Width of stroke, in pixels */ + uint32_t stroke_colour; /**< Colour of stroke XBGR */ + + enum nspdf_style_operation fill_type; /**< Fill plot type */ + uint32_t fill_colour; /**< Colour of fill XBGR */ +} nspdf_style; + + +enum nspdf_path_command { + NSPDF_PATH_MOVE = 0, + NSPDF_PATH_CLOSE, + NSPDF_PATH_LINE, + NSPDF_PATH_BEZIER, +}; + +struct nspdf_render_ctx { + const void *ctx; /**< context passed to drawing functions */ + + float device_space[6]; /* user space to device space transformation matrix */ + + /** + * Plots a path. + * + * Path plot consisting of lines and cubic Bezier curves. Line and fill + * colour is controlled by the style. All elements of the path are in + * device space. + * + * \param style Style controlling the path plot. + * \param p elements of path + * \param n nunber of elements on path + * \param transform A transform to apply to the path. + * \param ctx The drawing context. + * \return NSERROR_OK on success else error code. + */ + nspdferror (*path)(const struct nspdf_style *style, const float *p, unsigned int n, const float transform[6], const void *ctx); +}; + nspdferror nspdf_page_count(struct nspdf_doc *doc, unsigned int *pages_out); -nspdferror nspdf_page_render(struct nspdf_doc *doc, unsigned int page_num); +nspdferror nspdf_page_render(struct nspdf_doc *doc, unsigned int page_num, struct nspdf_render_ctx* render_ctx); #endif /* NSPDF_META_H_ */ diff --git a/src/cos_parse.c b/src/cos_parse.c index dea67f9..df706a4 100644 --- a/src/cos_parse.c +++ b/src/cos_parse.c @@ -1424,7 +1424,7 @@ cos_parse_content_streams(struct nspdf_doc *doc, if (cosobj->u.content == NULL) { res = NSPDFERROR_NOMEM; goto cos_parse_content_stream_error; - } + } for (stream_index = 0; stream_index < stream_count; stream_index++) { stream = *(streams + stream_index); @@ -149,7 +149,9 @@ nspdf_page_count(struct nspdf_doc *doc, unsigned int *pages_out) /* exported interface documented in nspdf/page.h */ nspdferror -nspdf_page_render(struct nspdf_doc *doc, unsigned int page_number) +nspdf_page_render(struct nspdf_doc *doc, + unsigned int page_number, + struct nspdf_render_ctx* render_ctx) { struct page_table_entry *page_entry; struct cos_content *page_content; /* page operations array */ @@ -158,8 +160,11 @@ nspdf_page_render(struct nspdf_doc *doc, unsigned int page_number) page_entry = doc->page_table + page_number; res = cos_get_content(doc, page_entry->contents, &page_content); - if (res == NSPDFERROR_OK) { - printf("%p\n", page_content); + if (res != NSPDFERROR_OK) { + return res; } + + printf("page %d content:%p\n", page_number, page_content); + return res; } diff --git a/test/parsepdf.c b/test/parsepdf.c index 7a64f4b..054e96d 100644 --- a/test/parsepdf.c +++ b/test/parsepdf.c @@ -55,6 +55,28 @@ read_whole_pdf(const char *fname, uint8_t **buffer, uint64_t *buffer_length) return NSPDFERROR_OK; } +static nspdferror render_pages(struct nspdf_doc *doc, unsigned int page_count) +{ + nspdferror res; + struct nspdf_render_ctx render_ctx; + unsigned int page_render_list[4] = { 0, 1, 0, 1}; + unsigned int page_index; + + for (page_index = 0; page_index < page_count; page_index++) { + res = nspdf_page_render(doc, page_index, &render_ctx); + if (res != NSPDFERROR_OK) { + break; + } + } + + for (page_index = 0; page_index < 4; page_index++) { + res = nspdf_page_render(doc, page_render_list[page_index], &render_ctx); + if (res != NSPDFERROR_OK) { + break; + } + } + return res; +} int main(int argc, char **argv) { @@ -94,17 +116,15 @@ int main(int argc, char **argv) } res = nspdf_page_count(doc, &page_count); - if (res != NSPDFERROR_OK) { - printf("page count failed (%d)\n", res); - return res; + if (res == NSPDFERROR_OK) { + printf("Pages:%d\n", page_count); } - printf("Pages:%d\n", page_count); - res = nspdf_page_render(doc, 0); - if (res != NSPDFERROR_OK) { - printf("page render failed (%d)\n", res); - return res; - } + res = render_pages(doc, page_count); + if (res != NSPDFERROR_OK) { + printf("page render failed (%d)\n", res); + return res; + } res = nspdf_document_destroy(doc); if (res != NSPDFERROR_OK) { |