Ghostscript postscript pswrite is the encoding text

Why is Ghostscript pswrite encode my text in its output? Consider the following MWE:

%!PS-Adobe-3.0 
%%Title: mwe.ps
%%Pages: 001
%%BoundingBox: 0 0 595 842
%%EndComments

%%Page: 1 1
%%PageBoundingBox: 0 0 595 842
0 0 1 setrgbcolor
0 0 595 842 rectfill
1 0 0 setrgbcolor
247 371 100 100 rectfill
/Times-Roman findfont
72 scalefont
setfont
newpath
247 300 moveto
(Chris) show
showpage

      

Saving this MWE file and viewing it in GSview will display a blue page with a red square and my name at the bottom. Now run this file through Ghostscript 9.06 with the following command line:

"c:\Program Files\gs\gs9.06\bin\gswin64c.exe" ^
  -dSAFER -dBATCH -dNOPAUSE ^
  -sDEVICE=pswrite -sPAPERSIZE=a4 -r72 -sOutputFile=mwe_gs.ps mwe.ps

      

See the Ghostscript output below. Can someone please explain what is going on here. Although the two direct fill commands are still obvious, my text (Chris) was encoded and is no longer distinguishable.

Is there an alternative postscript device that will save my text?

<snip>
%%Page: 1 1
%%PageBoundingBox: 0 0 595 842
%%BeginPageSetup
GS_pswrite_2_0_1001 begin
595 842 /a4 setpagesize
/pagesave save store 197 dict begin
1 1 scale
%%EndPageSetup
gsave mark
255 0 r6
0 0 595 842 rf
255 0 r3
247 371 100 100 rf
Q q
0 0 595 0 0 842 ^ Y
255 0 r3
249 299 43 50 /5D
$C
,6CW56m1G"ZORNkWR*rB:!c2;9rlWTH="2^^[(q"h>cG<omZ2l^=qC[XbO:8_[?kji-8^"N#3q*
jhL~>
,
289 300 41 49 /0P
$C
4r?0p$m<EkK3,0>s8W-!s8W-!s8W,u]<1irI=*p=<t0>_@<)>Is8K6,aTi'$~>
,
325 300 30 33 /5I
$C
49S"pc4+Rhs8W-!s8W)oqdD:saRZq[4+k%):]~>
,
349 300 24 49 /0T
$C
4q%Ms%;PqCs8W-!s8W%1_qkn/K?*sYFSGd:5Q~>
,
377 299 23 34 /5M
$C
-TQR7$&O'!K+D:XribR9;$mr4#sqUi.T@,dX=Y&Llg+F`d^HC#%$"]~>
,
cleartomark end end pagesave restore
 showpage
%%PageTrailer
%%Trailer
%%Pages: 1
%%EOF

      

NOTE. It may sound strange, but I am researching the idea of ​​using Ghostscript to "clear" postscript from a Matlab application.

+1


source to share


3 answers


"Text" has been converted to images, not vector paths. This is a serious limitation of the pswrite device, and one of the reasons it is deprecated, you must use the ps2write device. The only reason the pswrite device is still enabled is to use epswrite, which uses it (which is why the output of pswrite and epswrite looks the same). At some point the eps2write device will appear and pswrite will be encoded.

ps2write's output is compressed by default. If you need uncompressed output, use the -dCompressPages = false switch on the command line.



If all you want is the location of the text, you might want to consider the txtwrite device. By default, the implementation creates a textual representation of the input, but you can make it output fake XML instead, which includes things like the origin of the text.

+6


source


Here is a simple example of overriding a show statement to display information about the location of a show, as well as performing a standard show operation. With ghostscript you can run multiple files, so the header file will be a prefix for another file that changes the default behavior.

A revised show could include a name and font size. The data could be written to a disk file rather than dumped to the console. Any other operator can also be overridden, like hide, fill, hit ... Since the original operator is also called, you can convert the .ps to .pdf using the pdfwrite device and get the location information at the same time.

gswin32c.exe -dBATCH -dNOPAUSE  header.ps trash.ps
gswin32c.exe -sDEVICE=pdfwrite -dCompressPages=false -sOutputFile=test.pdf header.ps trash.ps

      

Output

currentpoint  x:247.0 y:300.0  pathbbox 249.015,298.992 400.066,349.184   text:Chris  currentrgbcolor:1.0,0.0,0.0( )
currentpoint  x:50.0 y:90.0  pathbbox 50.8682,89.2852 181.327,139.184   text:Fred  currentrgbcolor:1.0,0.0,0.0( )
currentpoint  x:150.0 y:200.0  pathbbox 150.867,184.298 304.154,247.673   text:Mary  currentrgbcolor:1.0,0.0,0.0( )
currentpoint  x:300.0 y:350.0  pathbbox 300.867,348.993 598.79,398.681   text:Mr. Green  currentrgbcolor:0.0,1.0,0.0( )
currentpoint  x:100.0 y:400.0  pathbbox 100.866,399.202 358.547,449.183   text:Mr. Blue  currentrgbcolor:0.0,0.0,1.0( )

      



Header.ps

/mydict 5 dict def
mydict begin
/show 
    {
    (currentpoint ) print 
    currentpoint exch 10 string cvs ( x:) print print  10 string cvs ( y:) print print
    gsave dup false charpath flattenpath 

    (  pathbbox ) print 
    pathbbox  
    4 -1 roll 10 string cvs print (,) print 
    3 -1 roll 10 string cvs print ( ) print 
    2 -1 roll 10 string cvs print (,) print 
    10 string cvs print ( ) print 
    grestore
    (  text:) 10 string cvs print   
    dup print ( ) print
    ( currentrgbcolor:) print 
    currentrgbcolor
    3 -1 roll 10 string cvs print (,) print
    2 -1 roll 10 string cvs print (,) print
    10 string cvs print ( ) ==
    systemdict /show get exec
} def

      

trash.ps

%!PS-Adobe-3.0 
%%Title: mwe.ps
%%Pages: 001
%%BoundingBox: 0 0 595 842
%%EndComments
%%Page: 1 1
%%PageBoundingBox: 0 0 595 842
0 0 1 setrgbcolor
0 0 595 842 rectfill
1 0 0 setrgbcolor
247 371 100 100 rectfill
/Times-Roman findfont
72 scalefont
setfont
newpath
247 300 moveto (Chris) show
50 90 moveto (Fred) show
150 200 moveto (Mary) show
0 1 0 setrgbcolor
300 350 moveto (Mr. Green) show
0 0 1 setrgbcolor
100 400 moveto (Mr. Blue) show
showpage

      

+1


source


The text has been converted to vector paths. 249 299 43 50 / 5D the first letter "C" begins, then 289 300 - "h", 289 300 - "r" ....

What pswrite did was eliminate the need for a font, so while your original code was using / Times-Roman, the distilled code doesn't need any font, but rather draws text using vectors.

I don't know exactly what you want, but you can try "ps2write" or "epswrite" as an alternative to "pswrite". pswrite is used to write to the ps level 1 standard, and ps2write will write the ps level 2 output. Nobody else requires ps 1, so level 2 would be acceptable. Epswit will write to encapsulated postscript (eps).

0


source







All Articles