Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are on the right track in my opinion. PostScript <em>is</em> a programming language, so for general purposes you must use a PostScript interpreter to process it. Simply parsing the file, or any other similar approach, won't work in the general case (though it might for a simple file).</p> <p>The original object you have quoted appears likely to be a glyph description in a font, probably a type 3 font, probably produced by Fontographer, but that's just guessing. Note thats a <em>glyph</em> not a font, a font is a collection of glyphs.</p> <p>If I were doing this I would start by redefining the various PostScript operators. For example, if you redefine 'show' you can pick up the text as it is drawn (actually there are several kinds of show operator, you need to redefine them all). At the same time you can pick the font dictionary up, and you can arrange to output it to the file.</p> <p>For example you might start with:</p> <pre><code>%!PS % redefine.ps % /OutputFile (/out.txt) (w) file def /show { OutputFile exch writestring } bind def </code></pre> <p>Then run this command:</p> <pre><code>gswin32 redefine.ps input.ps </code></pre> <p>It will run <code>redefine.ps</code> which redefines the operators, then it will interpret <code>input.ps</code>. The redefined 'show' operator will write the string arguments to any 'show' operations to a file called <code>/out.txt</code>.</p> <p>Obviously you can extend this to the other show operators. You can also take copies of the font dictionaries and then emit them as required. There's a bit of programming involved but here's an outline:</p> <pre><code>%!PS % /OutputFile (/out.txt) (w) file def %% FontStore will be an array of font dictionaries /FontStore 1 array def /CheckFont { currentfont /FontName get %% Extract the name of the current font from the %% font dictionary true %% termination condition FontStore { %% forall is called for each member of the array /FontName get %% get font name from stored font dictionary 2 index %% copy the current font name from the stack eq %% See if they are the same { pop %% remove the 'false' condition false %% replace it with a 'true' exit %% and exit the loop } if } forall exch pop %% remove stored font name { %% make the array one bigger, copy the old array, add the current font dict. } if } def /show { CheckFont OutputFile exch writestring } bind def /showpage { %% Emit the fonts if required, potentially reorder the stored strings etc. } bind def </code></pre> <p>Now whenever we execute a 'show', we will check to see if the current font is already stored, and store it if not. At the end of the page (when showpage is executed) we can do other things, like emitting the stored font dictionaries as fonts and so on.</p> <p>One thing you will probably want to do is record the positions of the strings as they arrive at 'show', the currentpoint operator will give you the x.y position at the time show occurs. Instead of writing these to a file you may decide to store the string and its position in an array. In fact you might construct a dictionary with useful information:</p> <pre><code>/show { 5 dict %% make a dictionary begin %% start it (put it on the dict stack as the current dict) /String exch def %% put the string operand in the dict. currentpoint %% get the current location /Y exch def %% store in the dict /X exch def %% currentfont %% get current font dict /FontName get %% get FontName /Font exch def %% store name in dict currentfont %% copy current dict to operand stack end %% close dictionary and remove from dict stack %% %% In here, add the newly created dictionary to an array of dictionaries %% } bind def </code></pre> <p>Now when you get to 'showpage', you have an array of fonts, and an array of string fragments with their properties. You can emit the fonts, then write out appropriate font selection criteria and strings to 'show' the strings in your output PostScript file.</p> <p>There is much more you can do, you can capture the colour, you will need teh CTM so you can calculate the font point size you need and so on.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload