summaryrefslogtreecommitdiff
path: root/Master/texmf/asymptote/plain_Label.asy
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-07-05 00:24:45 +0000
committerKarl Berry <karl@freefriends.org>2010-07-05 00:24:45 +0000
commit1fff2e715d8cf25331a3aab6d1324328cbdcf557 (patch)
tree50cc2d03dbc732b8bf70e46310a43e4bd53d55d6 /Master/texmf/asymptote/plain_Label.asy
parenta06e5c017823a9a6673af33599d3f9fe34b1b7e8 (diff)
asymptote 2.00
git-svn-id: svn://tug.org/texlive/trunk@19235 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf/asymptote/plain_Label.asy')
-rw-r--r--Master/texmf/asymptote/plain_Label.asy127
1 files changed, 87 insertions, 40 deletions
diff --git a/Master/texmf/asymptote/plain_Label.asy b/Master/texmf/asymptote/plain_Label.asy
index 4f9d9a20f11..86d11f8acc0 100644
--- a/Master/texmf/asymptote/plain_Label.asy
+++ b/Master/texmf/asymptote/plain_Label.asy
@@ -578,53 +578,100 @@ frame pack(pair align=2S ... object inset[])
return F;
}
-path[] texpath(Label L, bool tex=settings.tex != "none")
-{
- static string[] stringcache;
- static pen[] pencache;
- static path[][] pathcache;
- path[] g;
+path[] texpath(Label L, bool tex=settings.tex != "none", bool bbox=false)
+{
+ struct stringfont
+ {
+ string s;
+ real fontsize;
+ string font;
+
+ void operator init(Label L)
+ {
+ s=L.s;
+ fontsize=fontsize(L.p);
+ font=font(L.p);
+ }
+
+ pen pen() {return fontsize(fontsize)+fontcommand(font);}
+ }
+
+ bool lexorder(stringfont a, stringfont b) {
+ return a.s < b.s || (a.s == b.s && (a.fontsize < b.fontsize ||
+ (a.fontsize == b.fontsize &&
+ a.font < b.font)));
+ }
- string s=L.s;
- pen p=fontcommand(font(L.p))+fontsize(fontsize(L.p));
+ static stringfont[] stringcache;
+ static path[][] pathcache;
- // PDF tex engines lose track of the baseline.
- bool adjust=tex && basealign(L.p) == 1 && pdf();
- if(adjust) p=p+basealign;
+ static stringfont[] stringlist;
+ static bool adjust[];
- int k=0;
- int i;
- while((i=find(stringcache == s,++k)) >= 0) {
- if(pencache[i] == p) {
- g=pathcache[i];
- break;
+ path[] G;
+
+ stringfont s=stringfont(L);
+ pen p=s.pen();
+
+ int i=search(stringcache,s,lexorder);
+ if(i == -1 || lexorder(stringcache[i],s)) {
+ int k=search(stringlist,s,lexorder);
+ if(k == -1 || lexorder(stringlist[k],s)) {
+ ++k;
+ stringlist.insert(k,s);
+ // PDF tex engines lose track of the baseline.
+ adjust.insert(k,tex && basealign(L.p) == 1 && pdf());
}
}
- if(i == -1) {
- if(tex) {
- if(adjust) {
- g=_texpath("."+s,p);
- if(g.length == 0) return g;
- real y=min(g[0]).y;
- g.delete(0);
- g=shift(0,-y)*g;
- } else g=_texpath(s,p);
- } else g=textpath(s,p);
+ path[] transform(path[] g, Label L) {
+ pair m=min(g);
+ pair M=max(g);
+ pair dir=rectify(inverse(L.T)*-L.align.dir);
+ if(tex && basealign(L.p) == 1)
+ dir -= (0,(1-dir.y)*m.y/(M.y-m.y));
+ pair a=m+realmult(dir,M-m);
- stringcache.push(s);
- pencache.push(p);
- pathcache.push(g);
+ return shift(L.position+L.align.dir*labelmargin(L.p))*L.T*shift(-a)*g;
}
+
+ if(tex && bbox) {
+ frame f;
+ label(f,L);
+ return transform(box(min(f),max(f)),L);
+ }
+
+ if(stringlist.length > 0) {
+ path[][] g;
+ int n=stringlist.length;
+ string[] s=new string[n];
+ pen[] p=new pen[n];
+ for(int i=0; i < n; ++i) {
+ stringfont S=stringlist[i];
+ s[i]=adjust[i] ? "."+S.s : S.s;
+ p[i]=adjust[i] ? S.pen()+basealign : S.pen();
+ }
+
+ g=tex ? _texpath(s,p) : textpath(s,p);
+
+ if(tex)
+ for(int i=0; i < n; ++i)
+ if(adjust[i]) {
+ real y=min(g[i][0]).y;
+ g[i].delete(0);
+ g[i]=shift(0,-y)*g[i];
+ }
+
- pair a;
- if(g.length == 0) return g;
- pair m=min(g);
- pair M=max(g);
- pair dir=rectify(inverse(L.T)*-L.align.dir);
- if(tex && basealign(L.p) == 1)
- dir -= (0,(1-dir.y)*m.y/(M.y-m.y));
- a=m+realmult(dir,M-m);
-
- return shift(L.position+L.align.dir*labelmargin(p))*L.T*shift(-a)*g;
+ for(int i=0; i < stringlist.length; ++i) {
+ stringfont s=stringlist[i];
+ int j=search(stringcache,s,lexorder)+1;
+ stringcache.insert(j,s);
+ pathcache.insert(j,g[i]);
+ }
+ stringlist.delete();
+ adjust.delete();
+ }
+
+ return transform(pathcache[search(stringcache,stringfont(L),lexorder)],L);
}