% This file defines the Metafont macros for producing fonts copto and copti:
%copto ir "ordinary Coptic" and copti is "inclined Coptic".
%
% {limn output Sep 24 17:59:49 1995 from imageto output Sep 24 16:54:15 1995}
% Generated Tue Dec 31 14:44:16 1996.
% The original files were prepared by S. Rosmorduc in 1995; the necessity of
% making postscrip outlines (with mftrace and pfaedit) and of extending the set of glyphs
% with new signs required some modifications and a reorganization of the orignial material.
%
% The modifications were made by Claudio Beccari on Aug 3, 2004; the font and file names
% were changed according to the prescriptions of the GNU GPL; see below.
%
% The bundle contains the files copto.mf, copti.mf and coptbase.mf and
% the derived files which are: copto.tfm, copto.pk, copti.tfm, copti.pk (or whatelse
% the local METAFONT generating process calls the pk files, for example copto.600pk),
% and copto.pfb, copti.pfb; there is also a LaTeXe font definition file lcopcoptic.fd where
% the COP LaTeX encoding is defined and a coptic.sty extension package where some macros
% are defined for using inline Coptic script as well as displayed Coptic text with
% the facilities needed for some philological markup; such information was given by
% Cristiano Pulone.
%
% There is no encoding file and the pfb fonts are usable only under (La)TeX and
% pdf(la)tex and their drivers for producing postscript output or pdf output.
%
%
% There is no maintainer
%
% This font is in the public domain under the conditions of the GNU General Public Licence.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 1992 Free Software Foundation, Inc.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% |true_design_size| is supposed to be the design size of the original font.
% If the user does not set |designsize| on the command line, we default to the following.

true_design_size# := 10.000pt#;
default_design_size# := 10pt#;
if designsize = 0: designsize := default_design_size#; fi;

% Actually the font might be declared to be 12pt, but the inner workings set up
% by S. Rosmorduc make it difficult to simply change the true_ and the default_
% design sizes so as to produce a real 12pt font. I (CB) let it stand this way
% because the blacker design and the larger x-heigh make the Coptic script stand
% out in evidence both along the lines maily written in Latin characters
% and as displayed material.

% It's pointless to actually produce different TFM files for different
% design sizes: we have only one set of outlines, after all.  So we
% adjust the resolution to account for different sizes, by setting
% |mag|.  Then we reset |designsize| to the default.

if unknown mag: mag := 1; fi; mag := mag * designsize / default_design_size#;

% So we can produce output at varying sizes, all our dimensions are
% output in terms of the ad hoc parameter |u|.
%
u# := default_design_size# / true_design_size#;

designsize := default_design_size#;

% Macros from page 289 of {\sl The Metafontbook} for short-circuit evaluation.
%
def cand (text q) = startif true q else: false fi enddef;
def cor (text q) = startif true true else: q fi enddef;
tertiarydef p startif true = if p: enddef;

% The proof resolution of 2601.72 pixels per inch established by plain
% \MF\ does not always work, because the characters might be too large
% (or small, for that matter) for the paper size.  So, here we change
% the proof resolution to fit the design size of the font into
% |proof_size| inches.  To do this, we must know the resolution of the
% device the proof output will be printed on; we make |proof_resolution|
% default to 300.
%
if unknown mode cor ((mode = proof) or (mode = smoke)):
 % Given in inches:
 if unknown proof_size: proof_size := 4.982; fi;% era 7, ma veniva una dimensione strana e diversa da 2602 che e' il valore di default.

 % Given in pixels per inch:
 if unknown proof_resolution: proof_resolution := 300; fi;

 % Set up the new mode to be the same as the old one, except for the
 % resolution.
 original_mode := if known mode: mode else: proof fi;
 mode_def bzr_proof_mode =
   if original_mode = proof:
     proof_;
   else:
     smoke_;
   fi;
   pixels_per_inch
     := (proof_size * proof_resolution)
        * (72.27 / proof_resolution)
        * (72.27 / designsize);
        proofing:=3;
        let makebox=maketicks;
 enddef;
 mode := bzr_proof_mode;
fi;

% Set up the device values for this run.  Since we allow a nonstandard
% value of |proofing| (see below), we must save its value, if it has
% already been assigned.
%
if (known proofing) cand (proofing > 2):
 save_proofing := proofing;
fi


mode_setup;

if known save_proofing:
 proofing := save_proofing;
fi;


% We can't define the pixel-oriented version of |u| until after
% |mode_setup| has been called.

define_pixels (u);

ascender_height:=9.45u; ascender_height#:=9.45u#;
x_height:=5.6u; x_height#:=5.6u#;
descender_depth:=2u; descender_depth#:=2u#;

% Use a font that blends better with the \MF\ logo for the title line.
%
special "titlefont cmss8";

% If we are doing smoke proofs, put the character at its actual size on
% the output; if we're doing gray proofs, use a smaller font for the
% labels.
%

% Produce a |makelabel| command for each |z| point in |point_list| and
% each suffix in |suffixes|.
%
def general_label (text point_list, suffixes) =
 forsuffixes point_suffix = ,suffixes:
   forsuffixes point = point_list:
     % Unfortunately, the way in which the |str| operator formats its
     % argument (which is an arbitrary suffix) cannot be changed, so
     % the proofsheets end up showing "0 0" for the variable |z[0][0]|.
     makelabel (str point.point_suffix, z.point.point_suffix);
   endfor
 endfor
enddef;

% Define our labels for the proofsheets.  The person running Metafont
% can also see the control points on each spline, by setting
% |proofing>2| at the beginning.  (The {\tt plain.mf} macros only
% distinguish between |proofing=0|, |proofing>0| and |proofing>1|, so we
% are not disturbing them.)
%
def proof_labels (text t) =
 % We need to delimit the arguments here, so \MF\ knows where the
 % second |text| argument begins.  Our output uses the suffix |"s"| for
 % startpoints of segments, and the suffixes |"c1"| and |"c2"| for
 % control points.
 if proofing > 1: general_label (t) (s); fi;
 if proofing > 2: general_label (t) (c1,c2); fi;
enddef;


% We define our characters as filled outlines; page 206 of {\sl The
% Metafontbook} suggests disabling \MF's |autorounding| and
% |smoothing| features in that case.
%
autorounding := 0; % 0 avant pour les deux!
smoothing := 0;

% Sometimes we want to fill our paths, other times unfill them,
% depending on whether the winding number is positive or negative.  We
% could be absolutely safe here, and declare |temp_path| inside a group,
% at every invocation of |fill_or_unfill|; but this would waste time and
% space to no advantage, since we know exactly what kind of \MF\
% programs we output, and the variable |temp_path| is not used in them.
%
% Incidentally, we need a variable in the first place only because it is more
% efficient to avoid evaluating long paths more than once.
%
path temp_path;

def fill_or_unfill expr p =
 temp_path := p;
 if turningnumber temp_path > 0: fill else: unfill fi temp_path;
enddef;

% Since we can assume the font fills all cycles counterclockwise
% (because PostScript requires this), we want to disable the
% |turningnumber| checking which generates the `Strange path' errors.
% See p.112 and p.119 of the Metafontbook.
%
% (By the way, setting |turningcheck := 0| makes Metafont always use the
% filling rule for positive turning number, i.e., always |fill| and
% never |unfill|.  When would this be useful?)
%
turningcheck := 1;

% When we don't know the dimensions of the character we're defining
% before we define it, we have to use these to begin it:
def begin_no_dimen_char (expr c) =
 begingroup
 transform save_currenttransform;
 save_currenttransform := currenttransform;
 charcode:=if known c: byte c else: 0 fi;
 charic:=0; clearxy; clearit; clearpen; scantokens extra_beginchar;
enddef;

def end_no_dimen_char =
 currenttransform := save_currenttransform;
 endchar;
enddef;

% When use the above to start a character, must call this before `endchar'.
%
def set_char_dimens (expr w_sharp,h_sharp,d_sharp) =
charwd:=w_sharp;      charht:=h_sharp;       chardp:=d_sharp;
w:=hround(charwd*hppp); h:=vround(charht*hppp); d:=vround(chardp*hppp);
enddef;

% Move by shifting the current transform matrix.
%
def move (expr h_amount, v_amount) =
 currenttransform := currenttransform shifted (h_amount, v_amount);
enddef;

def hmove (expr amount) = move (amount, 0); enddef;
def vmove (expr amount) = move (0, amount); enddef;
def depart= 0; enddef;


transform modif; modif := identity;

% Definizione della currenttransform in cmbase.mf
%  currenttransform:=identity slanted slant
%   yscaled aspect_ratio scaled granularity;



%% Patch to get a better letter spacing.
extra_space_after:=0.9u#;

def beginchar(expr c,w_sharp,h_sharp,d_sharp) =
begingroup
charcode:=c + depart;
charwd:=w_sharp + extra_space_after;
charht:=h_sharp;       chardp:=d_sharp;
italcorr h_sharp-.5u#;
w:=hround(charwd*hppp); h:=vround(charht*hppp); d:=vround(chardp*hppp);
charic:=0; clearxy; clearit; clearpen; scantokens extra_beginchar;
transform save_currenttransform;
save_currenttransform= currenttransform;
currenttransform:= currenttransform transformed modif;
enddef;

def endchar =
scantokens extra_endchar;
if proofing>0: makebox(proofrule); fi
chardx:=w;     % desired width of the character in pixels
shipit;
if displaying>0: makebox(screenrule); showit; fi
currenttransform:= save_currenttransform;
endgroup enddef;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
font_coding_scheme := "# encoding for coptic font ";
font_identifier := "copto";