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