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