Reputation: 43
I'm trying to use the Ocaml Graphics package. I want to create a GUI for my chat server application. My code is:
let window = Graphics.open_graph "";
Graphics.set_window_title "caml-chat";
Graphics.set_font "ubuntu";
Graphics.set_text_size 12;
Graphics.draw_string "hello!"
However, Graphics.set_font "ubuntu"
does not work. The documentation says that the string argument is system dependent, but I cannot find any more information than that. The only mention I found was in the answers to this question, and it didn't work.
Does anyone know anything else about setting the font? (Or can point me in the direction of a simple graphics library with better documentation?)
Upvotes: 1
Views: 614
Reputation: 35280
Although you didn't specify your system, I will assume that it is Linux (I doubt that Windows has an ubuntu
font).
On Linux, the set_font
function passes the argument to the X Lib's XLoadFont function. You can use the fc-list
or xfontsel
utilities to query for the available fonts on your system, or call directly to the XListFonts
function.
For example,
fc-list | cut -d: -f2 | sort -u
will give you a list of font families, which you can pass to set_font
function. Some lines will have more than one family per line, separated with comman (,
). There are many more options, you can specify various styles, sizes, etc. But this is all out of the scope. You can the fontconfig guide to learn more about the font subsystem. For example, [here], at the section "Font Names", you can find the explanation of how the font name is constructed.
Upvotes: 0