svg-affine.cpp revision 1e7ac93d879b3dd8aeacf963f3d1d6fe92e4a621
#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 <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#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 <libnr/nr-convert2geom.h>
#include "svg.h"
#include "prefs-utils.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
bool
{
return true;
} else {
return false;
}
}
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;
}
gchar *
{
return sp_svg_transform_write(&transform);
}
gchar *
{
return sp_svg_transform_write(&t);
}
gchar *
{
return sp_svg_transform_write(&t);
}
gchar *
{
double e;
if (!transform) {
return NULL;
}
/* fixme: We could use t1 * t1 + t2 * t2 here instead */
/* We are more or less identity */
return NULL;
} else {
/* We are more or less scale */
gchar c[256];
unsigned p = 0;
strcpy (c + p, "scale(");
p += 6;
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
return g_strdup(c);
}
} else {
/* We are more or less translate */
gchar c[256];
unsigned p = 0;
strcpy (c + p, "translate(");
p += 10;
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
return g_strdup(c);
} 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++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
return g_strdup(c);
}
}
} 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++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
return g_strdup(c);
}
}