1104862Sru// -*- C++ -*- 2104862Sru 3104862Sru/* <groff_src_dir>/src/include/color.h 4104862Sru 5114402SruLast update: 14 Feb 2003 6104862Sru 7114402SruCopyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. 8104862Sru Written by Gaius Mulley <gaius@glam.ac.uk> 9104862Sru 10104862SruThis file is part of groff. 11104862Sru 12104862Srugroff is free software; you can redistribute it and/or modify it under 13104862Sruthe terms of the GNU General Public License as published by the Free 14104862SruSoftware Foundation; either version 2, or (at your option) any later 15104862Sruversion. 16104862Sru 17104862Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 18104862SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 19104862SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20104862Srufor more details. 21104862Sru 22104862SruYou should have received a copy of the GNU General Public License along 23104862Sruwith groff; see the file COPYING. If not, write to the Free Software 24151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 25104862Sru 26104862Sru#include <stddef.h> 27151497Sru#include "symbol.h" 28104862Sru 29104862Sruenum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY}; 30104862Sru 31104862Sruclass color { 32104862Sruprivate: 33104862Sru color_scheme scheme; 34104862Sru unsigned int components[4]; 35114402Sru color *next; 36114402Sru static color *free_list; 37104862Sru 38104862Sru int read_encoding(const color_scheme, const char * const, 39104862Sru const size_t); 40104862Sru 41104862Srupublic: 42151497Sru symbol nm; 43104862Sru enum {MAX_COLOR_VAL = 0xffff}; 44151497Sru color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {} 45104862Sru color(const color * const); 46114402Sru ~color(); 47114402Sru void *operator new(size_t); 48114402Sru void operator delete(void *); 49104862Sru 50104862Sru int operator==(const color & c) const; 51104862Sru int operator!=(const color & c) const; 52104862Sru 53104862Sru int is_default() { return scheme == DEFAULT; } 54104862Sru 55104862Sru // set color from given color component values 56104862Sru void set_default(); 57104862Sru void set_rgb(const unsigned int r, const unsigned int g, 58104862Sru const unsigned int b); 59104862Sru void set_cmy(const unsigned int c, const unsigned int m, 60104862Sru const unsigned int y); 61104862Sru void set_cmyk(const unsigned int c, const unsigned int m, 62104862Sru const unsigned int y, const unsigned int k); 63104862Sru void set_gray(const unsigned int g); 64104862Sru 65104862Sru // set color from a color string 66104862Sru int read_rgb(const char * const s); 67104862Sru int read_cmy(const char * const s); 68104862Sru int read_cmyk(const char * const s); 69104862Sru int read_gray(const char * const s); 70104862Sru 71104862Sru // Return the actual color scheme and retrieve the color components 72104862Sru // into a predefined vector (of length at least 4). 73104862Sru color_scheme get_components(unsigned int *c) const; 74104862Sru 75104862Sru // retrieve the components of a color 76104862Sru void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const; 77104862Sru void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const; 78104862Sru void get_cmyk(unsigned int *c, unsigned int *m, 79104862Sru unsigned int *y, unsigned int *k) const; 80104862Sru void get_gray(unsigned int *g) const; 81114402Sru 82114402Sru char *print_color(); 83104862Sru}; 84104862Sru 85104862Sru#define Cyan components[0] 86104862Sru#define Magenta components[1] 87104862Sru#define Yellow components[2] 88104862Sru#define Black components[3] 89104862Sru 90104862Sru#define Red components[0] 91104862Sru#define Green components[1] 92104862Sru#define Blue components[2] 93104862Sru 94104862Sru#define Gray components[0] 95104862Sru 96104862Sruextern color default_color; 97