+// Colors
+
+class color_spec {
+ double rgb[3];
+public:
+ color_spec(string s)
+ {
+ if (s.length() != 6)
+ die("Invalid color specification \"%s\": expecting 6 hex digits", s.c_str());
+ for (int i=0; i<3; i++)
+ {
+ int x = 0;
+ for (int j=0; j<2; j++)
+ {
+ char c = s[2*i+j];
+ if (c >= '0' && c <= '9')
+ x = (x << 4) | (c - '0');
+ else if (c >= 'a' && c <= 'f')
+ x = (x << 4) | (c - 'a' + 10);
+ else if (c >= 'A' && c <= 'F')
+ x = (x << 4) | (c - 'A' + 10);
+ }
+ rgb[i] = x / 255.;
+ }
+ }
+ string to_string()
+ {
+ return pdf_coord(rgb[0]) + " " + pdf_coord(rgb[1]) + " " + pdf_coord(rgb[2]);
+ }
+};
+