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