summaryrefslogtreecommitdiff
path: root/graphics/pstricks/base/generic/pstricks-color.tex
blob: 708a4260a5f9d97cbeaf88c2a57359815d8d3e47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
%% $Id: pstricks-arrows.tex 168 2021-08-28 08:43:24Z herbert $
%%
%% This is file `pstricks-color.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Herbert Voss <hvoss@tug.org>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pstricks-color' base code for color settings 
%%
%% fileversion and filedate see main file pstricks.tex
%%
\pstVerb{
  /pssetRGBcolor  /setrgbcolor  load def
  /pssetCMYKcolor /setcmykcolor load def
  /pssetGraycolor /setgray      load def
}
\def\@newcolor#1#2{%
  \expandafter\edef\csname #1\endcsname{\noexpand\pst@color{#2}}%
  %\expandafter\edef\csname color@#1\endcsname{#2}%
  \expandafter\edef\csname\string\color@#1\endcsname{#2}%    hv 1.14 2005-12-17
  \ignorespaces}
%
\def\pst@color#1{\def\pst@currentcolor{#1}\pstVerb{#1}\aftergroup\pst@endcolor}%
\def\pst@endcolor{\pstVerb{\pst@currentcolor}}
\def\pst@currentcolor{0 setgray}
\def\altcolormode{%
\def\pst@color##1{%
  \pstVerb{gsave ##1}\aftergroup\pst@endcolor}%
\def\pst@endcolor{\pstVerb{\pst@grestore}}}

\def\psgetRGBColorValues#1{\expandafter\psgetRGBColorvalues@i#1;}
\def\psgetRGBColorvalues@i#1#2#3#4#5;{\expandafter\psgetRGBColorvalues@ii#5,,,;}
\def\psgetRGBColorvalues@ii#1,#2,#3,#4;{%
  \ifx\relax#2\relax 
    #1  % gray color model
  \else
    #1 #2 #3
  \fi}

\def\psgetCMYKColorValues#1{\expandafter\psgetCMYKColorvalues@i#1;}
\def\psgetCMYKColorvalues@i#1#2#3#4#5;{\expandafter\psgetCMYKColorvalues@ii#5,,,,;}
\def\psgetCMYKColorvalues@ii#1,#2,#3,#4,#5;{%
  \ifx\relax#2\relax 
    #1  % gray color model
  \else
    #1 #2 #3 #4
  \fi}

\iffalse
\def\ps@RGB@model{rgb}
\def\psgetColorValues#1{\makeatletter\expandafter\psgetColorvalues@i#1;\makeatother} 
\gdef\psgetColorvalues@i#1#2#3#4#5;{%
  \scantokens{\def\pst@tempA{#4}}
  \if\pst@tempA\ps@RGB@model
    \expandafter\psgetRGBColorvalues@ii#5;
  \else
    \expandafter\psgetCMYKColorvalues@ii#5;
  \fi
}
\fi

\def\pssetMonochrome{%
  \pstVerb{
    /setrgbcolor { add add 0 gt {0}{1} ifelse setgray } def 
    /setcmykcolor{ 4 dict begin
      /k ED /y ED /m ED /c ED 
      1 1 k sub c mul k add sub 0.29 mul 
      1 1 k sub m mul k add sub 0.587 mul add 
      1 1 k sub y mul k add sub 0.114 mul add
      end 0 gt {0}{1} ifelse setgray } def }}
\def\pssetGrayscale{%
  \pstVerb{
    /setrgbcolor { 0.07 mul exch 0.71 mul add exch 0.21 mul add setgray } def 
    /setcmykcolor{ 4 dict begin
      /k ED /y ED /m ED /c ED 
      1 1 k sub c mul k add sub 0.29 mul 
      1 1 k sub m mul k add sub 0.587 mul add 
      1 1 k sub y mul k add sub 0.114 mul add
      end setgray } def }}
\def\psresetColor{\pstVerb{
    /setrgbcolor  tx@Dict begin /pssetRGBcolor  load end def 
    /setcmykcolor tx@Dict begin /pssetCMYKcolor load end def }}

%\def\pst@usecolor#1{\csname color@#1\endcsname\space}%    hv 1.14  2005--12-17
\def\pst@usecolor#1{\csname\string\color@#1\endcsname\space}
%
\def\newgray#1#2{%
    \pst@checknum{#2}\pst@tempg
    \@newcolor{#1}{\pst@tempg setgray}}%
\def\newrgbcolor#1#2{%
  \pst@expandafter\pst@getnumiii{#2} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi setrgbcolor}}
\def\newhsbcolor#1#2{%
  \pst@expandafter\pst@getnumiii{#2} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi sethsbcolor}}
\def\newcmykcolor#1#2{%
  \pst@expandafter\pst@getnumiv{#2} {} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi \pst@tempj setcmykcolor}}
\newgray{black}{0}
\newgray{darkgray}{.25}
\newgray{gray}{.5}
\newgray{lightgray}{.75}
\newgray{white}{1}
\newrgbcolor{red}{1 0 0}
\newrgbcolor{green}{0 1 0}
\newrgbcolor{blue}{0 0 1}
\newrgbcolor{yellow}{1 1 0}
\newrgbcolor{cyan}{0 1 1}
\newrgbcolor{magenta}{1 0 1}

\@ifundefined{xglobal}%  do we have xcolor loaded?
 {\@newcolor{randomgray}{tx@Dict begin Rand setgray end}%
  \@newcolor{randomrgb}{tx@Dict begin Rand Rand Rand setrgbcolor end}%
  \@newcolor{randomcmyk}{tx@Dict begin Rand Rand Rand Rand setcmykcolor end}%
  \@newcolor{randomhsb}{tx@Dict begin Rand Rand Rand sethsbcolor end}%
 }{%
  \definecolor[ps]{randomgray}{gray}{tx@Dict begin Rand end}%
  \definecolor[ps]{randomrgb}{rgb}{tx@Dict begin Rand Rand Rand end}%
  \definecolor[ps]{randomcmyk}{cmyk}{tx@Dict begin Rand Rand Rand Rand end}%
  \definecolor[ps]{randomhsb}{hsb}{tx@Dict begin Rand Rand Rand end}%
 }
%
\def\pst@getcolor#1#2{%
%  \@ifundefined{color@#1}%	hv 1.14  2005-12-17
  \@ifundefined{\string\color@#1}%
    {\@pstrickserr{Color `#1' not defined}\@eha}%
    {\edef#2{#1}}%
}
%
%% END: pstricks-color.tex
\endinput