[Fontconfig] Xft broken after upgrade

Philipp v. Hilgers p.v.hilgers at rz.hu-berlin.de
Wed Jun 18 19:36:39 EST 2003


Dear Developers,
since I upgrade to SuSE 8.2 with Xfree86 4.3.0 and fontconfig 1.0.1 and 
Xft.h,v 1.32, I can't any longer compile an Xft HelloX.c Example.
gcc  complains:
/usr/include/X11/Xft/Xft.h:36:35: fontconfig/fontconfig.h: Datei oder 
Verzeichnis nicht gefunden [file not found]
and goes on with messages like those:
/usr/include/X11/Xft/XftCompat.h:33: error: parse error before "XftChar8"
/usr/include/X11/Xft/XftCompat.h:34: error: parse error before "XftChar16"

.
.
.

I attached the whole example programm and the compile-command.

For any hint tanx in advance,

So long,

Philipp


*** Example ***

//gcc -o HelloX HelloX.c -L/usr/X11R6/lib -lfontconfig -lX11 -lXft
/*

   HelloX.C
   ========
   (c) Copyright Paul Griffiths 1999
   Email: mail at paulgriffiths.net

   "Hello, World!", X Window System style.

*/


#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

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


//added ->
#include <X11/Xdefs.h>
//<-
#include <X11/Xft/Xft.h>


//added ->
#include <fontconfig/fontconfig.h>
#include <freetype/freetype.h>
#include <freetype/tttables.h>
//<-
/*  Global variables  */

Display *     display;
int           screen_num;
static char * appname;




/*########################################################*/
/*# BEGIN:  TT/AA message */
/*{
	
	static char * msg = "Hello, X FreeType AA!";
	XftDraw *xftdraw;
	XftFont *xftfont;
	XftColor color_fg;
	XColor dummyc,fg;
	Status retval;
	
	xftdraw = XftDrawCreate(display, (Drawable) win,
				DefaultVisual(display, screen_num),
				DefaultColormap(display, screen_num));
	if (!xftdraw) {
		perror("XftDrawCreate(): Failed"); exit(1);}
	
	xftfont = XftFontOpen(display, screen_num,XFT_FAMILY, XftTypeString, 
"garamond",XFT_SIZE, XftTypeInteger, 25,0);
	if (!xftfont) {
		perror("XftFontOpen(): Failed"); exit(1);}
	
	retval = XAllocNamedColor(display,DefaultColormap(display,screen_num), 
"green", &fg, &dummyc);
	if (!retval) {
		perror("XAllocNamedColor(): Failed"); exit(1);}
	
	color_fg.color.red = dummyc.red;
	color_fg.color.green = dummyc.green;
	color_fg.color.blue = dummyc.blue;
	color_fg.color.alpha = 0x00ff00;
	color_fg.pixel = fg.pixel;
	
	XftDrawString8(xftdraw, &color_fg, xftfont, msg_x-30, msg_y+30,
		       (unsigned char *) msg, strlen(msg));
}*/

/*  main() function  */

int main( int argc, char * argv[] ) {

     /*  Window variables  */

     Window       win;
     int          x, y;
     unsigned int width, height;
     unsigned int border_width;
     char *       window_name = "Hello, X Window System!";
     char *       icon_name   = "HelloX";


     /*  Display variables  */

     char *       display_name = NULL;
     unsigned int display_width, display_height;


     /*  Miscellaneous X variables  */

     XSizeHints *  size_hints;
     XWMHints   *  wm_hints;
     XClassHint *  class_hints;
     XTextProperty windowName, iconName;
     XEvent        report;
     XFontStruct * font_info;
     XGCValues     values;
     GC            gc;

     static char * msg = "1234567890qwertzuiop!";
     XftDraw *xftdraw;
     XftFont *xftfont,*xftfont2 ;
     XftColor color_fg,color_fg2;
     XColor dummyc,fg, fg2;
     Status retval, retval2;


     appname = argv[0];


     /*  Allocate memory for our structures  */

     if ( !( size_hints  = XAllocSizeHints() ) ||
          !( wm_hints    = XAllocWMHints()   ) ||
          !( class_hints = XAllocClassHint() )    ) {
         fprintf(stderr, "%s: couldn't allocate memory.\n", appname);
         exit(EXIT_FAILURE);
     }


     /*  Connect to X server  */

     if ( (display = XOpenDisplay(display_name)) == NULL ) {
         fprintf(stderr, "%s: couldn't connect to X server %s\n",
                 appname, display_name);
         exit(EXIT_FAILURE);
     }


     /*  Get screen size from display structure macro  */

     screen_num     = DefaultScreen(display);
     display_width  = DisplayWidth(display, screen_num);
     display_height = DisplayHeight(display, screen_num);


     /*  Set initial window size and position, and create it  */

     x = y = 0;
     width  = display_width / 3;
     height = display_width / 3;


     win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
                               x, y, width, height, border_width,
                               BlackPixel(display, screen_num),
                               WhitePixel(display, screen_num));


     /*  Set hints for window manager before mapping window  */

     if ( XStringListToTextProperty(&window_name, 1, &windowName) == 0 ) {
         fprintf(stderr, "%s: structure allocation for windowName 
failed.\n",
                 appname);
         exit(EXIT_FAILURE);
     }

     if ( XStringListToTextProperty(&icon_name, 1, &iconName) == 0 ) {
         fprintf(stderr, "%s: structure allocation for iconName failed.\n",
                 appname);
         exit(EXIT_FAILURE);
     }

     size_hints->flags       = PPosition | PSize | PMinSize;
     size_hints->min_width   = 200;
     size_hints->min_height  = 100;

     wm_hints->flags         = StateHint | InputHint;
     wm_hints->initial_state = NormalState;
     wm_hints->input         = True;

     class_hints->res_name   = appname;
     class_hints->res_class  = "hellox";

     XSetWMProperties(display, win, &windowName, &iconName, argv, argc,
                      size_hints, wm_hints, class_hints);


     /*  Choose which events we want to handle  */

     XSelectInput(display, win, ExposureMask | KeyPressMask |
                  ButtonPressMask | StructureNotifyMask);


     /*  Load a font called "9x15"  */

     if ( (font_info = XLoadQueryFont(display, "9x15")) == NULL ) {
         fprintf(stderr, "%s: cannot open 9x15 font.\n", appname);
         exit(EXIT_FAILURE);
     }


     /*  Create graphics context  */

     gc = XCreateGC(display, win, 0, &values);

     XSetFont(display, gc, font_info->fid);
     XSetForeground(display, gc, BlackPixel(display, screen_num));


     /*  Display Window  */

     XMapWindow(display, win);


     /*  Enter event loop  */

     while ( 1 ) {
	    static char *message = "Hallo";
         static int    length;
         static int    font_height;
         static int    msg_x, msg_y;

         XNextEvent(display, &report);

         switch ( report.type ) {

         case Expose:

             if ( report.xexpose.count != 0 )
                 break;

             /*  Output message centrally in window  */

             length = XTextWidth(font_info, message, strlen(message));
             msg_x  = (width - length) / 2;

             font_height = font_info->ascent + font_info->descent;
             msg_y  = (height + font_height) / 2;

             XDrawString(display, win, gc, msg_x, msg_y,
                         message, strlen(message));

	    xftdraw = XftDrawCreate(display, (Drawable) win,
				DefaultVisual(display, screen_num),
				DefaultColormap(display, screen_num));
	    if (!xftdraw) {
		    perror("XftDrawCreate(): Failed"); exit(1);}
	

	
	    //xftfont = XftFontOpenXlfd 
(display,screen_num,"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-ru");
	     /*xftfont = XftFontOpen (display, screen_num,
                             XFT_FAMILY, XftTypeString, "helvetica",
                             XFT_SIZE, XftTypeDouble, 160.0,
                             XFT_WEIGHT, XftTypeInteger, XFT_WEIGHT_BOLD,
			    0);*/
	    xftfont = XftFontOpen (display,screen_num,
				   XFT_FAMILY, XftTypeString, "Courier New KOI-8",
                                XFT_SIZE, XftTypeDouble, 46.0,
                                XFT_ENCODING, XftTypeString, "koi8-ru",
                                NULL);
	
	    //xftfont = XftFontOpenName(display, screen_num, "lucida 
sans:encoding-r");
	    xftfont2 = XftFontOpenName(display, screen_num, "lucidux");

	    //xftfont = XftFontOpen(display, screen_num,XFT_FAMILY, 
XftTypeString,"garamond",XFT_SIZE, XftTypeInteger,80,0);
	    if (!xftfont) {
		    perror("XftFontOpen(): Failed"); exit(1);}
	
	    retval = XAllocNamedColor(display,DefaultColormap(display,screen_num),
				      "brown", &fg, &dummyc);
	    if (!retval) {
		    perror("XAllocNamedColor(): Failed"); exit(1);}
	
	    color_fg.color.red = dummyc.red;
	    color_fg.color.green = dummyc.green;
	    color_fg.color.blue = dummyc.blue;
	    color_fg.color.alpha =  0xE580;//0x00ff00;
	    color_fg.pixel = fg.pixel;


	    retval2 = 
XAllocNamedColor(display,DefaultColormap(display,screen_num),
				      "brown", &fg2, &dummyc);
	    if (!retval) {
		    perror("XAllocNamedColor(): Failed"); exit(1);}
	
	    color_fg2.color.red = dummyc.red;
	    color_fg2.color.green = dummyc.green;
	    color_fg2.color.blue = dummyc.blue;
	    color_fg2.color.alpha =  0xE580;//-1/2;
	    color_fg.pixel = fg2.pixel;
	

	
	    XftDrawString8(xftdraw, &color_fg, xftfont, msg_x-30, 
msg_y+30,"Äq", 2);
	
	    XftDrawString8(xftdraw, &color_fg2, xftfont2, msg_x-30, 
msg_y+60,"Test",4);

             break;


         case ConfigureNotify:

             /*  Store new window width & height  */

             width  = report.xconfigure.width;
             height = report.xconfigure.height;

             break;


         case ButtonPress:            /*  Fall through  */
         case KeyPress:

             /*  Clean up and exit  */

             XUnloadFont(display, font_info->fid);
             XFreeGC(display, gc);
             XCloseDisplay(display);
             exit(EXIT_SUCCESS);

         }
     }

     return EXIT_SUCCESS;   /*  We shouldn't get here  */
}






More information about the Fontconfig mailing list