%
% lycyracc.mf
%
%% Cyrillic font container with T2 encoding beta-support
%
% This file is future part of lxfonts package
% Version 3.4 // Patchlevel=0
% (c) O.Lapko
%
% This package belongs to the public domain under conditions similar to
% those of D. E. Knuth specified for the Computer Modern family of fonts.
% In particular, only the authors are entitled to modify this file
% and to save it under the same name.
%
% Content:
%
% accents from txaccent.mf (tc fonts) + Cyrillic accents
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Accents for capital letters
%

LHver_check(3,4); % like |version_check| in ec

% A dirty trick, better left unseen. |cap_height| and |cap_height#|
% are restored at the end of this file.

numeric saved_cap_height#; saved_cap_height#=cap_height#;
cap_height#:=hi.x_height#;
numeric saved_cap_height; saved_cap_height=cap_height;
cap_height:=hi.x_height;

%turn for this file: is_cap toggled by this value
cyrcaph:=true;

lhchar"Grave accent";
cyrchar_twice(Agrave,9u#,x_height#,0); % |put_gravis| changes the height
adjust_fit(0,0);
put_gravis;
repeat_once;
endchar;

lhchar"Acute accent"; % using acute from plfonts
cyrchar_twice(Aacute,9u#,x_height#,0); % |put_accent| changes the height
italcorr h#*slant-if serifs: 1.5 fi u#;
adjust_fit(0,0);
put_accent;
repeat_once;
endchar;

lhchar"Circumflex (hat) accent";
cyrchar(Ahat,9u#,cap_accent_height#,0);
if serifs: italcorr .5[x_height#,h#]*slant+.5hair#-1.75u#;
else: italcorr 2/3[x_height#,h#]*slant-.5stem#+.5vair#-.75u#;
fi
adjust_fit(0,0);
uppercase_hat(.5w,0,1,2,3,4,5);
penlabels(1,2,3,4,5); endchar;

lhchar"Tilde (squiggle) accent";
cyrchar(Atilde,9u#,cap_accent_height#,0);
italcorr h#*slant-u#;
adjust_fit(0,0);
uppercase_tilde(0,0,1,2,3,4,5);
penlabels(1,2,3,4,5); endchar;

lhchar"Umlaut (double dot) accent";
cyrchar(Aumlaut,9u#,cap_accent_height#,0);
adjust_fit(0,0);
uppercase_umlaut(0,0,1,2,3,4);
penlabels(1,2,3,4); endchar;

lhchar"Double acute accent (Long Hungarian umlaut accent)";
cyrchar_twice(Aacute_dbl,9u#,min(asc_height#,2x_height#),0);
italcorr h#*slant-u#;
adjust_fit(0,0);
if monospace: hpos_corr=-2u; put_accent; hpos_corr=2u; put_accent;
else: hpos_corr=-1.5u; put_accent; hpos_corr=1.5u; put_accent; fi
repeat_once;
endchar;

lhchar"Scandinavian circle accent";
cyrchar(Aring,13u#+.5width_adj#,cap_accent_height#,0);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
y[-1]= cap_height+if hefty: .5 fi accent_gap;
uppercase_circle(.5w,y[-1],1,2,3,4);
penlabels(1,2,3,4); endchar;

lhchar"Hachek (check) accent";
cyrchar(Ahachek,9u#,cap_accent_height#,0);
adjust_fit(0,0);
uc_hachek_accent(.5w);
endchar;

lhchar"Breve accent";
cyrchar(Abreve,9u#,cap_accent_height#,0);
italcorr h#*slant+.5vair#-1.5u#;
adjust_fit(0,0);
uppercase_breve(.5w,0,1,2,3);
penlabels(1,2,3); endchar;

lhchar"Macron (bar) accent";
numeric macron_breadth#; macron_breadth#=.2[vair#,stem#];
cyrchar(Abar,9u#,cap_accent_height#,0);
italcorr h#*slant-.75u#;
adjust_fit(0,0);
numeric macron_breadth; macron_breadth:=Vround .2[vair,stem];
pickup if serifs: crisp.nib else: fine.nib fi;
pos1(macron_breadth,90); pos2(macron_breadth,90);
top y1r=top y2r=h+o; lft x1=w-rt x2=hround 1.25u;
filldraw stroke z1e--z2e;  % bar
penlabels(1,2); endchar;

lhchar"Dot accent";
cyrchar_twice(Adot,5u#,x_height#,0);
adjust_fit(0,0);
put_dot(tiny,max(dot_size#,cap_curve#));
repeat_once;
endchar;

lhchar"Cedilla accent";
cyrchar(Acedilla,8u#,0,.875desc_depth#);
adjust_fit(0,0);
uppercase_cedilla(.5w,0,1,2,3,4,5);
penlabels(1,2,3,4,5); endchar;

lhchar"Ogonek";
cyrchar(Aogonek,5u#,0,desc_depth#);
italcorr 0;
adjust_fit(0,0);
%the_ogonek(.5w,0,1,2,3);
% polish-like "easy_ogonek" instead of Computer Modern "the_ogonek"
def the_pen=if known ogonek_pen: ogonek_pen
    elseif serifs: tiny elseif is_bold: fisp else: fine fi
enddef;
% |diag_end| refers to |tiny| pen, hence |tiny| in the following equation:
ogonek_pos=(.5w if not serifs: +.5stem if is_bold: +.75tiny fi\\ fi,.5the_pen)
   if serifs and not is_egyptian: +(.5xvair,0) fi;
easy_ogonek(the_pen, 1,2,3); % ogonek
penlabels(1,2,3); endchar;

%
% differs from lowercase form
%
lhchar "Cyrillic accent Ahcross - horisontal cross";
cyrchar(Ahcross,7u#,cap_height#,desc_depth#);
italcorr asc_height#*slant+.5dot_size#-2u#;
adjust_fit(0,0);
% hcross
pickup crisp.nib; numeric outer_jut;
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
pos1(bar,90); pos2(bar,90);
top y1r=top y2r=vround (.52h+.5bar)+eps;
x1=.5w-outer_jut; x2=.5w+outer_jut;
filldraw stroke z1e--z2e; % cross bar
endchar;

% differs from lowercase form
lhchar "Cyrillic accent Avcross - vertical cross";
cyrchar(Avcross,5u#,cap_height#,0);
italcorr asc_height#*slant+.5dot_size#-2u#;
adjust_fit(0,0);
% vcross
if serifs: pickup crisp.nib; else: pickup fine.nib; fi
pos1(bar,0); pos2(bar,0);
lft x1l=lft x2l=hround(.5w-.5bar);
top y2-bot y1=.5cap_height; .5[y1,y2]=.52h;
filldraw stroke z1e--z2e;
endchar;

lhchar "Cyrillic accent Aacute_cross - diagonal cross"; % cross from pl_ml (plfonts)
cyrchar_twice(Aacute_cross,7u#,cap_height#,0);
italcorr asc_height#*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#,serif_fit#);
numeric unbalance,outer_jut;
unbalance=if monospace: 1 else: 1.1 fi;
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
put_cyrcross(.5w,0,outer_jut,unbalance*outer_jut);
repeat_once;
endchar;

lhchar "Cyrillic accent Agrave_cross - diagonal cross"; % cross from pl_ml (plfonts)
cyrchar_twice(Agrave_cross,7u#,cap_height#,0);
italcorr asc_height#*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#,serif_fit#);
numeric unbalance,outer_jut;
unbalance=if monospace: 1 else: 1.1 fi;
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
put_cyrcross(.5w,0,-unbalance*outer_jut,-outer_jut);
repeat_once;
endchar;

lhchar"Cyrillic accent Agrave_dbl - double grave";
cyrchar_twice(Agrave_dbl,9u#,x_height#,0);
italcorr h#*slant-u#;
adjust_fit(0,0);
if monospace: hpos_corr=-2u; put_accent; hpos_corr=2u; put_accent;
else: hpos_corr=-1.5u; put_gravis; hpos_corr=1.5u; put_gravis; fi
repeat_once;
endchar;

lhchar "Cyrillic accent Acyrbreve - cyrillic breve";
cyrchar(Acyrbreve,9u#,cap_height#+acc_height#,0);
italcorr h#*slant+.5vair#-1.5u#;
adjust_fit(0,0);
cbreve(.5w,0, 1,2,3,4,5,6,7);
endchar;

lhchar"Cyrillic tie accent"; % centered
cyrchar(Atie,9u#,asc_height#,0);
italcorr 4/9[x_height#,asc_height#]*slant+4.5u#+2letter_fit#+.5hair#;
adjust_fit(if monospace:2u#,2u# else:serif_fit#,serif_fit# fi);
pickup fine.nib; pos1(hair,180); pos2(vround 1/5[vair,stem],90);
pos3(hair,0);
lft x1r=w-rt x3r=hround(2u-.5vair); x2=.5w;
y1=y3=4/9[x_height,asc_height]; top y2r=vround 8/9[x_height,asc_height];
filldraw stroke super_arc.e(1,2) & super_arc.e(2,3);  % arc
penlabels(1,2,3); endchar;

lhchar "Cyrillic frown accent";
cyrchar(Afrown,9u#,x_height#+acc_height#,0);
italcorr h#*slant+.5vair#-1.5u#;
adjust_fit(0,0);
%!!! uppercase_breve flipped
x_center:=.5w; y_move:=0; _one:=1; _two:=2; _three:=3;
%
pickup crisp.nib; pos[_one](vair,-180);
pos[_three](vair,0);
top y[_two]r=cap_height + acc_height;
x[_two]=hround x_center;
x[_two]-rt x[_one]l
  =(lft x[_three]l)-x[_two]
  =hround (2.5u if monospace: /expansion_factor fi -.5vair);
numeric mid_thickness;
mid_thickness=max(crisp.breadth,vround min(1/3[vair,stem],.5acc_height));%!!!
pos[_two](mid_thickness,90);
% |accent_gap| SHOULD be defined by the acute accent, before this macro runs
if unknown accent_gap: % accent_gap emulation
   if serifs:
      y[_two]'=h-.5mid_stem+eps-max(2/3[h,hi.x_height],hi.x_height+o+hair);
      accent_gap=a_ht-(y[_two]'+.5mid_stem)-hi.x_height;
   else:
      top y[_two]'=h-vround(2/3[h,hi.x_height]);
      accent_gap=a_ht-y[_two]'-hi.x_height;
   fi
fi
bot y[_one]=bot y[_three]=cap_height + if hefty: .5 fi accent_gap;
filldraw stroke z[_one]e{up}...z[_two]e{right}...
     {down}z[_three]e;  % stroke
%
penlabels(1,2,3); endchar;

lhchar "Cyrillic accent Abreve_long - long breve"; %accent width enlarged by 3u
cyrchar(Abreve_long,12u#,x_height#+acc_height#,0);
italcorr h#*slant+.5vair#-1.5u#;
adjust_fit(0,0);
x_center:=.5w; y_move:=0;
_one:=1; _two:=2; _three:=3;
pickup crisp.nib; pos[_one](vair,-180);
pos[_three](vair,0);
top y[_one]=top y[_three]=h;
x[_two]=x_center;
lft x[_one]r=hround(x[_two]-4.75u%!2.5u
   if monospace: /expansion_factor fi -0.5vair);
rt x[_three]r=hround(x[_two]+4.75u%!2.5u
   if monospace: /expansion_factor fi +0.5vair);
numeric mid_thickness; mid_thickness=vround 1/3[vair,stem];
pos[_two](mid_thickness,-90);
bot y[_two]r=
   vround max(x_height+o+tiny,1/3[x_height,h]+o-.5mid_thickness);
filldraw stroke z[_one]e{down}...
         z[_two]e{right}...{up}z[_three]e;  % stroke
endchar;

lhchar "Cyrillic accent Abar_long - long bar"; %accent width enlarged by 3u
cyrchar(Abar_long,12u#,lc_trema_height#,0);
italcorr h#*slant-.75u#;
adjust_fit(0,0);
numeric macron_breadth; macron_breadth:=Vround .2[vair,stem];
pickup if serifs: crisp.nib else: fine.nib fi;
pos1(macron_breadth,90); pos2(macron_breadth,90);
top y1r=top y2r=h+o; lft x1=w-rt x2=hround .5u;%!1.25u
filldraw stroke z1e--z2e;  % bar
penlabels(1,2); endchar;

%
% outsiders
%

lhchar "Cyrillic accent Adesc_up - uppercase descender";
cyrchar(Adesc_up,5u#,pdot_diam#,cap_sbeak#);
adjust_fit(0,cap_serif_fit#);
pickup tiny.nib;
pos1(cap_stem,0); pos2(cap_stem,0);
rt x1r=rt x2r=w-hround max(2u,3u-.5cap_stem);
top y1=h; bot y2=0;
inner_jut:=.5cap_stem+eps;
save bracket; bracket:=0;
numeric left_jut;
left_jut=if serifs:
	    max(limit_dist,if monospace: 1.414cap_jut else: 1.1cap_jut fi)
	 else: hround (r-rt x2r-.65u) fi;
cyr_serif(2,1,a,1/3,beak_darkness,left_jut,beak_jut); % right descender
endchar;

% Restore original values of |cap_height| and |cap_height#|
cap_height:=saved_cap_height; numeric saved_cap_height;
cap_height#:=saved_cap_height#; numeric saved_cap_height#;

cyrcaph:=false; %turned back

endinput;
%end of file
