Ghostscript - using a font in a form makes it unavailable

我与影子孤独终老i 提交于 2019-12-12 01:28:19

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18477930/ghostscript-using-a-font-in-a-form-makes-it-unavailable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!