Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / include / color.h
1 // -*- C++ -*-
2 /* <groff_src_dir>/src/include/color.h
3 Copyright (C) 2001-2018 Free Software Foundation, Inc.
4     Written by Gaius Mulley <gaius@glam.ac.uk>
5
6 This file is part of groff.
7
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21 #include <stddef.h>
22 #include "symbol.h"
23
24 enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY};
25
26 class color {
27 private:
28   color_scheme scheme;
29   unsigned int components[4];
30   color *next;
31
32   int read_encoding(const color_scheme, const char * const,
33                     const size_t);
34
35 public:
36   symbol nm;
37   enum {MAX_COLOR_VAL = 0xffff};
38   color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {}
39   color(const color * const);
40   ~color();
41
42   int operator==(const color & c) const;
43   int operator!=(const color & c) const;
44
45   int is_default() { return scheme == DEFAULT; }
46
47   // set color from given color component values
48   void set_default();
49   void set_rgb(const unsigned int r, const unsigned int g,
50                const unsigned int b);
51   void set_cmy(const unsigned int c, const unsigned int m,
52                const unsigned int y);
53   void set_cmyk(const unsigned int c, const unsigned int m,
54                 const unsigned int y, const unsigned int k);
55   void set_gray(const unsigned int g);
56           
57   // set color from a color string
58   int read_rgb(const char * const s);
59   int read_cmy(const char * const s);
60   int read_cmyk(const char * const s);
61   int read_gray(const char * const s);
62
63   // Return the actual color scheme and retrieve the color components
64   // into a predefined vector (of length at least 4).
65   color_scheme get_components(unsigned int *c) const;
66
67   // retrieve the components of a color
68   void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const;
69   void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const;
70   void get_cmyk(unsigned int *c, unsigned int *m,
71                 unsigned int *y, unsigned int *k) const;
72   void get_gray(unsigned int *g) const;
73
74   char *print_color();
75 };
76
77 #define Cyan components[0]
78 #define Magenta components[1]
79 #define Yellow components[2]
80 #define Black components[3]
81
82 #define Red components[0]
83 #define Green components[1]
84 #define Blue components[2]
85
86 #define Gray components[0]
87
88 extern color default_color;