svg-affine.cpp revision 3cddc158875c47546688b0746fb0f36a8b71a299
/*
* 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.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 *
{
// Special case: when all fields of the affine are zero,
// the optimized transformation is scale(0)
{
return g_strdup("scale(0)");
}
// FIXME legacy C code!
// the function sp_svg_number_write_de is stopping me from using a proper C++ string
unsigned p = 0; // position in the buffer
if (transform.isIdentity()) {
// We are more or less identity, so no transform attribute needed:
return NULL;
// We are more or less a uniform scale
strcpy (c + p, "scale(");
p += 6;
c[p++] = ')';
c[p] = '\000';
} else {
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
}
} else if (transform.isTranslation()) {
// We are more or less a pure translation
strcpy (c + p, "translate(");
p += 10;
c[p++] = ')';
c[p] = '\000';
} else {
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
}
} else if (transform.isRotation()) {
// We are more or less a pure rotation
strcpy(c + p, "rotate(");
p += 7;
c[p++] = ')';
c[p] = '\000';
// Solution found by Johan Engelen
// Refer to the matrix in svg-affine-test.h
// We are a rotation about a special axis
strcpy(c + p, "rotate(");
p += 7;
c[p++] = ',';
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
// We are more or less a pure skewX
strcpy(c + p, "skewX(");
p += 6;
c[p++] = ')';
c[p] = '\000';
// We are more or less a pure skewY
strcpy(c + p, "skewY(");
p += 6;
c[p++] = ')';
c[p] = '\000';
} else {
strcpy (c + p, "matrix(");
p += 7;
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ',';
c[p++] = ')';
c[p] = '\000';
}
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:fileencoding=utf-8:textwidth=99 :