@@ -1654,55 +1654,48 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
1654
1654
bbox_info , rotate = None , None
1655
1655
1656
1656
epsfile = tmpfile + '.eps'
1657
- with io .open (epsfile , 'wb' ) as epsh :
1657
+ with io .open (epsfile , 'wb' ) as epsh , io . open ( tmpfile , 'rb' ) as tmph :
1658
1658
write = epsh .write
1659
- with io .open (tmpfile , 'rb' ) as tmph :
1660
- line = tmph .readline ()
1661
- # Modify the header:
1662
- while line :
1663
- if line .startswith (b'%!PS' ):
1664
- write (b"%!PS-Adobe-3.0 EPSF-3.0\n " )
1665
- if bbox :
1666
- write (bbox_info .encode ('ascii' ) + b'\n ' )
1667
- elif line .startswith (b'%%EndComments' ):
1668
- write (line )
1669
- write (b'%%BeginProlog\n ' )
1670
- write (b'save\n ' )
1671
- write (b'countdictstack\n ' )
1672
- write (b'mark\n ' )
1673
- write (b'newpath\n ' )
1674
- write (b'/showpage {} def\n ' )
1675
- write (b'/setpagedevice {pop} def\n ' )
1676
- write (b'%%EndProlog\n ' )
1677
- write (b'%%Page 1 1\n ' )
1678
- if rotate :
1679
- write (rotate .encode ('ascii' ) + b'\n ' )
1680
- break
1681
- elif bbox and (line .startswith (b'%%Bound' ) \
1682
- or line .startswith (b'%%HiResBound' ) \
1683
- or line .startswith (b'%%DocumentMedia' ) \
1684
- or line .startswith (b'%%Pages' )):
1685
- pass
1686
- else :
1687
- write (line )
1688
- line = tmph .readline ()
1689
- # Now rewrite the rest of the file, and modify the trailer.
1690
- # This is done in a second loop such that the header of the embedded
1691
- # eps file is not modified.
1692
- line = tmph .readline ()
1693
- while line :
1694
- if line .startswith (b'%%EOF' ):
1695
- write (b'cleartomark\n ' )
1696
- write (b'countdictstack\n ' )
1697
- write (b'exch sub { end } repeat\n ' )
1698
- write (b'restore\n ' )
1699
- write (b'showpage\n ' )
1700
- write (b'%%EOF\n ' )
1701
- elif line .startswith (b'%%PageBoundingBox' ):
1702
- pass
1703
- else :
1704
- write (line )
1705
- line = tmph .readline ()
1659
+ # Modify the header:
1660
+ for line in tmph :
1661
+ if line .startswith (b'%!PS' ):
1662
+ write (b"%!PS-Adobe-3.0 EPSF-3.0\n " )
1663
+ if bbox :
1664
+ write (bbox_info .encode ('ascii' ) + b'\n ' )
1665
+ elif line .startswith (b'%%EndComments' ):
1666
+ write (line )
1667
+ write (b'%%BeginProlog\n '
1668
+ b'save\n '
1669
+ b'countdictstack\n '
1670
+ b'mark\n '
1671
+ b'newpath\n '
1672
+ b'/showpage {} def\n '
1673
+ b'/setpagedevice {pop} def\n '
1674
+ b'%%EndProlog\n '
1675
+ b'%%Page 1 1\n ' )
1676
+ if rotate :
1677
+ write (rotate .encode ('ascii' ) + b'\n ' )
1678
+ break
1679
+ elif bbox and line .startswith ((b'%%Bound' , b'%%HiResBound' ,
1680
+ b'%%DocumentMedia' , b'%%Pages' )):
1681
+ pass
1682
+ else :
1683
+ write (line )
1684
+ # Now rewrite the rest of the file, and modify the trailer.
1685
+ # This is done in a second loop such that the header of the embedded
1686
+ # eps file is not modified.
1687
+ for line in tmph :
1688
+ if line .startswith (b'%%EOF' ):
1689
+ write (b'cleartomark\n '
1690
+ b'countdictstack\n '
1691
+ b'exch sub { end } repeat\n '
1692
+ b'restore\n '
1693
+ b'showpage\n '
1694
+ b'%%EOF\n ' )
1695
+ elif line .startswith (b'%%PageBoundingBox' ):
1696
+ pass
1697
+ else :
1698
+ write (line )
1706
1699
1707
1700
os .remove (tmpfile )
1708
1701
shutil .move (epsfile , tmpfile )
0 commit comments