[Top][All Lists]

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

Re: [XForms] XForms and TrueType fonts

From: Rouben Rostamian
Subject: Re: [XForms] XForms and TrueType fonts
Date: Tue, 3 Jun 2014 06:40:31 -0400
User-agent: Mutt/1.5.22 (2013-10-16)

Hi Jens, just wanted to let you know that your Xft demo compiled
cleanly on Xubuntu after installing libxft-dev and a few
other packages.  The two strings look of the same size to me.
The Xft fonts are rendered smoothly.  The X11 show just a
slight amount of pixellation.

Thank you /very much/ for your time and effort in maintaining xforms.


---- original message -------------------------------------------
From: Jens Thoms Toerring <address@hidden>
Date: Tue, 3 Jun 2014 10:56:19 +0200
To: address@hidden
Reply-To: address@hidden, Development with and of XForms
Subject: Re: [XForms] XForms and TrueType fonts


   thanks to Rob Carpenter I realized that it was a bit
stupid to ask you if you're running any old systems that
don't support Xft and whatever is needed for that. Thus
here's a test program you can compile and run. If this
fails there's reason to be concerned that the system
isn't set up to the new font handling scheme. I append
the program and a very simple Makefile to this email.

A few comments: In the Makefile there's a part that executes:

    pkg-config --cflags freetype2

This should return any "unusual" CFLAGS needed for compiling
the program - on my machine it's "-I/usr/include/freetype2"
(which is not in the compilers default search path but con-
tains header files required by Xft). If this command doesn't
work you probably don't have the FreeType library (version 2)
and then your system may be one of the "old" ones.

The program itself shows two strings, one rendered using the
X11 core functions by XForms, the second using Xft etc. I've
tried to use the exact same font for both (helvetica oblique
in 24 points). If the program works (and you don't have it
switched off) you will notice that also the bitmap font gets
drawn with anti-aliasing by Xft. That would be one feature to
be expected from the new version - if you don't like anti-
aliasing it will have to be switched off via font-config.

On my system the font rendered with Xft is a bit smaller than
the one with X11 core functions.I have no idea why, could be
something misconfigired on my machine, but could also be some-
thing to be expected from an XForms version using Xft...

                           Best regards, Jens
  \   Jens Thoms Toerring  ________      address@hidden
   \_______________________________      http://toerring.de

#include <forms.h>
#include <X11/Xft/Xft.h>

typedef struct {
    FL_FORM   * f1;
    FL_OBJECT * canvas;
    FL_OBJECT * quit;
} FD_f1;

 * Function called when there's an Expose event for the canvas

static int
draw( FL_OBJECT * obj         FL_UNUSED_ARG,
      Window      win,
      int         win_width,
      int         win_height,
      XEvent    * xev         FL_UNUSED_ARG,
      void      * user_data   FL_UNUSED_ARG )
    const char * text = "This uses Xft";
    XGlyphInfo extents;
    XftFont * font;
    XftDraw * xftdraw;
    XRenderColor xrcolor;
    XftColor xftcolor;
    Display * display = fl_display;
    int screen        = fl_screen;
    Visual * visual   = fl_state[ fl_vmode ].xvinfo->visual;
    Colormap colormap = fl_state[ fl_vmode ].colormap;

    /* Try to get the exact same font as XForms uses (the inactive section
       should be equivalent) */

#if 1
    font = XftFontOpenXlfd( display, screen,
                            "-*-helvetica-medium-o-*-*-*-240-*-*-p-*-*-*" );
    font = XftFontOpen ( display, screen,
                         XFT_FAMILY, XftTypeString, "helvetica",
                         XFT_SIZE, XftTypeDouble, 24.0,
                         XFT_SLANT, XftTypeInteger, XFT_SLANT_OBLIQUE,
                         NULL );

    /* Get structure with information needed for rendering with either XRender
       or the X11 core protocol */

    xftdraw = XftDrawCreate( display, win, visual, colormap );

    /* Prepare color (white) for drawing the background */

    xrcolor.red   = 0xffff;
    xrcolor.green = 0xffff;
    xrcolor.blue  = 0xffff;
    xrcolor.alpha = 0xffff;

    XftColorAllocValue( display, visual, colormap, &xrcolor, &xftcolor );

    /* Draw the background (could also done with X11 XDrawRectangle())
       and afterwards release the color used */

    XftDrawRect( xftdraw, &xftcolor, 0, 0, win_width, win_height );
    XftColorFree( display, visual, colormap, &xftcolor );

    /* Prepare color (black) for drawing the string */

    xrcolor.red   = 0x0;
    xrcolor.green = 0x0;
    xrcolor.blue  = 0x0;
    xrcolor.alpha = 0xffff;

    XftColorAllocValue( display, visual, colormap, &xrcolor, &xftcolor );

    /* Get the size of the text to be drawn (for centering) */

    XftTextExtents8( display, font, ( XftChar8 const * ) text, strlen( text ),
                     &extents );

    /* Draw the text */

    XftDrawString8( xftdraw, &xftcolor, font,
                    ( win_width - extents.width ) / 2,
                    ( win_height + extents.height ) / 2,
                    ( XftChar8 const * ) text, strlen( text ) );

    /* Free all allocated resources */

    XftColorFree( display, visual, colormap, &xftcolor );
    XftDrawDestroy( xftdraw );
    XftFontClose( display, font );

    return 1;


FD_f1 *
create_form_f1( void )
    FL_OBJECT *obj;
    FD_f1 *fdui = fl_malloc( sizeof *fdui );

    fdui->f1 = fl_bgn_form( FL_NO_BOX, 280, 180 );

    fl_add_box( FL_FLAT_BOX, 0, 0, 280, 180, "" );

    obj = fl_add_text( FL_NORMAL_TEXT, 20, 20, 240, 40, "This uses X11" );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_boxtype( obj, FL_DOWN_BOX );
    fl_set_object_lsize( obj, FL_HUGE_SIZE );
    fl_set_object_lstyle( obj, FL_ITALIC_STYLE );
    fl_set_object_color( obj, FL_WHITE, FL_WHITE );

    obj = fdui->canvas = fl_add_canvas( FL_NORMAL_CANVAS, 20, 70, 240, 40, "" );
    fl_add_canvas_handler( obj, Expose, draw, NULL );

    fdui->quit = fl_add_button( FL_NORMAL_BUTTON, 90, 130, 100, 30, "Exit" );

    fl_end_form( );

    return fdui->f1->fdui = fdui;


main( int    argc,
      char * argv[ ] )
    FD_f1 *fd_f1;

    fl_initialize( &argc, argv, 0, 0, 0 );
    fd_f1 = create_form_f1( );

    fl_show_form( fd_f1->f1, FL_PLACE_CENTERFREE, FL_FULLBORDER,
                  "X11 versus Xft" );

    while ( fl_do_forms( ) != fd_f1->quit )
        /* empty */ ;

    fl_finish( );
    fl_free( fd_f1 );

    return 0;

xft_test: xft_test.c
        gcc -Wall -Wextra -o $@ $< $$(pkg-config --cflags freetype2) -lforms 

reply via email to

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