#!/usr/bin/perl -w # Copyright 2001, Felix Ritter (Felix.Ritter@gmx.de) # # Original script (color mode) Copyright 2000, # Andreas Widmann (widmann@rz.uni-leipzig.de) # # This script is free software; permission to use, copy, modify, and # distribute this software and its documentation for any purpose without # fee is hereby granted, provided that both the above copyright notice # and this permission notice appear in all copies and in supporting # documentation. # # This software is provided "as is" without express or implied warranty # of any kind. #introstuff sub usage_info() { print "gnuplot-boxfill.pl\n"; print " fills (and outlines) boxes in gnuplot 3.7.1 postscript files\n"; print "usage:\n"; print " gnuplot-boxfill.pl [-c | -g | -p] [-o] [-r] [-z] \n"; print "options:\n"; print " -c color fill (default)\n"; print " -g gray fill\n"; print " -p pattern fill\n"; print " -o draw outline\n"; print " -r remove \"currentpoint stroke M\" (experimental!)\n"; print " -z outline zero height boxes (experimental!)\n"; print "arguments:\n"; print " postscript input file\n"; print " postscript output file\n"; } if ($#ARGV < 1) { &usage_info(); exit(0); } $prolog = '/graymode true def /BfDict 400 dict def /dpiranges [ 2540 2400 1693 1270 1200 635 600 0 ] def /PatFreq [ 10.5833 10.0 9.4055 10.5833 10.0 10.5833 10.0 9.375 ] def /dpi 72 0 matrix defaultmatrix dtransform dup mul exch dup mul add sqrt def /screenIndex { 0 1 dpiranges length 1 sub { dup dpiranges exch get 1 sub dpi le {exit} {pop} ifelse } for } bind def /CurColors [ 0 0 0 1 0 0 0 1] def /RealSetgray /setgray load def /RealSetrgbcolor /setrgbcolor load def /RealSetcmykcolor { 4 1 roll 3 { 3 index add 0 max 1 min 1 exch sub 3 1 roll} repeat RealSetrgbcolor pop } bind def /tintCMYK { 1 tintGray sub CurColors 0 4 getinterval aload pop 4 index mul 5 1 roll 3 index mul 5 1 roll 2 index mul 5 1 roll mul 4 1 roll }bind def /tintRGB { 1 tintGray sub CurColors 4 3 getinterval aload pop 1 exch sub 3 index mul 1 exch sub 4 1 roll 1 exch sub 2 index mul 1 exch sub 4 1 roll 1 exch sub mul 1 exch sub 3 1 roll }bind def /combineColor { /tintGray 1 1 CurGray sub CurColors 7 get mul sub def graymode not { [/Pattern [/DeviceCMYK]] setcolorspace tintCMYK CurPat setcolor } { CurColors 3 get 1.0 ge { tintGray RealSetgray } { graymode { tintCMYK RealSetcmykcolor } { tintRGB RealSetrgbcolor } ifelse } ifelse } ifelse } bind def /patProcDict 5 dict dup begin <0f1e3c78f0e1c387> { 3 setlinewidth -1 -1 moveto 9 9 lineto stroke 4 -4 moveto 12 4 lineto stroke -4 4 moveto 4 12 lineto stroke} bind def <0f87c3e1f0783c1e> { 3 setlinewidth -1 9 moveto 9 -1 lineto stroke -4 4 moveto 4 -4 lineto stroke 4 12 moveto 12 4 lineto stroke} bind def <8142241818244281> { 1 setlinewidth -1 9 moveto 9 -1 lineto stroke -1 -1 moveto 9 9 lineto stroke } bind def <03060c183060c081> { 1 setlinewidth -1 -1 moveto 9 9 lineto stroke 4 -4 moveto 12 4 lineto stroke -4 4 moveto 4 12 lineto stroke} bind def <8040201008040201> { 1 setlinewidth -1 9 moveto 9 -1 lineto stroke -4 4 moveto 4 -4 lineto stroke 4 12 moveto 12 4 lineto stroke} bind def end def /patDict 15 dict dup begin /PatternType 1 def /PaintType 2 def /TilingType 3 def /BBox [ 0 0 8 8 ] def /XStep 8 def /YStep 8 def /PaintProc { begin patProcDict bstring known { patProcDict bstring get exec } { 8 8 true [1 0 0 -1 0 8] bstring imagemask } ifelse end } bind def end def /setPatternMode { pop pop dup patCache exch known { patCache exch get } { dup patDict /bstring 3 -1 roll put patDict 65 PatFreq screenIndex get div dup matrix scale makepattern dup patCache 4 -1 roll 3 -1 roll put } ifelse /CurGray 0 def /CurPat exch def /graymode false def combineColor } bind def /setGrayScaleMode { graymode not { /graymode true def } if /CurGray exch def combineColor } bind def BfDict begin [ /fillvals ] { 0 def } forall /SetPattern { fillvals exch get dup type /stringtype eq {8 1 setPatternMode} {setGrayScaleMode} ifelse } bind def /InitPattern { BfDict begin dup array /fillvals exch def dict /patCache exch def end } def /DefPattern { BfDict begin fillvals 3 1 roll put end } def 7 InitPattern 0 <03060c183060c081> DefPattern 1 <8040201008040201> DefPattern 2 <0f1e3c78f0e1c387> DefPattern 3 <0f87c3e1f0783c1e> DefPattern 4 <8142241818244281> DefPattern 5 <111111ff111111ff> DefPattern 6 0 DefPattern'; $outlinestyle = 'LTb'; if(grep(/^-o$/, @ARGV) == 1) { $outline = "\ngsave\ncurrentpoint $outlinestyle M redo stroke\ngrestore" } else { $outline = '' } #read input file open(IN, $ARGV[$#ARGV - 1]) || die "Cannot open $ARGV[$#ARGV - 1]\n"; $content = join('', ); close(IN); #search patterns $key = '(-*\d+ -*\d+ M\n)(-*\d+)( -*\d+ V\n)(-*\d+ -*\d+ [RM]\n-*\d+ -*\d+ V\n-*\d+ -*\d+ V\n-*\d+ -*\d+ V\n-*\d+ -*\d+ V\n)'; #$key = '(-*\d+ -*\d+ M\n)(-*\d+)( -*\d+ V\n)(-*\d+ -*\d+ [RM]\n-*\d+ -*\d+ V\n-*\d+ -*\d+ V\n)'; #experimental $box = '(?$ARGV[$#ARGV]") || die "Cannot open $ARGV[$#ARGV]\n"; print OUT "$content"; close(OUT);