Jürgen Spitzmüller wrote:
> In trunk, if you open a file that uses the outputLaTeXColor method of
> Color.cpp with a German locale, a wrong LaTeX output is generated (float
> values with comma as separator), and LaTeX fails. Try the attached example
> file with LANG=de_DE.
>
> This is a regression to 2.0.
It turns out the culprit is convert<string>(float), which uses
boost::lexical_cast, which is locale-dependent. See
http://boost.2283326.n4.nabble.com/lexical-cast-locale-dependent-result-was-lexical-cast-locale-dependent-result-td3331383.html
I followed the advice given in the quoted thread and used a stream instead of
convert in the outputLaTeXColor method (see attached patch). This fixes the
problem for me.
However, the problem might hit us on more places, and the question is if we
want convert<string> to be at all locale dependent.
Comments?
Jürgen
diff --git a/src/Color.cpp b/src/Color.cpp
index 31d5f62..dcd6a1e 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -110,11 +110,17 @@ string const outputLaTeXColor(RGBColor const & color)
++blue;
int const scale = 256;
#endif
- string output;
- output = convert<string>(float(red) / scale) + ", "
- + convert<string>(float(green) / scale) + ", "
- + convert<string>(float(blue) / scale);
- return output;
+ ostringstream os;
+#ifdef HAVE_LOCALE
+ // Use the standard "C" locale.
+ ofs.imbue(locale::classic());
+#endif
+ os << (float(red) / scale)
+ << ", "
+ << (float(green) / scale)
+ << ", "
+ << (float(blue) / scale);
+ return os.str();
}