%D \module
%D   [       file=font-lib,
%D        version=2011.01.13, % (copied fron font-ini)
%D          title=\CONTEXT\ Font Macros,
%D       subtitle=Libraries,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Font Macros / Libraries}

\unprotect

\newinteger\scaledfontmode
\newinteger\scaledfontsize
\newinteger\lastfontid

\newinteger\c_font_future_glyph_scale
\newinteger\c_font_scaled_font_mode_saved
\newinteger\c_font_scaled_points

\ifdefined\globalbodyfontsize \else \newdimension\globalbodyfontsize \fi
\ifdefined\localbodyfontsize  \else \newdimension\localbodyfontsize  \fi
\ifdefined\bodyfontsize       \else \newdimension\bodyfontsize       \fi

\registerctxluafile{font-ini}{autosuffix}
\registerctxluafile{font-log}{}
\registerctxluafile{font-con}{autosuffix} % kind of early
%registerctxluafile{font-cft}{}
\registerctxluafile{font-enc}{}
\registerctxluafile{font-fmp}{autosuffix}
\registerctxluafile{font-agl}{}           % if needed we can comment this and delay loading
\registerctxluafile{font-cid}{}           % cid maps
\registerctxluafile{font-map}{}

% helpers

\registerctxluafile{font-otr}{}           % opentype fontloader
\registerctxluafile{font-web}{}           % opentype fontloader
\registerctxluafile{font-cff}{autosuffix} % quadratic outlines
\registerctxluafile{font-ttf}{autosuffix} % cubic outlines
\registerctxluafile{font-dsp}{autosuffix}
\registerctxluafile{font-hsh}{autosuffix} % hashes used by context
\registerctxluafile{font-vfc}{autosuffix}
\registerctxluafile{font-prv}{}           % needs hashes
\registerctxluafile{font-vir}{}
\registerctxluafile{font-nod}{}
\registerctxluafile{font-oti}{}           % otf initialization
\registerctxluafile{font-ott}{}           % otf tables (first)
\registerctxluafile{font-otl}{autosuffix}
\registerctxluafile{font-oto}{autosuffix}
\registerctxluafile{font-otj}{autosuffix}
\registerctxluafile{font-oup}{autosuffix}
\registerctxluafile{font-ota}{autosuffix}
% \doifelsefileexists{font-ots-new.lmt} {
%     \registerctxluafile{font-ots-new}{autosuffix}
% } {
\registerctxluafile{font-ots}{autosuffix}
% }
\registerctxluafile{font-otd}{autosuffix}
\registerctxluafile{font-otc}{}
\registerctxluafile{font-oth}{}
% \doifelsefileexists{font-osd-new.lmt}{
%     \registerctxluafile{font-osd-new}{autosuffix}
% } {
    \registerctxluafile{font-osd}{}
% }
%registerctxluafile{font-osm}{}
\registerctxluafile{font-ogr}{autosuffix}

% we use otf code for type one

\registerctxluafile{font-onr}{autosuffix}
\registerctxluafile{font-one}{autosuffix}
\registerctxluafile{font-afk}{}

\registerctxluafile{font-txt}{autosuffix}

% tfm

\registerctxluafile{font-tpk}{autosuffix}
\registerctxluafile{font-tfm}{autosuffix}

% name database

\registerctxluafile{font-syn}{}
\registerctxluafile{font-trt}{}

% shapes

\registerctxluafile{font-shp}{autosuffix}

% so far

\registerctxluafile{font-pat}{} % patchers

\registerctxluafile{node-fnt}{autosuffix} % here

\registerctxluafile{font-lua}{}

\registerctxluafile{font-enh}{autosuffix}

\registerctxluafile{good-ini}{}
\registerctxluafile{good-gen}{autosuffix}
\registerctxluafile{good-ctx}{}
\registerctxluafile{good-mth}{autosuffix}

\registerctxluafile{font-def}{autosuffix}
\registerctxluafile{font-ctx}{autosuffix} % after def as it overloads

% extensions, order matters

\registerctxluafile{font-imp-checks}{autosuffix}
\registerctxluafile{font-imp-ligatures}{autosuffix}
\registerctxluafile{font-imp-tex}{}
\registerctxluafile{font-imp-reorder}{}
\registerctxluafile{font-imp-properties}{autosuffix}
\registerctxluafile{font-imp-unicode}{}
\registerctxluafile{font-imp-text}{autosuffix}
\registerctxluafile{font-imp-math}{autosuffix}
\registerctxluafile{font-imp-notused}{}
\registerctxluafile{font-imp-effects}{autosuffix}
\registerctxluafile{font-imp-quality}{autosuffix}
\registerctxluafile{font-imp-italics}{autosuffix}
\registerctxluafile{font-imp-dimensions}{}
\registerctxluafile{font-imp-spacekerns}{}
\registerctxluafile{font-imp-tweaks}{}
\registerctxluafile{font-imp-combining}{}
\registerctxluafile{font-imp-scripts}{autosuffix}
\registerctxluafile{font-imp-sanitize}{autosuffix} % fixes for indic fonts
\registerctxluafile{font-imp-digits}{autosuffix}
\registerctxluafile{font-imp-compound}{autosuffix}

\registerctxluafile{font-imp-tracing}{autosuffix} % comes last!

\registerctxluafile{font-fbk}{autosuffix}

\registerctxluafile{font-aux}{}

\registerctxluafile{font-lig}{autosuffix} % only for experiments so try to avoid it

%D Some low level helpers
%D
%D \starttyping
%D \def\TestLookup#specification%
%D   {\dolookupfontbyspec{#specification}
%D     pattern: #specification, found: \dolookupnoffound
%D    \blank
%D    \dorecurse {\dolookupnoffound} {%
%D      \recurselevel:~\dolookupgetkeyofindex{fontname}{\recurselevel}\quad
%D    }%
%D    \blank}
%D
%D \TestLookup{familyname=helveticaneue}
%D \TestLookup{familyname=helveticaneue,weight=bold}
%D \TestLookup{familyname=helveticaneue,weight=bold,style=italic}
%D \stoptyping

%D We can also move the lookups to the fonts.namespace (of commands) one can also
%D directly use the clf calls when speed is needed.

% todo: public implementors:

\permanent          \def\dolookupfontbyspec     #1{\clf_fontlookupinitialize{#1}}
\permanent          \def\dolookupnoffound         {\clf_fontlookupnoffound}
\permanent          \def\dolookupgetkeyofindex#1#2{\clf_fontlookupgetkeyofindex{#1}{#2}}
\permanent          \def\dolookupgetkey         #1{\clf_fontlookupgetkey{#1}}
\permanent          \def\cleanfontname          #1{\clf_cleanfontname{#1}}
\permanent\protected\def\setfontofid            #1{\clf_setfontofid{#1}}

%D I have to put it someplace, so here:
%D
%D \starttyping
%D     \definefontfeature[test][mode=plug,features=text]
%D     \definefont[FontA][Serif*test]
%D     \definefont[FontB][Serif*test]
%D     {\FontA aaa}{\FontB\glyphscale 1200  bbb}
%D     {\FontA aaa}{\FontB\glyphscale 1200  bbb}
%D \stoptyping

\protect \endinput
