diff options
Diffstat (limited to 'Build/source/utils/asymptote/runlabel.in')
-rw-r--r-- | Build/source/utils/asymptote/runlabel.in | 120 |
1 files changed, 50 insertions, 70 deletions
diff --git a/Build/source/utils/asymptote/runlabel.in b/Build/source/utils/asymptote/runlabel.in index 9503a0b0ee8..632f68df551 100644 --- a/Build/source/utils/asymptote/runlabel.in +++ b/Build/source/utils/asymptote/runlabel.in @@ -11,10 +11,10 @@ pen => primPen() picture* => primPicture() transform => primTransform() realarray* => realArray() - stringarray* => stringArray() - penarray* => penArray() - patharray* => pathArray() - patharray2* => pathArray2() + stringarray* => stringArray() + penarray* => penArray() + patharray* => pathArray() + patharray2* => pathArray2() #include "picture.h" #include "drawlabel.h" @@ -36,14 +36,14 @@ using types::penArray; using types::pathArray; using types::pathArray2; -void cannotread(const string& s) +void cannotread(const string& s) { ostringstream buf; buf << "Cannot read from " << s; error(buf); } -void cannotwrite(const string& s) +void cannotwrite(const string& s) { ostringstream buf; buf << "Cannot write to " << s; @@ -65,7 +65,7 @@ string currentpoint="print currentpoint ASYy ASYx "; string ASYinit="/ASYX currentpoint pop def /ASYY currentpoint exch pop def "; string ASY1="ASY1 {"+ASYinit+"/ASY1 false def} if "; -void endpath(std::ostream& ps) +void endpath(std::ostream& ps) { ps << ASY1 << pathforall << " (M) " << currentpoint << "currentpoint newpath moveto} bind def" << endl; @@ -77,7 +77,7 @@ void fillpath(std::ostream& ps) endpath(ps); } -void showpath(std::ostream& ps) +void showpath(std::ostream& ps) { ps << ASYx << newl << ASYy << newl @@ -87,7 +87,7 @@ void showpath(std::ostream& ps) fillpath(ps); } -array *readpath(const string& psname, bool keep, bool pdf=false, +array *readpath(const string& psname, bool keep, double hscale=1.0, double vsign=1.0) { double vscale=vsign*hscale; @@ -111,8 +111,8 @@ array *readpath(const string& psname, bool keep, bool pdf=false, #else const string null="/dev/null"; #endif - string epsdriver=getSetting<string>("epsdriver"); - cmd.push_back("-sDEVICE="+epsdriver); + string psdriver=getSetting<string>("psdriver"); + cmd.push_back("-sDEVICE="+psdriver); cmd.push_back("-sOutputFile="+null); cmd.push_back(stripDir(psname)); iopipestream gs(cmd,"gs","Ghostscript"); @@ -120,27 +120,27 @@ array *readpath(const string& psname, bool keep, bool pdf=false, stringstream buf; string s=gs.readline(); if(s.empty()) break; - if(!pdf) gs << newl; + gs << newl; -// Workaround broken stringstream container in MacOS 10.9 libc++. -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__ ) +// Workaround broken stringstream container in libc++. +#ifdef _LIBCPP_VERSION for(string::iterator i=s.begin(); i != s.end(); ++i) { if(isalpha(*i) && *i != 'e') {buf << " ";} buf << *i; } -#else +#else buf << s; #endif - + if(verbose > 2) cout << endl; - + mem::vector<solvedKnot> nodes; solvedKnot node; bool active=false; - + array *P=new array(0); PP->push(P); - + while(!buf.eof()) { char c; buf >> c; @@ -199,10 +199,10 @@ array *readpath(const string& psname, bool keep, bool pdf=false, } } } - + if(oldPath != NULL) setPath(oldPath); - + if(!keep) unlink(psname.c_str()); return PP; @@ -226,13 +226,13 @@ realarray *texsize(string *s, pen p=CURRENTPEN) { texinit(); processDataStruct &pd=processData(); - + string texengine=getSetting<string>("tex"); setpen(pd.tex,texengine,p); - + double width,height,depth; texbounds(width,height,depth,pd.tex,*s); - + array *t=new array(3); (*t)[0]=width; (*t)[1]=height; @@ -244,7 +244,7 @@ patharray2 *_texpath(stringarray *s, penarray *p) { size_t n=checkArrays(s,p); if(n == 0) return new array(0); - + string prefix=cleanpath(outname()); string psname=auxname(prefix,"ps"); string texname=auxname(prefix,"tex"); @@ -252,10 +252,10 @@ patharray2 *_texpath(stringarray *s, penarray *p) bbox b; string texengine=getSetting<string>("tex"); bool xe=settings::xe(texengine) || settings::lua(texengine) || - settings::context(texengine); + settings::context(texengine); texfile tex(texname,b,true); tex.miniprologue(); - + for(size_t i=0; i < n; ++i) { tex.setfont(read<pen>(p,i)); if(i != 0) { @@ -279,29 +279,25 @@ patharray2 *_texpath(stringarray *s, penarray *p) } tex.verbatimline(read<string>(s,i)+"\\ %"); } - + tex.epilogue(true); tex.close(); - + int status=opentex(texname,prefix,!xe); - + string pdfname,pdfname2,psname2; bool keep=getSetting<bool>("keep"); - - bool legacygs=false; + if(!status) { if(xe) { -// Use legacy ghostscript driver for gs-9.13 and earlier. - string epsdriver=getSetting<string>("epsdriver"); - legacygs=epsdriver == "epswrite"; - + string psdriver=getSetting<string>("psdriver"); 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::ios::binary); if(!ps) cannotwrite(psname); - + showpath(ps); mem::vector<string> pcmd; @@ -323,28 +319,13 @@ patharray2 *_texpath(stringarray *s, penarray *p) cmd.push_back("-dNOPAUSE"); cmd.push_back("-dBATCH"); if(safe) cmd.push_back("-dSAFER"); - cmd.push_back("-sDEVICE="+epsdriver); - // Work around eps2write bug that forces all postscript to first page. - cmd.push_back("-sOutputFile="+psname2+(legacygs ? "" : "%d")); + cmd.push_back("-sDEVICE="+psdriver); + cmd.push_back("-sOutputFile="+psname2); cmd.push_back(pdfname2); status=System(cmd,0,true,"gs"); - if(legacygs) { - std::ifstream in(psname2.c_str()); - ps << in.rdbuf(); - } else { - for(unsigned int i=1; i <= n ; ++i) { - ostringstream buf; - buf << psname2 << i; - const string& s=buf.str(); - const char *name=s.c_str(); - std::ifstream in(name,std::ios::binary); - ps << in.rdbuf(); - ps << "(>\n) print flush\n"; - in.close(); - if(!keep) unlink(name); - } - } + std::ifstream in(psname2.c_str()); + ps << in.rdbuf(); ps.close(); } } else { @@ -362,7 +343,7 @@ patharray2 *_texpath(stringarray *s, penarray *p) } } else error("texpath failed"); - + if(!keep) { // Delete temporary files. unlink(texname.c_str()); if(!getSetting<bool>("keepaux")) @@ -380,21 +361,20 @@ patharray2 *_texpath(stringarray *s, penarray *p) unlink(auxname(prefix,"tui").c_str()); } } - return xe ? readpath(psname,keep,!legacygs,0.1) : - readpath(psname,keep,false,0.12,-1.0); + return xe ? readpath(psname,keep,0.1) : readpath(psname,keep,0.12,-1.0); } patharray2 *textpath(stringarray *s, penarray *p) { size_t n=checkArrays(s,p); if(n == 0) return new array(0); - + string prefix=cleanpath(outname()); string outputname=auxname(prefix,getSetting<string>("textoutformat")); string textname=auxname(prefix,getSetting<string>("textextension")); std::ofstream text(textname.c_str()); - + if(!text) cannotwrite(textname); for(size_t i=0; i < n; ++i) { @@ -404,20 +384,20 @@ patharray2 *textpath(stringarray *s, penarray *p) << getSetting<string>("textepilogue") << endl; } text.close(); - + string psname=auxname(prefix,"ps"); std::ofstream ps(psname.c_str()); if(!ps) cannotwrite(psname); showpath(ps); - + mem::vector<string> cmd; cmd.push_back(getSetting<string>("textcommand")); push_split(cmd,getSetting<string>("textcommandOptions")); cmd.push_back(textname); iopipestream typesetter(cmd); typesetter.block(true,false); - + mem::vector<string> cmd2; cmd2.push_back(getSetting<string>("gs")); cmd2.push_back("-q"); @@ -426,7 +406,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="+getSetting<string>("epsdriver")); + cmd2.push_back("-sDEVICE="+getSetting<string>("psdriver")); cmd2.push_back("-sOutputFile=-"); cmd2.push_back("-"); iopipestream gs(cmd2,"gs","Ghostscript"); @@ -442,27 +422,27 @@ patharray2 *textpath(stringarray *s, penarray *p) typesetter.pipeclose(); gs.eof(); } - } + } string out2; gs >> out2; if(out2.empty() && !gs.running()) break; ps << out2; } ps.close(); - + if(verbose > 2) cout << endl; - + bool keep=getSetting<bool>("keep"); if(!keep) // Delete temporary files. unlink(textname.c_str()); - return readpath(psname,keep,false,0.1); + return readpath(psname,keep,0.1); } patharray *_strokepath(path g, pen p=CURRENTPEN) { array *P=new array(0); if(g.size() == 0) return P; - + string prefix=cleanpath(outname()); string psname=auxname(prefix,"ps"); bbox b; |