• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

problem caching EPS files with multiple forms

New Here ,
Oct 23, 2008 Oct 23, 2008

Copy link to clipboard

Copied

I'm attempting to use multiple forms for caching 1 or more EPS Files in a postscript document. I've followed Technical Note #5144 to the letter and use the "array of strings" method since I have to support Postscript level 2 printers. The arrays appear to be loaded with strings representing the EPS as expected.

If I use only a single form with 1 EPS it works great. I can execute the form anywhere on the page as many times as I want. If I add a 2nd form to the page it causes strange behavior. The 2nd form is drawn regardless of if I execute it or not. Even if I comment out ALL execform calls it still shows the 2nd form (the page should be blank).

I've boiled down the code to a faily simple example. I took out all the binary EPSF content for each form and instead have each form draw a circle.
If working write this postscript should be drawing a smiley face using 4 circles.
Should look something like this:
0 0
0
<> <--- This should show like a stretched out circle.

However, the mouth is actually drawn very small down in the lower left hand corner of the page. If you change the order of the forms definition then the mouth is drawn correctly but not the eyes and nose.
The forms as named EPSForm-Circle and EPSForm-Circle2

Here's the postscript
-------------------------------------
%!PS-Adobe-3.0
%%BoundingBox: 0 612 792 0
%%LanguageLevel: 2
%%Pages: 1
%%BeginProlog
%%BeginResource: procset forms_ops 1.0 0
userdict /forms_ops 10 dict dup begin put

/BeginEPSF { %def
userdict begin % Push userdict on dict stack
/b4_Inc_state save def % Save state for cleanup
/dict_count countdictstack def % Count objects on dict stack
/op_count count 1 sub def % Count objects on operand stack
/showpage { } def % Redefine showpage, { } = null proc
} bind def

/EndEPSF { %def
count op_count sub {pop} repeat % Clean up stacks
countdictstack dict_count sub {end} repeat
b4_Inc_state restore
end % userdict
} bind def

/buffer 16000 string def
/inputFile currentfile 0 (% $$EPS_EOD_Marker$$) /SubFileDecode filter def

/readdata { % array readdata --
1 { % put counter on stack
% stack: array counter
2 copy % stack: array counter array counter
inputFile buffer readstring % read contents of currentfile into buffer
% stack: array counter array counter string boolean
4 1 roll % put boolean indicating EOF lower on stack
16000 string copy % copy buffer string into new string
% stack: array counter boolean array counter newstring
put % put string into array
not {exit} if % if EOF has been reached, exit loop.
1 add % increment counter
} loop
% increment counter and place empty string in next position
1 add 2 copy () put pop
currentglobal true setglobal exch
0 1 array put % create an array for counter in global VM,
% so as not to be affected by save/restore calls in EPS file.
% place as first element of string array.
setglobal % restore previously set value
} bind def
currentdict readonly pop end
%%EndResource

%%EndProlog
%%BeginSetup

% set MaxFormItem to be equivalent to MaxFormCache
<< /MaxFormItem currentsystemparams /MaxFormCache get >> setuserparams

% make forms procset available
forms_ops begin
userdict begin

% setup 1st circle form resource
%%BeginResource: form EPSForm-Circle
/EPSForm-Circle
10 dict begin
/FormType 1 def
/BBox [0 0 100 100] def
/Matrix [1 0 0 1 0 0] def
/EPSArray 3 array def
/AcquisitionProc {
EPSArray dup 0 get dup 0 get
dup 3 1 roll
1 add 0 exch put
get
} bind def
/PaintProc {
TOPICS
Programming

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 23, 2008 Oct 23, 2008

Copy link to clipboard

Copied

The postscript was cut off on 1st post. Here is the remainder:
---------------
begin
BeginEPSF
EPSArray 0 get 0 1 put
//AcquisitionProc 0 () /SubFileDecode filter
cvx exec
EndEPSF
end
} bind def
currentdict end def % EPSForm-Circle
EPSForm-Circle /EPSArray get
readdata
%%BeginDocument: (Circle.eps)
50 50 3 0 360 arc closepath stroke
%%EndDocument
% $$EPS_EOD_Marker$$
%%EndResource

% setup 2nd circle form resource
%%BeginResource: form EPSForm-Circle2
/EPSForm-Circle2
10 dict begin
/FormType 1 def
/BBox [0 0 100 100] def
/Matrix [1 0 0 1 0 0] def
/EPSArray 3 array def
/AcquisitionProc {
EPSArray dup 0 get dup 0 get
dup 3 1 roll
1 add 0 exch put
get
} bind def
/PaintProc {
begin
BeginEPSF
EPSArray 0 get 0 1 put
//AcquisitionProc 0 () /SubFileDecode filter
cvx exec
EndEPSF
end
} bind def
currentdict end def % EPSForm-Circle2
EPSForm-Circle2 /EPSArray get
readdata
%%BeginDocument: (Circle2.eps)
50 50 3 0 360 arc closepath stroke
%%EndDocument
% $$EPS_EOD_Marker$$
%%EndResource

%%EndSetup
%%Page: 1 1

%%BeginPageSetup
/pgsave save def
%%EndPageSetup

% Draw left eyeball using Circle form
gsave
-350 100 translate
10.0 10.0 scale
EPSForm-Circle execform
grestore

% Draw right eyeball using Circle form
gsave
-100 100 translate
10.0 10.0 scale
EPSForm-Circle execform
grestore

% Draw nose using Circle form
gsave
-225 -500 translate
10.0 20.0 scale
EPSForm-Circle execform
grestore

% Draw mouth using Circle 2 form.
gsave
-720 -200 translate
20.0 10.0 scale
EPSForm-Circle2 execform
grestore

showpage
/pgsave load restore
%%PageTrailer

end % userdict
end % forms_ops
%%EOF

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2008 Oct 27, 2008

Copy link to clipboard

Copied

I found the problem.

The filter is automatically closed at the end of /readdata the 1st time you execute it.
If you call readdata again (with a second EPS file) it returns NULL and executes the postscript bytes in the 2nd EPS file instead of reading them into the string buffer.

The solution involves moving the define of the filter inside of the /readdata procedure.

OLD CODE:
-----------------------------------------
/buffer 16000 string def
/inputFile currentfile 0 (% $$EPS_EOD_Marker$$) /SubFileDecode filter def

/readdata { % array readdata --
1 { % put counter on stack
---------------------------------------------

FIXED CODE:
-----------------------------------------
/buffer 16000 string def

/readdata { % array readdata --
/inputFile currentfile 0 (% $$EPS_EOD_Marker$$) /SubFileDecode filter def

1 { % put counter on stack
---------------------------------------------

Looks like Technical Note #5144 could use a little updating!

I found this bug using the Postscript debugger PSAlter
The tool is a few years old but it works great!!

Mike M.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

LATEST
That's Aandi's child. Is it still PC only?

Miklos

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines