0

I am working on a unix machine. and I have a list of names in .eps file format. I know I can easily grep show lines to extract my names but they're not in the same order as in the figure. is there a way to extract names from the figure while preserving the order?

example:

    /ArialMT-ISOLatin1 findfont
    32 scalefont
    setfont
    0 0 0 setrgbcolor
    newpath
    0 0 moveto
    (King James) show
    grestore
    grestore
    grestore
    0 0 0 setrgbcolor
    [] 0 setdash
    5 setlinewidth
    0 setlinejoin
    1 setlinecap
    newpath
    -1013.087 5437.645 moveto
    -574.44269 5148.3467 lineto
    stroke
    0 0 0 setrgbcolor
    [] 0 setdash
    5 setlinewidth
    0 setlinejoin
    1 setlinecap
    newpath
    -801.10602 5042.689 moveto
    -683.66547 4973.3872 lineto
    stroke
    0 0 0 setrgbcolor
    [] 0 setdash
    5 setlinewidth
    0 setlinejoin
    0 setlinecap
    newpath
    -764.50114 5103.5574 moveto
    -789.24211 5063.1816 -813.3093 5022.3968 -836.69272 4981.22 curveto
    stroke
    gsave [0.8480481 -0.52991926 0.52991926 0.8480481 -3204.0386 27.010243]
    concat
    gsave [1 0 0 -1 -1554.9214 5600.4102] concat
    gsave
    /ArialMT-ISOLatin1 findfont
    32 scalefont
    setfont
    0 0 0 setrgbcolor
    newpath
    0 0 moveto
    (M. L. King) show
    ...

M.L.King should go before King James but could I do this by exploiting the coordinate system?

thnx

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

1 Answers1

0

First, I wanted to suggest to keep track of movements ie where the PostScript interpreter is putting the text, but that can be tricky since postscript is a fully fledged programming language. Another approach is to annotate your .eps files:

  1. open a file with the 'open' command
  2. for every show

    a. get the current coordianates by 'currentpoint'. this leaves the coordinates on the stack

    b. 'write' those two values into your file (as a .csv perhaps?) and the text which is going to be shown

  3. close the file with 'closefile'

Run your annotated .eps file through a PS interpreter. Sort the generated file on the coordinates with the Unix 'sort' command, don't forget the -n option for both keys (ie y coordinate and x coordinate). And you are done.

user1666959
  • 1,805
  • 12
  • 11