SVG support via libRSVG! (Now builds with SVG support on Ubuntu 07.04 (Fiesty))
This commit is contained in:
parent
b3805c4aea
commit
01fc74bd2d
4 changed files with 225 additions and 21 deletions
8
Makefile
8
Makefile
|
|
@ -103,8 +103,12 @@ SDL_MIXER_LIB=-lSDL_mixer
|
||||||
SDL_CFLAGS=$(shell sdl-config --cflags) $(SVG_CFLAGS)
|
SDL_CFLAGS=$(shell sdl-config --cflags) $(SVG_CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
SVG_LIB=-lcairo
|
SVG_LIB=-lrsvg-2 -lcairo
|
||||||
SVG_CFLAGS=-I/usr/include/cairo
|
SVG_CFLAGS=-I/usr/include/librsvg-2/librsvg \
|
||||||
|
-I/usr/include/gtk-2.0 \
|
||||||
|
-I/usr/include/glib-2.0 \
|
||||||
|
-I/usr/lib/glib-2.0/include \
|
||||||
|
-I/usr/include/cairo
|
||||||
|
|
||||||
|
|
||||||
# The entire set of CFLAGS:
|
# The entire set of CFLAGS:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
|
|
||||||
2007.June.12 (0.9.17)
|
2007.June.21 (0.9.17)
|
||||||
|
|
||||||
* Interface Improvements:
|
* Interface Improvements:
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
@ -50,12 +50,13 @@ $Id$
|
||||||
(Addresses SourceForge Bug #1070414)
|
(Addresses SourceForge Bug #1070414)
|
||||||
Mark K. Kim <mkkim214@gmail.com>
|
Mark K. Kim <mkkim214@gmail.com>
|
||||||
|
|
||||||
* Stamps now supports SVG vector-based graphics! (Via Cairo library)
|
* Stamps now supports SVG vector-based graphics!
|
||||||
(Only SVG versions of stamps are loaded, when both PNG and SVG
|
(Only SVG versions of stamps are loaded, when both PNG and SVG
|
||||||
variations are found.)
|
variations are found.)
|
||||||
|
|
||||||
(Experimental; build with "make nosvg" to disable SVG support and
|
* By default, uses librsvg-2 and libcairo2 (requires glib & much more).
|
||||||
Cairo dependency.)
|
* Use "make oldsvg" to build with libsvg and libcairo1 (older libs).
|
||||||
|
* Use "make nosvg" to completely disable SVG support.
|
||||||
|
|
||||||
* Stamps now shown in groups. Use previous & next buttons to
|
* Stamps now shown in groups. Use previous & next buttons to
|
||||||
cycle through stamp categories.
|
cycle through stamp categories.
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ INSTALL.txt for Tux Paint
|
||||||
|
|
||||||
Tux Paint - A simple drawing program for children.
|
Tux Paint - A simple drawing program for children.
|
||||||
|
|
||||||
Copyright 2002-2006 by Bill Kendrick and others
|
Copyright 2002-2007 by Bill Kendrick and others
|
||||||
bill@newbreedsoftware.com
|
bill@newbreedsoftware.com
|
||||||
http://www.tuxpaint.org/
|
http://www.tuxpaint.org/
|
||||||
|
|
||||||
June 27, 2002 - December 16, 2006
|
June 27, 2002 - June 21, 2007
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -76,12 +76,38 @@ Requirements:
|
||||||
|
|
||||||
http://www.gnu.org/software/gettext/
|
http://www.gnu.org/software/gettext/
|
||||||
|
|
||||||
Cairo, libsvg, svg-cairo [EXPERIMENTAL] [can be disabled]
|
SVG graphics support
|
||||||
----------------------------------------
|
--------------------
|
||||||
As of Tux Paint 0.9.17, SVG vector graphics are supported by the
|
As of Tux Paint 0.9.17, Tux Paint can load SVG
|
||||||
'Stamps' tool.
|
(Scalable Vector Graphics) images as stamps.
|
||||||
|
Two sets of libraries are supported, and SVG support can be
|
||||||
|
completely disabled (via "make nosvg")
|
||||||
|
|
||||||
http://www.cairographics.org/
|
librsvg-2, libCairo2 [newer libraries; default "make" target]
|
||||||
|
--------------------------------------------------------------
|
||||||
|
libRSVG 2
|
||||||
|
http://librsvg.sourceforge.net/
|
||||||
|
|
||||||
|
Cairo 2
|
||||||
|
http://www.cairographics.org/
|
||||||
|
|
||||||
|
Also depends on:
|
||||||
|
GdkPixbuf
|
||||||
|
GLib
|
||||||
|
http://www.gtk.org/
|
||||||
|
|
||||||
|
Pango
|
||||||
|
http://www.pango.org/
|
||||||
|
|
||||||
|
Older libraries ("make oldsvg")
|
||||||
|
-------------------------------
|
||||||
|
libcairo1
|
||||||
|
libsvg1
|
||||||
|
libsvg-cairo1
|
||||||
|
http://www.cairographics.org/
|
||||||
|
|
||||||
|
Also depends on:
|
||||||
|
libxml2
|
||||||
|
|
||||||
NetPBM Tools [OPTIONAL] [No longer used, by default]
|
NetPBM Tools [OPTIONAL] [No longer used, by default]
|
||||||
------------------------
|
------------------------
|
||||||
|
|
|
||||||
189
src/tuxpaint.c
189
src/tuxpaint.c
|
|
@ -22,7 +22,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
June 14, 2002 - June 19, 2007
|
June 14, 2002 - June 21, 2007
|
||||||
$Id$
|
$Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -361,12 +361,13 @@ extern WrapperData macosx;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "xyzsvg.h"
|
#include "rsvg.h"
|
||||||
#ifndef XYZ_SVG_H
|
#include "rsvg-cairo.h"
|
||||||
|
#if !defined(RSVG_H) || !defined(RSVG_CAIRO_H)
|
||||||
#error "---------------------------------------------------"
|
#error "---------------------------------------------------"
|
||||||
#error "If you installed libXYZ from packages, be sure"
|
#error "If you installed libRSVG from packages, be sure"
|
||||||
#error "to get the development package, as well!"
|
#error "to get the development package, as well!"
|
||||||
#error "(e.g., 'libXYZ-dev.rpm')"
|
#error "(e.g., 'librsvg2-dev.rpm')"
|
||||||
#error "---------------------------------------------------"
|
#error "---------------------------------------------------"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -16411,7 +16412,9 @@ int paintsound(int size)
|
||||||
|
|
||||||
#ifdef OLD_SVG
|
#ifdef OLD_SVG
|
||||||
|
|
||||||
|
// Old libcairo1, svg and svg-cairo based code
|
||||||
// Based on cairo-demo/sdl/main.c from Cairo (GPL'd, (c) 2004 Eric Windisch):
|
// Based on cairo-demo/sdl/main.c from Cairo (GPL'd, (c) 2004 Eric Windisch):
|
||||||
|
|
||||||
SDL_Surface * load_svg(char * file)
|
SDL_Surface * load_svg(char * file)
|
||||||
{
|
{
|
||||||
svg_cairo_t * scr;
|
svg_cairo_t * scr;
|
||||||
|
|
@ -16494,10 +16497,10 @@ SDL_Surface * load_svg(char * file)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create the cairo surface with the adjusted width and height
|
// Create the cairo surface with the adjusted width and height
|
||||||
|
|
||||||
cairo_surface = cairo_image_surface_create_for_data(image,
|
cairo_surface = cairo_image_surface_create_for_data(image,
|
||||||
CAIRO_FORMAT_ARGB32,
|
CAIRO_FORMAT_ARGB32,
|
||||||
width, height, stride);
|
width, height, stride);
|
||||||
|
|
||||||
cr = cairo_create(cairo_surface);
|
cr = cairo_create(cairo_surface);
|
||||||
if (cr == NULL)
|
if (cr == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -16571,11 +16574,181 @@ SDL_Surface * load_svg(char * file)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
// New libcairo2, rsvg and rsvg-cairo based code
|
||||||
SDL_Surface * load_svg(char * file)
|
SDL_Surface * load_svg(char * file)
|
||||||
{
|
{
|
||||||
printf("load_svg(%s)\n", file);
|
cairo_surface_t * cairo_surf;
|
||||||
|
cairo_t * cr;
|
||||||
|
RsvgHandle * rsvg_handle;
|
||||||
|
GError * gerr;
|
||||||
|
unsigned char * image;
|
||||||
|
int rwidth, rheight;
|
||||||
|
int width, height, stride;
|
||||||
|
float scale;
|
||||||
|
int bpp = 32, btpp = 4;
|
||||||
|
RsvgDimensionData dimensions;
|
||||||
|
SDL_Surface * sdl_surface, * sdl_surface_tmp;
|
||||||
|
Uint32 rmask, gmask, bmask, amask;
|
||||||
|
|
||||||
return (NULL);
|
#ifdef DEBUG
|
||||||
|
printf("load_svg(%s)\n", file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Create an RSVG Handle from the SVG file: */
|
||||||
|
|
||||||
|
rsvg_init();
|
||||||
|
|
||||||
|
gerr = NULL;
|
||||||
|
|
||||||
|
rsvg_handle = rsvg_handle_new_from_file(file, &gerr);
|
||||||
|
if (rsvg_handle == NULL)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "rsvg_handle_new_from_file() failed\n");
|
||||||
|
#endif
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
rsvg_handle_get_dimensions(rsvg_handle, &dimensions);
|
||||||
|
rwidth = dimensions.width;
|
||||||
|
rheight = dimensions.height;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("SVG is %d x %d\n", rwidth, rheight);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Pick best scale to render to (for the canvas in this instance of Tux Paint)
|
||||||
|
|
||||||
|
scale = pick_best_scape(rwidth, rheight, r_canvas.w, r_canvas.h);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("best scale is %.4f\n", scale);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
width = ((float) rwidth * scale);
|
||||||
|
height = ((float) rheight * scale);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("scaling to %d x %d (%f scale)\n", width, height, scale);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// scanline width
|
||||||
|
stride = width * btpp;
|
||||||
|
|
||||||
|
// Allocate space for an image:
|
||||||
|
image = calloc(stride * height, 1);
|
||||||
|
if (image == NULL)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "Unable to allocate image buffer\n");
|
||||||
|
#endif
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Create a surface for Cairo to draw into: */
|
||||||
|
|
||||||
|
cairo_surf = cairo_image_surface_create_for_data(image,
|
||||||
|
CAIRO_FORMAT_ARGB32,
|
||||||
|
width, height, stride);
|
||||||
|
|
||||||
|
if (cairo_surface_status(cairo_surf) != CAIRO_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "cairo_image_surface_create() failed\n");
|
||||||
|
#endif
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
free(image);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Create a new Cairo object: */
|
||||||
|
|
||||||
|
cr = cairo_create(cairo_surf);
|
||||||
|
if (cairo_status(cr) != CAIRO_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "cairo_create() failed\n");
|
||||||
|
#endif
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
cairo_surface_destroy(cairo_surf);
|
||||||
|
free(image);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Ask RSVG to render the SVG into the Cairo object: */
|
||||||
|
|
||||||
|
cairo_scale(cr, scale, scale);
|
||||||
|
|
||||||
|
/* FIXME: We can use cairo_rotate() here to rotate stamps! -bjk 2007.06.21 */
|
||||||
|
|
||||||
|
rsvg_handle_render_cairo(rsvg_handle, cr);
|
||||||
|
|
||||||
|
|
||||||
|
cairo_surface_finish(cairo_surf);
|
||||||
|
|
||||||
|
|
||||||
|
// Adjust the SDL surface to match the cairo surface created
|
||||||
|
// (surface mask of ARGB) NOTE: Is this endian-agnostic? -bjk 2006.10.25
|
||||||
|
rmask = 0x00ff0000;
|
||||||
|
gmask = 0x0000ff00;
|
||||||
|
bmask = 0x000000ff;
|
||||||
|
amask = 0xff000000;
|
||||||
|
|
||||||
|
// Create the SDL surface using the pixel data stored:
|
||||||
|
sdl_surface_tmp = SDL_CreateRGBSurfaceFrom((void *) image, width, height,
|
||||||
|
bpp, stride,
|
||||||
|
rmask, gmask, bmask, amask);
|
||||||
|
|
||||||
|
if (sdl_surface_tmp == NULL)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "SDL_CreateRGBSurfaceFrom() failed\n");
|
||||||
|
#endif
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
cairo_surface_destroy(cairo_surf);
|
||||||
|
free(image);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the SDL surface to the display format, for faster blitting:
|
||||||
|
sdl_surface = SDL_DisplayFormatAlpha(sdl_surface_tmp);
|
||||||
|
SDL_FreeSurface(sdl_surface_tmp);
|
||||||
|
|
||||||
|
if (sdl_surface == NULL)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "SDL_DisplayFormatAlpha() failed\n");
|
||||||
|
#endif
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
cairo_surface_destroy(cairo_surf);
|
||||||
|
free(image);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("SDL surface from %d x %d SVG is %d x %d\n",
|
||||||
|
rwidth, rheight, sdl_surface->w, sdl_surface->h);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Clean up: */
|
||||||
|
|
||||||
|
g_object_unref(rsvg_handle);
|
||||||
|
cairo_surface_destroy(cairo_surf);
|
||||||
|
free(image);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
rsvg_term();
|
||||||
|
|
||||||
|
return(sdl_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue