/contrib/groff/src/include/color.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 96 lines · 51 code · 17 blank · 28 comment · 1 complexity · 3e1fe3596ef55fca6fed82c499123a3d MD5 · raw file

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