/* Helper functions */ static void pdf_dev_stroke_state(fz_context *ctx, pdf_device *pdev, const fz_stroke_state *stroke_state) { gstate *gs = CURRENT_GSTATE(pdev); if (stroke_state == gs->stroke_state) return; if (gs->stroke_state && !memcmp(stroke_state, gs->stroke_state, sizeof(*stroke_state))) return; if (!gs->stroke_state || gs->stroke_state->linewidth != stroke_state->linewidth) { fz_append_printf(ctx, gs->buf, "%g w\n", stroke_state->linewidth); } if (!gs->stroke_state || gs->stroke_state->start_cap != stroke_state->start_cap) { int cap = stroke_state->start_cap; /* FIXME: Triangle caps aren't supported in pdf */ if (cap == FZ_LINECAP_TRIANGLE) cap = FZ_LINECAP_BUTT; fz_append_printf(ctx, gs->buf, "%d J\n", cap); } if (!gs->stroke_state || gs->stroke_state->linejoin != stroke_state->linejoin) { int join = stroke_state->linejoin; if (join == FZ_LINEJOIN_MITER_XPS) join = FZ_LINEJOIN_MITER; fz_append_printf(ctx, gs->buf, "%d j\n", join); } if (!gs->stroke_state || gs->stroke_state->miterlimit != stroke_state->miterlimit) { fz_append_printf(ctx, gs->buf, "%g M\n", stroke_state->miterlimit); } if (gs->stroke_state == NULL && stroke_state->dash_len == 0) {} else if (!gs->stroke_state || gs->stroke_state->dash_phase != stroke_state->dash_phase || gs->stroke_state->dash_len != stroke_state->dash_len || memcmp(gs->stroke_state->dash_list, stroke_state->dash_list, sizeof(float)*stroke_state->dash_len)) { int i; if (stroke_state->dash_len == 0) fz_append_byte(ctx, gs->buf, '['); for (i = 0; i < stroke_state->dash_len; i++) { if (i > 0) fz_append_byte(ctx, gs->buf, ' '); fz_append_printf(ctx, gs->buf, "%g", stroke_state->dash_list[i]); } fz_append_printf(ctx, gs->buf, "]%g d\n", stroke_state->dash_phase); } fz_drop_stroke_state(ctx, gs->stroke_state); gs->stroke_state = fz_keep_stroke_state(ctx, stroke_state); }
static void fz_list_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_display_node *node; fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_TEXT, ctm, NULL, NULL, 0); fz_try(ctx) { fz_bound_text(dev->ctx, text, stroke, ctm, &node->rect); node->item.text = fz_clone_text(dev->ctx, text); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } fz_catch(ctx) { fz_free_display_node(ctx, node); fz_rethrow(ctx); } fz_append_display_node(dev->user, node); }
static void fz_list_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_STROKE_PATH, ctm, colorspace, color, alpha); fz_try(ctx) { fz_bound_path(dev->ctx, path, stroke, ctm, &node->rect); node->item.path = fz_clone_path(dev->ctx, path); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } fz_catch(ctx) { fz_free_display_node(ctx, node); fz_rethrow(ctx); } fz_append_display_node(dev->user, node); }
static void fz_list_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_display_node *node; fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_PATH, ctm, NULL, NULL, 0); fz_try(ctx) { fz_bound_path(dev->ctx, path, stroke, ctm, &node->rect); if (rect) fz_intersect_rect(&node->rect, rect); node->item.path = fz_clone_path(dev->ctx, path); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } fz_catch(ctx) { fz_free_display_node(ctx, node); fz_rethrow(ctx); } fz_append_display_node(dev->user, node); }
static void fz_list_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_STROKE_TEXT, ctm, colorspace, color, alpha); node->item.text = NULL; fz_try(ctx) { node->rect = fz_bound_text(dev->ctx, text, ctm); node->item.text = fz_clone_text(dev->ctx, text); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } fz_catch(ctx) { fz_free_display_node(ctx, node); fz_rethrow(ctx); } fz_append_display_node(dev->user, node); }