Question

I'm seeing some weird behaviour in Ghostscript 9.06 and am wondering whether it's to do with my PS structure or something else.

We have an embedded font defined and then attempt to setup a form and use it as below. Underneath I also have some lines to put text directly on the page without using a form.

globaldict 
begin
true setglobal 
/frm_test <<
/FormType 1 /BBox [-842 -842 596 596] /Matrix [1 0 0 1 0 0] /PaintProc { pop
/ArialMT 7.0 selectfont
0 0 moveto
(Test text form) show
}   %endPaintProc
>> /Form defineresource pop
/form_test {/frm_test /Form findresource true setglobal execform false setglobal} bind def
%/form_test {/frm_test /Form findresource execform} bind def
false setglobal
end

gsave
10 820 translate
form_test
grestore

/ArialMT 7.0 selectfont
10 800 moveto
(Test text normal) show
showpage

The problem here is that the call to form_test trashes the font definition for both cases - Ghostscript cannot find the named font. If I never call form_test then the second case works.

If I swap the /form_test line with the commented out one below it, then it works fine. However what is this line doing? It appears to be forcing the form to operate within the global VM region but I'm not sure why this matters, and why any errors propagate to the following 'selectfont' if they occur.

Why can Acrobat Distiller deal with this - is it correct Postscript or not? Thanks.

Edit: Apparently changing the surrounding commands to save/restore instead of gsave/grestore prevents the problem from impacting the second text, but this doesn't explain why the font is unknown within the Form. Also I believe gsave/grestore should be sufficient as the form should have no side-effect except on the graphics state.

Was it helpful?

Solution

ArailMT is almost certainly not a 'font' its a TrueType font, unless you have embedded a type 42 definition earlier, its always hard to tell from a fragment of a PostScript program.

Why on earth are you doing everything in global VM ? And using globaldict too ? These are both very bad practices, anything in global VM will not be subject to save and restore, so it eats memory until the end of job.

Actually executing the form in a global VM context is even worse, since it will then store any resources defined in the course of the form in global VM. Since you call 'selectofnt' that will define the font resource, unless it is already present. Because you are running with global VM it will define the font in global VM instead of local VM thereby using up more memory.

The PostScript is 'correct', in the same sense that a C program can be lexically correct, but not do what you expect it to.

If you don't have a good reason to use global VM, then don't, is the simplest answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top