diff options
Diffstat (limited to 'Build/source/utils/asymptote/runlabel.in')
-rw-r--r-- | Build/source/utils/asymptote/runlabel.in | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/Build/source/utils/asymptote/runlabel.in b/Build/source/utils/asymptote/runlabel.in index 961e2e9e65a..b4595741251 100644 --- a/Build/source/utils/asymptote/runlabel.in +++ b/Build/source/utils/asymptote/runlabel.in @@ -20,7 +20,7 @@ pen => primPen() #include "drawlabel.h" #include "locate.h" - using namespace camp; +using namespace camp; using namespace vm; using namespace settings; @@ -87,7 +87,7 @@ void showpath(std::ostream& ps) fillpath(ps); } -array *readpath(const string& psname, bool keep, +array *readpath(const string& psname, bool keep, bool pdf=false, double hscale=1.0, double vsign=1.0) { double vscale=vsign*hscale; @@ -111,15 +111,15 @@ array *readpath(const string& psname, bool keep, #else const string null="/dev/null"; #endif - cmd.push_back("-sDEVICE=epswrite"); + cmd.push_back("-sDEVICE=eps2write"); cmd.push_back("-sOutputFile="+null); cmd.push_back(stripDir(psname)); iopipestream gs(cmd,"gs","Ghostscript"); - while(true) { + while(gs.running()) { stringstream buf; string s=gs.readline(); - if(s.empty() || !gs.running()) break; - gs << newl; + if(s.empty()) break; + if(!pdf) gs << newl; // Workaround broken stringstream container in MacOS 10.9 libc++. #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__ ) @@ -259,7 +259,7 @@ patharray2 *_texpath(stringarray *s, penarray *p) string dviname=auxname(prefix,"dvi"); bbox b; string texengine=getSetting<string>("tex"); - bool pdf=settings::pdf(texengine); + bool xe=settings::xe(texengine); texfile tex(texname,b,true); tex.miniprologue(); @@ -274,7 +274,7 @@ patharray2 *_texpath(stringarray *s, penarray *p) else tex.verbatimline("\\newpage"); } - if(!pdf) { + if(!xe) { tex.verbatimline("\\special{ps:"); tex.verbatimline(ASYx); tex.verbatimline(ASYy); @@ -290,35 +290,48 @@ patharray2 *_texpath(stringarray *s, penarray *p) tex.epilogue(true); tex.close(); - int status=opentex(texname,prefix); + int status=opentex(texname,prefix,!xe); - string pdfname; + string pdfname,pdfname2,psname2; if(!status) { - if(pdf) { + if(xe) { pdfname=auxname(prefix,"pdf"); + pdfname2=auxname(prefix+"_","pdf"); + psname2=auxname(prefix+"_","ps"); if(!fs::exists(pdfname)) return new array(n); - std::ofstream ps(psname.c_str()); + std::ofstream ps(psname.c_str(),std::ios::binary); if(!ps) cannotwrite(psname); showpath(ps); - mem::vector<string> cmd; - cmd.push_back(getSetting<string>("gs")); - cmd.push_back("-q"); - cmd.push_back("-dNOCACHE"); - cmd.push_back("-dNOPAUSE"); - cmd.push_back("-dBATCH"); - if(safe) cmd.push_back("-dSAFER"); - cmd.push_back("-sDEVICE=epswrite"); - cmd.push_back("-sOutputFile=-"); - cmd.push_back(pdfname); - iopipestream gs(cmd,"gs","Ghostscript"); - while(true) { - string line=gs.readline(); - if(line.empty() || !gs.running()) break; - ps << line; + mem::vector<string> pcmd; + pcmd.push_back(getSetting<string>("gs")); + pcmd.push_back("-q"); + pcmd.push_back("-dNOCACHE"); + pcmd.push_back("-dNOPAUSE"); + pcmd.push_back("-dBATCH"); + if(safe) pcmd.push_back("-dSAFER"); + pcmd.push_back("-sDEVICE=pdfwrite"); + pcmd.push_back("-sOutputFile="+pdfname2); + pcmd.push_back(pdfname); + status=System(pcmd,0,true,"gs"); + if(status == 0) { + mem::vector<string> cmd; + cmd.push_back(getSetting<string>("gs")); + cmd.push_back("-q"); + cmd.push_back("-dNOCACHE"); + cmd.push_back("-dNOPAUSE"); + cmd.push_back("-dBATCH"); + if(safe) cmd.push_back("-dSAFER"); + cmd.push_back("-sDEVICE=eps2write"); + cmd.push_back("-sOutputFile="+psname2); + cmd.push_back(pdfname2); + status=System(cmd,0,true,"gs"); + + std::ifstream in(psname2.c_str(),std::ios::binary); + ps << in.rdbuf(); + ps.close(); } - ps.close(); } else { if(!fs::exists(dviname)) return new array(n); mem::vector<string> dcmd; @@ -343,9 +356,11 @@ patharray2 *_texpath(stringarray *s, penarray *p) if(!getSetting<bool>("keepaux")) unlink(auxname(prefix,"aux").c_str()); unlink(auxname(prefix,"log").c_str()); - if(pdf) + if(xe) { unlink(pdfname.c_str()); - else + unlink(pdfname2.c_str()); + unlink(psname2.c_str()); + } else unlink(dviname.c_str()); if(settings::context(texengine)) { unlink(auxname(prefix,"top").c_str()); @@ -353,7 +368,8 @@ patharray2 *_texpath(stringarray *s, penarray *p) unlink(auxname(prefix,"tui").c_str()); } } - return pdf ? readpath(psname,keep,0.1) : readpath(psname,keep,0.12,-1.0); + return xe ? readpath(psname,keep,true,0.1) : + readpath(psname,keep,false,0.12,-1.0); } patharray2 *textpath(stringarray *s, penarray *p) @@ -398,7 +414,7 @@ patharray2 *textpath(stringarray *s, penarray *p) cmd2.push_back("-dBATCH"); cmd2.push_back("-P"); if(safe) cmd2.push_back("-dSAFER"); - cmd2.push_back("-sDEVICE=epswrite"); + cmd2.push_back("-sDEVICE=eps2write"); cmd2.push_back("-sOutputFile=-"); cmd2.push_back("-"); iopipestream gs(cmd2,"gs","Ghostscript"); @@ -427,7 +443,7 @@ patharray2 *textpath(stringarray *s, penarray *p) bool keep=getSetting<bool>("keep"); if(!keep) // Delete temporary files. unlink(textname.c_str()); - return readpath(psname,keep,0.1); + return readpath(psname,keep,false,0.1); } patharray *_strokepath(path g, pen p=CURRENTPEN) |