]> git.lyx.org Git - features.git/blobdiff - src/frontends/xforms/Color.C
Replace LString.h with support/std_string.h,
[features.git] / src / frontends / xforms / Color.C
index c691b284fb9e22ae64a772acb56d924a26df7a0c..93ad4dd0e311396c1cef385f626161eee8da5a30 100644 (file)
@@ -5,19 +5,21 @@
  *
  * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "Color.h"
-#include <algorithm> // max
-#include <cmath> // floor
-#include FORMS_H_LOCATION
+
+#include "support/LAssert.h"
+
+#include "lyx_forms.h"
+
+#include "support/std_sstream.h"
+#include <iomanip>
+
+namespace support = lyx::support;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::floor;
@@ -25,14 +27,25 @@ using std::floor;
 
 using std::max;
 using std::min;
+using std::setw;
+
 
 namespace {
 
 int const nohue = -1;
 
+int hexstrToInt(string const & str)
+{
+        int val = 0;
+        istringstream is(str);
+        is >> std::setbase(16) >> val;
+        return val;
+}
+
 } // namespace anon
 
 
+
 bool getRGBColor(LColor::color col,
                 unsigned int & r, unsigned int & g, unsigned int & b)
 {
@@ -55,6 +68,29 @@ bool getRGBColor(LColor::color col,
 }
 
 
+string const X11hexname(RGBColor const & col)
+{
+       ostringstream ostr;
+
+       ostr << '#' << std::setbase(16) << std::setfill('0')
+            << setw(2) << col.r
+            << setw(2) << col.g
+            << setw(2) << col.b;
+
+       return STRCONV(ostr.str());
+}
+
+
+RGBColor::RGBColor(string const & x11hexname)
+       : r(0), g(0), b(0) 
+{
+       support::Assert(x11hexname.size() == 7 && x11hexname[0] == '#');
+       r = hexstrToInt(x11hexname.substr(1,2));
+       g = hexstrToInt(x11hexname.substr(3,2));
+       b = hexstrToInt(x11hexname.substr(5,2));
+}
+
+
 RGBColor::RGBColor(HSVColor const & hsv)
 {
        double h = hsv.h;