00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef DrawingColor_INCLUDED
00030 #define DrawingColor_INCLUDED
00031
00032 #include <string>
00033 #include <sstream>
00034 #include <strings.h>
00035
00037
00038
00039
00041 class DrawingColor {
00042 public:
00043
00044
00045 DrawingColor(const std::string &name="white",unsigned char red=255,unsigned char green=255,unsigned char blue=255);
00046
00047 DrawingColor(const std::string &name,const std::string &postScriptOrHexTriplet);
00048
00049 DrawingColor(const std::string &name,double h,double s, double v);
00050
00051
00052 struct compare
00053 {
00054 bool operator()(const DrawingColor & c1, const DrawingColor & c2) const
00055 {
00056 return strcasecmp(c1._name.c_str(), c2._name.c_str() ) < 0;
00057 }
00058 };
00059
00060 void set(unsigned char red, unsigned char green, unsigned char blue);
00061 void set(const std::string &color);
00062 void setFromHSV(double h, double s, double v);
00063 std::string get(void) const;
00064 std::string getName(void) const;
00065 std::string getComplement(void) const;
00066 std::string getPostscript(void) const;
00067 bool useBlackInk(void) const;
00068
00069 static void setCutoffAdjustment(double value);
00070 static double getCutoffAdjustment(void);
00071
00072 double getHue(void) const {return _h;};
00073 double getSaturation(void) const {return _s;};
00074 double getValue(void) const {return _v;};
00075
00076
00077
00078 private:
00079
00080
00081
00082 std::string _name;
00083
00084 unsigned char _red;
00085 unsigned char _green;
00086 unsigned char _blue;
00087
00088
00089 double _h;
00090 double _s;
00091 double _v;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 static int _cutoff[36];
00102
00103
00104
00105
00106
00107
00108
00109 static double _cutoffAdjustment;
00110
00111 void _setColorFromString(const std::string &color);
00112 void _calculateHSV(void);
00113
00114 unsigned char _hexCharacterToInt(const char digit);
00115 std::string _intToHexString(unsigned char v) const;
00116 };
00117
00118 std::ostream& operator<<(std::ostream& s, const DrawingColor& color);
00119
00120 #endif
00121