News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Fonts in murgaLua (or FLTK)
Author Message
pdinoto
Junior Member
**


Posts: 19
Group: Registered
Joined: Jun 2007
Status: Offline
Reputation: 0
Post: #1
Fonts in murgaLua (or FLTK)

Hello,

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,
///Pablo

PD: Oh, BTW, happy birthday, John! :-)

06-24-2007 02:37 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: Fonts in murgaLua (or FLTK)

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:

Code:
Fl:set_font(4,"-xos4-terminus-medium-r-normal--12-120-72-72-c-60-iso8859-1")

or

Code:
Fl:set_font(fltk.FL_COURIER,"-xos4-terminus-medium-r-normal--*")

This post was last modified: 06-24-2007 03:34 PM by mikshaw.

06-24-2007 03:33 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #3
RE: Fonts in murgaLua (or FLTK)

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.

07-09-2007 02:36 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: Fonts in murgaLua (or FLTK)

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.

This post was last modified: 07-11-2007 08:54 AM by mikshaw.

07-11-2007 08:44 AM
Find all posts by this user Quote this message in a reply
pdinoto
Junior Member
**


Posts: 19
Group: Registered
Joined: Jun 2007
Status: Offline
Reputation: 0
Post: #5
RE: Fonts in murgaLua (or FLTK)

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!

07-15-2007 08:07 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: Fonts in murgaLua (or FLTK)

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:

Code:
Fl:set_font(fltk.FL_COURIER,"arial")
my_button=fltk:Fl_Button(10,10,120,25,"My Button")
my_button:labelfont(fltk.FL_COURIER)

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.

07-15-2007 09:05 AM
Find all posts by this user Quote this message in a reply
pdinoto
Junior Member
**


Posts: 19
Group: Registered
Joined: Jun 2007
Status: Offline
Reputation: 0
Post: #7
RE: Fonts in murgaLua (or FLTK)

Great!

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...

07-15-2007 03:41 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #8
RE: Fonts in murgaLua (or FLTK)

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,"-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
Fl:set_font(4,"-misc-fixed-*--13-*")
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.

07-15-2007 04:33 PM
Find all posts by this user Quote this message in a reply
pdinoto
Junior Member
**


Posts: 19
Group: Registered
Joined: Jun 2007
Status: Offline
Reputation: 0
Post: #9
RE: Fonts in murgaLua (or FLTK)

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!

07-16-2007 02:24 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: