%D \module
%D   [       file=type-otf,
%D        version=2007.07.30,
%D          title=\CONTEXT\ Typescript Macros,
%D       subtitle=Stix,
%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 recommend using the ttf files because we noticed that they are more original but
%D becuase we can't be sure what a distribution provides we don't use a suffix below.

%D We provide typescripts for version one and two of the stix fonts. There is a
%D xits variant based on the first (not opentype) release that also provides
%D bidirectional math. With (in 2022) stixtwo being frozsen for 2 years we can make
%D these the default now.
%D
%D Users should be aware of the fact that the stix filenames keep changing so if
%D something fails, make sure you have the files and that the names below match
%D those on your system. In \TEX\ distributions there's 2 and Two and math can have
%D -Regular appended or not. You can expect the \CONTEXT\ distribution to be kept up
%D to date.
%D
%D Per november 2022 we swithched from \OPENTYPE\ (otf) files to \TRUETYPE\ (ttf)
%D files. The main reason is that the metrics are cleaner, especially when one peeks
%D into the font for the purpose tweaking math (boundingbox, true positioning
%D unaffected by excessive hinting shown in in FontForge). It is yet unclear to us
%D (MS & HH) why there is this difference, but it might relate to the toolchain used
%D for generating these fonts. We might even switch to (smaller) unhinted \TRUETYPE\
%D fonts at some point but then we need to generate them ourselves). Anyway, the end
%D results are the same but we just want to be able to view it right.
%D
%D February, 2025: In non-compact mode the sizes of script and scriptscript
%D come from the bodyfontenvironment. For example, for 12pt, they are 9pt and 7pt,
%D respectively (font is loaded three times, and a bit late).
%D In compact mode is loaded directly, and the scaling factors come from the font
%D parameters (done in engine). We can, in both cases, override as we below. (Also
%D possible in the goodie file.)


\definefontfeature
  [stixtwomath]
  [ss02=yes] % otherwise weird (non italic) g

\definefontfeature[stixtwomath][copymathscripts=yes] % see lfg file

\starttypescriptcollection[stix]

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

    \starttypescript [\s!math] [stix,stixtwo,stix-nt,stixtwo-nt,xits]
        \checkedmapfontsize[\typescripttwo][\s!script]      [.65]% 70 in font
        \checkedmapfontsize[\typescripttwo][\s!scriptscript][.50]% 55 in font
    \stoptypescript

    \starttypescript [\s!math] [stix,stixtwo,xits] [\s!name]
        \definefontsynonym[\s!MathRoman]    [\s!file:stixtwomath-regular][\s!features={\s!math\mathsizesuffix,stixtwomath,stixtwo:mathextra,mathextra},\s!goodies=stixtwo-math]
        \definefontsynonym[\s!MathRomanBold][\s!file:stixtwomath-regular][\s!features={\s!math\mathsizesuffix,stixtwo-math-bold,stixtwomath,stixtwo:mathextra,mathextra},\s!goodies=stixtwo-math]
    \stoptypescript

    \starttypescript [\s!math] [stix-nt,stixtwo-nt] [\s!name]
        \definefontsynonym[\s!MathRoman]    [\s!file:stixtwomath-regular][\s!features={\s!math\mathsizesuffix,stixtwomath,stixtwo:mathextra,mathextra}]
        \definefontsynonym[\s!MathRomanBold][\s!file:stixtwomath-regular][\s!features={\s!math\mathsizesuffix,stixtwo-math-bold,stixtwomath,stixtwo:mathextra,mathextra}]
    \stoptypescript

    \starttypescript [\s!serif] [stix,stixtwo,xits] [\s!name]
        \setups[\s!font:\s!fallback:\s!serif]
        \definefontsynonym[\s!Serif]          [\s!file:stixtwotext-regular]   [\s!features=\s!default,\s!goodies=stixtwo-text]
        \definefontsynonym[\s!SerifBold]      [\s!file:stixtwotext-bold]      [\s!features=\s!default,\s!goodies=stixtwo-text]
        \definefontsynonym[\s!SerifItalic]    [\s!file:stixtwotext-italic]    [\s!features=\s!default,\s!goodies=stixtwo-text]
        \definefontsynonym[\s!SerifBoldItalic][\s!file:stixtwotext-bolditalic][\s!features=\s!default,\s!goodies=stixtwo-text]
    \stoptypescript

    \starttypescript[stix,stixtwo,xits,stix-nt,stixtwo-nt]
        \definetypeface [\typescriptone] [\s!rm] [\s!serif] [stixtwo]    [\s!default]
        \definetypeface [\typescriptone] [\s!ss] [\s!sans]  [dejavu]     [\s!default] [\s!rscale=0.895]
        \definetypeface [\typescriptone] [\s!tt] [\s!mono]  [dejavu]     [\s!default] [\s!rscale=0.895]
    \stoptypescript
    \starttypescript[stix,stixtwo,xits]
        \definetypeface [\typescriptone] [\s!mm] [\s!math]  [stixtwo]    [\s!default] [\s!direction=\s!both]
    \stoptypescript
    \starttypescript[stix-nt,stixtwo-nt]
        \definetypeface [\typescriptone] [\s!mm] [\s!math]  [stixtwo-nt] [\s!default] [\s!direction=\s!both]
    \stoptypescript

\stoptypescriptcollection
