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