xref: /trueos/contrib/groff/src/include/color.h (revision 513cdf04e173130783343fe42786eef6b8294c6e)
1 // -*- C++ -*-
2 
3 /* <groff_src_dir>/src/include/color.h
4 
5 Last update: 14 Feb 2003
6 
7 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
8     Written by Gaius Mulley <gaius@glam.ac.uk>
9 
10 This file is part of groff.
11 
12 groff is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 2, or (at your option) any later
15 version.
16 
17 groff is distributed in the hope that it will be useful, but WITHOUT ANY
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 for more details.
21 
22 You should have received a copy of the GNU General Public License along
23 with groff; see the file COPYING.  If not, write to the Free Software
24 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
25 
26 #include <stddef.h>
27 #include "symbol.h"
28 
29 enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY};
30 
31 class color {
32 private:
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 
41 public:
42   symbol nm;
43   enum {MAX_COLOR_VAL = 0xffff};
scheme(DEFAULT)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 
is_default()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 
96 extern color default_color;
97