# How to globally define a custom font?

I have to use a .tex template that basically sets the font for everything to be Calibri. In the preamble it is written:

\usepackage{mathspec}
\setallmainfonts{Calibri}
\setmainfont{Calibri}
\setmathfont{Calibri}
\setmathsfont{Calibri}
\defaultfontfeatures{Mapping=tex-text}
\setkomafont{section}{\fontsize{14pt}\selectfont{Calibri}}
\setkomafont{subsection}{\fontsize{14pt}\selectfont{Calibri}}
\setkomafont{subsubsection}{\fontsize{12pt}\selectfont{Calibri}}
\setsansfont{Calibri}


This would be no problem if Calibri would be supported by overleaf (the tool I really want to use), but it isn't. So I included the Calibri-Files from Windows into the project and replaced Calibri by CALIBRI.TTF (cf. this answer). Even this will compile, it leads to unwanted output: italics and bold faces are ignored. After realizing, that for some reasons, a font is separated into different files: one for the "normal" text, one for the bold faces etc. So following Part II, Section 1.2 of the fontspec package documentation (page 10), I managed to build the following MWE (using XeLaTeX as LaTeX engine) which prints text in italics and bold face:

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{mathspec}
\setmainfont{CALIBRI}[
Extension = .TTF ,
UprightFont = * ,
BoldFont = *B ,
ItalicFont = *I ]

\begin{document}
normal \textit{italics} \emph{emphasized} \textbf{bold}
\end{document}


The problem is, this will not work for all the other commands in the preamble. For example

\setallmainfonts{CALIBRI}[
Extension = .TTF ,
UprightFont = * ,
BoldFont = *B ,
ItalicFont = *I ]


gives the error The font "CALIBRI" cannot be found. I tried to "globally" define a new font via \newfontfamily (cf. this help page), but it is only usable locally in the text. So the question remains: how to globally define a custom font?