% CEMAC.MF --- version 3.0 (6 March 2002) --- (c) Harold W. de Wijn
% DRIVER FILE TO GENERATE CE MARK
% FILE SHOULD BE RENAMED WHENEVER IT IS MODIFIED!

message "CEMAC.MF v3.0 (6 March 2002) - (c) Harold W. de Wijn";

mode_setup;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Macros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

def draw_CE =
italcorr 9/10OuterDiameter#*S;

currenttransform:=identity if S<>0: slanted S fi;

pickup pencircle scaled Thickness;

% ---------- Circle segment ----------
Margin:=3/20OuterDiameter;
z6=(good.x(Margin+1/2Thickness),1/2h);
z0=z6 + (good.y(1/2OuterDiameter -1/2Thickness +1/2h) -1/2h, 0);
forsuffixes $=1,2,4,8,10,11: z$=z6 rotatedaround(z0,($-6)*22.5); endfor;

draw z1{z8-z10}..z2{left}..z4{z6-z2}..z6{down}..z8{z10-z6}..
   z10{right}..{z2-z4}z11;

extra_pixel:=1;
z31=(x0+1/20OuterDiameter,y2+pen_top+extra_pixel);
z32=(x31,y10+pen_bot-extra_pixel);
z33=(x1+pen_rt+max(pen_top*S,pen_bot*S)+extra_pixel,y32);
z34=(x33,y31);
cull currentpicture keeping (1,infinity) withweight 1;
unfill z31--z32--z33--z34--cycle;      % erase excess

penlabels(0,1,2,4,6,8,10,11,31,32,33,34);

% ---------- Bar ----------
if Bar=1:
draw z6--z0;

z41=(x0-1/20OuterDiameter,y0+pen_top+extra_pixel);
z42=(x41,y0+pen_bot-extra_pixel);
z43=(x0+pen_rt+max(pen_top*S,pen_bot*S)+extra_pixel,y42);
z44=(x43,y41);
cull currentpicture keeping (1,infinity) withweight 1;
unfill z41--z42--z43--z44--cycle;      % erase excess

penlabels(41,42,43,44);
fi;

enddef;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

def makebox(text r) =
for y=0,1/2h,h: r((y*S,y),(w+y*S,y)); endfor;
for x=0,Margin,w-Margin,w:
  if S=0: r((x,0),(x,h));
  else: for y=0,1/2h,h: r((x+y*S,y-0.01h),(x+y*S,y+0.01h)); endfor; fi;
endfor;
if S>0: r((w+charic*pt,3/4h),(w+charic*pt,h+o)); fi;
enddef;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

def outline =                % cf. The METAFONTbook, p.244
cull currentpicture keeping (1,infinity) withweight 1;
picture v; v:=currentpicture;
cull currentpicture keeping (1,1) withweight 3;
addto currentpicture also v
   -v shifted right -v shifted left -v shifted up -v shifted down;
cull currentpicture keeping (1,4);
enddef;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Generating symbols
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if unknown S: S:=0 fi;       % no slanting is default

% ---------- Font dimensions ----------
font_slant S;
font_x_height x_height#;
font_normal_space 6u#+2letter_fit#;
font_normal_stretch 3u#;
font_normal_shrink 2u#;
font_quad 18u#+4letter_fit#;
font_extra_space 2u#;

% ---------- CE marks ----------
BoxHeight#:=cap_height#;
OuterDiameter#:=BoxHeight# + 2o#;
Thickness#:=3/20OuterDiameter#;         % prescribed by geometry
BoxWidth#:=OuterDiameter#-Thickness#;   % prescribed by geometry
define_pixels(OuterDiameter,Thickness,o);

beginchar("C",BoxWidth#,BoxHeight#,0); Bar:=0; draw_CE; endchar;
beginchar("E",BoxWidth#,BoxHeight#,0); Bar:=1; draw_CE; endchar;

beginchar("c",BoxWidth#,BoxHeight#,0); Bar:=0; draw_CE; outline; endchar;
beginchar("e",BoxWidth#,BoxHeight#,0); Bar:=1; draw_CE; outline; endchar;

bye
