return a transformation matrix in preparation for nested transforms.
2003-09-12 Sven Neumann <sven@gimp.org> * app/vectors/gimpvectors-import.c (parse_svg_viewbox): return a transformation matrix in preparation for nested transforms.
This commit is contained in:

committed by
Sven Neumann

parent
5b33524acf
commit
2360c02c15
@ -1,3 +1,8 @@
|
|||||||
|
2003-09-12 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/vectors/gimpvectors-import.c (parse_svg_viewbox): return a
|
||||||
|
transformation matrix in preparation for nested transforms.
|
||||||
|
|
||||||
2003-09-12 Michael Natterer <mitch@gimp.org>
|
2003-09-12 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
* app/tools/gimpdrawtool.[ch]: added new functions
|
* app/tools/gimpdrawtool.[ch]: added new functions
|
||||||
|
@ -52,12 +52,6 @@ typedef enum
|
|||||||
PARSER_IN_UNKNOWN
|
PARSER_IN_UNKNOWN
|
||||||
} ParserState;
|
} ParserState;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
gint x, y;
|
|
||||||
gint w, h;
|
|
||||||
} Rectangle;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ParserState state;
|
ParserState state;
|
||||||
@ -66,7 +60,7 @@ typedef struct
|
|||||||
GimpImage *image;
|
GimpImage *image;
|
||||||
gboolean merge;
|
gboolean merge;
|
||||||
GimpVectors *vectors;
|
GimpVectors *vectors;
|
||||||
Rectangle viewbox;
|
GimpMatrix3 matrix;
|
||||||
} VectorsParser;
|
} VectorsParser;
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +79,9 @@ static void parser_start_unknown (VectorsParser *parser);
|
|||||||
static void parser_end_unknown (VectorsParser *parser);
|
static void parser_end_unknown (VectorsParser *parser);
|
||||||
|
|
||||||
static gboolean parse_svg_viewbox (const gchar *value,
|
static gboolean parse_svg_viewbox (const gchar *value,
|
||||||
Rectangle *rect);
|
gint width,
|
||||||
|
gint height,
|
||||||
|
GimpMatrix3 *matrix);
|
||||||
static gboolean parse_svg_transform (const gchar *value,
|
static gboolean parse_svg_transform (const gchar *value,
|
||||||
GimpMatrix3 *matrix);
|
GimpMatrix3 *matrix);
|
||||||
static void parse_path_data (GimpVectors *vectors,
|
static void parse_path_data (GimpVectors *vectors,
|
||||||
@ -205,10 +201,13 @@ parser_start_element (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
if (strcmp (*attribute_names, "viewBox") == 0)
|
if (strcmp (*attribute_names, "viewBox") == 0)
|
||||||
{
|
{
|
||||||
Rectangle rect;
|
GimpMatrix3 matrix;
|
||||||
|
|
||||||
if (parse_svg_viewbox (*attribute_values, &rect))
|
if (parse_svg_viewbox (*attribute_values,
|
||||||
parser->viewbox = rect;
|
parser->image->width,
|
||||||
|
parser->image->height,
|
||||||
|
&matrix))
|
||||||
|
parser->matrix = matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_names++;
|
attribute_names++;
|
||||||
@ -303,22 +302,13 @@ static void
|
|||||||
parser_add_vectors (VectorsParser *parser,
|
parser_add_vectors (VectorsParser *parser,
|
||||||
GimpVectors *vectors)
|
GimpVectors *vectors)
|
||||||
{
|
{
|
||||||
if (parser->viewbox.w && parser->viewbox.h)
|
GList *list;
|
||||||
|
|
||||||
|
for (list = vectors->strokes; list; list = list->next)
|
||||||
{
|
{
|
||||||
GList *list;
|
GimpStroke *stroke = list->data;
|
||||||
gdouble scale_x, scale_y;
|
|
||||||
|
|
||||||
scale_x = (gdouble) parser->image->width / (gdouble) parser->viewbox.w;
|
gimp_stroke_transform (stroke, &parser->matrix);
|
||||||
scale_y = (gdouble) parser->image->height / (gdouble) parser->viewbox.h;
|
|
||||||
|
|
||||||
for (list = vectors->strokes; list; list = list->next)
|
|
||||||
{
|
|
||||||
GimpStroke *stroke = list->data;
|
|
||||||
|
|
||||||
gimp_stroke_translate (stroke,
|
|
||||||
parser->viewbox.x, parser->viewbox.y);
|
|
||||||
gimp_stroke_scale (stroke, scale_x, scale_y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_image_add_vectors (parser->image, vectors, -1);
|
gimp_image_add_vectors (parser->image, vectors, -1);
|
||||||
@ -326,29 +316,36 @@ parser_add_vectors (VectorsParser *parser,
|
|||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_svg_viewbox (const gchar *value,
|
parse_svg_viewbox (const gchar *value,
|
||||||
Rectangle *rect)
|
gint width,
|
||||||
|
gint height,
|
||||||
|
GimpMatrix3 *matrix)
|
||||||
{
|
{
|
||||||
|
gdouble x, y, w, h;
|
||||||
gchar *tok;
|
gchar *tok;
|
||||||
gchar *str = g_strdup (value);
|
gchar *str = g_strdup (value);
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
|
|
||||||
|
x = y = w = h = 0;
|
||||||
|
|
||||||
|
gimp_matrix3_identity (matrix);
|
||||||
|
|
||||||
tok = strtok (str, ", \t");
|
tok = strtok (str, ", \t");
|
||||||
if (tok)
|
if (tok)
|
||||||
{
|
{
|
||||||
rect->x = g_ascii_strtod (tok, NULL);
|
x = g_ascii_strtod (tok, NULL);
|
||||||
tok = strtok (NULL, ", \t");
|
tok = strtok (NULL, ", \t");
|
||||||
if (tok)
|
if (tok)
|
||||||
{
|
{
|
||||||
rect->y = g_ascii_strtod (tok, NULL);
|
y = g_ascii_strtod (tok, NULL);
|
||||||
tok = strtok (NULL, ", \t");
|
tok = strtok (NULL, ", \t");
|
||||||
if (tok != NULL)
|
if (tok != NULL)
|
||||||
{
|
{
|
||||||
rect->w = g_ascii_strtod (tok, NULL);
|
w = g_ascii_strtod (tok, NULL);
|
||||||
tok = strtok (NULL, ", \t");
|
tok = strtok (NULL, ", \t");
|
||||||
if (tok)
|
if (tok)
|
||||||
{
|
{
|
||||||
rect->h = g_ascii_strtod (tok, NULL);
|
h = g_ascii_strtod (tok, NULL);
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,7 +354,16 @@ parse_svg_viewbox (const gchar *value,
|
|||||||
|
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
return success;
|
if (!success)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (x || y)
|
||||||
|
gimp_matrix3_translate (matrix, x, y);
|
||||||
|
|
||||||
|
if (w && h)
|
||||||
|
gimp_matrix3_scale (matrix, (gdouble) width / w, (gdouble) height / h);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
Reference in New Issue
Block a user