Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1843

Re: How to give colour as parameter to ghostscript

From ken <ken@spamcop.net>
Newsgroups comp.lang.postscript
Subject Re: How to give colour as parameter to ghostscript
Date 2014-03-31 14:00 +0100
Message-ID <MPG.2da3775c413c12ec9898be@usenet.plus.net> (permalink)
References <87y4zqsj9a.fsf@Equus.Decebal.nl>

Show all headers | View raw


In article <87y4zqsj9a.fsf@Equus.Decebal.nl>, Cecil@decebal.nl says...

> Normally I do something like the following:
>     /backgroundColor  {colorYellow} def
> 
> But I want to give the colour as a parameter to ghostscript:
>     -sbackgroundColor=colorNavy
> 
> What do I need to do in the postscript script to get the right value
> in backgroundColor?

Setting a variable on the command line like that simply defines it in 
systemdict with the given value.

So you can retrieve the value from systemdict :

systemdict /backgroundColor known {
  systemdict /backgroundColor get
} if

checks for the existence of the key 'backgroundColor' in systemdict, and 
if it finds it, retrieves it. Note that -s implies that the value is a 
PostScript string, you might find it more convenient to use -d which 
will allow you to associate the key with a name rather than a string.

Eg -dbackgroundColor=/colorNavy

Then you can use the name as a key to look up your color dictionary:

systemdict /backgroundColor known {
  systemdict /backgroundColor get
  colors exch get setcolor
} if

However, none of these seem to be quite what you are after. You seem to 
want to associate the name 'backgroundColor' with a packed array which 
has the executable bit set. Basically you can't do that from the command 
line.

Instead use -c and -f to send a small section of PostScript on the 
command line, or use one of the preceding examples but change the name 
of the parameter.

For example lets call the parameter 'SetBackgroundColor', and we'll set 
it with -d. Your command line then becomes:

gs .... -dSetBackgroundColor=/navyColor ......

And in your PostScript file:

    /colors <<
      .
      .
      .
      /colorNavy                { 0      0      0.5  }
      /colorNavyBlue            { 0.14   0.14   0.56 }
      /colorNeonBlue            { 0.3    0.3    1    }
      .
      .
      .
      /colorOrange              { 1      0.5    0    } % coral
      /colorOrangeRed           { 1      0.14   0    }
      .
      .
      .
      /colorRed                 { 1      0      0    }
      .
      .
      .
      /colorWhite               { 1      1      1    }
      /colorYellow              { 1      1      0    }
      /colorYellowGreen         { 0.6    0.8    0.2  }
    >> def

systemdict /SetBackgroundColor known {%% Check if name known
  systemdict /SetBackgroundColor get  %% get the object associated
                                      %% with the name
  colors exch get                     %% get the array from the dict
  /backgroundColor exch def           %% associate backgroundColo
                                      %% with that array.
} {                                   %% not set, choose a default
  /backgroundColor colors /colorOrange get def
} ifelse



			Ken

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to give colour as parameter to ghostscript Cecil Westerhof <Cecil@decebal.nl> - 2014-03-31 13:24 +0200
  Re: How to give colour as parameter to ghostscript ken <ken@spamcop.net> - 2014-03-31 14:00 +0100
  Re: How to give colour as parameter to ghostscript Cecil Westerhof <Cecil@decebal.nl> - 2014-03-31 14:47 +0200

csiph-web