Debian Codegraph @

texmf-dist/tex/plain/pdftoolbox/pdfGraphics/ptb-colors.tex

raw
1 \input ptb-utils
2
3 \_checkloaded{colors}
4
5 \def\_rgb_encode#1{#1 rg #1 RG}
6 \def\_rgb_encodebg#1{#1 rg}
7 \def\_rgb_encodefg#1{#1 RG}
8 \def\_cmyk_encode#1{#1 k #1 K}
9 \def\_cmyk_encodebg#1{#1 k}
10 \def\_cmyk_encodefg#1{#1 K}
11
12 \chardef\_colorstack=0
13 \def\_pdfcolor_restore{\pdfcolorstack\_colorstack pop\relax}
14
15 \def\_setcolor_code#1{\pdfcolorstack\_colorstack push{#1}\aftergroup\_pdfcolor_restore}
16
17 %\def\_colorbg_set#1#2{\pdfcolorstack\_colorstack push{\csname _#1_encodebg\endcsname{#2}}\aftergroup\_pdfcolor_restore}
18 %\def\_colorfg_set#1#2{\pdfcolorstack\_colorstack push{\csname _#1_encodefg\endcsname{#2}}\aftergroup\_pdfcolor_restore}
19 \def\_color_set#1#2{\_setcolor_code{\csname _#1_encode\endcsname{#2}}}
20 \def\_colorbg_set#1#2{\_setcolor_code{\csname _#1_encodebg\endcsname{#2}}}
21 \def\_colorfg_set#1#2{\_setcolor_code{\csname _#1_encodefg\endcsname{#2}}}
22
23 \def\_color_defined#1{\expanded{\noexpand\_color_set\csname c@#1\endcsname}}
24 \def\_colorbg_defined#1{\expanded{\noexpand\_colorbg_set\csname c@#1\endcsname}}
25 \def\_colorfg_defined#1{\expanded{\noexpand\_colorfg_set\csname c@#1\endcsname}}
26
27 %\def\_color_set#1#2{\pdfcolorstack\_colorstack push{\csname _#1_encode\endcsname{#2}}\aftergroup\_pdfcolor_restore}
28 % \_color_get_code{rgb/cmyk}{code}{fg/bg/empty}
29 \def\_color_get_code#1#2#3{\csname _#1_encode#3\endcsname{#2}}
30 % \_color_get_defined{color name}{fg/bg/empty}
31 \def\_color_get_defined#1#2{\expanded{\noexpand\_color_get_code\csname c@#1\endcsname{#2}}}
32
33
34 \def\__getcolorparam#1#2#3#4{%
35 \ifx^#3^%
36 \_afterfi{\expanded{\unexpanded{#1}{\_color_get_defined{#4}{#2}}}}%
37 \else%
38 \_afterfi{\expanded{\unexpanded{#1}{\_color_get_code{#3}{#4}{#2}}}}%
39 \fi
40 }
41 % \_getcolorparam{\macro}{fg/bg/empty}... (... is of the form rgb{...}, etc, or {color name})
42 \def\_getcolorparam#1#2#3#{\__getcolorparam{#1}{#2}{#3}}
43
44 \def\___setcolor#1#2#3#4\relax{%
45 \ifx^#3^%
46 \csname _color#1_defined\endcsname{#2}%
47 \else%
48 \csname _color#1_set\endcsname{#2}{#3}%
49 \fi%
50 }
51 \def\__setcolor#1#2#{\___setcolor{#1}{#2}}
52 % \_setcolor{fg/bg/empty}{color name/color space{...}} -> sets the color
53 \def\_setcolor#1#2{\expanded{\noexpand\__setcolor{#1}#2}{}\relax}
54
55 \def\___getcolor#1#2#3#4;{%
56 \ifx^#3^%
57 \_color_get_defined{#2}{#1}%
58 \else%
59 \_color_get_code{#2}{#3}{#1}%
60 \fi%
61 }
62 \def\__getcolor#1#2#{\___getcolor{#1}{#2}}
63 % \_getcolor{fg/bg/empty}{color name/color space{...}} -> gets the color
64 \def\_getcolor#1#2{\expanded{\noexpand\__getcolor{#1}#2}{};}
65
66
67 %\def\_color#1#2{%
68 % \ifx^#1^%
69 % \_color_defined{#2}%
70 % \else%
71 % \_color_set{#1}{#2}%
72 % \fi%
73 %}
74 \def\color{\_getcolorparam\_setcolor_code{}}
75
76 \def\_localcolor#1{%
77 \bgroup%
78 \_setcolor_code{#1}%
79 \let\_regU%
80 }
81 \def\localcolor{\_getcolorparam\_localcolor{}}
82
83 \def\definecolor#1#2#3{\_xp\def\csname c@#1\endcsname{{#2}{#3}}}
84 \def\letcolor#1#2{\_xp\edef\csname c@#1\endcsname{\csname c@#2\endcsname}}
85 \def\definecolormacro#1#2#3{\definecolor{#1}{#2}{#3}\_xp\def\csname #1\endcsname##1{\localcolor{#1}{##1}}}
86
87 \newbox\_colorbox
88 \def\_endhighlightbox{\quitvmode\hbox to\wd\_colorbox{\_xp\localcolor\_regA{\vrule height\ht\_colorbox width\wd\_colorbox depth\dp\_colorbox}\hss\box\_colorbox}\egroup}
89 \def\_highlightbox#1#2{\bgroup\def\_regA{#1{#2}}\setbox\_colorbox=\hbox\bgroup\aftergroup\_endhighlightbox\let\_regU}
90 \def\highlightbox#1#{\_highlightbox{#1}}
91
92 \def\bufferwidth{2pt}
93 \def\bufferheight{2pt}
94 \def\_bufferboxend{\hbox{\kern\bufferwidth\lower\dimexpr\bufferheight + \dp\_colorbox\relax\vbox{\kern\bufferheight\box\_colorbox\kern\bufferheight}\kern\bufferwidth}}
95 \def\_bufferbox{\setbox\_colorbox=\hbox\bgroup\aftergroup\_bufferboxend\let\_regU}
96
97 \def\framewidth{.3pt}
98 \def\_frameboxend{\hbox{\vrule width\framewidth\lower\dimexpr \framewidth + \dp\_colorbox\relax\vbox{\hrule height\framewidth\box\_colorbox\hrule height\framewidth}\vrule width\framewidth\relax}}
99 \def\_framebox{\setbox\_colorbox=\hbox\bgroup\aftergroup\_frameboxend\let\_regU}
100
101 \def\_coloredbox#1#2{\highlightbox#1{#2}\bgroup\_bufferbox\bgroup\aftergroup\egroup\let\_regU}
102 \def\coloredbox#1#{\_coloredbox{#1}}
103
104 \def\_framecoloredbox#1#2{\quitvmode\_framebox\bgroup\_coloredbox{#1}{#2}\bgroup\aftergroup\egroup\let\_regU}
105 \def\framecoloredbox#1#{\_framecoloredbox{#1}}
106
107 \def\framebox{\_framebox\bgroup\_bufferbox\bgroup\aftergroup\egroup\let\_regU}
108
109 \def\_pdf_pt_scale,{.996264 0 0 .996264 0 0 cm}
110
111 \def\_curvedbox#1#2#3#4#5{%
112 #1 \_nopt{#2pt-#5pt} m
113 \_nopt{#1pt-#5pt} \_nopt{#2pt-#5pt} \_nopt{#1pt-#5pt} #2 v
114 \_nopt{#1pt-#5pt} \_nopt{#2pt+#4pt} l
115 \_nopt{#1pt-#5pt} \_nopt{#2pt+#4pt+#5pt} #1 \_nopt{#2pt+#4pt+#5pt} v
116 \_nopt{#1pt+#3pt} \_nopt{#2pt+#4pt+#5pt} l
117 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt+#4pt+#5pt} \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt+#4pt} v
118 \_nopt{#1pt+#3pt+#5pt} #2 l
119 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt-#5pt} \_nopt{#1pt+#3pt} \_nopt{#2pt-#5pt} v
120 #1 \_nopt{#2pt-#5pt} l
121 }
122
123 \def\_blcorner#1#2#3#4#5#6#7#8#9{%
124 \if.#9
125 \_nopt{#5} \_nopt{#2} m
126 \else
127 \_nopt{#8} \_nopt{#2} m
128 \fi
129 \if-#7
130 \if.#6
131 #1 \_nopt{#2} l
132 \_nopt{#3} \_nopt{#2} \_nopt{#3} #4 v
133 \else
134 \_nopt{#3} \_nopt{#2} l
135 \fi
136 \else
137 #1 \_nopt{#2} m
138 \if.#6
139 #1 \_nopt{#2} l
140 \_nopt{#3} \_nopt{#2} \_nopt{#3} #4 v
141 \else
142 \_nopt{#3} \_nopt{#2} m
143 \fi
144 \fi
145 }
146
147 \def\_tlcorner#1#2#3#4#5#6{%
148 \if-#6
149 \if.#5
150 \_nopt{#1} \_nopt{#2} l
151 \_nopt{#1} \_nopt{#3} #4 \_nopt{#3} v
152 \else
153 \_nopt{#1} \_nopt{#3} l
154 \fi
155 \else
156 \if.#5
157 \_nopt{#1} \_nopt{#2} m
158 \_nopt{#1} \_nopt{#3} #4 \_nopt{#3} v
159 \else
160 \_nopt{#1} \_nopt{#3} m
161 \fi
162 \fi
163 }
164
165 \def\_trcorner#1#2#3#4#5#6{%
166 \if-#6
167 \if.#5
168 \_nopt{#1} \_nopt{#2} l
169 \_nopt{#3} \_nopt{#2} \_nopt{#3} \_nopt{#4} v
170 \else
171 \_nopt{#3} \_nopt{#2} l
172 \fi
173 \else
174 \if.#5
175 \_nopt{#1} \_nopt{#2} m
176 \_nopt{#3} \_nopt{#2} \_nopt{#3} \_nopt{#4} v
177 \else
178 \_nopt{#3} \_nopt{#2} m
179 \fi
180 \fi
181 }
182
183 \def\_brcorner#1#2#3#4#5#6{%
184 \if-#6
185 \if.#5
186 \_nopt{#1} #2 l
187 \_nopt{#1} \_nopt{#3} \_nopt{#4} \_nopt{#3} v
188 \else
189 \_nopt{#1} \_nopt{#3} l
190 \fi
191 \else
192 \if.#5
193 \_nopt{#1} #2 m
194 \_nopt{#1} \_nopt{#3} \_nopt{#4} \_nopt{#3} v
195 \else
196 \_nopt{#1} \_nopt{#3} m
197 \fi
198 \fi
199 }
200
201 % #1: origin x
202 % #2: origin y
203 % #3: width
204 % #4: height
205 % #5: curvature
206 % Note: #1...#4 do not take curvature into account
207 \def\_curvedbox#1#2#3#4#5#6#7#8#9{%
208 \if.#6
209 #1 \_nopt{#2pt-#5pt} m
210 \_nopt{#1pt-#5pt} \_nopt{#2pt-#5pt} \_nopt{#1pt-#5pt} #2 v
211 \else
212 \_nopt{#1pt-#5pt} \_nopt{#2pt-#5pt} m
213 \fi
214 \if.#7
215 \_nopt{#1pt-#5pt} \_nopt{#2pt+#4pt} l
216 \_nopt{#1pt-#5pt} \_nopt{#2pt+#4pt+#5pt} #1 \_nopt{#2pt+#4pt+#5pt} v
217 \else
218 \_nopt{#1pt-#5pt} \_nopt{#2pt+#4pt+#5pt} l
219 \fi
220 \if.#8
221 \_nopt{#1pt+#3pt} \_nopt{#2pt+#4pt+#5pt} l
222 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt+#4pt+#5pt} \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt+#4pt} v
223 \else
224 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt+#4pt+#5pt} l
225 \fi
226 \if.#9
227 \_nopt{#1pt+#3pt+#5pt} #2 l
228 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt-#5pt} \_nopt{#1pt+#3pt} \_nopt{#2pt-#5pt} v
229 \else
230 \_nopt{#1pt+#3pt+#5pt} \_nopt{#2pt-#5pt} l
231 \fi
232 %#1 \_nopt{#2pt-#5pt} l
233 }
234
235 \def\_curvedbox#1#2#3#4#5{%
236 \_blcorner{#1}{#2pt-#5pt}{#1pt-#5pt}{#2}{#1pt+#3pt}\_dotbl\_lineb{#1pt+#3pt+#5pt}\_dotbr\_space
237 \_tlcorner{#1pt-#5pt}{#2pt+#4pt}{#2pt+#4pt+#5pt}{#1}\_dottl\_linel\_space
238 \_trcorner{#1pt+#3pt}{#2pt+#4pt+#5pt}{#1pt+#3pt+#5pt}{#2pt+#4pt}\_dottr\_linet\_space
239 \_brcorner{#1pt+#3pt+#5pt}{#2}{#2pt-#5pt}{#1pt+#3pt}\_dotbr\_liner\_space
240 }
241
242 \def\_curvedboxbg#1#2#3#4#5{%
243 \_blcorner{#1}{#2pt-#5pt}{#1pt-#5pt}{#2}{#1pt+#3pt}\_dotbl-{#1pt+#3pt+#5pt}\_dotbr\_space
244 \_tlcorner{#1pt-#5pt}{#2pt+#4pt}{#2pt+#4pt+#5pt}{#1}\_dottl-\_space
245 \_trcorner{#1pt+#3pt}{#2pt+#4pt+#5pt}{#1pt+#3pt+#5pt}{#2pt+#4pt}\_dottr-\_space
246 \_brcorner{#1pt+#3pt+#5pt}{#2}{#2pt-#5pt}{#1pt+#3pt}\_dotbr-\_space
247 }
248
249
250 \def\_getdotsnlines#1#2#3#4#5#6#7#8\_nul{%
251 \edef\_lineb{#1}%
252 \edef\_dotbl{#2}%
253 \edef\_linel{#3}%
254 \edef\_dottl{#4}%
255 \edef\_linet{#5}%
256 \edef\_dottr{#6}%
257 \edef\_liner{#7}%
258 \edef\_dotbr{#8}%
259 }
260
261 \def\curvebuffer{4pt}
262 \def\curvewidth{1pt}
263 \def\_actual_curve_buf{\dimexpr\curvebuffer + \curvewidth\relax}
264 \def\boxshadowcolor{rgb{.9 .9 .9}}
265 \def\shadowxoff{3pt}
266 \def\shadowyoff{-3pt}
267
268 \long\def\curvedcolorbox#1#2#3#4{{%
269 \_xp\_getdotsnlines\expanded{#4}\_nul%
270 \setbox\_colorbox=\hbox{{#3}}%
271 \hbox{%
272 \lower\dimexpr\curvebuffer + \curvewidth + \dp\_colorbox\relax%
273 \vbox{%
274 \kern\_actual_curve_buf%
275 \hbox{%
276 \kern\_actual_curve_buf%
277 \pdfliteral{%
278 q \_pdf_pt_scale,
279 \_getcolor{}{\boxshadowcolor}
280 \_nopt{\curvewidth} w
281 \_curvedboxbg{\_nopt{\shadowxoff}}{\_nopt{-\dp\_colorbox+\shadowyoff}}{\_nopt{\wd\_colorbox}}{\_nopt{\ht\_colorbox+\dp\_colorbox}}{\_nopt{\curvebuffer}}\_space%#4
282 b
283 \_getcolor{bg}{#2}
284 \_getcolor{fg}{#1}
285 \_curvedboxbg{0}{\_nopt{-\dp\_colorbox}}{\_nopt{\wd\_colorbox}}{\_nopt{\ht\_colorbox+\dp\_colorbox}}{\_nopt{\curvebuffer}}\_space%#4
286 W f
287 }%
288 \rlap{\copy\_colorbox}%
289 \pdfliteral{%
290 Q
291 q
292 \_pdf_pt_scale,
293 \_nopt{\curvewidth} w
294 \_getcolor{fg}{#1}
295 \_curvedbox{0}{\_nopt{-\dp\_colorbox}}{\_nopt{\wd\_colorbox}}{\_nopt{\ht\_colorbox+\dp\_colorbox}}{\_nopt{\curvebuffer}}\_space%#4
296 S
297 Q
298 }%
299 \kern\wd\_colorbox%
300 \kern\_actual_curve_buf%
301 }%
302 \kern\_actual_curve_buf%
303 }%
304 }%
305 }}
306
307 \def\_pagecolor#1{\pdfliteral page{#1 0 0 \_nopt{\pdfpagewidth} \_nopt{\pdfpageheight} re f}}
308 \def\pagecolor{\_getcolorparam\_pagecolor{}}
309
310 \def\pageborder#1#2#3{%
311 \pdfliteral page{%
312 q
313 \_pdf_pt_scale,
314 \_getcolor{bg}{#1} \_getcolor{fg}{#2}
315 #3 w
316 0 0 \_nopt{\pdfpagewidth} \_nopt{\pdfpageheight} re b
317 Q
318 }%
319 }
320
321 \def\fakeboldwidth{.4}
322 \long\def\_fakebold[#1]#2{\pdfliteral{2 Tr #1 w}#2\pdfliteral{0 Tr}}
323 \def\fakebold{\_ifnextchar[ {\_fakebold}{\_fakebold[\fakeboldwidth]}}
324 \def\flip#1{{\setbox0=\hbox{#1}\kern\wd0\pdfsave\pdfliteral{-1 0 0 1 0 0 cm}\rlap{#1}\pdfrestore}}
325
326 \definecolormacro{red}{rgb}{1 0 0}
327 \definecolormacro{blue}{rgb}{0 0 1}
328 \definecolormacro{green}{rgb}{0 1 0}
329 \definecolormacro{yellow}{rgb}{1 1 0}
330 \definecolormacro{orange}{rgb}{1 .4 0}
331 \definecolormacro{purple}{rgb}{1 0 1}
332 \definecolormacro{white}{rgb}{1 1 1}
333 \definecolormacro{black}{rgb}{0 0 0}
334 \definecolormacro{darkgreen}{rgb}{0 .7 0}
335 \definecolormacro{grey}{rgb}{.5 .5 .5}
336