%! % POSTSCRIPT "WEB FRIENDLY" COLOR TINT MODULE % ============================================ % Copyright c 1999, 2011 by Don Lancaster and Syenrgetics, Box 809, Thatcher, AZ, 85552 % (928) 428-4073 don@tinaja.com < http://www.tinaja.com > % Consulting services available per < http://www.tinaja.com/info01.html > % Additional PostScript resources at < http://www.tinaja.com/pssamp1.asp > % All commercial rights and all electronic media rights fully reserved. % Personal use permitted provided header and entire file remains intact. % Linking welcome. Reposting expressly forbidden. % version 1.1 % ========================================================================== % "Web friendly" colors are a group of 216 tints based on % red, blue, and green being restricted to hex values of % $00, $33, $66, $99, $CC, and $FF each. % This routine accepts a number from 0 to 215 and generates % a "web friendly" color from it. Those colors are optionally displayed. % This is basically a "paint by numbers" scheme which reduces any color % to a single decimal number from 0 to 215. Thus greatly simplifying its % recognition and coding. % You can think of each color as a cublet arranged into a 6x6x6 master cube. % The principal diagonal of the cublet varies from black through gray to white. % Red is stronger to the east. Green is stronger to the north. Blue is stronger up. % The three remaining corners are strongest yellow, aqua, and magenta. % The code also shows how a self-building table lookup can avoid messy or cumbersome % math algorithms. % ===================================================================== % This code locks pdfmark commands out of a PostScript printer. /pdfmark where {pop}{userdict /pdfmark /cleartomark load put} ifelse /inches {72 mul} store /pagewide 8.0 inches store /pagehigh 6.2 inches store % code to custom trim to subject... /pdfmark where {pop}{userdict /pdfmark /cleartomark load put} ifelse [/CropBox [0 0 pagewide pagehigh] /PAGES pdfmark [ {Catalog} << /ViewerPreferences << /FitWindow true /CenterWindow true >> /PageLayout /SinglePage % no rolling /Pagemode /FullScreen % fullscreen if not on web /View [/XYZ null null 1 ] % force 100% >> /PUT pdfmark % ///////// (A) WEB FRIENDLY COLOR UTILITIES ///////////// % tintmat is a self-generating list of 216 triple color values /webtintmat [ 0 1 5 { /a exch store 0 1 5 { /b exch store 0 1 5 { 5 div b 5 div a 5 div }for } for } for ] def % setwebtint accepts a color number 0 to 215 and then % sets the PostScript color generator for later use... /setwebtint { abs cvi 216 cvi mod % restrict range webtintmat exch 3 mul 3 getinterval % get values from table aload pop setrgbcolor} def % and set them % The blocks are arranged as red to the right, green % up in order of increasing blue. % Some "pure color" sequences are % red: 0 1 2 3 4 5 % orange: 0 7 8 15 16 23 (sort of) % yellow: 0 7 14 21 28 35 % green: 0 6 12 18 24 30 % aqua: 0 42 84 126 168 210 % blue: 0 36 72 108 144 180 % magenta: 0 37 74 111 148 185 % purple 0 73 73 110 147 183 (sort of) % gray 0 43 86 129 172 215 % /////// (B) WEB FRIENDLY UTILITY DEMO ///////////// % This demo is activated by sending this entire file to % Acrobat Distiller. The routines in part (A) are required, % as are my Gonzo Utilities. % These are gotten from http://www.tinaja.com/psutils/gonzo.ps % Run my gonzo utilities (these are used in the demo only) % The following line needs modified per your gonzo location... % (C:\\Documents and Settings\\don\\Desktop\\gonzo\\gonzo.ps) run % use external gonzo (C:/Users/Don/Desktop/Ghost/gonzo.psl) run /cstretch 0 def /font1 /Arial-BoldMT [9 0 0 9 0 0 ] gonzofont /font2 /Revue 22 gonzofont /font3 /Revue 12 gonzofont font1 /util {gsave translate 0 0 mt 25 pu 25 pr 25 pd closepath curcolor bluval 36 mul add dup 5 string cvs exch setwebtint fill font1 currentcolor add add 1.5 gt {0 0 0 }{1 1 1} ifelse setcolor 12.5 exch 10 exch cc grestore}def /showwebcolors { gsave 0 0 translate /bluval 0 store showrg36 grestore gsave 175 0 translate /bluval 1 store showrg36 grestore gsave 350 0 translate /bluval 2 store showrg36 grestore gsave 0 175 translate /bluval 3 store showrg36 grestore gsave 175 175 translate /bluval 4 store showrg36 grestore gsave 350 175 translate /bluval 5 store showrg36 grestore } def /showrg36 { /curcolor 0 store 0 1 5 {/ver exch store 0 1 5 {28 mul ver 28 mul util /curcolor curcolor 1 add store } for } for } def 30 50 translate showwebcolors % these are excerpts from my url insertin utilities.. % This code locks pdfmark commands out of a PostScript printer. /pdfmark where {pop}{userdict /pdfmark /cleartomark load put} ifelse % /surl "start url" marks the beginning of a text sequence to be urled. % It also paints the text blue... /surl {mark /blue cvx 0.33 /setgray cvx % change text to blue /currentpoint cvx % remember box start /urly /exch cvx /store cvx /urlx /exch cvx /store cvx ] cvx % complete deferred command printlist exch 3 index exch put % stuff into gonzo printlist exch 1 add exch % increment gonzo list count } def % /eurl "end url" unmarks the end of a text sequence and sets up % the pdfmark needed to define the Acrobat web link. /eurl {mark % start deferred proc exch % position url string /aqua cvx 0 /setgray cvx % turn blue marker off /makeurl cvx % defer call of url builder ] cvx % complete deferred proc printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch % increment gonzo list count } def % /makeurl generates the pdfmark, receiving a {(urlstring) makeurl}. % Note that it is not called until formatted printlist time... /urlover 0.2 def % fraction of hot area over bounds /makeurl { /cururlname exch store % save the url string mark % start pdfmark currentfont /ScaleMatrix get 3 get /fsize exch store % guess height /Rect [ urlx fsize urlover mul sub % set box left x urly fsize urlover mul sub % set box left y currentpoint exch fsize urlover mul add exch fsize add ] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def /webtint {(http://www.tinaja.com/psutils/webcolor.psl)eurl} def font2 255 362 ("Web Friendly" PostScript Colors) cc font3 255 -27 (See |/surl http://www.tinaja.com/psutils/webcolor.psl|/webtint \ for sourcecode & use details.) cc showpage %%%%%%%%%%%%%%%% % Note that the color number 0-215 is red*5 + green*30 + blue*180 % It is based on permissible RGB hex web colors being $00, $33, $66, $99, $CC, or $FF. % blue value = colornumber 36 idiv 5 div. % red/green residue = colornumber 36 mod. This should be a value from 0 to 35. % green value = red/green residue 6 idiv 5 div % red value = red/green/residude 6 mod 5 div. % color setting command is then R G B setrgbcolor. % This is done automatically by the colornum setwebtint above, using table lookup % instead of a math algorithm. %%%%%%%%%%%%%%%% %% EOF