Graphics.TextFont differing weights

I’ve installed some great Fonts on my system, and they render really well in the Canvas control with all the standard syntax, e.g.:

Sub Paint(g As Graphics) g.Bold = True g.Italic = True g.TextFont = "Helvetica" g.TextSize = 18 g.DrawString("I love XOJO!", 10, 50)

However, many fonts have different weights, more than simply “Bold”, and I’m curious if these can be accessed.

For instance, if I have a font collection named “Roboto Mono” I have great success using g.TextFont = "Roboto Mono", and can even use g.Bold = True and get the expected results.

My confusion comes in knowing how to access the other versions of the font.

The collection of .TTF’s that I’ve installed may look like this…


…and I believe be default when I use “Roboto Mono” the font used is ‘RobotoMono-Regular.ttf’, and when I set the ‘bold’ attribute it’s likely using ‘RobotoMono-Bold.ttf’.

My primary question is can I use .TextFont to refer to any of the other weights/versions of the font set, or is only ‘Regular’, ‘Italic’, and ‘Bold’ available?

Have you tried using the full name?

Yes, I’ve totally tried using g.TextFont = "RobotoMono-Medium.ttf", and other permutations, but without any luck.

You have to use what the system thinks the display name is. I’m unsure, but I feel like this could vary between operating systems.
Try g.TextFont = "Roboto Mono Medium" as I’ve had success with custom fonts and different weights like this. You may be able to use Font on Mac to help get the right display name.

if anything you would NOT include the “.TTF”… it is the Font name, not the File name

If these fonts are installed in your system, just fire a word processor and note the font name (complete font name) and use that in your code.

If you get Roboto Mono Medium on your word processor, simply use that.
(or Roboto Mono-Bold,use that…)

I did see a posting about a command fc-list, which returns a list of fonts in this format…

/usr/share/fonts/truetype/kacst/KacstFarsi.ttf: KacstFarsi:style=Medium

…which can be dissected in this way…

/usr/share/fonts/truetype/kacst/KacstFarsi.ttf File name
: Separator
KacstFarsi Font name (note, remove the initial space)
: Separator
style= Medium The font ‘style’

I believe I’ve answered my own question, so to be thorough here’s what I’ve found…

In the host OS, using a word processing application, I’m able to see the font “DejaVu Serif”, which has a ‘style’ named “Condensed”. Using the fc-list command I was able to find the following line, which I was able to identify the name “DejaVu Serif Condensed”, which worked when used with g.TextFont = "DejaVu Serif Condensed"

/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book

So in summary, this helped me identify the name to use for setting the .TextFont property, when the ‘name’ isn’t readily known.