From 611d5ba5f27a5977d135e8a19a6490a3d4314702 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 6 Mar 2017 21:59:14 +0000 Subject: mcf2graph (6mar17) git-svn-id: svn://tug.org/texlive/trunk@43416 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf | 157 ++++++++++++++-------- 1 file changed, 102 insertions(+), 55 deletions(-) (limited to 'Master/texmf-dist/metapost') diff --git a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf index c2d6f991841..4fea2752498 100644 --- a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf +++ b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf @@ -1,5 +1,5 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% mcf2graph ver 4.10 Copyright (c) 2013-2017 Akira Yamaji +% mcf2graph ver 4.11 Copyright (c) 2013-2017 Akira Yamaji % % Permission is hereby granted, free of charge, to any person obtaining a copy of this software % and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -26,11 +26,12 @@ % Set outputformat to "png" : mpost -s ahangle=1 FILENAME % Set outputformat to "svg" : mpost -s ahangle=2 FILENAME % Set outputformat to MDL Molfile : mpost -s ahangle=3 FILENAME -% Set first font only (for test) : mpost -s ahlength=1 FILENAME +% Set make first font only : mpost -s ahlength=1 FILENAME % Set output report : mpost -s ahlength=2 FILENAME +% Set 'label' to use Metapost : mpost -s ahlength=3 FILENAME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tracingstats:=1; -message " This is mcf2graph ver 4.1 2017.2"; +message " This is mcf2graph ver 4.1 2017.3"; %------------------------------------------------------------------------------------------------- newinternal nA,nB,nC,nD,nE,nF,char_num,str_cnt,def_num,def_int,tbl_cnt; numeric save_para[],comD[][],parD[][],cntD[],tbl_str_wd[],tbl_atom[],tbl_subst[][],tbl_atom_wt[], @@ -40,7 +41,7 @@ picture atom_font[],str_font[],mol_stru[],save_pict; %------------------------------------------------------------------------------------------------- char_num:=str_cnt:=proc_end:=0; sw_numberA:=sw_numberB:=sw_mol_frame:=sw_auxout:=sw_solid:=sw_expand:=sw_font_frame:=sw_clip:=0; -sw_atom_frame:=sw_report:=sw_MOLout:=sw_subst_off:=sw_bond_single:=sw_auxfix:=sw_label_mp:=0; +sw_atom_frame:=sw_report:=sw_MOLout:=sw_subst_off:=sw_bond_single:=sw_auxfix:=0; numberA_start:=numberB_start:=1; numberA_end:=numberB_end:=4095; aux_max:=max_inf_num:=20; aux_delimiter:=";"; var1:="jobname"; tag1:="F"; var2:="char_num"; tag2:="C"; for i=3 upto aux_max: var[i]:=tag[i]:=""; endfor @@ -51,6 +52,7 @@ if (known green)and(known ahlength): mp_log_name:=jobname&"-info.aux"; if ahlength=1: proc_end:=1; fi % first molecular only if ahlength=2: sw_report:=1; def shipit = enddef; fi % report on + if ahlength=3: sw_label:=1; fi % use metapost label if ahangle=0: def shipit = enddef; % No image file elseif ahangle=1: outputformat:="png"; hppp:=vppp:=0.1; % PNG format elseif ahangle=2: outputformat:="svg"; % SVG format @@ -63,12 +65,15 @@ if (known green)and(known ahlength): def # = enddef; def Cp(expr s) = if known s: if s<>0: withcolor color_list[s] fi fi enddef; def define_pixels(text s) = enddef; - if sw_label_mp=0: def label = label_ext enddef; fi + if unknown sw_label: sw_label:=0; fi else: f_MP:=0; + string defaultfont; + sw_label:=0; def Cp(expr s) = enddef; def color = transform enddef; - def label = label_ext enddef; def printf expr s= message s enddef; + sw_label:=0; + def label = label_mf enddef; mode_setup; fi ahangle:=45; ahlength:=4; @@ -86,8 +91,16 @@ offset_thickness#:=0.2pt#; offset_bond_gap#:=0.3pt#; offset_zebra_gap#:=0.1p offset_atom#:=0.8pt#; offset_wedge#:=0.4pt#; thickness_font_frame#:=0.2pt#; max_bond_length#:=10mm; bond_len#:=8mm#; font_wd#:=30mm#; font_ht#:=20mm#; -labeloffset:=3bp; default_emb_font#:=5pt#; -%-------------------------------------------------------------------------------------------------- +%================================================================================================== +defaultfont:="uhvr8r"; % Helvetica +%%%%defaultfont:="ucrr8r"; % Courier +%%%%defaultfont:="ucrb8r"; % Courier bold +%%%%defaultfont:="utmr8r"; % Times +defaultsize#:=8pt#; +ext_defaultscale:=1; +labeloffset:=3bp; +define_pixels(defaultsize); +%================================================================================================== def_emb_start:=500; % 500 => 2499 for embedded definition (max 2000) def_usr_start:=2500; % 2500 => 2999 for user definition (max 500) def_int_start:=3000; % 3000 => 4000 for internal definition (max 1000) @@ -101,7 +114,7 @@ def_com(1)(si,dl,dr,db,dm,tm,wf,wb,bd,bz,zf,zb,dt,wv,nl,vf,vb,si_,wf_,wb_,bd_); %-------------------------------------------------------------------------------------------------- def parameter_list= sw_report,sw_numberA,sw_numberB,sw_mol_frame,sw_auxout,sw_solid,sw_expand,sw_MOLout, - sw_atom_frame,sw_font_frame,sw_subst_off,sw_bond_single,sw_clip,sw_label_mp, + sw_atom_frame,sw_font_frame,sw_subst_off,sw_bond_single,sw_clip,sw_label, margin_left_right,margin_top_bottom,ratio_atom_bond,ratio_thickness_bond,ratio_char_bond, ratio_chain_ring,max_bond_width,ratio_bondgap_bond,ratio_zebra_black,ratio_zebragap_bond, ratio_wedge_bond,ratio_atomgap_atom,ratio_bond_width,font_wd#,font_ht#,labeloffset, @@ -254,7 +267,8 @@ def FRR(expr a)(expr b)(expr c) = enddef; %================================================================================================== vardef $$(text t)(expr e) = - nA:=0; def_int:=def_int+1; + nA:=0; + def_int:=def_int+1; if known e:: if numeric e:: if (e>=si)and(e<=bd_):: if e==dl:: for list==t:: PA(_dl,list) endfor else:: for list==t:: PA(_set_adr,list) PA(_set_line,e) endfor fi @@ -275,7 +289,8 @@ vardef $$(text t)(expr e) = enddef; %------------------------------------------------------------------------------------------------- vardef @@(text t)(expr s)= - nA:=0; def_int:=def_int+1; + nA:=0; + def_int:=def_int+1; if known s:: if numeric s:: if (s>=H)and(s<=U):: for list==t:: @@ -308,12 +323,21 @@ enddef; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% def EXT(text s)= begingroup - save w,h,wd,ht,n,p,em; + save w,h,wd,ht,n,p,am,em,currentscale; pair p[]; - use_font(default_emb_font#); - w:=font_wd; h:=font_ht; wd:=w-2margin_left_right; ht:=h-2margin_top_bottom; + em=defaultscale*defaultsize; + %----------------------------------------------------------------------------------------------- + currentscale:=defaultscale:=ext_defaultscale; + if sw_label=0: + def label = label_mf enddef; + use_font(defaultscale*defaultsize#)(0.12defaultscale*defaultsize#); + fi + w:=font_wd; + h:=font_ht; + wd:=w-2margin_left_right; + ht:=h-2margin_top_bottom; p0:=(margin_left_right,margin_top_bottom); - em:=emb_font_size; + aw:=atom_wd; n:=cntM; for i=1 upto n: p[i]:=posM[1][i]; endfor s addto mol_stru[0] also currentpicture; clearit; f_ext:=1; @@ -322,60 +346,75 @@ enddef; %-------------------------------------------------------------------------------------------------- def ext(text s)= begingroup - save wd,ht,n,l,p,zw,sp,ep,em,A,B; + save wd,ht,n,l,p,sp,ep,am,em,A,B,currentscale; numeric A[]bra,B[]ang; pair p[],A[],B[],sp,ep; - use_font(default_emb_font#); + em=defaultscale*defaultsize; + %--------------------------------------------------------------------- + currentscale:=defaultscale:=ext_defaultscale; + if sw_label=0: + def label = label_mf enddef; + use_font(defaultscale*defaultsize#)(0.12defaultscale*defaultsize#); + fi + %--------------------------------------------------------------------- wd:=mol_wd; ht:=mol_ht; l:=bond_len; - em:=emb_font_size; + aw:=atom_wd; p0:=(minX,minY); - An:=cntA; Bn:=cntB; + An:=cntA; + Bn:=cntB; for i=1 upto An: A[i]:=posA[i]; A[i]bra:=ang_br[i]; endfor for i=1 upto Bn: sp:=posA[sB[i]]; ep:=posA[eB[i]]; B[i]:=0.5[sp,ep]; B[i]ang:=angB[i]; endfor s addto mol_stru[cntM] also currentpicture; clearit; endgroup; enddef; %-------------------------------------------------------------------------------------------------- -def use_font(expr WD)= +def use_font(expr WD)(expr PEN)= save_pict:=currentpicture; clearit; for i=1 upto 128: f_char[i]:=1; endfor - proc_char_setup(str_font)(WD); - emb_font_size#:=WD; - define_pixels(emb_font_size); + proc_char_setup(str_font)(WD)(PEN); currentpicture:=save_pict; enddef; %-------------------------------------------------------------------------------------------------- def puts(expr PA)(expr STR)= begingroup - save cp; pair cp; + save cp; + pair cp; cp:=PA; + nB:=0; + %---------------------------------------------------------------------------------- for i=0 upto length(STR)-1: nA:=ASCII(pic_c(i,STR)); - addto currentpicture also str_font[nA] shifted (cp-(0,emb_font_size*tbl_char_dp[nA])); - cp:=cp+(emb_font_size*tbl_char_wd[nA],0); + if nA=ASCII("_"): if nB=0: nB:=-.5; else: nB:=0; fi + elseif nA=ASCII("^"): if nB=0: nB:= .5; else: nB:=0; fi + else: + addto currentpicture also str_font[nA] shifted (cp+(0,em*(nB-tbl_char_dp[nA]))); + cp:=cp+(em*tbl_char_wd[nA],0); + fi endfor endgroup; enddef; %-------------------------------------------------------------------------------------------------- -vardef label_ext@#(expr STR,POS) = +vardef label_mf@#(expr STR,POS) = save oft,fx,fy,wds; pair oft,oft.lft,oft.rt,oft.top,oft.bot,oft.ulft,oft.llft,oft.urt,oft.lrt; wds:=0; - for i=0 upto length(STR)-1: - wds:=wds+emb_font_size*tbl_char_wd[ASCII(pic_c(i,STR))]; - endfor - oft:= ( 0, 0); fx:=0.5; fy:=0.5; - oft.lft:= ( -1, 0); fx.lft:=1; fy.lft:=0.5; - oft.rt := ( 1, 0); fx.rt :=0; fy.rt :=0.5; - oft.bot:= ( 0, -1); fx.bot:=0.5; fy.bot:=1; - oft.top:= ( 0, 1); fx.top:=0.5; fy.top:=0; - oft.ulft:=(-.7, .7); fx.ulft:=1; fy.ulft:=0; - oft.urt:= ( .7, .7); fx.urt:=0; fy.urt:=0; - oft.llft:=(-.7,-.7); fx.llft:=1; fy.llft:=1; - oft.lrt:= ( .7,-.7); fx.lrt:=0; fy.lrt:=1; - puts(POS+(labeloffset*oft@#)-(wds*fx@#,emb_font_size*fy@#))(STR); + if currentscale<>defaultscale: + use_font(defaultscale*defaultsize#)(0.12defaultscale*defaultsize#); + currentscale:=defaultscale; + fi + for i=0 upto length(STR)-1: wds:=wds+em*tbl_char_wd[ASCII(pic_c(i,STR))]; endfor + oft:= ( 0, 0); fx:=0.5; fy:=0.5; + oft.lft:= ( -1, 0); fx.lft:=1; fy.lft:=0.5; + oft.rt := ( 1, 0); fx.rt :=0; fy.rt :=0.5; + oft.bot:= ( 0, -1); fx.bot:=0.5; fy.bot:=1; + oft.top:= ( 0, 1); fx.top:=0.5; fy.top:=0; + oft.ulft:=(-.7, .7); fx.ulft:=1; fy.ulft:=0; + oft.urt:= ( .7, .7); fx.urt:=0; fy.urt:=0; + oft.llft:=(-.7,-.7); fx.llft:=1; fy.llft:=1; + oft.lrt:= ( .7,-.7); fx.lrt:=0; fy.lrt:=1; + puts(POS+(labeloffset*oft@#)-(wds*fx@#,em*fy@#))(STR); enddef; %------------------------------------------------------------------------------------------------- def draw_vector(expr POS,ROT,THICK,LEN)= @@ -405,10 +444,12 @@ def MCd(expr RW,RH)(expr FW,FH)(text TX)= if (sw_expand=1)or(sw_MOLout=1): expand_set; fi def_num:=def_usr_start; def_int:=def_int_start; - par_s=ASCII("{"); par_e=ASCII("}"); score_u=ASCII("_"); hat=ASCII("^"); + par_s:=ASCII("{"); par_e:=ASCII("}"); score_u:=ASCII("_"); hat:=ASCII("^"); cntA:=cntB:=cntP:=cntC:=0; strD[0]:=""; str_cnt:=2000; crR:=-ratio_chain_ring; %=============================================================================================== - ''(0)(TX,(_term,0)); proc_bond_atom(1); if (cntP>0)and(sw_subst_off=0): ps_get(1); fi + ''(0)(TX,(_term,0)); + proc_bond_atom(1); + if (cntP>0)and(sw_subst_off=0): ps_get(1); fi define_pixels(font_wd,font_ht,thickness_font_frame); char_use_check; if sw_solid=1: bond_len#:=font_wd#*ratio_bond_width; @@ -425,7 +466,7 @@ def MCd(expr RW,RH)(expr FW,FH)(text TX)= if bond_len#>max_bond_length#: bond_len#:=max_bond_length#; proc_size_setup; proc_skeleton; proc_scaling; fi fi - proc_char_setup(atom_font)(atom_wd#); + proc_char_setup(atom_font)(atom_wd#)(bond_pen_wd#*ratio_char_bond); %----------------------------------------------------------------------------------------------- for i=1 upto cntB: if lineB[i]=si_: draw_bond(i,sB[i],eB[i],angB[i],lineB[i]); fi endfor @@ -467,7 +508,8 @@ def ps_put(expr n,p)= enddef; %------------------------------------------------------------------------------------------------- def ps_get(expr n)= - nA:=cntP; nB:=cntD[0]; + nA:=cntP; + nB:=cntD[0]; for i=n upto cntP: PG(_jp_atom_abs,ps_adr[i]) PG(_push,1) for j=1 upto op_cnt[i]: PG(op_com[i][j],op_par[i][j]) endfor @@ -493,12 +535,12 @@ def proc_size_setup= zebra_gap#:= bond_len#*ratio_zebragap_bond+offset_zebra_gap#; bondgap#:= bond_len#*ratio_bondgap_bond+offset_bond_gap#; bond_pen_wd#:= bond_len#*ratio_thickness_bond+offset_thickness#; - char_pen_wd#:= bond_pen_wd#*ratio_char_bond; - define_pixels(bond_len,zebra_gap,wedge_wd,atom_wd,bondgap,bond_pen_wd,char_pen_wd); + define_pixels(bond_len,zebra_gap,wedge_wd,atom_wd,bondgap,bond_pen_wd); enddef; %------------------------------------------------------------------------------------------------- def proc_scaling= - minX:=minY:=4095.999; max_x:=max_y:=-4095.999; + minX:=minY:=4095.999; + max_x:=max_y:=-4095.999; for i=1 upto cntA: xpos:=xpart(posA[i]); ypos:=ypart(posA[i]); if numS[i]<>0: str_len:=nC:=nD:=0; @@ -540,7 +582,8 @@ def proc_bond_atom(expr n)= for i=0 upto 5: stkA[i]:=stkB[i]:=0; endfor %----------------------------------------------------------------------------------------------- for i=n upto cntD[0]: - com:=comD[0][i]; par:=parD[0][i]; + com:=comD[0][i]; + par:=parD[0][i]; if com=_push: if par=1: stkL[adrS]:=bondL; stkA[incr adrS]:=adrA:=cntA; stkB[adrS]:=adrB:=cntB; elseif par=0: temp_len:=bondL; fi @@ -592,7 +635,8 @@ def proc_bond_atom(expr n)= enddef; %------------------------------------------------------------------------------------------------- def add_atom= - lineB[incr cntB]:=lineT; lineT:=si; + lineB[incr cntB]:=lineT; + lineT:=si; if lenT=crR: lenB[cntB]:=bondL; else: lenB[cntB]:=lenT; lenT:=crR; fi if f_bra=0: cntA:=cntA+1; sB[cntB]:=cntA; numS[cntA]:=strAT; strAT:=0; if f_MP=1: colorA[cntA]:=colorB[cntA]:=0; fi else: f_bra:=0; fi @@ -808,6 +852,8 @@ Si:='("{Si}");Al:='("{Al}");Mg:='("{Mg}");Zn:='("{Zn}");As:='("{As}");Cu:='("{Cu Ag:='("{Ag}");Au:='("{Au}");Sn:='("{Sn}");Cl:='("{Cl}");Br:='("{Br}");Li:='("{Li}"); Na:='("{Na}");Ca:='("{Ca}");Hg:='("{Hg}");Ni:='("{Ni}");Ti:='("{Ti}");U:='("U"); %------------------------------------------------------------------------------------------------- +R:='("R"); R1:='("{R^1^}"); R2:='("{R^2^}"); R3:='("{R^3^}"); R4:='("R^4^"); R5:='("{R^5^}"); +%------------------------------------------------------------------------------------------------- plus:='("+"); minus:='("-"); HH:='("H{_2_}"); NH:='(N,*/*H); NnoH:='(); SO:='(S,//O); SOO :='(S,//O^-35,//O^35); CHO:='("CHO"); OH:='("OH"); COOH:='("COOH"); CH2:='("C{H_2_}"); CH3:='("C{H_3_}"); CN:='("CN"); NH2:='("N{H_2_}"); NO2:='("N{O_2_}"); SH:='("SH"); @@ -847,25 +893,29 @@ char_size_set(.5)( 1)( 0)("il"); char_size_set(.7)( 1)(.24)("pqg"); char_size_set(.7)(.8)( 0)("acekosuvxzwry"); char_size_set(.4)( 1)( 0)(".,:;'`"); +char_size_set( 0)( 0)( 0)("^_"); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -def proc_char_setup(suffix FONT)(expr SIZE)= +def proc_char_setup(suffix FONT)(expr SIZE)(expr PEN_WD)= begingroup save Z,aW,aH,fW,hW,hW,hH,fP,hP,vL,hL,PO,POh,sH,FD; pair Z[]; %--------------------------------------------------------------- def FD(expr c)(text s)= if f_char[ASCII(c)]=1: + fP#:=PEN_WD; + hP#:=0.5PEN_WD; aW#:=SIZE*tbl_char_wd[ASCII(c)]*(1-ratio_atomgap_atom*2); aH#:=SIZE*tbl_char_ht[ASCII(c)]*(1-ratio_atomgap_atom*2); - define_pixels(aW,aH); + define_pixels(fP,hP,aW,aH); fW:=aW-hP; hW:=.5aW; fH:=aH-hP; hH:=.5aH; Z01:=( 0,hP); Z02:=(hP, 0); Z03:=(hP,hP); Z04:=(aW,hP); Z05:=(fW, 0); Z08:=( 0,hH); Z09:=(hP,hH); Z10:=(fW,hH); Z12:=( 0,fH); Z13:=(hP,fH); Z14:=(hW,fH); Z16:=(aW,fH); Z18:=(hP,aH); Z19:=(hW,hP); Z20:=(hW,hH); Z06:=(hW,aH); Z07:=(hW, 0); Z11:=(hW,aW); Z15:=(fW,aH); Z17:=(aW,hH); + pickup pencircle scaled fP; s; FONT[ASCII(c)]:= - currentpicture shifted (ratio_atomgap_atom*atom_wd,ratio_atomgap_atom*atom_wd); + currentpicture shifted (ratio_atomgap_atom*atom_wd,ratio_atomgap_atom*atom_wd); clearit; fi enddef; @@ -878,9 +928,6 @@ def POh= (hP,.25aH)..Z19..(fW,.25aH)..Z20..cycle enddef; def sH expr n= shifted (0,n) enddef; def SP(expr m,n)expr p=subpath(m*length(p),n*length(p)) of p enddef; %================================================================================================== -pickup pencircle scaled char_pen_wd; -fP:=char_pen_wd; hP:=.5char_pen_wd; -%------------------------------------------------------------------------------------------ FD(" ")(); FD(".")(drawdot Z19 wpcs fP); FD(",")(drawdot Z19 wpcs fP; draw (hW+.5fP,hP)..(hW+.3fP,-fP)..(hW-.5fP,hP-2fP)); -- cgit v1.2.3