]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/groff/src/include/color.h
This commit was generated by cvs2svn to compensate for changes in r146901,
[FreeBSD/FreeBSD.git] / contrib / groff / src / include / color.h
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, 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   color *next;
35   static color *free_list;
36
37   int read_encoding(const color_scheme, const char * const,
38                     const size_t);
39
40 public:
41   enum {MAX_COLOR_VAL = 0xffff};
42   color() : scheme(DEFAULT){}
43   color(const color * const);
44   ~color();
45   void *operator new(size_t);
46   void operator delete(void *);
47
48   int operator==(const color & c) const;
49   int operator!=(const color & c) const;
50
51   int is_default() { return scheme == DEFAULT; }
52
53   // set color from given color component values
54   void set_default();
55   void set_rgb(const unsigned int r, const unsigned int g,
56                const unsigned int b);
57   void set_cmy(const unsigned int c, const unsigned int m,
58                const unsigned int y);
59   void set_cmyk(const unsigned int c, const unsigned int m,
60                 const unsigned int y, const unsigned int k);
61   void set_gray(const unsigned int g);
62           
63   // set color from a color string
64   int read_rgb(const char * const s);
65   int read_cmy(const char * const s);
66   int read_cmyk(const char * const s);
67   int read_gray(const char * const s);
68
69   // Return the actual color scheme and retrieve the color components
70   // into a predefined vector (of length at least 4).
71   color_scheme get_components(unsigned int *c) const;
72
73   // retrieve the components of a color
74   void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const;
75   void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const;
76   void get_cmyk(unsigned int *c, unsigned int *m,
77                 unsigned int *y, unsigned int *k) const;
78   void get_gray(unsigned int *g) const;
79
80   char *print_color();
81 };
82
83 #define Cyan components[0]
84 #define Magenta components[1]
85 #define Yellow components[2]
86 #define Black components[3]
87
88 #define Red components[0]
89 #define Green components[1]
90 #define Blue components[2]
91
92 #define Gray components[0]
93
94 extern color default_color;