anewguy
May 24th, 2012, 08:55 AM
I have a C program using GTK that uses gtk_font_button_new. That returns a string containing the font name followed by 1 or more possible "attribute" like bold or italic and finally the font size. An example might be:
Andale Mono 22
where "Andale Mono" is the font name and 22 is the font size
== or ==
Andale Mono Bold 22
== or ==
Andale Mono Bold Italic 22
Obviously, some font names are longer than 2 words as well.
I tried to write a function to look backwards in a string until either the beginning of the string or a space, then copy that portion of the string (without the space). I thought I could pull out the length that way. I thought I could use either the same routine to search for trailing "attribute" and pull them out 1 at a time as well, then just copy the rest of the string which would be the font name.
I could not figure out how to do this and make it work. It would compile clean, I could find the string length, set up the "from" and the "to" for a strncpy, but it always aborted with a segment fault at runtime.
I have since removed all that from my code so I could just start from scratch on that part.
So:
- does anyone know a SIMPLE way (someone a few months ago before I stopped working on this for a while suggested a pango routine, but I don't understand pango at all) to parse out the font name, any attributes and finally the size from such strings?
- does anyone know of a way in GTK to display just the font families? I really want to just have the font selection be something like:
Arial
Andale Mono
etc.
and let me program separately for inputting the size and attributes?
Thanks in advance!
Dave ;)
Andale Mono 22
where "Andale Mono" is the font name and 22 is the font size
== or ==
Andale Mono Bold 22
== or ==
Andale Mono Bold Italic 22
Obviously, some font names are longer than 2 words as well.
I tried to write a function to look backwards in a string until either the beginning of the string or a space, then copy that portion of the string (without the space). I thought I could pull out the length that way. I thought I could use either the same routine to search for trailing "attribute" and pull them out 1 at a time as well, then just copy the rest of the string which would be the font name.
I could not figure out how to do this and make it work. It would compile clean, I could find the string length, set up the "from" and the "to" for a strncpy, but it always aborted with a segment fault at runtime.
I have since removed all that from my code so I could just start from scratch on that part.
So:
- does anyone know a SIMPLE way (someone a few months ago before I stopped working on this for a while suggested a pango routine, but I don't understand pango at all) to parse out the font name, any attributes and finally the size from such strings?
- does anyone know of a way in GTK to display just the font families? I really want to just have the font selection be something like:
Arial
Andale Mono
etc.
and let me program separately for inputting the size and attributes?
Thanks in advance!
Dave ;)