/*
* Inkscape::SVG::PathString - builder for SVG path strings
*
* Copyright 2008 Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
* Copyright 2013 Tavmjong Bah <tavmjong@free.fr>
*
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See the file COPYING for details.
*
*/
#include "svg/path-string.h"
#include "svg/stringstream.h"
#include "preferences.h"
#include <algorithm>
// 1<=numericprecision<=16, doubles are only accurate upto (slightly less than) 16 digits (and less than one digit doesn't make sense)
// Please note that these constants are used to allocate sufficient space to hold serialized numbers
force_repeat_commands(Inkscape::Preferences::get()->getBool("/options/svgoutput/forcerepeatcommands"))
{
format = (PATHSTRING_FORMAT)prefs->getIntLimited("/options/svgoutput/pathstring_format", 1, 0, PATHSTRING_FORMAT_SIZE - 1 );
numericprecision = std::max<int>(minprec,std::min<int>(maxprec, prefs->getInt("/options/svgoutput/numericprecision", 8)));
}
// For absolute and relative paths... the entire path is kept in the "tail".
// For optimized path, at a switch between absolute and relative, add tail to commonbase.
// For absolute and relative paths... do nothing.
switch (format) {
case PATHSTRING_ABSOLUTE:
break;
case PATHSTRING_RELATIVE:
break;
case PATHSTRING_OPTIMIZE:
{
// Store common prefix
// Copy rel to abs
abs_op_repeated = false;
// We do not have to copy abs to rel:
// _rel_state.str.size()+2 < _abs_state.str.size()+abs_added_size
// _rel_state.str.size()+rel_added_size < _abs_state.str.size()+2
// _abs_state.str.size()+2 > _rel_state.str.size()+rel_added_size
// Store common prefix
// Copy abs to rel
rel_op_repeated = false;
}
}
break;
default:
}
}
str += ' ';
appendNumber(v);
}
str += ' ';
appendNumber(p[Geom::X]);
str += ',';
appendNumber(p[Geom::Y]);
}
str += ' ';
appendNumber(v, rv);
}
str += ' ';
str += ',';
}
// NOTE: The following appendRelativeCoord function will not be exact if the total number of digits needed
// to represent the difference exceeds the precision of a double. This is not very likely though, and if
// it does happen the imprecise value is not likely to be chosen (because it will probably be a lot longer
// than the absolute value).
// NOTE: This assumes v and r are already rounded (this includes flushing to zero if they are < 10^minexp)
int const digitsEnd = (int)floor(log10(std::min(fabs(v),fabs(r)))) - numericprecision; // Position just beyond the last significant digit of the smallest (in absolute sense) number
if (r == 0) {
} else if (v == 0) {
} else if (numDigits>0) {
} else {
// This assumes the input numbers are already rounded to 'precision' digits
str += '0';
}
}
str += ' ';
str += ',';
}
str += ' ';
appendRelativeCoord(v, r);
}
size_t const reserve = precision+1+1+1+1+3; // Just large enough to hold the maximum number of digits plus a sign, a period, the letter 'e', another sign and three digits for the exponent
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...)
}
void Inkscape::SVG::PathString::State::appendNumber(double v, double &rv, int precision, int minexp) {
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...)
}
/*
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 :