0

Writing C-code to create graphics on a Raspberry PI. O/S is raspbian v.9 aka "stretch", default installation from noobs. xlsfonts shows some fonts available, but there must be many more. How can I select fonts of various sizes and use them with the xlib text drawing functions? There are several font packages installed but they do not show up in xlsfonts - do I need to "activate" then in some way?

char    *fontname_12="Liberation Mono:style=Bold"; // this won't work
char    *fontname_12="fixed";   // only this will work
font_map = XLoadQueryFont(dpy, fontname_12);

output of xlsfonts:

-misc-fixed-medium-r-semicondensed--0-0-75-75-c-0-iso8859-1
-misc-fixed-medium-r-semicondensed--13-100-100-100-c-60-iso8859-1
-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
6x13
cursor
fixed

font packages detected with dpkg -l | grep font:

console-setup
fontconfig
fontconfig-config
fontconfig-infinality
fonts-dejavu
fonts-dejavu-core
fonts-dejavu-extra
fonts-droid-fallback
fonts-freefont-ttf
fonts-liberation2
fonts-noto-mono
fonts-piboto
Karel Adams
  • 185
  • 2
  • 19

1 Answers1

0

xlsfonts gives you a list of core fonts. Nothing uses core fonts these days anymore due to various limitations (e.g. only bitmap fonts). Instead, Xft is the way to go.

However, instead I'd suggest to just straight go to Pango and cairo instead of doing low-level X11 stuff.

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39
  • I looked into the Cairo thing, it looks like overkill for what I need to do - I only need primitives like lines and circle segments, and text. Also I am concerned about performance, running on a slowish raspberry. – Karel Adams Aug 23 '18 at 06:03
  • 1
    Well, if you want to use Xft directly, take a look at https://keithp.com/~keithp/render/Xft.tutorial. Note that the top answer in https://stackoverflow.com/questions/17078247/linux-c-xft-how-to-use-it actively discourages this (and is worth a read). – Uli Schlachter Aug 23 '18 at 09:56
  • Also, just because cairo can do fancy things, does not mean that it has to be slow. In fact, I wouldn't be surprised if cairo manages to be actually faster for some things. – Uli Schlachter Aug 23 '18 at 09:57