summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-05-26 21:24:42 +0000
committerKarl Berry <karl@freefriends.org>2019-05-26 21:24:42 +0000
commit5a993557f8f849481525f4d473d6c9f1da51981d (patch)
tree937613e39639ec08aafd9428bdbce4d4fcb9556e /Master/texmf-dist/metapost
parentc4383680c5d2c9766477cf8faabfa021f280fc11 (diff)
mcf2graph (26may19)
git-svn-id: svn://tug.org/texlive/trunk@51227 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost')
-rw-r--r--Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf167
1 files changed, 139 insertions, 28 deletions
diff --git a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
index 12652c004bf..364e83f1a5f 100644
--- a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
+++ b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf
@@ -1,5 +1,5 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% mcf2graph ver 4.41 Copyright (c) 2013-2019 Akira Yamaji
+% mcf2graph ver 4.42 Copyright (c) 2013-2019 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,
@@ -36,7 +36,7 @@
% Set to use plain.mp (label,arrow,atom) : mpost -s labeloffset=2 FILENAME
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tracingstats:=1;
-message " This is mcf2graph ver 4.41 2019.05";
+message " This is mcf2graph ver 4.42 2019.05";
%-------------------------------------------------------------------------------------------------
newinternal char_num,str_cnt,sub_usr,sub_int,tbl_cnt,sharp_char;
numeric save_num[],comD[][],parD[][],cntD[],tbl_atom[],tbl_subst[][],
@@ -44,7 +44,7 @@ numeric save_num[],comD[][],parD[][],cntD[],tbl_atom[],tbl_subst[][],
string save_str[],tbl_atom_str[],strD[],var[],tag[],out_file_name,out_file_aux,out_file_rep,
aux_delimiter,atomfont,save_atomfont,save_defaultfont;
pair save_pair[],msize,mposition,fsize,fmargin,save_mposition;
-picture mol_stru[];
+picture mol_stru[],save_picture,temp_picture;
path arrow_path,arrow_head;
%-------------------------------------------------------------------------------------------------
char_num:=str_cnt:=proc_end:=mangle:=sw_label_emu:=sw_calc:=sw_extall:=0;
@@ -97,12 +97,19 @@ if (known green)and(known ahlength):
def endchar = endfig enddef;
def printf expr s= write s to out_file_name enddef;
def # = enddef;
+ vardef totalweight expr a= 0 enddef;
def Cp(expr s) = if known s: if s<>0: withcolor color_list[s] fi fi enddef;
def ext(text TXT)= sw_extall:=sw_calc:=1; def EXTALL = TXT enddef; enddef;
if atomfont="": atomfont:="draw"; fi % default atom font
if defaultfont="": defaultfont:="draw"; fi % default label font
%-----------------------------------------------------------------------------------------
else: f_MP:=0;
+ %-----------------------------------
+ def image = image_emu enddef;
+ def llcorner = llcorner_emu enddef;
+ def lrcorner = lrcorner_emu enddef;
+ def urcorner = urcorner_emu enddef;
+ def ulcorner = ulcorner_emu enddef;
string defaultfont;
dotlabeldiam:=3bp;
def Cp(expr s) = enddef;
@@ -126,7 +133,7 @@ ratio_thickness_bond:=0.015; ratio_thickness_char:=0.1;
ratio_char_bond:=1.5; ratio_bondgap_bond:=0.15; ratio_zebragap_bond:=0.12;
ratio_zebra_black:=0.4; ratio_wedge_bond:=0.12; ratio_atomgap_atom:=0.050;
offset_thickness:=0.2bp; offset_bond_gap:=0.3bp; offset_zebra_gap:=0.1bp;
-offset_atom:=0.8pt; offset_wedge:=0.4bp;
+offset_atom:=0.8pt; offset_wedge:=0.4bp; max_labelsize:=20mm;
thickness_fframe:=0.2bp; thickness_mframe:=0.2bp; thickness_aframe:=0.1bp;
max_blength:=10mm; blength:=0; mangle:=0;
%--------------------------------------------------------------------------------------------------
@@ -139,6 +146,7 @@ defaultsize:=8bp;
defaultscale:=1;
labeloffset:=3bp;
ext_defaultline:=0.5bp;
+lonepairdiam:=lonepairspace:=circlediam:=circlepen:=0;
%==================================================================================================
sub_emb_start:=500; % 500 => 2499 for embedded sub structure (max 2000)
sub_usr_start:=2500; % 2500 => 2999 for user sub structure (max 500)
@@ -157,7 +165,7 @@ def parameter_list=
sw_aframe,sw_fframe,sw_subst_off,sw_single,sw_trimming,sw_arrow,sw_label_emu,
ratio_atom_bond,ratio_thickness_bond,ratio_char_bond,
ratio_chain_ring,ratio_bondgap_bond,ratio_zebra_black,ratio_zebragap_bond,ratio_thickness_char,
- ratio_wedge_bond,ratio_atomgap_atom,
+ ratio_wedge_bond,ratio_atomgap_atom,lonepairdiam,lonepairspace,
blength,offset_atom,offset_wedge,max_blength,offset_zebra_gap,offset_bond_gap,
thickness_fframe,thickness_mframe,thickness_aframe,offset_thickness,
numberA_start,numberA_end,numberB_start,numberB_end,
@@ -214,7 +222,7 @@ def beginfont(text s)=
inf_NO,inf_EN,inf_JN,inf_FM,inf_CAS,inf_USE,inf_EXA,inf_EXB,inf_MW;
%------------------------------------------------------------------------------------------------
def ext=ext_font enddef;
- def add=add_mol enddef;
+ def add=add_mole enddef;
%------------------------------------------------------------------------------------------------
inf_NO:=inf_EN:=inf_JN:=inf_FM:=inf_CAS:=inf_USE:=inf_EXA:=inf_EXB:=inf_MW:="";
cal_MW:=cal_MW_str:=cal_FM:="";
@@ -478,18 +486,35 @@ def ext_setup=
fi
enddef;
%--------------------------------------------------------------------------------------------------
-def add_mol(text TXT)=
+def add_mole(text TXT)=
begingroup
- save w,h,n,l,p,am,aw,A,B;
- numeric A[]dir,B[]dir;
- pair p[],A[],B[],B[]s,B[]e;
+ save w,h,n,l,p,am,aw,A,B,plus,minus,lonepair,**,/*;
+ numeric A[]dir,B[]up,A[]ang,B[]ang;
+ pair p[],A[],B[],B[]s,B[]e,B[]m,A[]up,A[]left,A[]right,A[]down,
+ B[]up,B[]left,B[]right,B[]down;
+ path B[];
ext_setup;
+ def plus=circled_plus_add enddef;
+ def minus=circled_minus_add enddef;
+ def lonepair=lone_pair_add enddef;
+ let **=scaled;
+ primarydef a /* b = point b of a enddef;
w:=mol_wd; h:=mol_ht; l:=blength; aw:=atom_wd;
p0:=(minX,minY);
An:=cntA; Bn:=cntB;
- for i=1 upto An: A[i]:=posA[i]; A[i]dir:=angX[i]; endfor
+ lonepairdiam:=0.3aw;
+ lonepairspace:=.7aw;
+ circlediam:=.6aw;
+ circlepen:=.2bp;
+ for i=1 upto An:
+ A[i]:=posA[i]; A[i]ang:=angX[i]; A[i]up:=dir(angX[i]);
+ A[i]left:=dir(angX[i]+90); A[i]right:=dir(angX[i]-90); A[i]down:=dir(angX[i]+180);
+ endfor
for i=1 upto Bn:
- B[i]s:=posA[sB[i]]; B[i]e:=posA[eB[i]]; B[i]:=0.5[B[i]s,B[i]e]; B[i]dir:=angB[i];
+ B[i]s:=posA[sB[i]]; B[i]e:=posA[eB[i]]; B[i]m:=0.5[B[i]s,B[i]e];
+ B[i]:=B[i]s--B[i]e;
+ B[i]ang:=angB[i]; B[i]up:=dir(angB[i]);
+ B[i]down:=dir(angB[i]+180); B[i]left:=dir(angB[i]+90); B[i]right:=dir(angB[i]-90);
endfor
TXT addto mol_stru[cntM] also currentpicture; clearit;
endgroup;
@@ -512,23 +537,100 @@ def ext_font(text TXT)=
endgroup;
enddef;
%--------------------------------------------------------------------------------------------------
-vardef label_emu@#(expr STR,POS) = %% modified 'thelabel@#(expr s,z)' of plain.mp
- save oft,fx,fy,wds,sC,bA;
- pair oft,oft.lft,oft.rt,oft.top,oft.bot,oft.ulft,oft.llft,oft.urt,oft.lrt;
+vardef image_emu(text TXT) =
+ save_picture:=currentpicture;
+ currentpicture:=nullpicture;
+ TXT;
+ temp_picture:=currentpicture;
+ currentpicture:=save_picture;
+ temp_picture
+enddef;
+%--------------------------------------------------------------------------------------------------
+vardef scan_picture(expr PIC,SD)=
+ save save_pic,nA,nB,nC,nD,nE,nS,iw,erase_h,erase_v;
+ picture save_pic;
+ path erase_h,erase_v;
+ nD:=0.2bp;
+ if (SD=1)or(SD=3): nS:=-max_labelsize; nE:=max_labelsize; nB:=nD; nC:=-nD;
+ elseif (SD=2)or(SD=4): nS:=max_labelsize; nE:=-max_labelsize; nB:=-nD; nC:=0;
+ fi
+ if (SD=1)or(SD=2):
+ erase_h:=unitsquare xscaled 2max_labelsize yscaled nD shifted (-max_labelsize,nC);
+ elseif (SD=3)or(SD=4):
+ erase_v:=unitsquare xscaled nD yscaled 2max_labelsize shifted (nC,-max_labelsize);
+ fi
+ save_pic:=currentpicture;
+ currentpicture:=PIC;
+ erase fill unitsquare scaled nD shifted (-max_labelsize,-max_labelsize);
+ iw:=totalweight currentpicture;
+ if iw>=0:
+ for i=nS step nB until nE:
+ if (SD=1)or(SD=2): erase fill erase_h shifted (0,i);
+ elseif (SD=3)or(SD=4): erase fill erase_v shifted (i,0);
+ fi
+ nA:=i;
+ exitif (totalweight currentpicture)<iw;
+ endfor
+ else:
+ nA:=0;
+ fi
+ currentpicture:=save_pic;
+ nA
+enddef;
+%--------------------------------------------------------------------------------------------------
+vardef llcorner_emu(expr b)= (scan_picture(b,3),scan_picture(b,1)) enddef;
+vardef lrcorner_emu(expr b)= (scan_picture(b,4),scan_picture(b,1)) enddef;
+vardef urcorner_emu(expr b)= (scan_picture(b,4),scan_picture(b,2)) enddef;
+vardef ulcorner_emu(expr b)= (scan_picture(b,3),scan_picture(b,2)) enddef;
+%--------------------------------------------------------------------------------------------------
+vardef circled_plus_add=
+ save nA,nB;
+ nA:=circlediam;
+ nB:=circlepen;
+ image(draw fullcircle scaled nA withpen pencircle scaled nB;
+ draw (-.5nA,0)--(.5nA,0) withpen pencircle scaled nB;
+ draw (0,-.5nA)--(0,.5nA) withpen pencircle scaled nB;
+ )
+enddef;
+%--------------------------------------------------------------------
+vardef circled_minus_add=
+ save nA,nB;
+ nA:=circlediam;
+ nB:=circlepen;
+ image(draw fullcircle scaled nA withpen pencircle scaled nB;
+ draw (-.5nA,0)--(.5nA,0) withpen pencircle scaled nB;
+ )
+enddef;
+%--------------------------------------------------------------------
+vardef lone_pair_add expr ANG=
+ save nA,nB;
+ nA:=lonepairdiam;
+ nB:=lonepairspace;
+ image(draw (0,0) withpen pencircle scaled nA;
+ draw ((0,nB) rotated ANG) withpen pencircle scaled nA;)
+enddef;
+%--------------------------------------------------------------------------------------------------
+vardef label_emu@#(expr OBJ,POS) = %% modified 'thelabel@#(expr s,z)' of plain.mp
+ save oft,fx,fy,wds,sC,bA,pA,pB,pC,pD;
+ pair oft,oft.lft,oft.rt,oft.top,oft.bot,oft.ulft,oft.llft,oft.urt,oft.lrt,pA,pB,pC,pD;
string sC;
picture bA;
wds:=0;
- for i=0 upto length(STR)-1:
- sC:=pic_c(i,STR);
- if not((sw_label_emu=1)and((sC="_")or(sC="^"))):
- if (defaultfont="draw")or(f_MP=0):
- wds:=wds+defaultscale*defaultsize*tbl_char_wd[ASCII(sC)];
- else:
- bA:=sC infont defaultfont scaled defaultscale;
- wds:=wds+xpart(lrcorner bA-llcorner bA);
+ %---------------------------------------------------------------
+ if string OBJ:
+ for i=0 upto length(OBJ)-1:
+ sC:=pic_c(i,OBJ);
+ if not((sw_label_emu=1)and((sC="_")or(sC="^"))):
+ if (defaultfont="draw")or(f_MP=0):
+ wds:=wds+defaultscale*defaultsize*tbl_char_wd[ASCII(sC)];
+ else:
+ bA:=sC infont defaultfont scaled defaultscale;
+ wds:=wds+xpart(lrcorner bA-llcorner bA);
+ fi
fi
- fi
- endfor
+ endfor
+ fi
+ %---------------------------------------------------------------
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;
@@ -538,11 +640,20 @@ vardef label_emu@#(expr STR,POS) = %% modified 'thelabel@#(expr s,z)' of plain.m
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@#,defaultscale*defaultsize*fy@#))(STR);
+ %---------------------------------------------------------------
+ if string OBJ:
+ puts(POS+(labeloffset*oft@#)-(wds*fx@#,defaultscale*defaultsize*fy@#))(OBJ);
+ elseif picture OBJ:
+ pA:=llcorner(OBJ);
+ pB:=urcorner(OBJ);
+ pC:=.5(pB-pA) xscaled xpart(oft@#) yscaled ypart(oft@#);
+ pD:=.5(pA+pB);
+ addto currentpicture also OBJ shifted (POS+labeloffset*oft@#+pC-pD);
+ fi
enddef;
%-------------------------------------------------------------------------------------------------
-vardef dotlabel_emu@#(expr STR,POS)=
- label_emu@#(STR,POS); draw POS withpen pencircle scaled dotlabeldiam;
+vardef dotlabel_emu@#(expr OBJ,POS)=
+ label_emu@#(OBJ,POS); draw POS withpen pencircle scaled dotlabeldiam;
enddef;
%==================================================================================================
def drawarrow_emu expr PAT = arrow_path:=PAT; draw_arrow enddef;