SVG: Add support for CAIRO_CONTENT_COLOR in create_similar.

Also add support for testing this feature in test/cairo-test.c
And a bunch of unwanted commit of sgml files.
This commit is contained in:
Emmanuel Pacaud 2006-04-16 15:42:49 +02:00
parent d0356a87f7
commit 714bb88832
29 changed files with 167 additions and 19 deletions

View file

@ -14,3 +14,6 @@ BeOS surface support
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,6 +14,9 @@ How a font should be rendered
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_font_options_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Base class for fonts
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_font_face_t ##### -->
<para>

View file

@ -14,3 +14,6 @@ Font support for FreeType
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ OpenGL accelerated rendering using the Glitz library
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -17,6 +17,9 @@ Rendering to memory buffers
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### ENUM cairo_format_t ##### -->
<para>

View file

@ -29,6 +29,9 @@ Generic matrix operations
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT cairo_matrix_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Creating paths and manipulating path data
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT cairo_path_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Gradients and filtered sources
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_pattern_t ##### -->
<para>

View file

@ -14,3 +14,6 @@ Rendering PDF documents
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,6 +14,9 @@ Reading and writing PNG images
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### USER_FUNCTION cairo_read_func_t ##### -->
<para>

View file

@ -14,3 +14,6 @@ Rendering PostScript documents
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ Rendering to Quartz surfaces
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,6 +14,9 @@ Caching metrics for a particular font size
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_scaled_font_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Decoding cairo's status
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### ENUM cairo_status_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Base class for surfaces
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_surface_t ##### -->
<para>

View file

@ -14,6 +14,9 @@ Rendering text and sets of glyphs
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT cairo_glyph_t ##### -->
<para>

View file

@ -14,3 +14,6 @@ Manipulating the current transformation matrix
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,6 +14,9 @@ Generic data types used in the cairo API
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### FUNCTION cairo_bool_t ##### -->
<para>

View file

@ -114,6 +114,9 @@ if (cairo_version() >= %CAIRO_VERSION_ENCODE(1, 0, 0))
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### MACRO CAIRO_VERSION ##### -->
<para>

View file

@ -14,3 +14,6 @@ Font support for Microsoft Windows
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ Microsoft Windows surface support
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ X Window System rendering using the XCB library
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ X Window System rendering using the XCB library
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ XLib/Xrender Backend
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -14,3 +14,6 @@ X Window System rendering using XLib
</para>
<!-- ##### SECTION Stability_Level ##### -->

View file

@ -24,6 +24,9 @@ The cairo drawing context
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### TYPEDEF cairo_t ##### -->
<para>

View file

@ -80,6 +80,8 @@ struct cairo_svg_document {
struct cairo_svg_surface {
cairo_surface_t base;
cairo_content_t content;
unsigned int id;
double width;
@ -112,8 +114,9 @@ _cairo_svg_document_reference (cairo_svg_document_t *document);
static cairo_surface_t *
_cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
double width,
double height);
cairo_content_t content,
double width,
double height);
static const cairo_surface_backend_t cairo_svg_surface_backend;
@ -129,7 +132,8 @@ _cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream,
if (document == NULL)
return NULL;
surface = _cairo_svg_surface_create_for_document (document, width, height);
surface = _cairo_svg_surface_create_for_document (document, CAIRO_CONTENT_COLOR_ALPHA,
width, height);
document->owner = surface;
_cairo_svg_document_destroy (document);
@ -234,11 +238,12 @@ cairo_svg_surface_set_dpi (cairo_surface_t *surface,
static cairo_surface_t *
_cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
double width,
double height)
cairo_content_t content,
double width,
double height)
{
cairo_svg_surface_t *surface;
xmlNodePtr clip, clip_rect;
xmlNodePtr clip, rect;
int clip_id;
char buffer[CAIRO_SVG_DTOSTR_BUFFER_LEN];
@ -262,11 +267,11 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
clip = xmlNewChild (document->xml_node_defs, NULL, CC2XML ("clipPath"), NULL);
snprintf (buffer, sizeof buffer, "clip%d", clip_id);
xmlSetProp (clip, CC2XML ("id"), C2XML (buffer));
clip_rect = xmlNewChild (clip, NULL, CC2XML ("rect"), NULL);
rect = xmlNewChild (clip, NULL, CC2XML ("rect"), NULL);
_cairo_dtostr (buffer, sizeof buffer, width);
xmlSetProp (clip_rect, CC2XML ("width"), C2XML (buffer));
xmlSetProp (rect, CC2XML ("width"), C2XML (buffer));
_cairo_dtostr (buffer, sizeof buffer, height);
xmlSetProp (clip_rect, CC2XML ("height"), C2XML (buffer));
xmlSetProp (rect, CC2XML ("height"), C2XML (buffer));
surface->xml_node = xmlNewNode (NULL, CC2XML ("g"));
surface->xml_root_node = surface->xml_node;
@ -276,9 +281,19 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document,
snprintf (buffer, sizeof buffer, "url(#clip%d)", clip_id);
xmlSetProp (surface->xml_node, CC2XML ("clip-path"), C2XML (buffer));
if (content == CAIRO_CONTENT_COLOR) {
rect = xmlNewChild (surface->xml_node, NULL, CC2XML ("rect"), NULL);
_cairo_dtostr (buffer, sizeof buffer, width);
xmlSetProp (rect, CC2XML ("width"), C2XML (buffer));
_cairo_dtostr (buffer, sizeof buffer, height);
xmlSetProp (rect, CC2XML ("height"), C2XML (buffer));
xmlSetProp (rect, CC2XML ("style"), CC2XML ("opacity:1; stroke:none; fill:rgb(0,0,0);"));
}
surface->modified = TRUE;
surface->previous_id = surface->id;
surface->content = content;
return &surface->base;
}
@ -290,8 +305,12 @@ _cairo_svg_surface_create_similar (void *abstract_src,
{
cairo_svg_surface_t *template = abstract_src;
if (content != CAIRO_CONTENT_COLOR_ALPHA &&
content != CAIRO_CONTENT_COLOR)
return (cairo_surface_t *) &_cairo_surface_nil;
return _cairo_svg_surface_create_for_document (template->document,
width, height);
content, width, height);
}
static cairo_status_t
@ -524,7 +543,8 @@ emit_composite_svg_pattern (xmlNodePtr node,
xmlAddChild (document->xml_node_defs, xmlCopyNode (surface->xml_root_node, 1));
child = xmlNewChild (node, NULL, CC2XML("use"), NULL);
snprintf (buffer, sizeof buffer, "#surface%d", surface->previous_id);
snprintf (buffer, sizeof buffer, "#surface%d",
surface->modified ? surface->id : surface->previous_id);
xmlSetProp (child, CC2XML ("xlink:href"), C2XML (buffer));
if (!is_pattern) {
@ -1061,9 +1081,28 @@ _cairo_svg_surface_paint (void *abstract_surface,
if (surface->clip_level == 0 &&
(op == CAIRO_OPERATOR_CLEAR ||
op == CAIRO_OPERATOR_SOURCE)) {
xmlFreeNode (surface->xml_root_node->children);
if (op == CAIRO_OPERATOR_CLEAR)
return CAIRO_STATUS_SUCCESS;
xmlNodePtr child = surface->xml_root_node->children;
while (child != NULL) {
xmlUnlinkNode (child);
xmlFreeNode (child);
child = surface->xml_root_node->children;
}
if (op == CAIRO_OPERATOR_CLEAR) {
if (surface->content == CAIRO_CONTENT_COLOR) {
xmlNodePtr rect;
char buffer[CAIRO_SVG_DTOSTR_BUFFER_LEN];
rect = xmlNewChild (surface->xml_node, NULL, CC2XML ("rect"), NULL);
_cairo_dtostr (buffer, sizeof buffer, surface->width);
xmlSetProp (rect, CC2XML ("width"), C2XML (buffer));
_cairo_dtostr (buffer, sizeof buffer, surface->height);
xmlSetProp (rect, CC2XML ("height"), C2XML (buffer));
xmlSetProp (rect, CC2XML ("style"), CC2XML ("opacity:1; stroke:none; fill:rgb(0,0,0);"));
}
return CAIRO_STATUS_SUCCESS;
}
}
emit_paint (surface->xml_node, surface, op, source);

View file

@ -1304,6 +1304,7 @@ typedef struct _svg_target_closure
{
char *filename;
int width, height;
cairo_surface_t *target;
} svg_target_closure_t;
static cairo_surface_t *
@ -1330,7 +1331,19 @@ create_svg_surface (cairo_test_t *test,
free (ptc);
return NULL;
}
cairo_svg_surface_set_dpi (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
ptc->target = surface;
surface = cairo_surface_create_similar (ptc->target,
CAIRO_CONTENT_COLOR,
width, height);
} else {
ptc->target = NULL;
}
cairo_surface_set_user_data (surface, &svg_closure_key, ptc, NULL);
return surface;
}
@ -1340,15 +1353,26 @@ svg_surface_write_to_png (cairo_surface_t *surface, const char *filename)
svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key);
char command[4096];
cairo_surface_finish (surface);
if (ptc->target) {
cairo_t *cr;
cr = cairo_create (ptc->target);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
cairo_destroy (cr);
cairo_surface_finish (surface);
surface = ptc->target;
}
cairo_surface_finish (surface);
sprintf (command, "./svg2png %s %s",
ptc->filename, filename);
if (system (command) != 0)
return CAIRO_STATUS_WRITE_ERROR;
return CAIRO_STATUS_WRITE_ERROR;
return CAIRO_STATUS_SUCCESS;
}
static void
@ -1593,10 +1617,14 @@ cairo_test_expecting (cairo_test_t *test, cairo_test_draw_function_t draw,
create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
#endif
#if CAIRO_HAS_SVG_SURFACE && CAIRO_CAN_TEST_SVG_SURFACE
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR,
create_svg_surface, svg_surface_write_to_png, cleanup_svg },
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA,
create_svg_surface, svg_surface_write_to_png, cleanup_svg },
/* A SVG surface is COLOR_APLHA by default, and currently a create
* similar with content != COLOR_ALPHA will return a nil surface.
* So don't test COLOR for now. */
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR,
create_svg_surface, svg_surface_write_to_png, cleanup_svg },
#endif
#if CAIRO_HAS_BEOS_SURFACE
{ "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR,