Murga-Projects Forums

Full Version: Fonts in murgaLua (or FLTK)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I am not sure if this is possible, but I would like to use a monospaced font other than courier.

Is that possible? Do I need to compile fltk by my own, or the fonts in fltk are selectable at runtime?

Thanks in advance,

PD: Oh, BTW, happy birthday, John! :-)
Fl:set_font(<font_name or number>,<new_font> )

For font names/numbers, consult the enumerations.html file.
I have no idea how system font names translate to different platforms.

On Linux I can change the courier font to terminus like this:




I just remembered that I've been using the non-xft version of murgaLua on linux, which doesn't use freetype fonts. After trying the above example with the xft version, the bitmap terminus font didn't work. As I have no idea how freetype fonts are identified, I couldn't say if it works at all. I tried several variants, including the X font names listed in fonts.dir and the filename itself, but I couldn't get the font to change in the xft-enabled version of murgaLua.
After messing with this a little more, it does appear to work using the font name (without the .ttf extension) for some fonts. The truetype fonts that were installed with my distribution do not seem to work, but a few of those that I downloaded myself and added to the $HOME/.fonts directory do. I assume this directory is automatically added by Xorg, since i didn't see any mention of it in the startx script or my personal configs. In any case, it does not seem to be very reliable. If you were going to use a font by its exact name, I'd recommend doing it only if you plan to be the only person using that script. I guess it would be kind of like using fonts in HTML. There is no way to say whether or not a specific font is going to work on an arbitrary machine, so you use font families instead and leave it up to the enduser to tweak his own specific fonts.

EDIT: I got the other ttf fonts working. It's not the filename that is needed, but the font name within the file. It just happened that the ones that worked had the same file names as their internal names.
I have no idea how to tell exactly what a ttf font name is other than to open the font in a text editor and search for something that looks like it might fit. I'm guessing Windows will probably give you the proper name in the "add fonts" window.
But it's still not going to work if you try this in a distributed script. The given font will need to be available on the user's system, truetype fonts don't work on non-xft murgaLua, and apparently non-truetype fonts don't work on regular murgaLua.
Thanks mikshaw.

I am not quite sure I understand: Is Fl:set_font a fltk call that I have to "translate" to the matching murgaLua binding?

Can you provide a code snippet where you set the font as you described and then it is used on a button label, for instance?

From this you should already know I am just starting with this... :-)
Thanks a lot!
Both of those examples are in murgaLua syntax, so should work as is.
They both change the built-in courier font constant to your desired font (4 is equivalent to fltk.FL_COURIER). Then to use it, just use fltk.FL_COURIER (or 4) as your font:

my_button=fltk:Fl_Button(10,10,120,25,"My Button")

Any place that would normally use a fixed-width font, such as following @f in Fl_Browser, will automatically use your customized FL_COURIER font without needing to specify what font to use.

Depending on what type of text you want to change, the actual method might not be "labelfont". For example, if my_button was an Input text field and you wanted to change the font of the typed-in text, it would be my_button:textfont(fltk.FL_COURIER). Consult the FLTK documentation for the method needed with the particular class you are using.


Now it is much clear, thanks.

So far I've been unable to change a button to, say, fixed. I guess I am not giving the right font name. I'm using Linux, Kubuntu feisty (7.04), by the way.

Thanks again for the support. Will keep investigating...
Unless you have a truetype or opentype version of fixed, I don't know that it would work with the standard xft-enabled MurgaLua. Hopefully this is not the case, and I just have more learning and experimenting to do with fonts, but so far it seems that bitmap fonts (pcf, for example) dont work in the standard murgaLua binary. If you were to try the non-xft version, you'd probably find that fixed will work. I think it works with both X font aliases and the full or abbreviated X font name:
Fl:set_font(4,"fixed") -- assuming there is a "fixed" alias, which there typically is

I've been going back and forth between the two murgaLua Linux binaries, and I still haven't decided which I prefer. The non-xft version does a good job of displaying most of the fonts I use most often (terminus, artwiz, proggy, lfp), but the default FLTK fonts are hideous. The defaults look fine with xft, but I don't get to use my favorite bitmap fonts. It's a pickle.
Oh, yes.... same happening here: fixed works with murgaLua_nonXft.

I have read in other projects forums about the very different nature of font selection when using xft, and it seems like a little of black magic: X is in the middle of the transition to modular building, old recipes are no longer applicable...

Anyway, I got what I wanted: Choose which font murgaLua uses. Thanks again!
Reference URL's