%% This file is public domain.
%% Originally written 1998, Ivan A Derzhanski.
%% Notice added by Clea F. Rees 2009/01/06.
%% 
% eira.mf: Irish diacritics and macros

ailm_fada := oct"033";                 Ailm_fada := oct"003";
eabhadh_fada := oct"034";              Eabhadh_fada := oct"004";
iodha_fada := oct"035";                Iodha_fada := oct"005";
oir_fada := oct"036";                  Oir_fada := oct"006";
uwr_fada := oct"037";                  Uwr_fada := oct"007";

def fada(suffix $) =
x.fad1-x.fad2=3u; .5[x.fad1,x.fad2]=x$;
if serifs: pickup crisp.nib;
 y.fad1+.5stem=h+eps;
 y.fad2=max(2/3[h,x_height],x_height+o+hair,y$+o+.5tiny);
 numeric theta; theta=angle(z.fad2-z.fad1)+90;
 pos.fad1(stem,theta); pos.fad2(hair,theta);
 filldraw circ_stroke z.fad1e--z.fad2e;  % diagonal
else: pickup fine.nib; pos.fad1(stem,0); pos.fad2(vair,0);
 top y.fad1=h; bot y.fad2=max(vround 2/3[h,x_height],y$r+o+.5tiny);
 filldraw stroke z.fad1e--z.fad2e; fi  % diagonal
penlabels(fad1,fad2); enddef;

dot_diam# := max(dot_size#,cap_curve#);
beith_h := oct"166";            Beith_h := oct"126";
coll_h := oct"153";             Coll_h := oct"113";
dair_h := oct"152";             Dair_h := oct"112";
fearn_h := oct"161";            Fearn_h := oct"121";
gort_h := oct"171";             Gort_h := oct"131";
muin_h := oct"167";             Muin_h := oct"127";
peith_bhog_h := oct"040";       Peith_Bhog_h := oct"000";
sail_h := oct"172";             Sail_h := oct"132";
teine_h := oct"170";            Teine_h := oct"130";
agus_lig := oct"031";

def gen_ponc (expr meawn) =
pickup tiny.nib; pos.ponc1(dot_diam,0); pos.ponc2(dot_diam,90);
x.ponc1=x.ponc2=meawn;
top y.ponc2r=h+1;
if bot y.ponc2l<x_height+o+slab:
  y.ponc2l:=min(y.ponc2r-eps,x_height+o+slab+.5tiny); fi
y.ponc1=.5[y.ponc2l,y.ponc2r]; dot(ponc1,ponc2);  % dot
penlabels(ponc1,ponc2); enddef;

cmchar "Dot accent";
numeric dot_diam#; dot_diam#=max(dot_size#,cap_curve#);
beginchar(oct"032",5u#,min(old_asc_height#,10/7x_height#+.5dot_diam#),0);
define_whole_blacker_pixels(dot_diam);
italcorr h#*slant+.5dot_diam#-2u#;
adjust_fit(0,0); gen_ponc (.5w); endchar;

def aspirate(suffix $) = gen_ponc (x$); enddef;

def trasnawn(suffix $,@)(expr jut) =
 pickup crisp.nib; pos@1(hround(hair-stem_corr),0); pos@2(bar,90);
 lft x@0=lft x@1l=tiny.lft x$l; top y@1=tiny.top y$r;
 lft x@2=lft x@0-jut; y@2r=y@1-serif_drop;
 y@0=y@2l-bracket-eps;
 if serif_drop>0: erase fill z@1--top z@1
   --(x@2r,top y@1)--z@2r--cycle; fi % erase excess at top
 filldraw z@1l{down}...{left}z@2r--z@2l{right}
  ...1/3[(x@0,y@2l),.5[z@2l,z@0] ]{z@0-z@2l}
  ...{down}z@0--(x@1,y@0)--cycle;  % sloped serif
 z@3=(tiny.rt x$r,y@2);
 erase fill top z@1r{right}...(x@3,y@2){down}--(x@3,top y@1r)--cycle;
 labels(@0,@1,@2,@3); enddef;

def guta_beag (expr ainm, achar) (suffix $) =
 scantokens("cmchar") ainm;
 beginchar (substring (0,1) of ainm, achar, x_height#, 0);
  gen_letter;
 endchar;
 scantokens("cmchar") (ainm & " fada");
 beginchar (scantokens (ainm & "_fada"),
   achar, min(old_asc_height#,2x_height#), 0);
  gen_letter; fada ($);
 endchar;
enddef;

def guta_mowr (expr ainm, achar) (suffix $) =
 scantokens("cmchar") ainm;
 beginchar (substring (0,1) of ainm, achar, cap_height#, 0);
  gen_letter;
 endchar;
 scantokens("cmchar") (ainm & " fada");
 beginchar (scantokens (ainm & "_fada")-guta_offset,
   achar, cap_asc_height#, 0);
  gen_letter; fada ($);
 endchar;
enddef;

def consan_beag (expr ainm, achar, doimh) (suffix $) =
 scantokens("cmchar") ainm;
 beginchar (substring (0,1) of ainm, achar, x_height#, doimh);
  gen_letter;
 endchar;
 scantokens("cmchar") (ainm & " haitch");
 beginchar (scantokens (ainm & "_h"), achar,
   min(old_asc_height#,10/7x_height#+.5dot_diam#), doimh);
  gen_letter; aspirate ($);
 endchar;
enddef;

def consan_mowr (expr ainm, achar, doimh) (suffix $) =
 scantokens("cmchar") ainm;
 beginchar (substring (0,1) of ainm, achar, cap_height#, doimh);
  gen_letter;
 endchar;
 scantokens("cmchar") (ainm & " haitch");
 beginchar (scantokens (ainm & "_h"), achar, cap_asc_height#, doimh);
  gen_letter; aspirate ($);
 endchar;
enddef;

cmchar "agus";
beginchar(agus_lig,8u#,x_height#,desc_depth#);
italcorr x_height#*slant;
adjust_fit(0,0);
numeric arm_thickness, bot_width, top_shift, top_hair;
if hefty: arm_thickness=Vround(slab+2stem_corr); top_shift=0;
 bot_width=hround .51[curve,cap_curve]; top_hair=.4[thin_join,bot_width];
else: arm_thickness=Vround .4[stem,cap_stem]; top_shift=.5u;
 bot_width=flare; top_hair=cap_hair; fi
if top_hair<tiny.breadth: top_hair:=tiny.breadth; fi
pickup crisp.nib;
if arm_thickness<=2currentbreadth: arm_thickness:=2currentbreadth+eps; fi
pos2(.5arm_thickness,90); pos1(arm_thickness,70);
top y1r=top y2r=h; rt x2=hround(w-.75u+top_shift);
lft x1r=hround(.75u+.5top_shift);
filldraw stroke z1e{x2l-x1r,2(y2l-y1r)} .. z2e;
penpos2'(2epsilon,-90); z2'=z2r;
pickup tiny.nib; pos4(top_hair,0);
bot y4=max(h-arm_thickness,h-slab,bot y2l); rt x4r=crisp.rt x2;
pos5(top_hair,0); y5=-d; lft x5l=hround(5.5u+top_shift-.5top_hair);
if hefty: erase fill rt z4r--z4r...{down}z5r
  --(rt x4r,y5)--cycle;  % erase excess at top
 filldraw stroke z4e...{down}z5e;  % stroke
else:
 erase fill rt z4r--z4r--z5r--(rt x4r,y5)--cycle;  % erase excess at top
 filldraw stroke z4e---z5e; fi  % stroke
penlabels(1,2,4,5); endchar;

