File: ccommand

package info (click to toggle)
lout 3.25-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,252 kB
  • ctags: 3,152
  • sloc: ansic: 31,182; makefile: 254; awk: 83
file content (113 lines) | stat: -rw-r--r-- 4,394 bytes parent folder | download
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

###########################################################################
#                                                                         #
#   @ColourCommand                                                        #
#                                                                         #
#   Jeff Kingston                                                         #
#   19 October 2001                                                       #
#                                                                         #
#   @ColourCommand converts a colour expressed in a manner that the       #
#   ordinary user can comprehend into the PostScript or PDF command       #
#   needed to obtain that colour, suitable for passing to @SetColour      #
#   or including in the left parameter of @Graphic.                       #
#                                                                         #
#   This symbol is needed in various places so I've taken the coward's    #
#   way out and @SysIncluded it at those places.                          #
#                                                                         #
#   Examples of behaviour for the PostScript back end:                    #
#                                                                         #
#       Parameter                 Result                                  #
#       ------------------------------------------------------------      #
#       black                     "0.0 0.0 0.0 setrgbcolor"               #
#       darkblue                  "0.0 0.0 0.5 setrgbcolor"               #
#       white                     "1.0 1.0 1.0 setrgbcolor"               #
#       none                      ""                                      #
#       nochange                  ""                                      #
#       ""                        ""                                      #
#       rgb <red> <blue> <green>  "<red> <blue> <green> setrgbcolor"      #
#       cymk <c> <y> <m> <k>      "<c> <y> <m> <k> setcymkcolor"          #
#       ------------------------------------------------------------      #
#                                                                         #
#   @ColourCommand also does the right thing for the PDF back end;        #
#   its result is always empty for the PlainText back end.                #
#                                                                         #
###########################################################################

def @ColourCommand right @Body
{
    def @RGB right coords
    {
	@BackEnd @Case {
	    PostScript @Yield { coords "setrgbcolor" }
	    PDF        @Yield { coords "rg" coords "RG" }
	    PlainText  @Yield ""
	}
    }

    def @CMYK right coords
    {
	@BackEnd @Case {
	    PostScript @Yield { coords "setcmykcolor" }
	    PDF        @Yield { coords "k" coords "K" }
	    PlainText  @Yield ""
	}
    }

    def @RGBElse right alt
    {
	{ "rgb" @Common @Body } @Case {
	    "rgb" @Yield @RGB { "rgb" @Rump @Body }
	    else  @Yield alt
	}
    }

    def @CMYKElse right alt
    {
	{ "cmyk" @Common @Body } @Case {
	    "cmyk" @Yield @CMYK { "cmyk" @Rump @Body }
	    else  @Yield alt
	}
    }

    def @NoChangeElse right alt
    {
	@Body @Case {
	    { "nochange" "none" "" } @Yield ""
	    else              @Yield alt
	}
    }

    def @RGBCoords
    {
	@Body @Case {
	    black	@Yield	{ 0.0 0.0 0.0 }
	    darkblue	@Yield	{ 0.0 0.0 0.5 }
	    blue	@Yield	{ 0.0 0.0 1.0 }
	    lightblue	@Yield	{ 0.5 0.5 1.0 }
	    darkgreen	@Yield	{ 0.0 0.5 0.0 }
	    green	@Yield	{ 0.0 1.0 0.0 }
	    lightgreen	@Yield	{ 0.5 1.0 0.5 }
	    darkred	@Yield	{ 0.5 0.0 0.0 }
	    red		@Yield	{ 1.0 0.0 0.0 }
	    lightred	@Yield	{ 1.0 0.5 0.5 }
	    darkcyan	@Yield	{ 0.0 0.5 0.5 }
	    cyan	@Yield	{ 0.0 1.0 1.0 }
	    lightcyan	@Yield	{ 0.5 1.0 1.0 }
	    darkmagenta	@Yield	{ 0.5 0.0 0.5 }
	    magenta	@Yield	{ 1.0 0.0 1.0 }
	    lightmagenta @Yield	{ 1.0 0.5 1.0 }
	    darkyellow	@Yield	{ 0.5 0.5 0.0 }
	    yellow	@Yield	{ 1.0 1.0 0.0 }
	    lightyellow	@Yield	{ 1.0 1.0 0.5 }
	    darkgray	@Yield	{ 0.2 0.2 0.2 }
	    gray	@Yield	{ 0.5 0.5 0.5 }
	    lightgray	@Yield	{ 0.8 0.8 0.8 }
	    darkgrey	@Yield	{ 0.2 0.2 0.2 }
	    grey	@Yield	{ 0.5 0.5 0.5 }
	    lightgrey	@Yield	{ 0.8 0.8 0.8 }
	    white	@Yield	{ 1.0 1.0 1.0 }
	}
    }

    @RGBElse @CMYKElse @NoChangeElse @RGB @RGBCoords
}