[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XForms] Help with XForms

From: Sunny
Subject: Re: [XForms] Help with XForms
Date: Fri, 11 Apr 2014 12:06:30 +0530


I'm trying both the default font and a newly added one (DejaVu Sans).
I was trying to change the the label size that is drawn on buttons by
default - I am not using any text drawing function directly.

Actually none of the lsizes work on my system for any font (lstyle).
At first I thought that the default font was crappy and had no sizes,
but this doesn't seem to be the case.

So for variety, I changed the font to DejaVu Sans which is a very
popular font with many sizes. And indeed on a word processor, I can
set the size for this font to anywhere between 2 to 72.

Well, the font shows up but with an ugly size of 120. button->lsize
seems to report the size as 20 which is plain wrong. _AND_ the actual
label size doesn't change when fl_set_object_lsize() is called. It's
almost like this function doesn't do anything;

I think you'll see what I mean when you try the following program. I
setup a counter and whenever the value of the counter is changed the
size of the button's label should also change, depending on the
counter value.

But of course the button's label size doesn't actually change on the
screen, it remains constant. Maybe I'm doing something wrong?

#include <forms.h>
#include <stdio.h>
#include <stdlib.h>

#define DEJAVU_SANS 20

struct form_data
    FL_OBJECT *button, *counter;

void setup_dejavu_font()
    fl_set_font_name(DEJAVU_SANS, "-*-dejavu

void change_button_font(FL_OBJECT *selector, long argument)
    struct form_data *data;
    FL_POPUP_RETURN *selected_item;

    data          = (struct from_data *) argument;
    selected_item = fl_get_select_item(selector);
    fprintf(stderr, "Item which goes by index %d was selected\n",

    case 0: /* Default Font */
        fprintf(stderr, "Setting button style to default style\n");
        fl_set_object_lstyle(data->button, 0);
        fl_set_counter_value(data->counter, data->button->lsize);

    case 1: /* DejaVu Sans */
        fprintf(stderr, "Setting button style DEJAVU_SANS\n");
        fl_set_object_lstyle(data->button, DEJAVU_SANS);
        fl_set_counter_value(data->counter, data->button->lsize);

        fprintf(stderr, "Unknown selection\n");

int main(int argc, char **argv)
    FL_FORM     *simple_form;
    FL_OBJECT   *button, *counter, *selector;
    struct form_data data;

    fl_set_icm_color(FL_COL1, 255, 255, 255);
    fl_set_icm_color(FL_MCOL, 255, 55, 55);
    fl_initialize(&argc, argv, "Forms Test", 0, 0);


    simple_form = fl_bgn_form(FL_UP_BOX, 200, 280);

    button      = fl_add_button(FL_NORMAL_BUTTON, 40, 50, 120, 50, "Button");

    counter     = fl_add_counter(FL_NORMAL_COUNTER, 40, 100, 120, 50,
"Button Size Slider");
    fl_set_counter_value(counter, button->lsize);
    fl_set_counter_bounds(counter, 20, 200);
    fl_set_counter_step(counter, 1, 10);

    selector    = fl_add_select(FL_NORMAL_SELECT, 40, 180, 120, 50, "");
    fl_add_select_items(selector, "Regular Font|DejaVu Sans", NULL);

    data.button  = button;
    data.counter = counter;
    fl_set_object_callback(selector, change_button_font, (long) &data);

    fl_show_form(simple_form, FL_PLACE_MOUSE, FL_NOBORDER, "Button lsize Test");

    while (fl_do_forms() == counter)
        int size;

        size = fl_get_counter_value(counter);
        fprintf(stderr, "Setting button lsize to %d\n", size);

        fl_set_object_lsize(button, size);

    return 0;

If I set the 8th field of the DEJAVU font-string to 80, then the font
shows up in a nice regular size. Not the ugly 120 which just looks
bad. I am currently changing it programmatically by the
fl_get_font_name() and fl_set_font_name() combo I mentioned earlier -
which works.

Also, the library for some reason crashes if you keep on increasing
the counter value for 10 times or more. It seems to be related to the
way the font is cached (???) in fonts.c. I have attached the backtrace
as a text file - could you please have a look?

On 11/04/2014, Jens Thoms Toerring <address@hidden> wrote:
> Hi,
> On Thu, Apr 10, 2014 at 03:13:04PM +0530, Sunny wrote:
>> I am not able to change font/label sizes with fl_set_object_lsize(). I
>> understand that not all sizes may be installed for that font on my
>> system, but none of the FL_HUGE_SIZE, FL_LARGE_SIZEs worked.
> The default choice of fonts is very, very conservative, i.e.
> all (non-ancient) systems I've ever seen did have freely
> scalable versions of the fonts used. Do you really get the
> ugly "I don't know what else to use font"?
> Which function for drawing the text are you using? (I have
> to ask stuoid questions since also to me the font handling
> isn't something I've dealt with a lot in recent times;-)
>> My workaround is adding a fl_get_font_name() function which fetches
>> the font-string and modifies the width and height field directly and
>> set it via fl_set_font_name().
> But none of these fields are set in the default fonts, they all
> go like this
>   -*-courier-medium-r-*-*-*-?-*-*-*-*-*-*
> So if you set widths and heights you actually should reduce
> the pool of fonts that can be used. I would have expected
> that you would have to change the font name field.
>> Is there a better alternative?
> I think so. Currently 16 fonts are "pre-defined", but the
> font table has 48 (FL_MAXFONTS) slots. Thus you should be
> able to add 32 further fonts. That should be possible using
> the
> int fl_set_font_name( int n, const char * name );
> function. 'n' is the index in the table (you can even
> overwrite the default fonts), and 'name' is the X font
> name - preferably, if it's a scalable font, containing a
> '?' for the size field, so it can be scaled.
> Once you have added a new font this way use the index 'n'
> in fl_set_object_lstyle(). If the font is scalable (and has
> a '?' in the size field) it should also react properly to
> fl_set_object_lsize().
> Please keep in mind that this is from (hazy) memort and a
> short look into the sources, so it could be quite wrong...
> So complain loudly if it doesn't work!
>> Oh, while we are on this subject, can we add a corresponding
>> fl_get_font_name() function to the library? It doesn't have one by
>> default.
>> --- a/fonts.c
>> +++ b/fonts.c
>> @@ -231,6 +231,18 @@ fl_set_font_name( int          n,
>>      return try_get_font_struct( n, FL_DEFAULT_SIZE, 1 ) ? 0 : -1;
>>  }
>> +char *
>> +fl_get_font_name( int index )
>> +{
>> +    if ( index < 0 || index >= FL_MAXFONTS )
>> +    {
>> +        M_warn( __func__, "Bad font index" );
>> +        return NULL;
>> +    }
>> +
>> +    return fl_fonts[index].fname;
>> +}
>> +
> I'll definitely consider this, just please give me a bit
> of time;-)
>                          Best regards, Jens
> --
>   \   Jens Thoms Toerring  ________      address@hidden
>    \_______________________________      http://toerring.de

Attachment: xforms-font-debug
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]