name the vectors after the path id as found in the SVG.
2003-09-15 Sven Neumann <sven@gimp.org> * app/vectors/gimpvectors-import.c: name the vectors after the path id as found in the SVG. * app/vectors/gimpvectors-export.c: further improved formatting.
This commit is contained in:

committed by
Sven Neumann

parent
d885f25196
commit
00c7d7b402
@ -1,3 +1,10 @@
|
|||||||
|
2003-09-15 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/vectors/gimpvectors-import.c: name the vectors after the
|
||||||
|
path id as found in the SVG.
|
||||||
|
|
||||||
|
* app/vectors/gimpvectors-export.c: further improved formatting.
|
||||||
|
|
||||||
2003-09-15 Simon Budig <simon@gimp.org>
|
2003-09-15 Simon Budig <simon@gimp.org>
|
||||||
|
|
||||||
* app/vectors/gimpvectors-export.c: Save an id-attribute
|
* app/vectors/gimpvectors-export.c: Save an id-attribute
|
||||||
|
@ -80,10 +80,10 @@ gimp_vectors_export (const GimpImage *image,
|
|||||||
fprintf (file,
|
fprintf (file,
|
||||||
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
||||||
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"
|
||||||
"\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
|
" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
|
||||||
fprintf (file,
|
fprintf (file,
|
||||||
"<svg viewBox=\"0 0 %d %d\"\n"
|
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n"
|
||||||
" xmlns=\"http://www.w3.org/2000/svg\">\n",
|
" viewBox=\"0 0 %d %d\">\n\n",
|
||||||
image->width, image->height);
|
image->width, image->height);
|
||||||
|
|
||||||
if (vectors)
|
if (vectors)
|
||||||
@ -98,8 +98,7 @@ gimp_vectors_export (const GimpImage *image,
|
|||||||
gimp_vectors_export_path (GIMP_VECTORS (list->data), file);
|
gimp_vectors_export_path (GIMP_VECTORS (list->data), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (file,
|
fprintf (file, "</svg>\n");
|
||||||
"</svg>\n");
|
|
||||||
|
|
||||||
if (fclose (file))
|
if (fclose (file))
|
||||||
{
|
{
|
||||||
@ -119,13 +118,13 @@ gimp_vectors_export_path (const GimpVectors *vectors,
|
|||||||
const gchar *name = gimp_object_get_name (GIMP_OBJECT (vectors));
|
const gchar *name = gimp_object_get_name (GIMP_OBJECT (vectors));
|
||||||
gchar *data = gimp_vectors_path_data (vectors);
|
gchar *data = gimp_vectors_path_data (vectors);
|
||||||
gchar *esc_name;
|
gchar *esc_name;
|
||||||
|
|
||||||
esc_name = g_markup_escape_text (name, strlen (name));
|
esc_name = g_markup_escape_text (name, strlen (name));
|
||||||
|
|
||||||
fprintf (file,
|
fprintf (file,
|
||||||
" <path id=\"%s\"\n"
|
" <path id=\"%s\"\n"
|
||||||
" fill=\"none\" stroke=\"black\" stroke-width=\"1\"\n"
|
" fill=\"none\" stroke=\"black\" stroke-width=\"1\"\n"
|
||||||
" d=\"%s\"/>\n",
|
" d=\"%s\" />\n",
|
||||||
esc_name, data);
|
esc_name, data);
|
||||||
|
|
||||||
g_free (esc_name);
|
g_free (esc_name);
|
||||||
@ -183,11 +182,11 @@ gimp_vectors_path_data (const GimpVectors *vectors)
|
|||||||
g_string_append_printf (str, " %s,%s", x_string, y_string);
|
g_string_append_printf (str, " %s,%s", x_string, y_string);
|
||||||
|
|
||||||
if (i % 3 == 1)
|
if (i % 3 == 1)
|
||||||
g_string_append_printf (str, "\n ");
|
g_string_append_printf (str, "\n ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closed && control_points->len > 3)
|
if (closed && control_points->len > 3)
|
||||||
g_string_append_printf (str, "Z");
|
g_string_append_printf (str, "Z");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -218,15 +217,15 @@ gimp_vectors_path_data (const GimpVectors *vectors)
|
|||||||
g_string_append_printf (str, " %s,%s", x_string, y_string);
|
g_string_append_printf (str, " %s,%s", x_string, y_string);
|
||||||
|
|
||||||
if (i % 3 == 1)
|
if (i % 3 == 1)
|
||||||
g_string_append_printf (str, "\n ");
|
g_string_append_printf (str, "\n ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closed && control_points->len > 1)
|
if (closed && control_points->len > 1)
|
||||||
g_string_append_printf (str, " Z");
|
g_string_append_printf (str, " Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_free (control_points, TRUE);
|
g_array_free (control_points, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_string_free (str, FALSE);
|
return g_strchomp (g_string_free (str, FALSE));
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,12 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct _SvgHandler SvgHandler;
|
typedef struct _SvgHandler SvgHandler;
|
||||||
|
|
||||||
struct _SvgHandler
|
struct _SvgHandler
|
||||||
{
|
{
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gdouble width;
|
gdouble width;
|
||||||
gdouble height;
|
gdouble height;
|
||||||
|
gchar *id;
|
||||||
GList *paths;
|
GList *paths;
|
||||||
GimpMatrix3 *transform;
|
GimpMatrix3 *transform;
|
||||||
|
|
||||||
@ -60,6 +60,12 @@ struct _SvgHandler
|
|||||||
const gchar **values);
|
const gchar **values);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
gchar *id;
|
||||||
|
GList *strokes;
|
||||||
|
} SvgPath;
|
||||||
|
|
||||||
|
|
||||||
static void svg_parser_start_element (GMarkupParseContext *context,
|
static void svg_parser_start_element (GMarkupParseContext *context,
|
||||||
const gchar *element_name,
|
const gchar *element_name,
|
||||||
@ -94,10 +100,10 @@ static void svg_handler_path (SvgHandler *handler,
|
|||||||
|
|
||||||
static SvgHandler svg_handlers[] =
|
static SvgHandler svg_handlers[] =
|
||||||
{
|
{
|
||||||
{ "svg", 0, 0, NULL, NULL, svg_handler_svg },
|
{ "svg", 0, 0, NULL, NULL, NULL, svg_handler_svg },
|
||||||
{ "g", 0, 0, NULL, NULL, svg_handler_group },
|
{ "g", 0, 0, NULL, NULL, NULL, svg_handler_group },
|
||||||
{ "path", 0, 0, NULL, NULL, svg_handler_path },
|
{ "path", 0, 0, NULL, NULL, NULL, svg_handler_path },
|
||||||
{ NULL, 0, 0, NULL, NULL, NULL }
|
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -132,7 +138,6 @@ gimp_vectors_import (GimpImage *image,
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
GQueue *stack;
|
GQueue *stack;
|
||||||
GList *paths;
|
GList *paths;
|
||||||
GList *list;
|
|
||||||
SvgHandler *base;
|
SvgHandler *base;
|
||||||
gboolean success = TRUE;
|
gboolean success = TRUE;
|
||||||
gsize bytes;
|
gsize bytes;
|
||||||
@ -178,31 +183,41 @@ gimp_vectors_import (GimpImage *image,
|
|||||||
{
|
{
|
||||||
if (base->paths)
|
if (base->paths)
|
||||||
{
|
{
|
||||||
GimpVectors *vectors;
|
GimpVectors *vectors = NULL;
|
||||||
|
|
||||||
base->paths = g_list_reverse (base->paths);
|
base->paths = g_list_reverse (base->paths);
|
||||||
|
|
||||||
|
merge = merge && base->paths->next;
|
||||||
|
|
||||||
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_VECTORS_IMPORT,
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_VECTORS_IMPORT,
|
||||||
_("Import Paths"));
|
_("Import Paths"));
|
||||||
|
|
||||||
vectors = gimp_vectors_new (image, _("Imported Path"));
|
|
||||||
|
|
||||||
for (paths = base->paths; paths; paths = paths->next)
|
for (paths = base->paths; paths; paths = paths->next)
|
||||||
{
|
{
|
||||||
for (list = paths->data; list; list = list->next)
|
SvgPath *path = paths->data;
|
||||||
gimp_vectors_stroke_add (vectors, GIMP_STROKE (list->data));
|
GList *list;
|
||||||
|
|
||||||
if (!merge && paths->next)
|
if (!merge || !vectors)
|
||||||
{
|
{
|
||||||
|
vectors = gimp_vectors_new (image,
|
||||||
|
((merge || !path->id) ?
|
||||||
|
_("Imported Path") : path->id));
|
||||||
gimp_image_add_vectors (image, vectors, -1);
|
gimp_image_add_vectors (image, vectors, -1);
|
||||||
vectors = gimp_vectors_new (image, _("Imported Path"));
|
gimp_vectors_freeze (vectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (paths->data);
|
for (list = path->strokes; list; list = list->next)
|
||||||
paths->data = NULL;
|
gimp_vectors_stroke_add (vectors, GIMP_STROKE (list->data));
|
||||||
|
|
||||||
|
if (!merge)
|
||||||
|
gimp_vectors_thaw (vectors);
|
||||||
|
|
||||||
|
g_list_free (path->strokes);
|
||||||
|
path->strokes = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_image_add_vectors (image, vectors, -1);
|
if (merge)
|
||||||
|
gimp_vectors_thaw (vectors);
|
||||||
|
|
||||||
gimp_image_undo_group_end (image);
|
gimp_image_undo_group_end (image);
|
||||||
}
|
}
|
||||||
@ -217,10 +232,14 @@ gimp_vectors_import (GimpImage *image,
|
|||||||
{
|
{
|
||||||
for (paths = base->paths; paths; paths = paths->next)
|
for (paths = base->paths; paths; paths = paths->next)
|
||||||
{
|
{
|
||||||
for (list = paths->data; list; list = list->next)
|
SvgPath *path = paths->data;
|
||||||
|
GList *list;
|
||||||
|
|
||||||
|
for (list = path->strokes; list; list = list->next)
|
||||||
g_object_unref (list->data);
|
g_object_unref (list->data);
|
||||||
|
|
||||||
g_list_free (paths->data);
|
g_free (path->id);
|
||||||
|
g_list_free (path->strokes);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (base->paths);
|
g_list_free (base->paths);
|
||||||
@ -285,9 +304,10 @@ svg_parser_end_element (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
for (paths = handler->paths; paths; paths = paths->next)
|
for (paths = handler->paths; paths; paths = paths->next)
|
||||||
{
|
{
|
||||||
GList *list;
|
SvgPath *path = paths->data;
|
||||||
|
GList *list;
|
||||||
|
|
||||||
for (list = paths->data; list; list = list->next)
|
for (list = path->strokes; list; list = list->next)
|
||||||
gimp_stroke_transform (GIMP_STROKE (list->data),
|
gimp_stroke_transform (GIMP_STROKE (list->data),
|
||||||
handler->transform);
|
handler->transform);
|
||||||
}
|
}
|
||||||
@ -347,12 +367,17 @@ svg_handler_path (SvgHandler *handler,
|
|||||||
const gchar **names,
|
const gchar **names,
|
||||||
const gchar **values)
|
const gchar **values)
|
||||||
{
|
{
|
||||||
|
SvgPath *path = g_new0 (SvgPath, 1);
|
||||||
|
|
||||||
while (*names)
|
while (*names)
|
||||||
{
|
{
|
||||||
if (strcmp (*names, "d") == 0)
|
if (strcmp (*names, "id") == 0 && !path->id)
|
||||||
{
|
{
|
||||||
handler->paths = g_list_prepend (handler->paths,
|
path->id = g_strdup (*values);
|
||||||
parse_path_data (*values));
|
}
|
||||||
|
else if (strcmp (*names, "d") == 0 && !path->strokes)
|
||||||
|
{
|
||||||
|
path->strokes = parse_path_data (*values);
|
||||||
}
|
}
|
||||||
else if (strcmp (*names, "transform") == 0 && !handler->transform)
|
else if (strcmp (*names, "transform") == 0 && !handler->transform)
|
||||||
{
|
{
|
||||||
@ -365,6 +390,8 @@ svg_handler_path (SvgHandler *handler,
|
|||||||
names++;
|
names++;
|
||||||
values++;
|
values++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handler->paths = g_list_prepend (handler->paths, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Reference in New Issue
Block a user