diff options
author | Karl Berry <karl@freefriends.org> | 2009-05-18 23:33:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-05-18 23:33:08 +0000 |
commit | 0a3a4a0193ef03921995cac67f8c91c6e352d059 (patch) | |
tree | 4fd204ddd01ff808c75e91ce290a9b28a1e90696 /Build/source/utils/asymptote/runtime.in | |
parent | 7c769b8e95cd5bd87da30c618e5198d6d12461e1 (diff) |
asymptote 1.73
git-svn-id: svn://tug.org/texlive/trunk@13217 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/runtime.in')
-rw-r--r-- | Build/source/utils/asymptote/runtime.in | 152 |
1 files changed, 125 insertions, 27 deletions
diff --git a/Build/source/utils/asymptote/runtime.in b/Build/source/utils/asymptote/runtime.in index decee0727b1..f0136b0bfd9 100644 --- a/Build/source/utils/asymptote/runtime.in +++ b/Build/source/utils/asymptote/runtime.in @@ -61,6 +61,8 @@ stringarray* => stringArray() stringarray2* => stringArray2() #include <cfloat> +#include <iostream> +#include <fstream> #include <time.h> #include <sys/times.h> #include <locale.h> @@ -865,13 +867,15 @@ void unused(void *) { } -pair readpair(stringstream& s, bool tex) +static const double twelvepercent=0.12; +static const double tenpercent=0.1; + +pair readpair(stringstream& s, double hscale=1.0, double vscale=1.0) { - static const double f=12.0/100.0; double x,y; s >> y; s >> x; - return tex ? pair(f*x,-f*y) : pair(x,y); + return pair(hscale*x,vscale*y); } // Ignore unclosed begingroups but not spurious endgroups. @@ -887,7 +891,8 @@ string ASYo="/ASYo {( ) print 12 string cvs print} bind def"; string pathforall="{(M) print ASYo ASYo} {(L) print ASYo ASYo} {(C) print ASYo ASYo ASYo ASYo ASYo ASYo} {(c) print} pathforall"; string currentpoint="print currentpoint ASYo ASYo "; -array *readpath(const string& psname, bool tex, bool keep) +array *readpath(const string& psname, bool keep, + double hscale=1.0, double vscale=1.0) { array *P=new array(0); ostringstream pipe; @@ -895,9 +900,9 @@ array *readpath(const string& psname, bool tex, bool keep) << "' -q -dNOPAUSE -dBATCH"; if(safe) pipe << " -dSAFER"; #ifdef __CYGWIN__ - string null="NUL"; + const string null="NUL"; #else - string null="/dev/null"; + const string null="/dev/null"; #endif pipe << " -sDEVICE=epswrite -sOutputFile="+null+" '" << psname << "'"; iopipestream gs(pipe.str().c_str(),"gs","Ghostscript"); @@ -944,13 +949,13 @@ array *readpath(const string& psname, bool tex, bool keep) } active=false; cyclic=false; - node.pre=node.point=readpair(buf,tex)-offset; + node.pre=node.point=readpair(buf,hscale,vscale)-offset; node.straight=false; break; } case 'L': { - pair point=readpair(buf,tex)-offset; + pair point=readpair(buf,hscale,vscale)-offset; pair delta=(point-node.point)*third; node.post=node.point+delta; node.straight=true; @@ -962,9 +967,9 @@ array *readpath(const string& psname, bool tex, bool keep) } case 'C': { - pair point=readpair(buf,tex)-offset; - pair pre=readpair(buf,tex)-offset; - node.post=readpair(buf,tex)-offset; + pair point=readpair(buf,hscale,vscale)-offset; + pair pre=readpair(buf,hscale,vscale)-offset; + node.post=readpair(buf,hscale,vscale)-offset; node.straight=false; nodes.push_back(node); active=true; @@ -979,7 +984,7 @@ array *readpath(const string& psname, bool tex, bool keep) } case 'Z': { - offset=readpair(buf,tex); + offset=readpair(buf,hscale,vscale); break; } } @@ -1018,6 +1023,20 @@ pair gamma(pair z) return root2pi*pow(t,z+0.5)*exp(-t)*x; } +void cannotread(const string& s) +{ + ostringstream buf; + buf << "Cannot read from " << s << endl; + error(buf); +} + +void cannotwrite(const string& s) +{ + ostringstream buf; + buf << "Cannot write to " << s << endl; + error(buf); +} + // Autogenerated routines: @@ -1243,7 +1262,82 @@ patharray *_texpath(string *s, pen p=CURRENTPEN) unlink(auxname(prefix,"log").c_str()); unlink(dviname.c_str()); } - return readpath(psname,true,keep); + return readpath(psname,keep,twelvepercent,-twelvepercent); +} + +patharray *textpath(string *s, pen p=CURRENTPEN) +{ + array *P=new array(0); + if(s->empty()) return P; + + int status=0; + string prefix=outname(); + spaceToUnderscore(prefix); + string outputname=auxname(prefix,getSetting<string>("textoutputtype")); + + string textname=auxname(prefix,getSetting<string>("textextension")); + std::ofstream text(textname.c_str()); + + if(!text) cannotwrite(textname); + + text << getSetting<string>("textprologue"); + text << p.Font() << endl; + text << *s; + text << getSetting<string>("textepilogue"); + text.close(); + + ostringstream cmd; + string textcommand=getSetting<string>("textcommand"); + cmd << textcommand << " '" << textname << "' '" + << outputname << "'"; + bool quiet=verbose <= 2; + status=System(cmd,quiet ? 1 : 0); + + string epsname=auxname(prefix,"eps"); + + if(status == 0) { + ostringstream cmd; + cmd << "'" << getSetting<string>("gs") + << "' -q -dNOCACHE -dNOPAUSE -dBATCH"; + if(safe) cmd << " -dSAFER"; + cmd << " -sDEVICE=epswrite -sOutputFile='" << epsname << "' '" + << outputname << "'"; + status=System(cmd,0,true,"gs"); + } + + if(status != 0) + error("textpath failed"); + + string psname=auxname(prefix+"_","ps"); + std::ifstream eps(epsname.c_str()); + std::ofstream ps(psname.c_str()); + + if(!eps) cannotread(epsname); + if(!ps) cannotwrite(psname); + + ps << ASYo << endl + << "/ASY1 true def" << endl + << "/fill {ASY1 {(Z) " << currentpoint << "/ASY1 false def} if " + << pathforall << " (M) " << currentpoint + << "currentpoint newpath moveto } bind def" << endl + << "/stroke {ASY1 {(Z) " << currentpoint + << "/ASY1 false def} if strokepath " + << pathforall << " (M) " << currentpoint + << "currentpoint newpath moveto } bind def" << endl; + string line; + while(getline(eps,line)) + ps << line << endl; + ps << "(E) print" << endl; + eps.close(); + ps.close(); + + bool keep=getSetting<bool>("keep"); + if(!keep) { // Delete temporary files. + unlink(textname.c_str()); + unlink(outputname.c_str()); + unlink(epsname.c_str()); + } + return readpath(psname,keep,tenpercent,tenpercent); } patharray *_strokepath(path g, pen p=CURRENTPEN) @@ -1255,7 +1349,7 @@ patharray *_strokepath(path g, pen p=CURRENTPEN) spaceToUnderscore(prefix); string psname=auxname(prefix,"ps"); bbox b; - psfile ps(psname, false); + psfile ps(psname,false); ps.prologue(b); ps.verbatimline(ASYo); ps.verbatimline("/stroke {(Z) "+currentpoint+pathforall+"} bind def"); @@ -1267,7 +1361,7 @@ patharray *_strokepath(path g, pen p=CURRENTPEN) ps.verbatimline("(M) "+currentpoint+"(E) print"); ps.epilogue(); ps.close(); - return readpath(psname,false,getSetting<bool>("keep")); + return readpath(psname,getSetting<bool>("keep")); } void _draw(picture *f, path g, pen p) @@ -1551,18 +1645,18 @@ void shipout(string prefix=emptystring, picture *f, picture *preamble=NULL, void shipout3(string prefix, picture *f, string format=emptystring, real width, real height, real angle, triple m, triple M, - realarray2 *t, triplearray *lights, realarray2 *diffuse, - realarray2 *ambient, realarray2 *specular, bool viewportlighting, - bool view=true) + realarray2 *t, realarray *background, triplearray *lights, + realarray2 *diffuse, realarray2 *ambient, realarray2 *specular, + bool viewportlighting, bool view=true) { size_t n=checkArrays(lights,diffuse); checkEqual(n,checkArray(ambient)); checkEqual(n,checkArray(specular)); - f->shipout3(prefix,format,width,height,angle,m,M,copyArray2C(t,true,4),n, - copyTripleArrayC(lights),copyArray2C(diffuse,false,4), - copyArray2C(ambient,false,4),copyArray2C(specular,false,4), - viewportlighting,view); + f->shipout3(prefix,format,width,height,angle,m,M,copyArray2C(t,true,4), + copyArrayC(background),n,copyTripleArrayC(lights), + copyArray2C(diffuse,false,4),copyArray2C(ambient,false,4), + copyArray2C(specular,false,4),viewportlighting,view); } void shipout3(string prefix, picture *f) @@ -4010,28 +4104,32 @@ real abs(triple v) return v.length(); } -real polar(triple v) +real polar(triple v, bool warn=true) { + if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) return 0.0; return v.polar(); } -real azimuth(triple v) +real azimuth(triple v, bool warn=true) { + if(!warn && v.getx() == 0.0 && v.gety() == 0.0) return 0.0; return v.azimuth(); } -real colatitude(triple v) +real colatitude(triple v, bool warn=true) { + if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) return 0.0; return degrees(v.polar()); } -real latitude(triple v) +real latitude(triple v, bool warn=true) { + if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) return 0.0; return 90.0-degrees(v.polar()); } // Return the longitude of v in [0,360). -real longitude(triple v, bool warn=true) +real longitude(triple v, bool warn=true) { if(!warn && v.getx() == 0.0 && v.gety() == 0.0) return 0.0; return principalBranch(degrees(v.azimuth())); |