I'm using Diagrams library to generate some text with a custom font. Looking at the documentation for Text it is not clear how can one specify particular .ttf font file? I tried using different .ttf files like in the example below, but no one worked.
discountText :: Maybe Int -> Diagram B
discountText discount =
case discount of
Nothing -> mempty
Just value ->
text (show value ++ " %") # font "Roboto-Light.ttf" # fontSize 90
Another alternative seems to be SVGFonts, but I would like to achieve this without another library. So how do you guys set custom fonts in Diagrams?
UPD: I find the answer given below very explanatory. To solve the problem I actually ended up using SVGFonts which adds extra step of converting .ttf into .svg, but does the job.
Font handling in Diagrams
is highly dependent on the backend. diagrams-cairo
should be able to use any TTF font on your system. On Linux, it will look up names using FontConfig. It should use the OS-provided font lookup mechanism on other OSes, but I can't recall ever testing this myself.
What backend are you planning to use? I'm partial to diagrams-cairo
for text handling, but it's the most difficult backend to install, especially on not-Linux. It's likely other backends have improved since the last time I tested their text handling, also.