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