OTF and TTF fonts
Fonts files are often found in zip archives or tarballs and Reanimate can download them for you. Let's look at Magnolia Script as an example. It's a free OTF font, available for download in a zip-file: https://dl.dafont.com/dl/?f=magnolia_script
We'll use the zipArchive
function for downloading and unpacking the file. For safety reasons, we have to specify the SHA256 hash of the file we're downloading. This prevents unexpected changes. We can use an incorrect hash value to find the real checksum:
magnoliaFont :: FilePath
magnoliaFont = zipArchive
"https://dl.dafont.com/dl/?f=magnolia_script"
"missing"
When we use an incorrect hash value, we'll get an error message like this:
Exception: URL https://dl.dafont.com/dl/?f=magnolia_script
Expected SHA256: missing
Actual SHA256: XeXawkqqnSPgxK7G72RdL39ddKPrrLPCwJB7dojuulc=
Copy-pasting the actual SHA256 value gives us the proper code for downloading the Magnolia Script font:
magnoliaFont :: FilePath
magnoliaFont = zipArchive
"https://dl.dafont.com/dl/?f=magnolia_script"
"XeXawkqqnSPgxK7G72RdL39ddKPrrLPCwJB7dojuulc="
Next we'll use the font folder in a TeX configuration:
magnolia = TexConfig {
texConfigEngine = XeLaTeX,
texConfigHeaders =
[ "\\usepackage[no-math]{fontspec}",
"\\setmainfont[\
\Mapping=tex-text,\
\Path={" <> T.pack magnoliaFont <> "/},\
\Extension=.otf]\
\{Magnolia Script}"
],
texConfigPostScript = [] }
The magnolia
configuration is ready for formatting text:
magnoliaFont :: FilePath magnoliaFont = zipArchive "https://dl.dafont.com/dl/?f=magnolia_script" "XeXawkqqnSPgxK7G72RdL39ddKPrrLPCwJB7dojuulc=" magnolia = TexConfig { texConfigEngine = XeLaTeX, texConfigHeaders = [ "\\usepackage[no-math]{fontspec}", "\\setmainfont[\ \Mapping=tex-text,\ \Path={" <> T.pack magnoliaFont <> "/},\ \Extension=.otf]\ \{Magnolia Script}" ], texConfigPostScript = [] } animation :: Animation animation = scene $ showCfg "Magnolia" magnolia showCfg :: T.Text -> TexConfig -> Scene s () showCfg name cfg = do let title = scale 2 $ center $ latexCfg cfg name line1 = center $ latexCfg cfg "Pack My Box" line2 = center $ latexCfg cfg "With Five Dozen" line3 = center $ latexCfg cfg "Liquour Jugs" header <- oNew title oModify header $ oTopY .~ screenTop oShow header l1 <- oNew line1 l1 `oBelow` header oShow l1 l2 <- oNew line2 l2 `oBelow` l1 oShow l2 l3 <- oNew line3 l3 `oBelow` l2 oShow l3 wait 1 oBelow a b = do aBot <- oRead b oBottomY oModifyS a $ do oMarginTop .= 0 oTopY .= aBot