summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d1cc078)
raw | patch | inline | side by side (parent: d1cc078)
author | mental <mental@users.sourceforge.net> | |
Wed, 28 Feb 2007 04:34:21 +0000 (04:34 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Wed, 28 Feb 2007 04:34:21 +0000 (04:34 +0000) |
-- dynamic allocation won't hurt you, but buffer overruns will!
index 130480608413469142ab004966ed618dfd29b3f7..3e01a749820fb16a23c08c1aa8ab8d625d682f77 100644 (file)
center_set = true;
}
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, t)) {
- clone->setAttribute("transform", affinestr);
- } else {
- clone->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(t);
+ clone->setAttribute("transform", affinestr);
+ g_free(affinestr);
if (opacity < 1.0) {
sp_repr_set_css_double(clone, "opacity", opacity);
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index 896d4d29f5f349d0706bfdbf3cd7b95fcd4324d2..a6a66e952e9c1b3b515ebb5823bbe5f89d854fd7 100644 (file)
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
@@ -347,12 +347,9 @@ static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform) {
sp_svg_transform_read(t_str, &item_t);
item_t *= local.inverse();
// (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, item_t)) {
- pathRepr->setAttribute("transform", affinestr);
- } else {
- pathRepr->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(item_t);
+ pathRepr->setAttribute("transform", affinestr);
+ g_free(affinestr);
}
Inkscape::Selection *selection = sp_desktop_selection(desktop);
index 78ea135076387886839cdaaea2c3a9f2f54e430d..f55694fcf05a29e5539209bcb9eb292331dd5fd3 100644 (file)
gr->gradientTransform = squeeze;
{
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gr->gradientTransform)) {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gr->gradientTransform);
+ SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
+ g_free(c);
}
} else {
sp_repr_set_svg_double(repr, "x1", (center - NR::Point(width/2, 0))[NR::X]);
@@ -350,12 +347,9 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
// apply skew to the gradient
gr->gradientTransform = skew;
{
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gr->gradientTransform)) {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gr->gradientTransform);
+ SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
+ g_free(c);
}
// Matrix to convert points to userspace coords; postmultiply by inverse of skew so
@@ -423,12 +417,9 @@ sp_gradient_transform_multiply(SPGradient *gradient, NR::Matrix postmul, bool se
}
gradient->gradientTransform_set = TRUE;
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gradient->gradientTransform)) {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gradient->gradientTransform);
+ SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", c);
+ g_free(c);
}
SPGradient *
@@ -925,12 +916,9 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::
gradient->gradientTransform = new_transform;
gradient->gradientTransform_set = TRUE;
if (write_repr) {
- gchar s[256];
- if (sp_svg_transform_write(s, 256, gradient->gradientTransform)) {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", s);
- } else {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", NULL);
- }
+ gchar *s=sp_svg_transform_write(gradient->gradientTransform);
+ SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", s);
+ g_free(s);
} else {
SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
index d3fff18e938aeb20e27474c11a62f46509912978..1885ca6eb2cb56ede4c2d539fba5d2e3a784666d 100644 (file)
@@ -101,12 +101,9 @@ void sp_selection_copy_one (Inkscape::XML::Node *repr, NR::Matrix full_t, GSList
// write the complete accumulated transform passed to us
// (we're dealing with unattached repr, so we write to its attr
// instead of using sp_item_set_transform)
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, full_t)) {
- copy->setAttribute("transform", affinestr);
- } else {
- copy->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(full_t);
+ copy->setAttribute("transform", affinestr);
+ g_free(affinestr);
*clip = g_slist_prepend(*clip, copy);
}
@@ -185,12 +182,9 @@ GSList *sp_selection_paste_impl (SPDocument *document, SPObject *parent, GSList
sp_svg_transform_read(t_str, &item_t);
item_t *= local.inverse();
// (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, item_t)) {
- copy->setAttribute("transform", affinestr);
- } else {
- copy->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(item_t);
+ copy->setAttribute("transform", affinestr);
+ g_free(affinestr);
}
parent->appendChildRepr(copy);
}
// Write transform
- gchar c[256];
- if (sp_svg_transform_write(c, 256, t)) {
- repr->setAttribute("transform", c);
- }
+ gchar *c=sp_svg_transform_write(t);
+ repr->setAttribute("transform", c);
+ g_free(t);
// add the new repr to the parent
parent->appendChild(repr);
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 71dc0e20e3f9e70ccdd7d26938628a243a499acb..94e6ce6c200c41d70604144082e91df9e5f237cf 100644 (file)
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
}
if ((flags & SP_OBJECT_WRITE_ALL) || gr->gradientTransform_set) {
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gr->gradientTransform)) {
- repr->setAttribute("gradientTransform", c);
- } else {
- repr->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gr->gradientTransform);
+ repr->setAttribute("gradientTransform", c);
+ g_free(c);
}
if ((flags & SP_OBJECT_WRITE_ALL) || gr->spread_set) {
diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index bb94425c5beccbe8dbc88fc2966f86c1aae78704..91afd8db112f38f16c68863ea3ad0fab143fbc55 100644 (file)
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
// This is just a way to temporarily remember the transform in repr. When repr is
// reattached outside of the group, the transform will be written more properly
// (i.e. optimized into the object if the corresponding preference is set)
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, ctrans)) {
- nrepr->setAttribute("transform", affinestr);
- } else {
- nrepr->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(ctrans);
+ nrepr->setAttribute("transform", affinestr);
+ g_free(affinestr);
items = g_slist_prepend (items, nrepr);
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index cefa7f82a15048e499a780e95321b95d64491f51..6893c752bedb159efc681df5a6ea526de710f3c7 100644 (file)
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
{
SPItem *item = SP_ITEM(object);
- gchar c[256];
- if (sp_svg_transform_write(c, 256, item->transform)) {
- repr->setAttribute("transform", c);
- } else {
- repr->setAttribute("transform", NULL);
- }
+ gchar *c = sp_svg_transform_write(item->transform);
+ repr->setAttribute("transform", c);
+ g_free(c);
SPObject const *const parent = SP_OBJECT_PARENT(object);
/** \todo Can someone please document why this is conditional on having
diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp
index 8de8ac77b1a3e1a3beffbe7af6b0d3d8c76f6dcc..3640a6768030b88a3e8e666c7a664239621ce5f1 100644 (file)
--- a/src/sp-pattern.cpp
+++ b/src/sp-pattern.cpp
@@ -484,12 +484,9 @@ sp_pattern_transform_multiply (SPPattern *pattern, NR::Matrix postmul, bool set)
}
pattern->patternTransform_set = TRUE;
- gchar c[256];
- if (sp_svg_transform_write(c, 256, pattern->patternTransform)) {
- SP_OBJECT_REPR(pattern)->setAttribute("patternTransform", c);
- } else {
- SP_OBJECT_REPR(pattern)->setAttribute("patternTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(pattern->patternTransform);
+ SP_OBJECT_REPR(pattern)->setAttribute("patternTransform", c);
+ g_free(c);
}
const gchar *
@@ -503,13 +500,9 @@ pattern_tile (GSList *reprs, NR::Rect bounds, SPDocument *document, NR::Matrix t
sp_repr_set_svg_double(repr, "width", bounds.extent(NR::X));
sp_repr_set_svg_double(repr, "height", bounds.extent(NR::Y));
- gchar t[256];
- if (sp_svg_transform_write(t, 256, transform)) {
- repr->setAttribute("patternTransform", t);
- } else {
- repr->setAttribute("patternTransform", NULL);
- }
-
+ gchar *t=sp_svg_transform_write(transform);
+ repr->setAttribute("patternTransform", t);
+ g_free(t);
defsrepr->appendChild(repr);
const gchar *pat_id = repr->attribute("id");
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index a23d6da02727eda7752da84de035a4bdba21d190..e5154c130b3bd504988d7a12de0f054ace327639 100644 (file)
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -474,11 +474,7 @@ sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustrin
// premultiply by the inverse of parent's repr
SPItem *parent_item = SP_ITEM(sp_desktop_document(desktop)->getObjectByRepr(parent));
NR::Matrix local = sp_item_i2doc_affine(parent_item);
- gchar affinestr[80];
- gchar *transform = NULL;
- if (!local.test_identity() && sp_svg_transform_write(affinestr, 79, local.inverse())) {
- transform = affinestr;
- }
+ gchar *transform = sp_svg_transform_write(local);
// now that we have the result, add it on the canvas
if ( bop == bool_op_cut || bop == bool_op_slice ) {
@@ -575,6 +571,8 @@ sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustrin
Inkscape::GC::release(repr);
}
+ g_free(transform);
+
sp_document_done(sp_desktop_document(desktop), verb, description);
delete res;
diff --git a/src/svg/svg-affine.cpp b/src/svg/svg-affine.cpp
index 6565b93538aa2cc80a9965523748c219744e9d00..71ee5dcb5278a4b2e3567cbdb200460cfb3c58c2 100644 (file)
--- a/src/svg/svg-affine.cpp
+++ b/src/svg/svg-affine.cpp
#define EQ(a,b) (fabs ((a) - (b)) < 1e-9)
-unsigned
-sp_svg_transform_write(gchar str[], unsigned const size, NR::Matrix const &transform)
+gchar *
+sp_svg_transform_write(NR::Matrix const &transform)
{
NRMatrix const t(transform);
- return sp_svg_transform_write(str, size, &t);
+ return sp_svg_transform_write(&t);
}
-unsigned
-sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transform)
+gchar *
+sp_svg_transform_write(NRMatrix const *transform)
{
double e;
if (!transform) {
- *str = 0;
- return 0;
+ return NULL;
}
e = 0.000001 * NR_MATRIX_DF_EXPANSION (transform);
@@ -183,8 +182,7 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo
if (NR_DF_TEST_CLOSE (transform->c[4], 0.0, e) && NR_DF_TEST_CLOSE (transform->c[5], 0.0, e)) {
if (NR_DF_TEST_CLOSE (transform->c[0], 1.0, e) && NR_DF_TEST_CLOSE (transform->c[3], 1.0, e)) {
/* We are more or less identity */
- *str = 0;
- return 0;
+ return NULL;
} else {
/* We are more or less scale */
gchar c[256];
@@ -195,11 +193,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo
c[p++] = ',';
p += sp_svg_number_write_de (c + p, transform->c[3], prec, min_exp, FALSE);
c[p++] = ')';
+ c[p] = '\000';
g_assert( p <= sizeof(c) );
- p = MIN (p, size - 1 );
- memcpy (str, c, p);
- str[p] = 0;
- return p;
+ return g_strdup(c);
}
} else {
if (NR_DF_TEST_CLOSE (transform->c[0], 1.0, e) && NR_DF_TEST_CLOSE (transform->c[3], 1.0, e)) {
@@ -212,11 +208,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo
c[p++] = ',';
p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE);
c[p++] = ')';
+ c[p] = '\000';
g_assert( p <= sizeof(c) );
- p = MIN(p, size - 1);
- memcpy (str, c, p);
- str[p] = 0;
- return p;
+ return g_strdup(c);
} else {
gchar c[256];
unsigned p = 0;
@@ -234,11 +228,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo
c[p++] = ',';
p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE);
c[p++] = ')';
+ c[p] = '\000';
g_assert( p <= sizeof(c) );
- p = MIN(p, size - 1);
- memcpy (str, c, p);
- str[p] = 0;
- return p;
+ return g_strdup(c);
}
}
} else {
@@ -258,11 +250,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo
c[p++] = ',';
p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE);
c[p++] = ')';
+ c[p] = '\000';
g_assert( p <= sizeof(c) );
- p = MIN(p, size - 1);
- memcpy (str, c, p);
- str[p] = 0;
- return p;
+ return g_strdup(c);
}
}
diff --git a/src/svg/svg.h b/src/svg/svg.h
index b607773818b84025bfbfed29bb2059e9057487c4..60b44f8e86cd8d3b82ea59b50bbf9cebd5ee0239 100644 (file)
--- a/src/svg/svg.h
+++ b/src/svg/svg.h
bool sp_svg_transform_read(gchar const *str, NR::Matrix *transform);
-unsigned sp_svg_transform_write(gchar str[], unsigned size, NR::Matrix const &transform);
-unsigned sp_svg_transform_write(gchar str[], unsigned size, NRMatrix const *transform);
+gchar *sp_svg_transform_write(NR::Matrix const &transform);
+gchar *sp_svg_transform_write(NRMatrix const *transform);
double sp_svg_read_percentage (const char * str, double def);