svg-affine.cpp revision 6c7f5d1327d2ca00d7df575258146637834da3f4
#define __SP_SVG_AFFINE_C__
/*
* SVG data parser
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Raph Levien <raph@acm.org>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 1999 Raph Levien
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glib/gstrfuncs.h>
#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-translate-ops.h>
#include <libnr/nr-rotate-fns.h>
#include <libnr/nr-rotate-matrix-ops.h>
#include <libnr/nr-scale-matrix-ops.h>
#include <libnr/nr-translate-matrix-ops.h>
#include <libnr/nr-translate-rotate-ops.h>
#include "svg.h"
#include "prefs-utils.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
bool
{
int idx;
char keyword[32];
double args[6];
int n_args;
idx = 0;
/* skip initial whitespace */
/* parse keyword */
char c;
if (g_ascii_isalpha (c) || c == '-') {
} else {
break;
}
}
/* skip whitespace */
idx++;
char c;
char *end_ptr;
/* skip whitespace */
//printf("took %d chars from '%s' to make %f\n",
// end_ptr-(str+idx),
// str+idx,
// args[n_args]);
/* skip optional comma */
} else if (c == ')') {
break;
} else {
return false;
}
}
idx++;
/* ok, have parsed keyword and args, now modify the transform */
if (n_args != 6) return false;
a = NR_MATRIX_D_FROM_DOUBLE(args) * a;
if (n_args == 1) {
args[1] = 0;
} else if (n_args != 2) {
return false;
}
if (n_args == 1) {
} else if (n_args != 2) {
return false;
}
return false;
}
if (n_args == 3) {
* rot
* a );
} else {
a = rot * a;
}
if (n_args != 1) return false;
0, 0)
* a );
if (n_args != 1) return false;
0, 1,
0, 0)
* a );
} else {
return false; /* unknown keyword */
}
/* Skip trailing whitespace */
}
*transform = a;
return true;
}
unsigned
{
}
unsigned
{
double e;
if (!transform) {
*str = 0;
return 0;
}
/* fixme: We could use t1 * t1 + t2 * t2 here instead */
/* We are more or less identity */
*str = 0;
return 0;
} else {
/* We are more or less scale */
gchar c[256];
unsigned p = 0;
strcpy (c + p, "scale(");
p += 6;
c[p++] = ',';
c[p++] = ')';
g_assert( p <= sizeof(c) );
str[p] = 0;
return p;
}
} else {
/* We are more or less translate */
gchar c[256];
unsigned p = 0;
strcpy (c + p, "translate(");
p += 10;
c[p++] = ',';
c[p++] = ')';
g_assert( p <= sizeof(c) );
str[p] = 0;
return p;
} else {
gchar c[256];
unsigned p = 0;
strcpy (c + p, "matrix(");
p += 7;
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ')';
g_assert( p <= sizeof(c) );
str[p] = 0;
return p;
}
}
} else {
gchar c[256];
unsigned p = 0;
strcpy (c + p, "matrix(");
p += 7;
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ')';
g_assert( p <= sizeof(c) );
str[p] = 0;
return p;
}
}