%D \module
%D   [       file=type-imp-vraille,
%D        version=2021.11.17,
%D          title=\CONTEXT\ Typescript Macros,
%D       subtitle=Braille (using Dejavu fonts),
%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.

\continuewhenlmtxmode

%D There is no need to waste money on a commercial braille font if we have dejavu. After
%D all it's just dots. We also don't need features.

\registerctxluafile{font-imp-braille}{autosuffix}

% todo : not fallback, just replace directly .. special case anyway .. now inefficient and slow

\starttypescriptcollection[braille]

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

    \definefontfeature[brailletext]  [braille=text]    % no ligatures, no kerning etc
    \definefontfeature[braillemath]  [braille=math]    % no ligatures, no kerning etc
    \definefontfeature[serifbraille] [features=none]   % no ligatures, no kerning etc
    \definefontfeature[sansbraille]  [features=none]   % no ligatures, no kerning etc
    \definefontfeature[monobraille]  [features=none]   % no ligatures, no kerning etc
    \definefontfeature[mathbraille]  [features=none]   % [compactmath=yes] % no ssty so compact anyway

    % Maybe some day sans and mono will also have braille but it doesn't really matter because we
    % don't really need sans and for mono we only need the fixed spacing.

    \definefontfallback[BrailleMono] [\s!name:dejavuserif*brailletext][0x0000-0x1FFFF][force=yes]
    \definefontfallback[BrailleSerif][\s!name:dejavuserif*brailletext][0x0000-0x1FFFF][force=yes]
    \definefontfallback[BrailleSans] [\s!name:dejavuserif*brailletext][0x0000-0x1FFFF][force=yes]
   %\definefontfallback[BrailleMath] [\s!name:dejavuserif*braillemath][0x0000-0x1FFFF][force=yes]

    \definefontfallback[BrailleMonoBold] [\s!name:dejavuserifbold*brailletext][0x0000-0x1FFFF][force=yes]
    \definefontfallback[BrailleSerifBold][\s!name:dejavuserifbold*brailletext][0x0000-0x1FFFF][force=yes]
    \definefontfallback[BrailleSansBold] [\s!name:dejavuserifbold*brailletext][0x0000-0x1FFFF][force=yes]

    \starttypescript [\s!serif] [braille] [\s!name]
        \definefontsynonym [\s!Serif]           [\s!name:dejavuserif]    [\s!features=serifbraille,\s!fallbacks=BrailleSerif]
        \definefontsynonym [\s!SerifBold]       [\s!name:dejavuserifbold][\s!features=serifbraille,\s!fallbacks=BrailleSerifBold]
        \definefontsynonym [\s!SerifItalic]     [\s!Serif]
        \definefontsynonym [\s!SerifBoldItalic] [\s!SerifBold]
        \definefontsynonym [\s!SerifSlanted]    [\s!Serif]
        \definefontsynonym [\s!SerifBoldSlanted][\s!SerifBold]
    \stoptypescript

    \starttypescript [\s!sans] [braille] [\s!name]
        \definefontsynonym [\s!Sans]           [\s!name:dejavusans]    [\s!features=sansbraille,\s!fallbacks=BrailleSans]
        \definefontsynonym [\s!SansBold]       [\s!name:dejavusansbold][\s!features=sansbraille,\s!fallbacks=BrailleSansBold]
        \definefontsynonym [\s!SansItalic]     [\s!Sans]
        \definefontsynonym [\s!SansBoldItalic] [\s!SansBold]
        \definefontsynonym [\s!SansSlanted]    [\s!Sans]
        \definefontsynonym [\s!SansBoldSlanted][\s!SansBold]
    \stoptypescript

    \starttypescript [\s!mono] [braille] [\s!name]
        \definefontsynonym [\s!Mono]           [\s!name:dejavusansmono]    [\s!features=monobraille,\s!fallbacks=BrailleMono]
        \definefontsynonym [\s!MonoBold]       [\s!name:dejavusansmonobold][\s!features=monobraille,\s!fallbacks=BrailleMonoBold]
        \definefontsynonym [\s!MonoItalic]     [\s!Mono]
        \definefontsynonym [\s!MonoBoldItalic] [\s!MonoBold]
        \definefontsynonym [\s!MonoSlanted]    [\s!Mono]
        \definefontsynonym [\s!MonoBoldSlanted][\s!MonoBold]
    \stoptypescript

    \starttypescript [\s!math][braille] [\s!name]
        \loadfontgoodies[dejavu-math]
       %\definefontsynonym[\s!MathRoman]    [\s!file:texgyredejavu-math][\s!features={mathbraille,\s!math\mathsizesuffix},\s!fallbacks=BrailleMath]
       %\definefontsynonym[\s!MathRomanBold][\s!file:texgyredejavu-math][\s!features={mathbraille,\s!math\mathsizesuffix,dejavu-math-bold},\s!fallbacks=BrailleMath]
        \definefontsynonym[\s!MathRoman]    [\s!file:texgyredejavu-math][\s!features={braillemath,\s!math\mathsizesuffix},\s!goodies=dejavu-math]
        \definefontsynonym[\s!MathRomanBold][\s!file:texgyredejavu-math][\s!features={braillemath,\s!math\mathsizesuffix,dejavu-math-bold},\s!goodies=dejavu-math]
    \stoptypescript

    \starttypescript[braille]
        \definetypeface [braille] [\s!rm] [\s!serif] [braille] [\s!default]
        \definetypeface [braille] [\s!ss] [\s!sans]  [braille] [\s!default]
        \definetypeface [braille] [\s!tt] [\s!mono]  [braille] [\s!default]
        \definetypeface [braille] [\s!mm] [\s!math]  [braille] [\s!default]
    \stoptypescript

\stoptypescriptcollection
