From d2d566cf50835d728f1c65ebeccf914b43d81867 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 7 Feb 2018 22:52:41 +0000 Subject: extend path operations in render --- src/page.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/page.c b/src/page.c index 984228b..3b2371b 100644 --- a/src/page.c +++ b/src/page.c @@ -329,6 +329,13 @@ render_operation_h(struct graphics_state *gs) return NSPDFERROR_OK; } +static inline nspdferror +render_operation_n(struct graphics_state *gs) +{ + gs->path_idx = 0; + return NSPDFERROR_OK; +} + static inline nspdferror gsc_to_device(struct graphics_state_color * gsc, uint32_t *c_out) { @@ -402,6 +409,50 @@ render_operation_f(struct graphics_state *gs, struct nspdf_render_ctx* render_ct return NSPDFERROR_OK; } +static inline nspdferror +render_operation_b(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx) +{ + struct nspdf_style style; + style.stroke_type = NSPDF_OP_TYPE_SOLID; + style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width; + gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour, &style.stroke_colour); + + style.fill_type = NSPDF_OP_TYPE_SOLID; + gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour, &style.fill_colour); + + gs->path[gs->path_idx++] = NSPDF_PATH_CLOSE; + + render_ctx->path(&style, + gs->path, + gs->path_idx, + gs->param_stack[gs->param_stack_idx].ctm, + render_ctx->ctx); + gs->path_idx = 0; + + return NSPDFERROR_OK; +} + +static inline nspdferror +render_operation_B(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx) +{ + struct nspdf_style style; + style.stroke_type = NSPDF_OP_TYPE_SOLID; + style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width; + gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour, &style.stroke_colour); + + style.fill_type = NSPDF_OP_TYPE_SOLID; + gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour, &style.fill_colour); + + render_ctx->path(&style, + gs->path, + gs->path_idx, + gs->param_stack[gs->param_stack_idx].ctm, + render_ctx->ctx); + gs->path_idx = 0; + + return NSPDFERROR_OK; +} + static inline nspdferror render_operation_S(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx) @@ -762,11 +813,17 @@ nspdf_page_render(struct nspdf_doc *doc, case CONTENT_OP_f: case CONTENT_OP_f_: + res = render_operation_f(&gs, render_ctx); + break; + case CONTENT_OP_B: case CONTENT_OP_B_: + res = render_operation_B(&gs, render_ctx); + break; + case CONTENT_OP_b: case CONTENT_OP_b_: - res = render_operation_f(&gs, render_ctx); + res = render_operation_b(&gs, render_ctx); break; case CONTENT_OP_s: @@ -778,6 +835,10 @@ nspdf_page_render(struct nspdf_doc *doc, res = render_operation_S(&gs, render_ctx); break; + case CONTENT_OP_n: /* end path */ + res = render_operation_n(&gs); + break; + /* graphics state operations */ case CONTENT_OP_w: /* line width */ res = render_operation_w(operation, &gs); -- cgit v1.2.3