12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "sys-defines.h"
- #include "extern.h"
- #define NUM_SVG_COLORNAMES 16
- static const plColorNameInfo _svg_colornames[NUM_SVG_COLORNAMES + 1] =
- {
- {"aqua", 0x00, 0xff, 0xff},
- {"black", 0x00, 0x00, 0x00},
- {"blue", 0x00, 0x00, 0xff},
- {"fuchsia", 0xff, 0x00, 0xff},
- {"gray", 0x80, 0x80, 0x80},
- {"green", 0x00, 0x80, 0x00},
- {"lime", 0x00, 0xff, 0x00},
- {"maroon", 0x80, 0x00, 0x00},
- {"navy", 0x00, 0x00, 0x80},
- {"olive", 0x80, 0x80, 0x00},
- {"purple", 0x80, 0x00, 0x80},
- {"red", 0xff, 0x00, 0x00},
- {"silver", 0xc0, 0xc0, 0xc0},
- {"teal", 0x00, 0x80, 0x80},
- {"white", 0xff, 0xff, 0xff},
- {"yellow", 0xff, 0xff, 0x00},
- {NULL, 0, 0, 0}
- };
- const char *
- _libplot_color_to_svg_color (plColor color_48, char charbuf[8])
- {
- plColor color_24;
- int i;
- bool found = false;
- const char *svg_color;
-
- color_24.red = ((unsigned int)color_48.red) >> 8;
- color_24.green = ((unsigned int)color_48.green) >> 8;
- color_24.blue = ((unsigned int)color_48.blue) >> 8;
-
- for (i = 0; i < NUM_SVG_COLORNAMES; i++)
- {
- if (color_24.red == _svg_colornames[i].red
- && color_24.green == _svg_colornames[i].green
- && color_24.blue == _svg_colornames[i].blue)
- {
- found = true;
- break;
- }
- }
- if (found)
- svg_color = _svg_colornames[i].name;
- else
- {
- sprintf (charbuf, "#%02x%02x%02x",
- color_24.red, color_24.green, color_24.blue);
- svg_color = charbuf;
- }
-
- return svg_color;
- }
|