path-string.cpp revision 9caef2c351db046dc0024b025adee891df3a6771
#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)));
switch (format) {
case PATHSTRING_ABSOLUTE:
case PATHSTRING_RELATIVE:
case PATHSTRING_OPTIMIZE:
abs_op_repeated = false;
// _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
rel_op_repeated = false;
appendNumber(v);
// 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
// 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
} else if (numDigits>0) {
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...)