%D \module
%D   [       file=type-imp-cambria,
%D        version=2007.07.30,
%D          title=\CONTEXT\ Typescript Macros,
%D       subtitle=Microsoft Cambria,
%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.

%D We use Dejavu as it covers wider range of monospaced glyphs.

\loadtypescriptfile[dejavu]

\startluacode
 -- if CONTEXTLMTXMODE and CONTEXTLMTXMODE > 0 then
        fonts.handlers.otf.addfeature {
            name  = "frac",
            type  = "substitution",
            files = {
                "cambria.ttc"
            },
            data  = {
                [0x2044] = 0x2215,
                [0x2215] = 0x2044,
            }
        }
 -- end
\stopluacode

\starttypescriptcollection[cambria]

    % \setupmathradical[\c!leftmargin=.05mq,\c!mindepth=.05mx]%

    \pushglobalsetups
        \startsetups[\s!math:cambria]
            \setmathradicalparameter\c!leftmargin{.05mq}%
            \setmathradicalparameter\c!mindepth  {.05mx}%
        \stopsetups
    \popglobalsetups

    % microsoft: cambria.ttc  cambria.ttc cambriab.ttf cambriai.ttf cambriaz.ttf
    % ascender : cambmath.ttf cambria.ttf cambriab.ttf cambriai.ttf cambriaz.ttf

    \doifunknownfontfeature {cambria-math-bold} {\definefontfeature[cambria-math-bold][boldened]}

    \starttypescript [\s!math] [cambria,cambria-nt]
        \checkedmapfontsize[\typescripttwo][\s!script]      [.73]
        \checkedmapfontsize[\typescripttwo][\s!scriptscript][.60]
    \stoptypescript

    \starttypescript [\s!math,\s!serif] [cambria,cambria-nt]
        \doifelsefile{cambria.ttc} {
            % microsoft cabria
            \definefontsynonym [CambriaMath]  [\s!file:cambria.ttc(Cambria Math)]
            \definefontsynonym [CambriaSerif] [\s!file:cambria.ttc(Cambria)]
        } {
            % ascender cambria
            \definefontsynonym [CambriaMath]  [\s!file:cambmath.ttf]
            \definefontsynonym [CambriaSerif] [\s!file:cambria.ttf]
        }
        \definefontsynonym [CambriaSerifBold]       [\s!file:cambriab.ttf]
        \definefontsynonym [CambriaSerifItalic]     [\s!file:cambriai.ttf]
        \definefontsynonym [CambriaSerifBoldItalic] [\s!file:cambriaz.ttf]
    \stoptypescript

    \starttypescript [\s!math] [cambria] [\s!name]
        \loadfontgoodies[cambria-math]
        \definefontsynonym [\s!MathRoman]     [CambriaMath] [\s!features={\s!math\mathsizesuffix,cambria:mathextra,mathextra},\s!goodies=cambria-math]
        \definefontsynonym [\s!MathRomanBold] [CambriaMath] [\s!features={\s!math\mathsizesuffix,cambria-math-bold,cambria:mathextra,mathextra},\s!goodies=cambria-math]
    \stoptypescript

    \starttypescript [\s!math] [cambria-nt] [\s!name]
        \loadfontgoodies[cambria-math]
        \definefontsynonym [\s!MathRoman]     [CambriaMath] [\s!features={\s!math\mathsizesuffix,cambria:mathextra,mathextra}]
        \definefontsynonym [\s!MathRomanBold] [CambriaMath] [\s!features={\s!math\mathsizesuffix,cambria-math-bold,cambria:mathextra,mathextra}]
    \stoptypescript

    \starttypescript [\s!serif] [cambria,cambria-nt] [\s!name]
        \setups[\s!font:\s!fallback:\s!serif]
        \definefontsynonym [\s!Serif]           [CambriaSerif]           [\s!features=\s!default,\s!goodies=cambria]
        \definefontsynonym [\s!SerifBold]       [CambriaSerifBold]       [\s!features=\s!default,\s!goodies=cambria]
        \definefontsynonym [\s!SerifItalic]     [CambriaSerifItalic]     [\s!features=\s!default,\s!goodies=cambria]
        \definefontsynonym [\s!SerifBoldItalic] [CambriaSerifBoldItalic] [\s!features=\s!default,\s!goodies=cambria]
    \stoptypescript

    \starttypescript [cambria,cambria-nt]
        \definetypeface [\typescriptone] [\s!rm] [\s!serif] [cambria]        [\s!default]
        \definetypeface [\typescriptone] [\s!ss] [\s!sans]  [dejavu]         [\s!default]
        \definetypeface [\typescriptone] [\s!tt] [\s!mono]  [dejavu]         [\s!default]
        \definetypeface [\typescriptone] [\s!mm] [\s!math]  [\typescriptone] [\s!default]
    \stoptypescript

\stoptypescriptcollection
