summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-12-29 00:00:16 +0200
committerMarius <mariausol@gmail.com>2012-12-29 00:00:16 +0200
commitf8d3835211dbbac2ed31376d655642571db52f4e (patch)
tree81017e6a4f1c5351cf2bc4d3b15a1b838e4394e4 /metapost
parent290581646ba1e91eb2be7086ec32653d1a33841f (diff)
downloadcontext-f8d3835211dbbac2ed31376d655642571db52f4e.tar.gz
beta 2012.12.28 20:30
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mp-chem.mpiv51
1 files changed, 29 insertions, 22 deletions
diff --git a/metapost/context/base/mp-chem.mpiv b/metapost/context/base/mp-chem.mpiv
index 954174f0d..6739dcaf7 100644
--- a/metapost/context/base/mp-chem.mpiv
+++ b/metapost/context/base/mp-chem.mpiv
@@ -66,7 +66,7 @@ chem_setting_axis := false ;
chem_axis_rulethickness := 1pt ;
chem_emwidth := 10pt ; % EmWidth or \the\emwidth does not work...
chem_b_length := 3 chem_emwidth ;
-chem_text_offset := -.71chem_emwidth ; % 1/sqrt(2)
+chem_text_offset := -.3chem_emwidth ; % -.71chem_emwidth ; % 1/sqrt(2)
chem_center_offset := .5 chem_emwidth ;
chem_picture_offset := chem_emwidth ;
chem_dbl_offset := .05 ;
@@ -1404,10 +1404,8 @@ vardef chem_midz@#(suffix $) (expr p) (text t) = % MIDZ
enddef ;
vardef chem_rz@#(suffix $) (expr p) (text t) = % RZ
-% draw chem_text@#
-% (t, chem_do((point p-1 of chem_r_path[$]) chem_transformed($))) ;
-% freedotlabel(t,chem_do((point p-1 of chem_r_path[$]) chem_transformed($)),center chem_r_path[$] chem_transformed($))
- freelabel(t,chem_do((point p-1 of chem_r_path[$]) chem_transformed($)),center chem_r_path[$] chem_transformed($))
+ draw chem_text@#
+ (t, chem_do((point p-1 of chem_r_path[$]) chem_transformed($))) ;
enddef ;
vardef chem_lrz@#(suffix $) (expr p) (text t) = % LRZ
@@ -1485,32 +1483,41 @@ enddef ;
vardef chem_symbol(expr t) = draw textext(t) ; enddef ;
-vardef chem_align@#(expr pic,off) =
+vardef chem_align@#(expr pic) =
pic
if (mfun_labtype@# >= 10) :
shifted (0,ypart center pic)
fi
- shifted (chem_text_offset*mfun_laboff@# - (mfun_labxf@#*lrcorner pic + mfun_labyf@#*ulcorner pic + (1-mfun_labxf@#-mfun_labyf@#)*llcorner pic))
-enddef ;
-
-vardef chem_text@#(expr txt, z) = % adapted copy of thelabel@
- save off ; numeric off ; off := chem_text_offset ;
-
- chem_pic := textext(txt) rotated -chem_setting_rotation ;
- chem_pic :=
- if (length(str @#) > 0) and ((str @#) = "auto") :
- if (abs z)>.71chem_emwidth : chem_align.autoalign(angle(z))
- else : chem_align fi
+ shifted (-(mfun_labxf@#*lrcorner pic + mfun_labyf@#*ulcorner pic + (1-mfun_labxf@#-mfun_labyf@#)*llcorner pic))
+enddef ;
+
+vardef chem_text@#(expr txt, z) =
+ chem_pic := textext(txt) ;
+ if length(str @#)=0 :
+ chem_pic := chem_align(chem_pic) ;
+ elseif (str @#) = "auto" :
+ if z<>origin :
+ chem_num0 := abs(angle(z rotated chem_setting_rotation)) ;
+ if chem_num0<=60 :
+ chem_pic := chem_align.rt (chem_pic) xshifted chem_text_offset ;
+ elseif chem_num0>=120 :
+ chem_pic := chem_align.lft(chem_pic) xshifted -chem_text_offset ;
+ else :
+ chem_pic := chem_align (chem_pic) ;
+ fi
else :
- chem_align@#
+ chem_pic := chem_align (chem_pic) ;
fi
- (chem_pic,off) ;
- chem_pic := chem_pic shifted z ;
+ else :
+ chem_pic := chem_align@#(chem_pic) shifted (chem_text_offset*mfun_laboff@#) ;
+ fi
+ chem_pic := (chem_pic rotated -chem_setting_rotation) shifted z ;
if chem_text_trace :
- draw z withpen pencircle scaled 2pt withcolor red ;
+ draw z withpen pencircle scaled 2pt withcolor red ;
draw boundingbox chem_pic withpen pencircle scaled 1pt withcolor red ;
- fi ;
+ fi
+
chem_pic
enddef ;