| Commit | Line | Data |
|---|---|---|
| 92d0a6a6 JR |
1 | // -*- C++ -*- |
| 2 | ||
| 3 | /* <groff_src_dir>/src/include/color.h | |
| 4 | ||
| 4d3e9548 | 5 | Last update: 5 Jan 2009 |
| 92d0a6a6 | 6 | |
| 4d3e9548 | 7 | Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. |
| 92d0a6a6 JR |
8 | Written by Gaius Mulley <gaius@glam.ac.uk> |
| 9 | ||
| 10 | This file is part of groff. | |
| 11 | ||
| 12 | groff is free software; you can redistribute it and/or modify it under | |
| 13 | the terms of the GNU General Public License as published by the Free | |
| 4d3e9548 JL |
14 | Software Foundation, either version 3 of the License, or |
| 15 | (at your option) any later version. | |
| 92d0a6a6 JR |
16 | |
| 17 | groff is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 18 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 20 | for more details. | |
| 21 | ||
| 4d3e9548 JL |
22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
| 92d0a6a6 JR |
24 | |
| 25 | #include <stddef.h> | |
| 26 | #include "symbol.h" | |
| 27 | ||
| 28 | enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY}; | |
| 29 | ||
| 30 | class color { | |
| 31 | private: | |
| 32 | color_scheme scheme; | |
| 33 | unsigned int components[4]; | |
| 34 | color *next; | |
| 35 | static color *free_list; | |
| 36 | ||
| 37 | int read_encoding(const color_scheme, const char * const, | |
| 38 | const size_t); | |
| 39 | ||
| 40 | public: | |
| 41 | symbol nm; | |
| 42 | enum {MAX_COLOR_VAL = 0xffff}; | |
| 43 | color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {} | |
| 44 | color(const color * const); | |
| 45 | ~color(); | |
| 46 | void *operator new(size_t); | |
| 47 | void operator delete(void *); | |
| 48 | ||
| 49 | int operator==(const color & c) const; | |
| 50 | int operator!=(const color & c) const; | |
| 51 | ||
| 52 | int is_default() { return scheme == DEFAULT; } | |
| 53 | ||
| 54 | // set color from given color component values | |
| 55 | void set_default(); | |
| 56 | void set_rgb(const unsigned int r, const unsigned int g, | |
| 57 | const unsigned int b); | |
| 58 | void set_cmy(const unsigned int c, const unsigned int m, | |
| 59 | const unsigned int y); | |
| 60 | void set_cmyk(const unsigned int c, const unsigned int m, | |
| 61 | const unsigned int y, const unsigned int k); | |
| 62 | void set_gray(const unsigned int g); | |
| 63 | ||
| 64 | // set color from a color string | |
| 65 | int read_rgb(const char * const s); | |
| 66 | int read_cmy(const char * const s); | |
| 67 | int read_cmyk(const char * const s); | |
| 68 | int read_gray(const char * const s); | |
| 69 | ||
| 70 | // Return the actual color scheme and retrieve the color components | |
| 71 | // into a predefined vector (of length at least 4). | |
| 72 | color_scheme get_components(unsigned int *c) const; | |
| 73 | ||
| 74 | // retrieve the components of a color | |
| 75 | void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const; | |
| 76 | void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const; | |
| 77 | void get_cmyk(unsigned int *c, unsigned int *m, | |
| 78 | unsigned int *y, unsigned int *k) const; | |
| 79 | void get_gray(unsigned int *g) const; | |
| 80 | ||
| 81 | char *print_color(); | |
| 82 | }; | |
| 83 | ||
| 84 | #define Cyan components[0] | |
| 85 | #define Magenta components[1] | |
| 86 | #define Yellow components[2] | |
| 87 | #define Black components[3] | |
| 88 | ||
| 89 | #define Red components[0] | |
| 90 | #define Green components[1] | |
| 91 | #define Blue components[2] | |
| 92 | ||
| 93 | #define Gray components[0] | |
| 94 | ||
| 95 | extern color default_color; |