From 6c7f5d1327d2ca00d7df575258146637834da3f4 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Tue, 31 Oct 2006 21:21:41 +0000 Subject: [PATCH] make svg numeric precision, minimum exponent, and the use of named colors (as well as shortened color triads like #ccc) configurable via prefs --- src/preferences-skeleton.h | 1 + src/svg/css-ostringstream.cpp | 22 ++++++++++++++-------- src/svg/stringstream.cpp | 3 ++- src/svg/svg-affine.cpp | 35 +++++++++++++++++++---------------- src/svg/svg-color.cpp | 9 +++++++-- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index e833157ed..a76e6c19a 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -199,6 +199,7 @@ static char const preferences_skeleton[] = " ondark=\"4294967295\"" //ffffffff " clips=\"16711935\"" // 00ff00ff " masks=\"65535\"/>\n" // 0x0000ffff +" \n" " \n" "\n" " " diff --git a/src/svg/css-ostringstream.cpp b/src/svg/css-ostringstream.cpp index 91b1cfcfb..d59b8083a 100644 --- a/src/svg/css-ostringstream.cpp +++ b/src/svg/css-ostringstream.cpp @@ -1,5 +1,6 @@ #include "svg/css-ostringstream.h" #include "svg/strip-trailing-zeros.h" +#include "prefs-utils.h" #include #include @@ -13,21 +14,26 @@ Inkscape::CSSOStringStream::CSSOStringStream() /* This one is (currently) needed though, as we currently use ostr.precision as a sort of variable for storing the desired precision: see our two precision methods and our operator<< methods for float and double. */ - ostr.precision(8); + ostr.precision(prefs_get_int_attribute("options.svgoutput", "numericprecision", 8)); } static void write_num(Inkscape::CSSOStringStream &os, unsigned const prec, double const d) { char buf[32]; // haven't thought about how much is really required. - if (prec != 8) { - static bool warned; - if (!warned) { - g_warning("Using precision of 8 instead of the requested %u. Won't re-warn.", prec); - warned = true; - } + switch (prec) { + case 10: g_ascii_formatd(buf, sizeof(buf), "%.10f", d); + case 9: g_ascii_formatd(buf, sizeof(buf), "%.9f", d); + case 8: g_ascii_formatd(buf, sizeof(buf), "%.8f", d); + case 7: g_ascii_formatd(buf, sizeof(buf), "%.7f", d); + case 6: g_ascii_formatd(buf, sizeof(buf), "%.6f", d); + case 5: g_ascii_formatd(buf, sizeof(buf), "%.5f", d); + case 4: g_ascii_formatd(buf, sizeof(buf), "%.4f", d); + case 3: g_ascii_formatd(buf, sizeof(buf), "%.3f", d); + case 2: g_ascii_formatd(buf, sizeof(buf), "%.2f", d); + case 1: g_ascii_formatd(buf, sizeof(buf), "%.1f", d); + case 0: g_ascii_formatd(buf, sizeof(buf), "%.0f", d); } - g_ascii_formatd(buf, sizeof(buf), "%.8f", d); os << strip_trailing_zeros(buf); } diff --git a/src/svg/stringstream.cpp b/src/svg/stringstream.cpp index 5ef5c2ec0..cdb29c865 100644 --- a/src/svg/stringstream.cpp +++ b/src/svg/stringstream.cpp @@ -1,5 +1,6 @@ #include "svg/stringstream.h" #include "svg/strip-trailing-zeros.h" +#include "prefs-utils.h" Inkscape::SVGOStringStream::SVGOStringStream() { @@ -11,7 +12,7 @@ Inkscape::SVGOStringStream::SVGOStringStream() /* This one is (currently) needed though, as we currently use ostr.precision as a sort of variable for storing the desired precision: see our two precision methods and our operator<< methods for float and double. */ - ostr.precision(8); + ostr.precision(prefs_get_int_attribute("options.svgoutput", "numericprecision", 8)); } Inkscape::SVGOStringStream & diff --git a/src/svg/svg-affine.cpp b/src/svg/svg-affine.cpp index 1c8b4211c..6565b9353 100644 --- a/src/svg/svg-affine.cpp +++ b/src/svg/svg-affine.cpp @@ -27,6 +27,7 @@ #include #include #include "svg.h" +#include "prefs-utils.h" #ifndef M_PI # define M_PI 3.14159265358979323846 @@ -174,6 +175,8 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo } e = 0.000001 * NR_MATRIX_DF_EXPANSION (transform); + int prec = prefs_get_int_attribute("options.svgoutput", "numericprecision", 8); + int min_exp = prefs_get_int_attribute("options.svgoutput", "minimumexponent", -8); /* fixme: We could use t1 * t1 + t2 * t2 here instead */ if (NR_DF_TEST_CLOSE (transform->c[1], 0.0, e) && NR_DF_TEST_CLOSE (transform->c[2], 0.0, e)) { @@ -188,9 +191,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo unsigned p = 0; strcpy (c + p, "scale("); p += 6; - p += sp_svg_number_write_de (c + p, transform->c[0], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[0], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[3], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[3], prec, min_exp, FALSE); c[p++] = ')'; g_assert( p <= sizeof(c) ); p = MIN (p, size - 1 ); @@ -205,9 +208,9 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo unsigned p = 0; strcpy (c + p, "translate("); p += 10; - p += sp_svg_number_write_de (c + p, transform->c[4], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[4], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[5], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE); c[p++] = ')'; g_assert( p <= sizeof(c) ); p = MIN(p, size - 1); @@ -219,17 +222,17 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo unsigned p = 0; strcpy (c + p, "matrix("); p += 7; - p += sp_svg_number_write_de (c + p, transform->c[0], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[0], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[1], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[1], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[2], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[2], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[3], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[3], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[4], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[4], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[5], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE); c[p++] = ')'; g_assert( p <= sizeof(c) ); p = MIN(p, size - 1); @@ -243,17 +246,17 @@ sp_svg_transform_write(gchar str[], unsigned const size, NRMatrix const *transfo unsigned p = 0; strcpy (c + p, "matrix("); p += 7; - p += sp_svg_number_write_de (c + p, transform->c[0], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[0], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[1], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[1], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[2], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[2], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[3], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[3], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[4], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[4], prec, min_exp, FALSE); c[p++] = ','; - p += sp_svg_number_write_de (c + p, transform->c[5], 6, -8, FALSE); + p += sp_svg_number_write_de (c + p, transform->c[5], prec, min_exp, FALSE); c[p++] = ')'; g_assert( p <= sizeof(c) ); p = MIN(p, size - 1); diff --git a/src/svg/svg-color.cpp b/src/svg/svg-color.cpp index db2a89150..57003064a 100644 --- a/src/svg/svg-color.cpp +++ b/src/svg/svg-color.cpp @@ -17,6 +17,7 @@ # include "config.h" #endif +#include "prefs-utils.h" #include "svg-color.h" #include "svg-icc-color.h" #include @@ -409,7 +410,7 @@ rgb24_to_css(char *const buf, unsigned const rgb24) strcpy(buf, src); } - assert(sp_svg_read_color(buf, 0xff) == (rgb24 << 8)); + // assert(sp_svg_read_color(buf, 0xff) == (rgb24 << 8)); } /** @@ -425,7 +426,11 @@ sp_svg_write_color(gchar *buf, unsigned const buflen, guint32 const rgba32) g_assert(8 <= buflen); unsigned const rgb24 = rgba32 >> 8; - rgb24_to_css(buf, rgb24); + if (prefs_get_int_attribute("options.svgoutput", "usenamedcolors", 0)) { + rgb24_to_css(buf, rgb24); + } else { + g_snprintf(buf, buflen, "#%06x", rgb24); + } } static GHashTable * -- 2.30.2