summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ac2e9e3)
raw | patch | inline | side by side (parent: ac2e9e3)
author | joncruz <joncruz@users.sourceforge.net> | |
Thu, 8 Oct 2009 08:44:05 +0000 (08:44 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Thu, 8 Oct 2009 08:44:05 +0000 (08:44 +0000) |
src/svg/path-string.cpp | patch | blob | history | |
src/svg/svg-affine.cpp | patch | blob | history | |
src/svg/svg-length.cpp | patch | blob | history | |
src/svg/svg.h | patch | blob | history |
index 0baaf521ea59b1fbda10628f359c545489d6c07f..a850d7c108bb02b312089084a7f88fa34a4054f5 100644 (file)
--- a/src/svg/path-string.cpp
+++ b/src/svg/path-string.cpp
@@ -129,7 +129,7 @@ void Inkscape::SVG::PathString::State::appendNumber(double v, int precision, int
size_t const oldsize = str.size();
str.append(reserve, (char)0);
char* begin_of_num = const_cast<char*>(str.data()+oldsize); // Slightly evil, I know (but std::string should be storing its data in one big block of memory, so...)
- size_t added = sp_svg_number_write_de(begin_of_num, v, precision, minexp);
+ size_t added = sp_svg_number_write_de(begin_of_num, reserve, v, precision, minexp);
str.resize(oldsize+added); // remove any trailing characters
}
diff --git a/src/svg/svg-affine.cpp b/src/svg/svg-affine.cpp
index 1ff9776e5dbe5d95b3c09d831076e4bb7530431a..91a9fa7e5365db7fa869715fb38b83ff1a470384 100644 (file)
--- a/src/svg/svg-affine.cpp
+++ b/src/svg/svg-affine.cpp
unsigned p = 0;
strcpy (c + p, "scale(");
p += 6;
- p += sp_svg_number_write_de (c + p, transform[0], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[3], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
unsigned p = 0;
strcpy (c + p, "translate(");
p += 10;
- p += sp_svg_number_write_de (c + p, transform[4], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[5], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
unsigned p = 0;
strcpy (c + p, "matrix(");
p += 7;
- p += sp_svg_number_write_de (c + p, transform[0], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[1], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[1], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[2], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[2], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[3], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[4], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[5], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
unsigned p = 0;
strcpy (c + p, "matrix(");
p += 7;
- p += sp_svg_number_write_de (c + p, transform[0], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[1], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[1], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[2], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[2], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[3], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[4], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
c[p++] = ',';
- p += sp_svg_number_write_de (c + p, transform[5], prec, min_exp);
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
c[p++] = ')';
c[p] = '\000';
g_assert( p <= sizeof(c) );
diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index 1d41f9871165198a9b080c60c282a58bdd37539b..942f74d46af3b324c7fddb5a49a6b78a9a7388da 100644 (file)
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
if ((gchar const *) e == str) {
return 0;
}
-
+
*val = v;
return 1;
}
if ((gchar const *) e == str) {
return 0;
}
-
+
*val = v;
return 1;
}
c[16u - (++i)] = '0' + (val % 10u);
val /= 10u;
} while (val > 0u);
-
+
memcpy(buf, &c[16u - i], i);
buf[i] = 0;
-
+
return i;
}
-static unsigned int sp_svg_number_write_i(gchar *buf, int val)
+static unsigned int sp_svg_number_write_i(gchar *buf, int bufLen, int val)
{
int p = 0;
unsigned int uval;
}
p += sp_svg_number_write_ui(buf+p, uval);
-
+
return p;
}
-static unsigned sp_svg_number_write_d(gchar *buf, double val, unsigned int tprec, unsigned int fprec)
+static unsigned sp_svg_number_write_d(gchar *buf, int bufLen, double val, unsigned int tprec, unsigned int fprec)
{
/* Process sign */
int i = 0;
@@ -103,15 +103,15 @@ static unsigned sp_svg_number_write_d(gchar *buf, double val, unsigned int tprec
buf[i++] = '-';
val = fabs(val);
}
-
+
/* Determine number of integral digits */
int idigits = 0;
if (val >= 1.0) {
idigits = (int) floor(log10(val)) + 1;
}
-
+
/* Determine the actual number of fractional digits */
- fprec = MAX(fprec, tprec - idigits);
+ fprec = MAX(static_cast<int>(fprec), static_cast<int>(tprec) - idigits);
/* Round value */
val += 0.5 / pow(10.0, fprec);
/* Extract integral and fractional parts */
@@ -146,7 +146,7 @@ static unsigned sp_svg_number_write_d(gchar *buf, double val, unsigned int tprec
return end_i;
}
-unsigned int sp_svg_number_write_de(gchar *buf, double val, unsigned int tprec, int min_exp)
+unsigned int sp_svg_number_write_de(gchar *buf, int bufLen, double val, unsigned int tprec, int min_exp)
{
int eval = (int)floor(log10(fabs(val)));
if (val == 0.0 || eval < min_exp) {
@@ -158,12 +158,12 @@ unsigned int sp_svg_number_write_de(gchar *buf, double val, unsigned int tprec,
(unsigned int)eval+1;
unsigned int maxnumdigitsWithExp = tprec + ( eval<0 ? 4 : 3 ); // It's not necessary to take larger exponents into account, because then maxnumdigitsWithoutExp is DEFINITELY larger
if (maxnumdigitsWithoutExp <= maxnumdigitsWithExp) {
- return sp_svg_number_write_d(buf, val, tprec, 0);
+ return sp_svg_number_write_d(buf, bufLen, val, tprec, 0);
} else {
val = eval < 0 ? val * pow(10.0, -eval) : val / pow(10.0, eval);
- int p = sp_svg_number_write_d(buf, val, tprec, 0);
+ int p = sp_svg_number_write_d(buf, bufLen, val, tprec, 0);
buf[p++] = 'e';
- p += sp_svg_number_write_i(buf + p, eval);
+ p += sp_svg_number_write_i(buf + p, bufLen - p, eval);
return p;
}
}
float computed;
char *next = (char *) str;
std::vector<SVGLength> list;
-
+
while (sp_svg_length_read_lff(next, &unit, &value, &computed, &next)) {
SVGLength length;
(*next == ',' || *next == ' ' || *next == '\n' || *next == '\r' || *next == '\t')) {
// the list can be comma- or space-separated, but we will be generous and accept
// a mix, including newlines and tabs
- next++;
+ next++;
}
-
+
if (!next || !*next) {
break;
}
if (e == str) {
return 0;
}
-
+
if (!e[0]) {
/* Unitless */
if (unit) {
diff --git a/src/svg/svg.h b/src/svg/svg.h
index 0eab21226578da5dfcac06fdb0ebf9004a605274..0b2c3ae531addf69233a81c0104b798119c70ef1 100644 (file)
--- a/src/svg/svg.h
+++ b/src/svg/svg.h
-#ifndef __SP_SVG_H__
-#define __SP_SVG_H__
+#ifndef SEEN_SP_SVG_H
+#define SEEN_SP_SVG_H
/*
* SVG data parser
* - no valid end character checking
* Return FALSE and let val untouched on error
*/
-
-unsigned int sp_svg_number_read_f (const gchar *str, float *val);
-unsigned int sp_svg_number_read_d (const gchar *str, double *val);
+
+unsigned int sp_svg_number_read_f( const gchar *str, float *val );
+unsigned int sp_svg_number_read_d( const gchar *str, double *val );
/*
* No buffer overflow checking is done, so better wrap them if needed
*/
-unsigned int sp_svg_number_write_de (gchar *buf, double val, unsigned int tprec, int min_exp);
+unsigned int sp_svg_number_write_de( gchar *buf, int bufLen, double val, unsigned int tprec, int min_exp );
/* Length */
* Any return value pointer can be NULL
*/
-unsigned int sp_svg_length_read_computed_absolute (const gchar *str, float *length);
-std::vector<SVGLength> sp_svg_length_list_read (const gchar *str);
-unsigned int sp_svg_length_read_ldd (const gchar *str, SVGLength::Unit *unit, double *value, double *computed);
+unsigned int sp_svg_length_read_computed_absolute( const gchar *str, float *length );
+std::vector<SVGLength> sp_svg_length_list_read( const gchar *str );
+unsigned int sp_svg_length_read_ldd( const gchar *str, SVGLength::Unit *unit, double *value, double *computed );
std::string sp_svg_length_write_with_units(SVGLength const &length);
gchar *sp_svg_transform_write(Geom::Matrix const &transform);
gchar *sp_svg_transform_write(Geom::Matrix const *transform);
-double sp_svg_read_percentage (const char * str, double def);
+double sp_svg_read_percentage( const char * str, double def );
/* NB! As paths can be long, we use here dynamic string */
-Geom::PathVector sp_svg_read_pathv (char const * str);
-gchar * sp_svg_write_path (Geom::PathVector const &p);
-gchar * sp_svg_write_path (Geom::Path const &p);
+Geom::PathVector sp_svg_read_pathv( char const * str );
+gchar * sp_svg_write_path( Geom::PathVector const &p );
+gchar * sp_svg_write_path( Geom::Path const &p );
-#endif
+#endif // SEEN_SP_SVG_H
/*
Local Variables: