summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/drawlabel.cc
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2014-05-17 18:06:46 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2014-05-17 18:06:46 +0000
commit8e7ea45ebf7c1c4dbca970656d00684cc5d53720 (patch)
tree8c8a67fb417b3e9ccf6a4dcbd17361f8e36683f2 /Build/source/utils/asymptote/drawlabel.cc
parent02783996c279399df9780678ce424ab563bfee73 (diff)
asy 2.31 sources
git-svn-id: svn://tug.org/texlive/trunk@34080 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/drawlabel.cc')
-rw-r--r--Build/source/utils/asymptote/drawlabel.cc114
1 files changed, 38 insertions, 76 deletions
diff --git a/Build/source/utils/asymptote/drawlabel.cc b/Build/source/utils/asymptote/drawlabel.cc
index 5f009e1087f..e887879b52d 100644
--- a/Build/source/utils/asymptote/drawlabel.cc
+++ b/Build/source/utils/asymptote/drawlabel.cc
@@ -24,82 +24,44 @@ void drawLabel::labelwarning(const char *action)
<< "\" " << action << " to avoid overwriting" << endl;
}
-int wait(iopipestream &tex, const char *s, const char **abort,
- bool ignore=false)
-{
- int rc=tex.wait(s,abort);
- if(rc > 0) {
- if(fataltex[rc-1]) {
- tex.pipeclose();
- ignore=false;
- } else {
- tex << "\n";
- tex.wait(s,abort);
- tex << "\n";
- tex.wait(s,abort);
- }
-
- if(!ignore) {
- string s=tex.message();
- tex.shred();
- reportError(s);
- }
- }
- tex.shred();
- return rc;
-}
-
// Reads one of the dimensions from the pipe.
-void texdim(iopipestream& tex, double& dest,
- const string command, const string name,
- const char **abort)
+void texdim(iopipestream& tex, double& dest, const string command,
+ const string name)
{
- string texbuf;
+ string start(">dim(");
+ string stop(")dim");
+ string expect("pt"+stop+"\n\n*");
- tex << ("\\showthe\\" + command + "\\ASYbox\n");
- tex >> texbuf;
-
- string cannotread="Cannot read label "+name;
+ // ask the tex engine for dimension
+ tex << "\\immediate\\write16{" << start << "\\the\\" << command << "\\ASYbox"
+ << stop << "}\n";
+ // keep reading output until ')dim\n\n*' is read
+ tex.wait(expect.c_str());
+ string buffer = tex.getbuffer();
- if (texbuf[0] == '>' && texbuf[1] == ' ')
+ size_t dim1=buffer.find(start);
+ size_t dim2=buffer.find("pt" + stop);
+ string cannotread="Cannot read label "+name;
+ if (dim1 != string::npos && dim2 != string::npos) {
+ string n=buffer.substr(dim1+start.size(),dim2-dim1-start.size());
try {
- dest=lexical::cast<double>(texbuf.c_str()+2,true)*tex2ps;
+ dest=lexical::cast<double>(n,true)*camp::tex2ps;
} catch(lexical::bad_cast&) {
- reportError(cannotread);
+ camp::reportError(cannotread);
}
- else
- reportError(cannotread);
-
- tex << "\n";
- wait(tex,"\n*",abort);
+ } else {
+ camp::reportError(cannotread);
+ }
}
-bool texbounds(double& width, double& height, double& depth,
- iopipestream& tex, string& s, const char **abort, bool warn,
- bool Inline)
+void texbounds(double& width, double& height, double& depth,
+ iopipestream& tex, string& s)
{
- string texbuf;
-
tex << "\\setbox\\ASYbox=\\hbox{" << stripblanklines(s) << "}\n\n";
- int rc=wait(tex,texready.c_str(),abort,Inline);
- if(rc) {
- tex << "\\show 0\n";
- tex.wait("\n*");
-
- if(warn && getSetting<bool>("debug")) {
- ostringstream buf;
- buf << "Cannot determine size of label \"" << s << "\"";
- reportWarning(buf);
- }
-
- return false;
- }
-
- texdim(tex, width, "wd", "width", abort);
- texdim(tex, height, "ht", "height", abort);
- texdim(tex, depth, "dp", "depth", abort);
-
- return true;
+ tex.wait(texready.c_str());
+ texdim(tex,width,"wd","width");
+ texdim(tex,height,"ht","height");
+ texdim(tex,depth,"dp","depth");
}
inline double urand()
@@ -110,15 +72,16 @@ inline double urand()
void setpen(iopipestream& tex, const string& texengine, const pen& pentype)
{
- const char **abort=texabort(texengine);
bool Latex=latex(texengine);
- if(Latex) {
- if(setlatexfont(tex,pentype,drawElement::lastpen))
- wait(tex,"\n*",abort);
+ if(Latex && setlatexfont(tex,pentype,drawElement::lastpen)) {
+ tex << "\n";
+ tex.wait(texready.c_str());
+ }
+ if(settexfont(tex,pentype,drawElement::lastpen,Latex)) {
+ tex << "\n";
+ tex.wait(texready.c_str());
}
- if(settexfont(tex,pentype,drawElement::lastpen,Latex))
- wait(tex,"\n*",abort);
drawElement::lastpen=pentype;
}
@@ -128,13 +91,12 @@ void drawLabel::getbounds(iopipestream& tex, const string& texengine)
if(havebounds) return;
havebounds=true;
- const char **abort=texabort(texengine);
setpen(tex,texengine,pentype);
+ texbounds(width,height,depth,tex,label);
- bool nullsize=size.empty();
- if(!texbounds(width,height,depth,tex,label,abort,nullsize,
- getSetting<bool>("inlinetex")) && !nullsize)
- texbounds(width,height,depth,tex,size,abort,false);
+ if(width == 0.0 && height == 0.0 && depth == 0.0 && !size.empty())
+ texbounds(width,height,depth,tex,size);
+
enabled=true;
Align=inverse(T)*align;