Add support for CAIRO_CONTENT_COLOR

This commit is contained in:
Anton Danilkin 2021-05-01 23:11:13 +02:00
parent a3e01d9e8c
commit bd487e64fc
4 changed files with 52 additions and 24 deletions

View file

@ -218,8 +218,6 @@ _cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
cairo_surface_t *image;
double x_offset, y_offset;
double x_scale, y_scale;
svg_target_closure_t *ptc = cairo_surface_get_user_data (surface,
&svg_closure_key);
if (page != 0)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
@ -230,15 +228,6 @@ _cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
cairo_surface_set_device_offset (image, x_offset, y_offset);
cairo_surface_set_device_scale (image, x_scale, y_scale);
surface = _cairo_boilerplate_get_image_surface (image, 0, width, height);
if (ptc->target) {
cairo_surface_t *old_surface = surface;
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
cairo_t *cr = cairo_create (surface);
cairo_set_source_surface (cr, old_surface, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
cairo_surface_destroy (old_surface);
}
cairo_surface_destroy (image);
return surface;
@ -293,6 +282,19 @@ static const cairo_boilerplate_target_t targets[] = {
_cairo_boilerplate_svg_cleanup,
NULL, NULL, FALSE, TRUE, TRUE
},
{
"svg11", "svg", ".svg", NULL,
CAIRO_SURFACE_TYPE_RECORDING, CAIRO_CONTENT_COLOR, 1,
"cairo_svg_surface_create",
_cairo_boilerplate_svg11_create_surface,
cairo_surface_create_similar,
_cairo_boilerplate_svg_force_fallbacks,
_cairo_boilerplate_svg_finish_surface,
_cairo_boilerplate_svg_get_image_surface,
_cairo_boilerplate_svg_surface_write_to_png,
_cairo_boilerplate_svg_cleanup,
NULL, NULL, FALSE, TRUE, TRUE
},
};
CAIRO_BOILERPLATE (svg, targets)

View file

@ -218,8 +218,6 @@ typedef struct _cairo_svg_surface {
unsigned int source_id;
unsigned int depth;
cairo_content_t content;
double width;
double height;
cairo_bool_t surface_bounded;
@ -277,6 +275,11 @@ _cairo_svg_surface_emit_composite_pattern (cairo_output_stream_t *output,
unsigned int pattern_id,
const cairo_matrix_t *parent_matrix);
static cairo_status_t
_cairo_svg_surface_emit_paint (cairo_output_stream_t *output,
cairo_svg_surface_t *surface,
const cairo_pattern_t *source);
static const cairo_surface_backend_t cairo_svg_surface_backend;
static const cairo_paginated_surface_backend_t cairo_svg_surface_paginated_backend;
@ -621,10 +624,10 @@ _cairo_svg_paint_box_add_padding (cairo_box_double_t *box)
double width = box->p2.x - box->p1.x;
double height = box->p2.y - box->p1.y;
box->p1.x -= width / 10;
box->p1.y -= height / 10;
box->p2.x += width / 10;
box->p2.y += height / 10;
box->p1.x -= width / 10.0;
box->p1.y -= height / 10.0;
box->p2.x += width / 10.0;
box->p2.y += height / 10.0;
}
static void
@ -858,8 +861,6 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
surface->source_id = surface->base.unique_id;
surface->depth = 0;
surface->content = content;
surface->width = width;
surface->height = height;
surface->surface_bounded = bounded;
@ -887,7 +888,7 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
paginated = _cairo_paginated_surface_create (&surface->base,
surface->content,
surface->base.content,
&cairo_svg_surface_paginated_backend);
status = paginated->status;
if (status == CAIRO_STATUS_SUCCESS) {
@ -1996,6 +1997,9 @@ _cairo_svg_surface_emit_recording_surface (cairo_svg_surface_t *surface,
document->owner->x_fallback_resolution,
document->owner->y_fallback_resolution);
if (source->base.content == CAIRO_CONTENT_COLOR) {
_cairo_svg_surface_emit_paint (svg_surface->xml_node, svg_surface, &_cairo_pattern_black.base);
}
status = _cairo_recording_surface_replay (&source->base, paginated_surface);
if (unlikely (status)) {
cairo_surface_destroy (paginated_surface);
@ -2683,7 +2687,7 @@ _cairo_svg_surface_emit_fill_style (cairo_output_stream_t *output,
const cairo_matrix_t *parent_matrix)
{
_cairo_output_stream_printf (output,
" fill-rule=\"%s\" ",
" fill-rule=\"%s\"",
fill_rule == CAIRO_FILL_RULE_EVEN_ODD ? "evenodd" : "nonzero");
return _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, parent_matrix);
}
@ -2823,6 +2827,19 @@ _cairo_svg_surface_do_operator (cairo_output_stream_t *output,
cairo_status_t status;
cairo_svg_document_t *document = surface->document;
// For operators that do not always produce opaque output, we first need to emit a black paint
// if the content does not have alpha
if (surface->base.content == CAIRO_CONTENT_COLOR && (op == CAIRO_OPERATOR_CLEAR ||
op == CAIRO_OPERATOR_SOURCE ||
op == CAIRO_OPERATOR_IN ||
op == CAIRO_OPERATOR_OUT ||
op == CAIRO_OPERATOR_DEST_IN ||
op == CAIRO_OPERATOR_DEST_OUT ||
op == CAIRO_OPERATOR_DEST_ATOP ||
op == CAIRO_OPERATOR_XOR)) {
_cairo_svg_surface_emit_paint (output, surface, &_cairo_pattern_black.base);
}
if (op == CAIRO_OPERATOR_CLEAR) {
/*
* The result is the same as one of the SOURCE operation application with the same arguments,

View file

@ -32,7 +32,7 @@ void
example (cairo_t *cr, char *name)
{
cairo_save (cr);
cairo_push_group (cr);
cairo_push_group_with_content (cr, cairo_surface_get_content (cairo_get_target (cr)));
cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
cairo_clip (cr);
@ -107,14 +107,23 @@ example (cairo_t *cr, char *name)
cairo_set_source_rgba (cr, 0, 0, 0.9, 0.4);
cairo_fill (cr);
cairo_pop_group_to_source (cr);
cairo_pattern_t *pattern = cairo_pop_group (cr);
cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
cairo_clip (cr);
// Make problems with CAIRO_CONTENT_COLOR visible
if (cairo_surface_get_content (cairo_get_target (cr)) == CAIRO_CONTENT_COLOR) {
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
}
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
cairo_paint (cr);
cairo_restore (cr);
cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 17);
cairo_set_font_size (cr, 17);
cairo_move_to (cr, WIDTH + 20, 70);
cairo_set_source_rgb (cr, 1, 1, 0);
cairo_show_text (cr, name);

View file

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB