svg-affine.cpp revision 3375512f3173e051906785f0d0fd5d74320efd17
/*
* 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-convert2geom.h>
#include "svg.h"
#include "preferences.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;
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
} 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 *
{
/* 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);
}
}
gchar *
{
return sp_svg_transform_write(*transform);
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :