add optionnal disabled by default SVG backend.

include SVG backend files.
include SVG_SURFACE_FEATURE.
rename dtostr to _cairo_dtostr for use in cairo-svg-surface.c.
_cairo_dtostr declaration.
new.
new.
build svg-surface and svg-clip.
new.
new.
This commit is contained in:
Emmanuel Pacaud 2005-12-08 13:09:26 +00:00
parent 73df5f2d62
commit b2f973e7f4
11 changed files with 1723 additions and 13 deletions

View file

@ -1,3 +1,19 @@
2005-12-08 Emmanuel Pacaud <emmanuel.pacaud@free.fr>
* configure.in: add optionnal disabled by default SVG backend.
* src/Makefile.am: include SVG backend files.
* src/cairo-features.h.in: include SVG_SURFACE_FEATURE.
* src/cairo-output-stream.c: rename dtostr to _cairo_dtostr for use in
cairo-svg-surface.c.
* src/cairoint.h: _cairo_dtostr declaration.
* src/cairo-svg.h: new.
* src/cairo-svg-surface.c: new.
* test/Makefile.am: build svg-surface and svg-clip.
* test/svg-surface.c: new.
* test/svg-surface.h: new.
2005-12-07 Carl Worth <cworth@cworth.org>
* ROADMAP: Note that that PDF backend has been incorporated into

View file

@ -432,6 +432,37 @@ AC_SUBST(PDF_LIBS)
dnl ===========================================================================
AC_ARG_ENABLE(svg,
[ --enable-svg Enable cairo's SVG backend],
[use_svg=$enableval], [use_svg=no])
if test x"$have_ft_load_sfnt_table" != "xyes" ; then
AC_MSG_WARN([PDF backend requires FreeType 2.1.4 or newer, disabling])
use_svg=no
fi
if test "x$use_svg" = "xyes" ; then
use_svg=no
if $PKG_CONFIG --exists libxml-2.0 ; then
# Sets XML_CFLAGS, XML_LIBS
PKG_CHECK_MODULES(XML, libxml-2.0)
use_svg=yes
else
AC_MSG_WARN([SVG requires libxml2, which is not found in pkg-config search path, disabling])
fi
fi
AM_CONDITIONAL(CAIRO_HAS_SVG_SURFACE, test "x$use_svg" = "xyes")
if test "x$use_svg" = "xyes"; then
SVG_SURFACE_FEATURE="#define CAIRO_HAS_SVG_SURFACE 1"
fi
AC_SUBST(SVG_SURFACE_FEATURE)
CAIRO_CFLAGS="$CAIRO_CFLAGS $XML_CFLAGS"
CAIRO_LIBS="$CAIRO_LIBS $XML_LIBS"
dnl ===========================================================================
dnl This check should default to 'yes' once we have code to actually
dnl check for the atsui font backend.
@ -537,18 +568,19 @@ dnl ===========================================================================
echo ""
echo "cairo will be compiled with the following surface backends:"
echo " Xlib: $use_xlib"
echo " Quartz: $use_quartz"
echo " XCB: $use_xcb"
echo " Win32: $use_win32"
echo " Xlib: $use_xlib"
echo " Quartz: $use_quartz"
echo " XCB: $use_xcb"
echo " Win32: $use_win32"
echo " PostScript: $use_ps"
echo " PDF: $use_pdf"
echo " glitz: $use_glitz"
echo " PDF: $use_pdf"
echo " SVG: $use_svg"
echo " glitz: $use_glitz"
echo ""
echo "the following font backends:"
echo " FreeType: $use_freetype"
echo " Win32: $use_win32"
echo " ATSUI: $use_atsui"
echo " FreeType: $use_freetype"
echo " Win32: $use_win32"
echo " ATSUI: $use_atsui"
echo ""
echo "and the following features:"
echo " PNG functions: $use_png"

View file

@ -11,6 +11,11 @@ libcairo_pdf_sources = cairo-pdf-surface.c
libcairo_font_subset_sources = cairo-font-subset.c cairo-font-subset-private.h
endif
if CAIRO_HAS_SVG_SURFACE
libcairo_svg_headers = cairo-svg.h
libcairo_svg_sources = cairo-svg-surface.c
endif
if CAIRO_HAS_PNG_FUNCTIONS
libcairo_png_sources = cairo-png.c
endif
@ -80,6 +85,7 @@ cairoinclude_HEADERS = \
$(libcairo_ft_headers) \
$(libcairo_glitz_headers) \
$(libcairo_pdf_headers) \
$(libcairo_svg_headers) \
$(libcairo_ps_headers) \
$(libcairo_quartz_headers) \
$(libcairo_win32_headers) \
@ -139,6 +145,7 @@ libcairo_la_SOURCES = \
$(libcairo_ft_sources) \
$(libcairo_ps_sources) \
$(libcairo_pdf_sources) \
$(libcairo_svg_sources) \
$(libcairo_font_subset_sources) \
$(libcairo_png_sources) \
$(libcairo_xlib_sources) \

View file

@ -59,6 +59,8 @@
@PDF_SURFACE_FEATURE@
@SVG_SURFACE_FEATURE@
@XLIB_SURFACE_FEATURE@
@QUARTZ_SURFACE_FEATURE@

View file

@ -119,8 +119,8 @@ _cairo_output_stream_write_hex_string (cairo_output_stream_t *stream,
* http://mail.gnome.org/archives/gtk-devel-list/2001-October/msg00087.html
*/
static int
dtostr (char *buffer, size_t size, double d)
int
_cairo_dtostr (char *buffer, size_t size, double d)
{
struct lconv *locale_data;
const char *decimal_point;
@ -233,7 +233,7 @@ _cairo_output_stream_vprintf (cairo_output_stream_t *stream,
snprintf (buffer, sizeof buffer, "%s", va_arg (ap, const char *));
break;
case 'f':
dtostr (buffer, sizeof buffer, va_arg (ap, double));
_cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double));
break;
case 'c':
buffer[0] = va_arg (ap, int);

1330
src/cairo-svg-surface.c Normal file

File diff suppressed because it is too large Load diff

63
src/cairo-svg.h Normal file
View file

@ -0,0 +1,63 @@
/* cairo - a vector graphics library with display and print output
*
* cairo-svg.h
*
* Copyright © 2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
*/
#ifndef CAIRO_SVG_H
#define CAIRO_SVG_H
#include <cairo.h>
#if CAIRO_HAS_SVG_SURFACE
CAIRO_BEGIN_DECLS
cairo_surface_t *
cairo_svg_surface_create (const char *filename,
double width_in_points,
double height_in_points);
cairo_surface_t *
cairo_svg_surface_create_for_stream (cairo_write_func_t write_func,
void *closure,
double width_in_points,
double height_in_points);
void
cairo_svg_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi);
CAIRO_END_DECLS
#else /* CAIRO_HAS_SVG_SURFACE */
# error Cairo was not compiled with support for the svg backend
#endif /* CAIRO_HAS_SVG_SURFACE */
#endif /* CAIRO_SVG_H */

View file

@ -2144,6 +2144,9 @@ _cairo_output_stream_create_for_file (const char *filename);
cairo_private void
_cairo_error (cairo_status_t status);
cairo_private int
_cairo_dtostr (char *buffer, size_t size, double d);
/* Avoid unnecessary PLT entries. */
slim_hidden_proto(cairo_get_current_point)

View file

@ -73,6 +73,10 @@ if CAIRO_HAS_PDF_SURFACE
TESTS += pdf-surface pdf-clip
endif
if CAIRO_HAS_SVG_SURFACE
TESTS += svg-surface svg-clip
endif
if CAIRO_HAS_PS_SURFACE
TESTS += ps-surface
endif
@ -294,7 +298,9 @@ paint_LDADD = $(LDADDS)
paint_with_alpha_LDADD = $(LDADDS)
path_data_LDADD = $(LDADDS)
pdf_surface_LDADD = $(LDADDS)
svg_surface_LDADD = $(LDADDS)
pdf_clip_LDADD = $(LDADDS)
svg_clip_LDADD = $(LDADDS)
pixman_rotate_LDADD = $(LDADDS)
ps_surface_LDADD = $(LDADDS)
pthread_show_text_LDADD = $(LDADDS)
@ -340,7 +346,9 @@ CLEANFILES = \
*.log \
ps-surface.ps \
pdf-surface.pdf \
pdf-clip.pdf
svg-surface.svg \
pdf-clip.pdf \
svg-clip.svg
check-valgrind:
TESTS_ENVIRONMENT="libtool --mode=execute valgrind --tool=memcheck --suppressions=./.valgrind-suppressions --leak-check=yes --show-reachable=yes" $(MAKE) check 2>&1 | tee valgrind.log

134
test/svg-clip.c Normal file
View file

@ -0,0 +1,134 @@
/*
* Copyright © 2005 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Red Hat, Inc. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Red Hat, Inc. makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Kristian Høgsberg <krh@redhat.com>
*/
#include <stdio.h>
#include <cairo-svg.h>
#include "cairo-test.h"
/* Test SVG clipping */
#define WIDTH_IN_POINTS 600
#define HEIGHT_IN_POINTS 600
static void
test_clip (cairo_t *cr, double width, double height)
{
cairo_t *cr2;
/* Basic test; set a square clip and draw a circle to be clipped
* against it.*/
cairo_rectangle (cr, 100, 100, 400, 400);
cairo_clip (cr);
cairo_arc (cr, 300, 300, 210, 0, 2 * M_PI);
cairo_set_source_rgb (cr, 1, 0, 0);
cairo_fill (cr);
/* Add a plus shaped clip path to the square clip and draw a big
* green square to test the new clip path. */
cairo_save (cr);
cairo_rectangle (cr, 250, 100, 100, 400);
cairo_rectangle (cr, 100, 250, 400, 100);
cairo_clip (cr);
cairo_rectangle (cr, 0, 0, 600, 600);
cairo_set_source_rgb (cr, 0, 1, 0);
cairo_fill (cr);
cairo_restore (cr);
/* Set a bezier shape in addition to the rectangle clip set before
* the cairo_save() to verify that we successfully removed the
* plus shaped clip path and can set a new clip.*/
cairo_move_to (cr, 600, 0);
cairo_curve_to (cr, 300, 600, 0, 300, 600, 0);
cairo_clip (cr);
cairo_rectangle (cr, 0, 0, 600, 600);
cairo_set_source_rgb (cr, 0, 0, 1);
cairo_fill (cr);
/* Create a new context for this surface to test overlapped
* drawing from two contexts */
cr2 = cairo_create (cairo_get_target (cr));
/* Using the new context, draw a black vertical line, which should
* appear unclipped on top of everything drawn so far. */
cairo_move_to (cr2, 110, 0);
cairo_line_to (cr2, 110, 600);
cairo_stroke (cr2);
/* Using the first context, draw another black vertical line.
* This line should be clipped agaist the bezier clipping path set
* earlier. */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to (cr, 400, 0);
cairo_line_to (cr, 400, 600);
cairo_stroke (cr);
cairo_destroy (cr2);
/* Test reset clip. Draw a transparent black circle over
* everything. Specifically, make sure the circle extends outside
* the square clip set at the top of this function. */
cairo_reset_clip (cr);
cairo_arc (cr, 300, 300, 220, 0, 2 * M_PI);
cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
cairo_fill (cr);
}
int
main (void)
{
cairo_t *cr;
const char *filename = "svg-clip.svg";
cairo_surface_t *surface;
printf("\n");
surface = cairo_svg_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
if (surface == NULL) {
fprintf (stderr, "Failed to create svg surface for file %s\n", filename);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
test_clip (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
cairo_show_page (cr);
cairo_destroy (cr);
cairo_surface_destroy (surface);
printf ("svg-surface: Please check %s to make sure it looks happy.\n",
filename);
return 0;
}

115
test/svg-surface.c Normal file
View file

@ -0,0 +1,115 @@
/*
* Copyright © 2005 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Red Hat, Inc. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Red Hat, Inc. makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Carl D. Worth <cworth@cworth.org>
*/
#include <stdio.h>
#include <cairo-svg.h>
#include "cairo-test.h"
/* Pretty boring test just to make sure things aren't crashing ---
* no verification that we're getting good results yet.
* But you can manually view the image to make sure it looks happy.
*/
#define WIDTH_IN_INCHES 3
#define HEIGHT_IN_INCHES 3
#define WIDTH_IN_POINTS (WIDTH_IN_INCHES * 72.0)
#define HEIGHT_IN_POINTS (HEIGHT_IN_INCHES * 72.0)
static void
draw (cairo_t *cr, double width, double height)
{
#define STROKE_WIDTH .04
double size;
if (width > height)
size = height;
else
size = width;
cairo_translate (cr, (width - size) / 2.0, (height - size) / 2.0);
cairo_scale (cr, size, size);
/* Fill face */
cairo_arc (cr, 0.5, 0.5, 0.5 - STROKE_WIDTH, 0, 2 * M_PI);
cairo_set_source_rgb (cr, 1, 1, 0);
cairo_save (cr);
{
cairo_fill (cr);
}
cairo_restore (cr);
cairo_set_source_rgb (cr, 0, 0, 0);
/* Stroke face */
cairo_set_line_width (cr, STROKE_WIDTH / 2.0);
cairo_stroke (cr);
/* Eyes */
cairo_set_line_width (cr, STROKE_WIDTH);
cairo_arc (cr, 0.3, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
cairo_fill (cr);
cairo_arc (cr, 0.7, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
cairo_fill (cr);
/* Mouth */
cairo_move_to (cr, 0.3, 0.7);
cairo_curve_to (cr,
0.4, 0.8,
0.6, 0.8,
0.7, 0.7);
cairo_stroke (cr);
}
int
main (void)
{
cairo_t *cr;
const char *filename = "svg-surface.svg";
cairo_surface_t *surface;
printf("\n");
surface = cairo_svg_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
if (surface == NULL) {
fprintf (stderr, "Failed to create svg surface for file %s\n", filename);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
draw (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
cairo_show_page (cr);
cairo_destroy (cr);
cairo_surface_destroy (surface);
printf ("svg-surface: Please check svg-surface.svg to make sure it looks happy.\n");
return 0;
}