1276305Sngie// -*- C++ -*- 2236769Sobrien 3236769Sobrien/* <groff_src_dir>/src/include/color.h 4236769Sobrien 5236769SobrienLast update: 14 Feb 2003 6236769Sobrien 7236769SobrienCopyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. 8236769Sobrien Written by Gaius Mulley <gaius@glam.ac.uk> 9236769Sobrien 10236769SobrienThis file is part of groff. 11236769Sobrien 12238152Sobriengroff is free software; you can redistribute it and/or modify it under 13236769Sobrienthe terms of the GNU General Public License as published by the Free 14236769SobrienSoftware Foundation; either version 2, or (at your option) any later 15236769Sobrienversion. 16240330Smarcel 17237578Sobriengroff is distributed in the hope that it will be useful, but WITHOUT ANY 18237578SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 19237578SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20236769Sobrienfor more details. 21236769Sobrien 22236769SobrienYou should have received a copy of the GNU General Public License along 23236769Sobrienwith groff; see the file COPYING. If not, write to the Free Software 24236769SobrienFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 25236769Sobrien 26237578Sobrien#include <stddef.h> 27237578Sobrien#include "symbol.h" 28237578Sobrien 29237578Sobrienenum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY}; 30237578Sobrien 31237578Sobrienclass color { 32237578Sobrienprivate: 33237578Sobrien color_scheme scheme; 34236769Sobrien unsigned int components[4]; 35236769Sobrien color *next; 36236769Sobrien static color *free_list; 37236769Sobrien 38236769Sobrien int read_encoding(const color_scheme, const char * const, 39236769Sobrien const size_t); 40236769Sobrien 41236769Sobrienpublic: 42236769Sobrien symbol nm; 43236769Sobrien enum {MAX_COLOR_VAL = 0xffff}; 44236769Sobrien color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {} 45236769Sobrien color(const color * const); 46246223Ssjg ~color(); 47236769Sobrien void *operator new(size_t); 48276305Sngie void operator delete(void *); 49276305Sngie 50276305Sngie int operator==(const color & c) const; 51246223Ssjg int operator!=(const color & c) const; 52236769Sobrien 53236769Sobrien int is_default() { return scheme == DEFAULT; } 54246223Ssjg 55236769Sobrien // set color from given color component values 56236769Sobrien void set_default(); 57236769Sobrien void set_rgb(const unsigned int r, const unsigned int g, 58236769Sobrien const unsigned int b); 59242102Ssjg void set_cmy(const unsigned int c, const unsigned int m, 60237578Sobrien const unsigned int y); 61246223Ssjg void set_cmyk(const unsigned int c, const unsigned int m, 62236769Sobrien const unsigned int y, const unsigned int k); 63236769Sobrien void set_gray(const unsigned int g); 64236769Sobrien 65246223Ssjg // set color from a color string 66236769Sobrien int read_rgb(const char * const s); 67236769Sobrien int read_cmy(const char * const s); 68246223Ssjg int read_cmyk(const char * const s); 69236769Sobrien int read_gray(const char * const s); 70237578Sobrien 71246223Ssjg // Return the actual color scheme and retrieve the color components 72236769Sobrien // into a predefined vector (of length at least 4). 73246223Ssjg color_scheme get_components(unsigned int *c) const; 74236769Sobrien 75237578Sobrien // retrieve the components of a color 76240330Smarcel void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const; 77240330Smarcel void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const; 78246223Ssjg void get_cmyk(unsigned int *c, unsigned int *m, 79240330Smarcel unsigned int *y, unsigned int *k) const; 80240330Smarcel void get_gray(unsigned int *g) const; 81236769Sobrien 82236769Sobrien char *print_color(); 83236769Sobrien}; 84238152Sobrien 85238152Sobrien#define Cyan components[0] 86236769Sobrien#define Magenta components[1] 87236769Sobrien#define Yellow components[2] 88246223Ssjg#define Black components[3] 89242102Ssjg 90242102Ssjg#define Red components[0] 91236769Sobrien#define Green components[1] 92236769Sobrien#define Blue components[2] 93246223Ssjg 94246223Ssjg#define Gray components[0] 95246223Ssjg 96246223Ssjgextern color default_color; 97246223Ssjg