setting font in fltk

30 views
Skip to first unread message

Klaus Rudolph

unread,
Oct 29, 2025, 3:34:39 PMOct 29
to fltk.general
I copied a bit of code from test/fonts.cxx

I was able to get a list of font names and the index of the list
e.g. I found something like 


Nr: 43 Attrib:  name BPdots
Nr: 44 Attrib: Bold  name BPdots bold
Nr: 45 Attrib:  name BPdots Light
Nr: 46 Attrib:  name BPdotsDiamond
Nr: 47 Attrib: Bold  name BPdotsDiamond bold
Nr: 48 Attrib:  name BPdotsDiamond Light
Nr: 49 Attrib:  name BPdotsMinus
Nr: 50 Attrib: Bold  name BPdotsMinus bold
Nr: 51 Attrib:  name BPdotsPlus
Nr: 52 Attrib: Bold  name BPdotsPlus bold
Nr: 53 Attrib:  name BPdotsSquares
Nr: 54 Attrib: Bold  name BPdotsSquares bold
Nr: 55 Attrib:  name BPdotsSquares Light
Nr: 56 Attrib:  name BPdotsVertical
Nr: 57 Attrib: Bold  name BPdotsVertical bold

which means, font with name "BPdots bold" has index 44.

If I do:
fl_font(44, 40);
fl_draw( "Hallo world", 10,20);

it works as expected, I got the selected font in size 40. Perfect!

My question is:

If I have the name like "BPdots bold", how can I set my font? OK, I can run through the list and get the index. But I expect there is some function, which already do this for me. 

I tried:

            Fl::set_font( 1, "BPdots" );
            fl_font( 1, 40 );

or
            Fl::set_font( 1, "BPdots bold" );
            fl_font( 1, 40 );

Both this did not select the font I want to see. ( or maybe did nothing )

Any hints how I can achieve this? Is there some more documentation? BTW: I use # 1 in Fl::set_font( 1, "BPdots" ); But can I have some "free" number? Maybe totally on the wrong path?

Regards
 Klaus



Albrecht Schlosser

unread,
Oct 29, 2025, 4:35:22 PMOct 29
to fltkg...@googlegroups.com
On 10/29/25 20:34 'Klaus Rudolph' via fltk.general wrote:
> I copied a bit of code from test/fonts.cxx

Which bit?

> I was able to get a list of font names and the index of the list
> e.g. I found something like
>
>
> Nr: 43 Attrib:  name BPdots
> Nr: 44 Attrib: Bold  name BPdots bold
> Nr: 45 Attrib:  name BPdots Light
> Nr: 46 Attrib:  name BPdotsDiamond
> ...
> which means, font with name "BPdots bold" has index 44.

Yes, I assume you called something like Fl::set_fonts(...) in the "bit
of code" mentioned above. Correct?

> My question is:
>
> If I have the name like "BPdots bold", how can I set my font? OK, I
> can run through the list and get the index. But I expect there is some
> function, which already do this for me.

Yes, this is not how it should be done. Setting "all" fonts like - I
assume you did - above is wateful.

> I tried:
>
>             Fl::set_font( 1, "BPdots" );
>             fl_font( 1, 40 );
>
> or
>             Fl::set_font( 1, "BPdots bold" );
>             fl_font( 1, 40 );
>
> Both this did not select the font I want to see. ( or maybe did nothing )

Please check the documentation of Fl::set_font(fnum, name):
https://www.fltk.org/doc-1.4/group__fl__attributes.html#ga15dee80a622a9ab2798acfdc0aabcd95

> Any hints how I can achieve this? Is there some more documentation?

As you can see in the docs mentioned above, this is - like the available
font names - platform specific. On some platforms (see docs) you need to
add one character before the font name. On some platforms you need only
the family name, on others the full font name.

Which platform are you using for your tests?

> BTW: I use # 1 in Fl::set_font( 1, "BPdots" ); But can I have some
> "free" number? Maybe totally on the wrong path?

The first "free" font number (i.e. the first font that's not loaded
automatically at startup) is FL_FREE_FONT. You can use this and the
following font numbers to load your own, specific fonts.

If you have further questions after reading the docs, please feel free
to ask again, but please post more details about your platform and code.

Albrecht Schlosser

unread,
Oct 29, 2025, 4:50:33 PMOct 29
to fltkg...@googlegroups.com
On 10/29/25 21:35 'Albrecht Schlosser' via fltk.general wrote:
> Yes, this is not how it should be done. Setting "all" fonts like - I
> assume you did - above is wateful.

*wasteful

Klaus Rudolph

unread,
Nov 1, 2025, 6:50:26 AMNov 1
to fltk.general
Thanks you support! At first: It works now! Great!

I am now talking about version 1.5.x on Linux with X11 AND wayland support.
I compiled without any special settings for used features during CMake install.

This means ( from README.cmake.txt )
FLTK_USE_XFT      - default ON

And if I understand set_font() docu:

  • Windows, X11, Xft: use the family name prefixed by one character to indicate the desired font variant. Characters ' ', 'I', 'B', 'P' denote plain, italic, bold, and bold-italic variants, respectively. For example, string "IGabriola" is to be used to denote the "Gabriola italic" font. The "Oblique" suffix, in whatever case, is to be treated as "italic", that is, prefix the family name with 'I'.
  • Other platforms, i.e., X11 + Pango, Wayland, macOS: use the full font name as returned by function Fl::get_font_name() or as listed by applications test/fonts or test/utf8. No prefix is to be added.


Is it right, that this will result in different behaviour with X11+Xft and wayland? 

What is the recommended solution if my application should work on X11 and wayland for this? Should I disable Xft during build of the library or should I check which version to use during runtime?
If I should check during runtime, is looking for fl_wl_display() and fl_x11_display() the right solution? Or should I take a look inside the environment? XDG_SESSION_TYPE=x11?

Is there a way to determine during compile time to find out if Xft is compiled in? Are there any macros predefined if the CMake option is in place or not?

BTW: In autotools it was possible to see the used and also automatic selected macros inside config.log. Is there something similar to CMake?

You see, I am confused "a bit" :-)

Regards
 Klaus

Albrecht Schlosser

unread,
Nov 1, 2025, 7:20:53 AMNov 1
to fltkg...@googlegroups.com
On 11/1/25 11:50 'Klaus Rudolph' via fltk.general wrote:
Thanks you support! At first: It works now! Great!

Welcome!


I am now talking about version 1.5.x on Linux with X11 AND wayland support.
I compiled without any special settings for used features during CMake install.

This means ( from README.cmake.txt )
FLTK_USE_XFT      - default ON

And if I understand set_font() docu:

  • Windows, X11, Xft: use the family name prefixed by one character to indicate the desired font variant. Characters ' ', 'I', 'B', 'P' denote plain, italic, bold, and bold-italic variants, respectively. For example, string "IGabriola" is to be used to denote the "Gabriola italic" font. The "Oblique" suffix, in whatever case, is to be treated as "italic", that is, prefix the family name with 'I'.
  • Other platforms, i.e., X11 + Pango, Wayland, macOS: use the full font name as returned by function Fl::get_font_name() or as listed by applications test/fonts or test/utf8. No prefix is to be added.
Is it right, that this will result in different behaviour with X11+Xft and wayland?

No, AFAICT. If you build FLTK with Wayland support, then X11 automatically uses the same platform specific stuff. This means that X11 is using the "X11 + Pango" variant, i.e. the second point mentioned in the docs.

I didn't write this specific part of the docs, but for clarification I think that the first enumeration could be changed to "Windows, X11, X11 + Xft", i.e. X11 with or w/o Xft (but always w/o Pango). If you are using Pango explicitly or by including Wayland support, the second enumeration applies.


What is the recommended solution if my application should work on X11 and wayland for this? Should I disable Xft during build of the library or should I check which version to use during runtime?

See above. If you build the library with Wayland support and see in the build log that either Wayland or Pango is mentioned in the build summary, then you should be fine for all Linux builds.


If I should check during runtime, is looking for fl_wl_display() and fl_x11_display() the right solution?

This can be used for special cases. It shows you which platform has been selected at runtime (only one of these two can be true). But if you are using these and want your program to work on Windows or macOS as well you will need further checks of build time macros.


Or should I take a look inside the environment? XDG_SESSION_TYPE=x11?

No. Even if `XDG_SESSION_TYPE=wayland` our "hybrid" FLTK library can still execute programs in X11 mode, for instance by using the env. variable FLTK_BACKEND=x11.


Is there a way to determine during compile time to find out if Xft is compiled in? Are there any macros predefined if the CMake option is in place or not?

As I wrote before, there's a build configuration summary at the end of the CMake configure phase, similar to the old config log.

The file FL/fl_config.h contains the most important macros that can be useful at runtime, e.g. FLTK_USE_CAIRO, FLTK_USE_X11, and FLTK_USE_WAYLAND, but this means only that the respective support has been compiled in. FLTK_USE_X11 and FLTK_USE_WAYLAND can both be true at the same time in the "hybrid" library.


BTW: In autotools it was possible to see the used and also automatic selected macros inside config.log. Is there something similar to CMake?

See above: configuration summary at the end of the CMake configure stage.


You see, I am confused "a bit" :-)

Yes, I confess that the lot of possible options can be confusing. I hope I could clarify some points.

Klaus Rudolph

unread,
Nov 1, 2025, 10:31:20 AMNov 1
to fltk.general
See above. If you build the library with Wayland support and see in the build log that either Wayland or Pango is mentioned in the build summary, then you should be fine for all Linux builds.

"build log". That is what I am searching for. I only recognize  something on the console after the config stage, but it is, as I can see, not stored anywhere. I am right?

 Regards
 Klaus

imm

unread,
Nov 1, 2025, 10:57:57 AMNov 1
to General FLTK
Klaus,

Just to add a little to what Albrecht said, reading your posts I wonder if you are focusing to much on the role of xft in all this.
It's likely that any font system on Linux will be using xft and fontconfig in some capacity, so you don't want to turn it off.
Historically fltk would use the xft/fontconfig API directly, whereas more recently we've been using pango and Cairo more. That brings advantages in many areas - not least it makes Wayland integration easier, and better anti aliasing of rendering generally.
In font terms a big advantage is that pango does a good job of substitution of missing glyphs, if the selected face doesn't have the character, whereas our old system might have gaps ..

The downside is that the rules used to select the font differ, so switching between the two might look subtly different in some cases.

Recent fltk with the Cairo/pango backend should look "the same" under X11 or Wayland, but that may be a bit different from what it would look like under (say) 1.3.x with our older font handling. But probably not very different...

Or it might look the same...

Sometimes you just need to try it!
--
Ian
From my Fairphone FP3
   

Albrecht Schlosser

unread,
Nov 1, 2025, 12:26:40 PMNov 1
to fltkg...@googlegroups.com
On 11/1/25 15:31 'Klaus Rudolph' via fltk.general wrote:
See above. If you build the library with Wayland support and see in the build log that either Wayland or Pango is mentioned in the build summary, then you should be fine for all Linux builds.

"build log". That is what I am searching for. I only recognize  something on the console after the config stage, but it is, as I can see, not stored anywhere. I am right?

Yes, the build log is not stored automatically, it's up to you to save it, e.g. by redirecting output to a file. But you can always execute another CMake configure/build which *does* show you the configure output, like:

$ cd /path/to/fltk/build
$ cmake .
-- Checking Wayland requirements ...
-- Checking Wayland requirements: OK

-- Configuration Summary for FLTK 1.5.0 generated by CMake 3.25.1 --

-- The following OPTIONAL packages have been found:

 * Doxygen
 * LATEX
 * ZLIB
 * PNG
 * JPEG
 * GLEW

-- Static libraries    will be built in: /path/to/fltk/build/lib
-- Shared libraries    will be built in: /path/to/fltk/build/lib
-- The forms library   will be built in: /path/to/fltk/build/lib
-- The OpenGL library  will be built in: /path/to/fltk/build/lib
-- fluid               will be built in: /path/to/fltk/build/bin
-- fltk-options        will be built in: /path/to/fltk/build/bin
-- Test programs       will be built in: /path/to/fltk/build/bin/test
-- Example programs    will be built in: /path/to/fltk/build/bin/examples
-- 
-- FLTK Library (API) version     1.5.0
-- ABI version (FL_ABI_VERSION)   10501
-- Build configuration            Debug
-- Installation prefix            /path/to/fltk-1.5

-- Bundled Libraries              JPEG     = System: /usr/lib/x86_64-linux-gnu/libjpeg.so
--                                PNG      = System: /usr/lib/x86_64-linux-gnu/libpng.so
--                                ZLIB     = System: /usr/lib/x86_64-linux-gnu/libz.so
--                                Libdecor = Bundled
-- Use DBUS                       Yes

-- Use Wayland                    Yes (can also run as X11 client)
-- All drawing uses Cairo         Yes
-- Use Pango                      Yes
-- Fl_Cairo_Window support        Yes (standard)

-- CMAKE_CXX_STANDARD             11
-- CMAKE_CXX_STANDARD_REQUIRED    Yes
-- CMAKE_CXX_EXTENSIONS           No

-- End of Configuration Summary --

-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/fltk/build

... followed by `cmake --build .` (which should actually do nothing after a previous successful build), ...  etc. etc..

Reply all
Reply to author
Forward
0 new messages