Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / groff / src / include / color.h
1 // -*- C++ -*-
2
3 /* <groff_src_dir>/src/include/color.h
4
5 Last update: 10 Apr 2002
6
7 Copyright (C) 2001, 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25
26 #include <stddef.h>
27
28 enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY};
29
30 class color {
31 private:
32   color_scheme scheme;
33   unsigned int components[4];
34
35   int read_encoding(const color_scheme, const char * const,
36                     const size_t);
37
38 public:
39   enum {MAX_COLOR_VAL = 0xffff};
40   color() : scheme(DEFAULT){}
41   color(const color * const);
42
43   int operator==(const color & c) const;
44   int operator!=(const color & c) const;
45
46   int is_default() { return scheme == DEFAULT; }
47
48   // set color from given color component values
49   void set_default();
50   void set_rgb(const unsigned int r, const unsigned int g,
51                const unsigned int b);
52   void set_cmy(const unsigned int c, const unsigned int m,
53                const unsigned int y);
54   void set_cmyk(const unsigned int c, const unsigned int m,
55                 const unsigned int y, const unsigned int k);
56   void set_gray(const unsigned int g);
57           
58   // set color from a color string
59   int read_rgb(const char * const s);
60   int read_cmy(const char * const s);
61   int read_cmyk(const char * const s);
62   int read_gray(const char * const s);
63
64   // Return the actual color scheme and retrieve the color components
65   // into a predefined vector (of length at least 4).
66   color_scheme get_components(unsigned int *c) const;
67
68   // retrieve the components of a color
69   void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const;
70   void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const;
71   void get_cmyk(unsigned int *c, unsigned int *m,
72                 unsigned int *y, unsigned int *k) const;
73   void get_gray(unsigned int *g) const;
74 };
75
76 #define Cyan components[0]
77 #define Magenta components[1]
78 #define Yellow components[2]
79 #define Black components[3]
80
81 #define Red components[0]
82 #define Green components[1]
83 #define Blue components[2]
84
85 #define Gray components[0]
86
87 extern color default_color;