diff options
-rw-r--r-- | source/fitz/draw-device.c | 81 | ||||
-rw-r--r-- | source/fitz/list-device.c | 24 | ||||
-rw-r--r-- | source/fitz/svg-device.c | 42 | ||||
-rw-r--r-- | source/fitz/trace-device.c | 11 |
4 files changed, 107 insertions, 51 deletions
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 3c8d79dc..e337c482 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -421,6 +421,9 @@ fz_draw_fill_path(fz_context *ctx, fz_device *devp, const fz_path *path, int eve fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; + if (colorspace == NULL && model != NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "color destination requires source color"); + if (flatness < 0.001f) flatness = 0.001f; @@ -437,9 +440,14 @@ fz_draw_fill_path(fz_context *ctx, fz_device *devp, const fz_path *path, int eve state = fz_knockout_begin(ctx, dev); n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, colorspace, color); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, colorspace, color); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = alpha * 255; fz_scan_convert(ctx, gel, even_odd, &bbox, state->dest, colorbv); @@ -476,6 +484,9 @@ fz_draw_stroke_path(fz_context *ctx, fz_device *devp, const fz_path *path, const fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; + if (colorspace == NULL && model != NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "color destination requires source color"); + if (linewidth * expansion < aa_level) linewidth = aa_level / expansion; if (flatness < 0.001f) @@ -497,9 +508,14 @@ fz_draw_stroke_path(fz_context *ctx, fz_device *devp, const fz_path *path, const state = fz_knockout_begin(ctx, dev); n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, colorspace, color); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, colorspace, color); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = alpha * 255; #ifdef DUMP_GROUP_BLENDS @@ -767,13 +783,21 @@ fz_draw_fill_text(fz_context *ctx, fz_device *devp, const fz_text *text, const f fz_text_span *span; int i, n; + if (colorspace == NULL && model != NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "color destination requires source color"); + if (state->blendmode & FZ_BLEND_KNOCKOUT) state = fz_knockout_begin(ctx, dev); n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, colorspace, color); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, colorspace, color); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = alpha * 255; shapebv = 255; @@ -850,13 +874,21 @@ fz_draw_stroke_text(fz_context *ctx, fz_device *devp, const fz_text *text, const fz_text_span *span; int i, n; + if (colorspace == NULL && model != NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "color destination requires source color"); + if (state->blendmode & FZ_BLEND_KNOCKOUT) state = fz_knockout_begin(ctx, dev); n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, colorspace, color); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, colorspace, color); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = alpha * 255; for (span = text->head; span; span = span->next) @@ -1207,9 +1239,14 @@ fz_draw_fill_shade(fz_context *ctx, fz_device *devp, fz_shade *shade, const fz_m unsigned char *s; int x, y, n, i; n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, shade->colorspace, shade->background); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, shade->colorspace, shade->background); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = 255; n = dest->n; @@ -1481,6 +1518,9 @@ fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const fz_matrix inverse; fz_irect src_area; + if (colorspace == NULL && model != NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "color destination requires source color"); + fz_pixmap_bbox(ctx, state->dest, &clip); fz_intersect_irect(&clip, &state->scissor); @@ -1547,9 +1587,14 @@ fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const } n = model ? model->n : 0; - fz_convert_color(ctx, model, colorfv, colorspace, color); - for (i = 0; i < n; i++) - colorbv[i] = colorfv[i] * 255; + if (n > 0) + { + fz_convert_color(ctx, model, colorfv, colorspace, color); + for (i = 0; i < n; i++) + colorbv[i] = colorfv[i] * 255; + } + else + i = 0; colorbv[i] = alpha * 255; fz_paint_image_with_color(state->dest, &state->scissor, state->shape, pixmap, &local_ctm, colorbv, !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES), devp->flags & FZ_DEVFLAG_GRIDFIT_AS_TILED); diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c index d5e13375..dc8b1f0b 100644 --- a/source/fitz/list-device.c +++ b/source/fitz/list-device.c @@ -257,12 +257,7 @@ fz_append_display_node( rect_off = size; size += SIZE_IN_NODES(sizeof(fz_rect)); } - if (color && !colorspace) - { - /* SoftMasks can omit a colorspace, but we know what they mean */ - colorspace = fz_device_gray(ctx); - } - if (colorspace) + if (color || colorspace) { if (colorspace != writer->colorspace) { @@ -307,7 +302,7 @@ fz_append_display_node( else { int i; - int n = colorspace->n; + int n = colorspace ? colorspace->n : 0; colorspace_off = size; size += SIZE_IN_NODES(sizeof(fz_colorspace *)); @@ -378,7 +373,7 @@ fz_append_display_node( else { int i; - int n = colorspace->n; + int n = colorspace ? colorspace->n : 0; for (i=0; i < n; i++) if (color[i] != 0.0f) break; @@ -394,7 +389,6 @@ fz_append_display_node( } if (color) { - int i, n; const float *wc = &writer->color[0]; @@ -569,7 +563,8 @@ fz_append_display_node( default: { fz_colorspace **out_colorspace = (fz_colorspace **)(void *)(&node_ptr[colorspace_off]); - int i, n = colorspace->n; + int i, n; + n = colorspace ? colorspace->n : 0; *out_colorspace = fz_keep_colorspace(ctx, colorspace); writer->colorspace = fz_keep_colorspace(ctx, colorspace); @@ -1296,7 +1291,9 @@ fz_drop_display_list_imp(fz_context *ctx, fz_storable *list_) cs_n = 4; break; case CS_OTHER_0: - cs_n = (*(fz_colorspace **)node)->n; + cs_n = 0; + if (*(fz_colorspace **)node) + cs_n = (*(fz_colorspace **)node)->n; fz_drop_colorspace(ctx, *(fz_colorspace **)node); node += SIZE_IN_NODES(sizeof(fz_colorspace *)); break; @@ -1442,7 +1439,7 @@ fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, cons } if (n.cs) { - int i; + int i, en; fz_drop_colorspace(ctx, colorspace); switch (n.cs) @@ -1485,7 +1482,8 @@ fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, cons case CS_OTHER_0: colorspace = fz_keep_colorspace(ctx, *(fz_colorspace **)(node)); node += SIZE_IN_NODES(sizeof(fz_colorspace *)); - for (i = 0; i < colorspace->n; i++) + en = colorspace ? colorspace->n : 0; + for (i = 0; i < en; i++) color[i] = 0.0f; break; } diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index bb9a8fe0..998e4019 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -184,19 +184,22 @@ svg_dev_fill_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspace, fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; - if (colorspace != fz_device_rgb(ctx)) + if (colorspace) { - /* If it's not rgb, make it rgb */ - fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color); - color = rgb; - } + if (colorspace != fz_device_rgb(ctx)) + { + /* If it's not rgb, make it rgb */ + fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color); + color = rgb; + } - if (color[0] == 0 && color[1] == 0 && color[2] == 0) - { - /* don't send a fill, as it will be assumed to be black */ + if (color[0] == 0 && color[1] == 0 && color[2] == 0) + { + /* don't send a fill, as it will be assumed to be black */ + } + else + fz_printf(ctx, out, " fill=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); } - else - fz_printf(ctx, out, " fill=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); if (alpha != 1) fz_printf(ctx, out, " fill-opacity=\"%g\"", alpha); } @@ -207,14 +210,21 @@ svg_dev_stroke_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspac fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; - if (colorspace != fz_device_rgb(ctx)) + if (colorspace) { - /* If it's not rgb, make it rgb */ - fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color); - color = rgb; + if (colorspace != fz_device_rgb(ctx)) + { + /* If it's not rgb, make it rgb */ + fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color); + color = rgb; + } + fz_printf(ctx, out, " fill=\"none\" stroke=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); + } + else + { + /* don't send a stroke, as the color will be assumed to be none */ + fz_printf(ctx, out, " fill=\"none\""); } - - fz_printf(ctx, out, " fill=\"none\" stroke=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); if (alpha != 1) fz_printf(ctx, out, " stroke-opacity=\"%g\"", alpha); } diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c index 2965f958..0b77c075 100644 --- a/source/fitz/trace-device.c +++ b/source/fitz/trace-device.c @@ -17,10 +17,13 @@ static void fz_trace_color(fz_context *ctx, fz_output *out, fz_colorspace *colorspace, const float *color, float alpha) { int i; - fz_printf(ctx, out, " colorspace=\"%s\" color=\"", colorspace->name); - for (i = 0; i < colorspace->n; i++) - fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); - fz_printf(ctx, out, "\""); + if (colorspace) + { + fz_printf(ctx, out, " colorspace=\"%s\" color=\"", colorspace->name); + for (i = 0; i < colorspace->n; i++) + fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); + fz_printf(ctx, out, "\""); + } if (alpha < 1) fz_printf(ctx, out, " alpha=\"%g\"", alpha); } |