I try to convert an postscript file such that individual, adjacent polygons (drawn by gnuplot's filledcurve mode) are converted to one single polygon. See also this related question:
To to so, I'm facing the following problem.
the polygons have such a structure in the ps-file
some statements
A1 A2 A3 A4 A5
B1 B2 B3 B4 B5
some statements
A1,A2.. etc are numbers. The processed file should then look like this (arbitrary example here)
some statements
A1 A2
B1 B2
B1+A2 B5-A4
B1+A2 B5-A5
B1 B2
A1 A2
some statements
Here, e.g. B1+A2 should be the result of the arithmetic operation, i.e. a float. How can one something like this in python? Somehow I need to scan the file, math certain lines and save them (i.e. the individual fields as in awk)?
EDIT:
a section from the original postscript file looks like this
5918 4703 N
399 0 V
0 70 V
-399 0 V
0 -70 V
Z stroke
LT0
630 399 N 0 -3498 586 131 0 3490 h
1216 522 N 0 -3525 1171 204 0 3498 h
2387 699 N 0 -3557 1171 134 0 3525 h
3558 801 N 0 -3587 1171 55 0 3557 h
4729 826 N 0 -3613 1171 -20 0 3587 h
5900 780 N 0 -3624 585 -43 0 3613 h
% End plot #1
1.000 UL
LTb
0.500 UL
LTa
0.13 0.13 0.13 C 630 280 M
5855 0 V
stroke
where N and h stand for
/N {newpath moveto} bind def
/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def
in this file we have 6 polygons, they are defined between the line "LT0" and "% end plot #1". The lines where polygons are defined are easy to match with regex
/^[0-9,-]+\ [0-9,-]+\ N\ [0-9]\ [0-9,-]+\ [0-9,-]+\ [0-9,-]+\ [0-9,-]+\ [0-9,-]+ h/
I'd like to convert them into something like
newpath
630 399 moveto
1216 522 lineto
2387 699 lineto
3558 801 lineto
4729 826 lineto
5900 780 lineto
.. .. ..
.. .. ..
The new polygon has therefore more lines of code as I'd like to define the absolute coordinates point by point. replacing single lines does not work.