コード例 #1
0
ファイル: loadfont.c プロジェクト: ghaerr/microwindows
int
main(int ac, char **av)
{
	Display *d;
	Font 	f;

	d = XOpenDisplay(NULL);
	if (!d)
		exit(1);

	f = XLoadFont(d, FONT1);	/* 6x10 prefix*/
	printf("Font1 number:%ld is %s\n",f,FONT1);
	XUnloadFont(d, f);
	f = XLoadFont(d, FONT2);	/* non-scaled*/
	printf("Font2 number:%ld is %s\n",f,FONT2);
	XUnloadFont(d, f);
	f = XLoadFont(d, FONT3);	/* scaled, pixelsize 24*/
	printf("Font3 number:%ld is %s\n",f,FONT3);
	XUnloadFont(d, f);
	f = XLoadFont(d, FONT4);	/* FLTK helvB10 non-scaled*/
	printf("Font4 number:%ld is %s\n",f,FONT4);
	XUnloadFont(d, f);
	f = XLoadFont(d, FONT5);	/* sample fonts.dir adobe TTF*/
	printf("Font5 number:%ld is %s\n",f,FONT5);
	XUnloadFont(d, f);

	return 0;
}
コード例 #2
0
ファイル: u_free.c プロジェクト: harbaum/xfig-gcode
void free_Fonts(void)
{
  int i;
  struct xfont   *nf;


  for (i=0; i<NUM_FONTS; i++) {
    for (nf = x_fontinfo[i].xfontlist; nf != NULL;) {
      XUnloadFont(tool_d, nf->fid);
      if (nf->fstruct != NULL)
	  XFreeFont(tool_d, nf->fstruct); 
      if (nf->fset != NULL)
	  XFreeFontSet(tool_d, nf->fset); 
      nf = nf->next;
    } 
  }
  if (bold_font!=NULL) {
    XFreeFont(tool_d, bold_font); 
  }
  if (roman_font!=NULL) {
    XFreeFont(tool_d, roman_font); 
  };
  if (button_font!=NULL) {
    XFreeFont(tool_d, button_font); 
  };
	XFreeGC(tool_d, sr_xor_gc);

	for (i=0; i<NUMOPS; i++) {
		XFreeGC(tool_d, gccache[i]);
	}
	for (i=0; i<NUMFILLPATS; i++) {
		XFreeGC(tool_d, fill_gc[i]);
	}
}
コード例 #3
0
ファイル: tkUnixRFont.c プロジェクト: nzavagli/UnrealPy
static void
FinishedWithFont(
    UnixFtFont *fontPtr)
{
    Display *display = fontPtr->display;
    int i;
    Tk_ErrorHandler handler = Tk_CreateErrorHandler(display, -1, -1, -1, NULL,
	    (ClientData) NULL);

    for (i = 0; i < fontPtr->nfaces; i++) {
	if (fontPtr->faces[i].ftFont) {
	    XftFontClose(fontPtr->display, fontPtr->faces[i].ftFont);
	}
	if (fontPtr->faces[i].charset) {
	    FcCharSetDestroy(fontPtr->faces[i].charset);
	}
    }
    if (fontPtr->faces) {
	ckfree((char *)fontPtr->faces);
    }
    if (fontPtr->pattern) {
	FcPatternDestroy(fontPtr->pattern);
    }
    if (fontPtr->ftDraw) {
	XftDrawDestroy(fontPtr->ftDraw);
    }
    if (fontPtr->font.fid) {
	XUnloadFont(fontPtr->display, fontPtr->font.fid);
    }
    if (fontPtr->fontset) {
	FcFontSetDestroy(fontPtr->fontset);
    }
    Tk_DeleteErrorHandler(handler);
}
コード例 #4
0
ファイル: ssh-askpass2.c プロジェクト: AnthraX1/rk
void close_display()
{
  XFreeModifiermap(modifiers);
  XUnloadFont(display, font);
  ssh_xfree(led_state);
  XCloseDisplay(display);
}
コード例 #5
0
ファイル: x11gui.cpp プロジェクト: jefferis/rgl
// ---------------------------------------------------------------------------
void X11GUIFactory::disconnect()
{
  // process pending XDestroyNotify events
  if (xdisplay) {
    XSync(xdisplay, False);
    processEvents();
  }

  // free XVisualInfo structure
  if (xvisualinfo) {
    XFree(xvisualinfo);
    xvisualinfo = 0;
  }

  // free xfont
  if (xfont) {
    XUnloadFont(xdisplay, xfont);
    xfont = 0;
  }
  
  // disconnect from X server
  if (xdisplay) {
    XCloseDisplay(xdisplay);
    xdisplay = 0;
  }
}
コード例 #6
0
ファイル: sun-os.c プロジェクト: dreal-deps/capdDynSys-3.0
void eventloop(void (*expose)(), void (*resize)(), void (*buttonpress)())
/* This is the main event loop */
{
   for(;;){
/* get events, use first to display text and graphics */
      XNextEvent(display, &report);
      switch  (report.type)
      {
         case Expose: handleExpose(expose); break;
         case ConfigureNotify: handleResize(resize);break;
         case ButtonPress: (*buttonpress)(); break;
         case KeyPress:
           /*****************************
           -- user stuff here for key press in window---
           e.g. exit program (note that, typing q in window exits)
           ******************************/
            XUnloadFont(display, font_info->fid);
            XFreeGC(display, drawgc);
            XCloseDisplay(display);
         default:
        /* all events selected by StructureNotifyMask
         * except ConfigureNotify are thrown away here,
         * since nothing is done with them */
            break;
      }
   }
}
コード例 #7
0
ファイル: ClDisplay.c プロジェクト: dimkr/tinyxlib
int
XCloseDisplay (
	register Display *dpy)
{
	register _XExtension *ext;
	register int i;

	if (!(dpy->flags & XlibDisplayClosing))
	{
	    dpy->flags |= XlibDisplayClosing;
	    for (i = 0; i < dpy->nscreens; i++) {
		    register Screen *sp = &dpy->screens[i];
		    XFreeGC (dpy, sp->default_gc);
	    }
	    if (dpy->cursor_font != None) {
		XUnloadFont (dpy, dpy->cursor_font);
	    }
	    XSync(dpy, 1);  /* throw away pending events, catch errors */
	    /* call out to any extensions interested */
	    for (ext = dpy->ext_procs; ext; ext = ext->next) {
		if (ext->close_display)
		    (*ext->close_display)(dpy, &ext->codes);
	    }
	    /* if the closes generated more protocol, sync them up */
	    if (dpy->request != dpy->last_request_read)
		XSync(dpy, 1);
	}
	_XDisconnectDisplay(dpy->trans_conn);
	_XFreeDisplayStructure (dpy);
	return 0;
}
コード例 #8
0
ファイル: xstext.c プロジェクト: ArielleBassanelli/gempak
void xrmfnt ( int font_no )
/************************************************************************
 * xrmfnt								*
 *									*
 * This function will unload the numbered font in the internal table	*
 * and move the rest of the fonts forward in the array.			*
 *									*
 * xrmfnt ( font_no )							*
 *									*
 * Input parameters:							*
 *	font_no		int		Font number to unload 		*
 **									*
 * Log:									*
 * C. Lin/EAI            9/93        					*
 * C. Lin/EAI            2/95   Add check for font_no		        *
 ***********************************************************************/
{
	int	i;

/*---------------------------------------------------------------------*/

	if ( font_no > MAX_LOAD_FONTS )
		return;

	XUnloadFont ( gemdisplay, loadfonts[font_no].id );

	for ( i = font_no+1; i < nfont; i++ ) {
	    strcpy( loadfonts[i-1].name, loadfonts[i].name );
	    loadfonts[i-1].id = loadfonts[i].id;
	}

}
コード例 #9
0
ファイル: main.c プロジェクト: VujinovM/anjuta
int main (int argc, char *argv[])
{
	Display              *dpy;
	Visual               *visual;
	int                   depth;
	XSetWindowAttributes  attributes;
	Window                win;
	XFontStruct         *fontinfo;
	XColor               color, dummy;
	XGCValues            gr_values;
	GC                   gc;
	XKeyEvent event;

	dpy = XOpenDisplay(NULL);
	visual = DefaultVisual(dpy, 0);
	depth  = DefaultDepth(dpy, 0);
	attributes.background_pixel = XWhitePixel(dpy, 0);
	/* create the application window */
	win = XCreateWindow(dpy, XRootWindow(dpy, 0),
			50, 50, 400, 400, 5, depth,
			InputOutput, visual, CWBackPixel,
			&attributes);
	XSelectInput(dpy, win, ExposureMask | KeyPressMask |
			ButtonPressMask | StructureNotifyMask);

	fontinfo = XLoadQueryFont(dpy, "6x10");
	XAllocNamedColor(dpy, DefaultColormap(dpy, 0),
		"green", &color, &dummy);
	gr_values.font = fontinfo->fid;
	gr_values.foreground = color.pixel;
	gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values);
	XMapWindow(dpy, win);

	/* run till key press */
	while(1){
		XNextEvent(dpy, (XEvent *)&event);
		switch(event.type) {
			case Expose:
				XDrawLine(dpy, win, gc, 0, 0, 100, 100);
				XDrawRectangle(dpy, win, gc, 140, 140, 50, 50);
				XDrawString(dpy, win, gc, 100, 100, "hello X world", 13);
				break;
			case ButtonPress:
			case KeyPress:
				XUnloadFont(dpy, fontinfo->fid);
				XFreeGC(dpy, gc);
				XCloseDisplay(dpy);
				exit(0);
				break;
			case ConfigureNotify:
				/* reconfigure size of window here */
				break;
			default:
				break;
		}
	}
	return(0);
}
コード例 #10
0
ファイル: xlsfonts.c プロジェクト: aosm/X11apps
static
void get_list(char *pattern)
{
    int           available = nnames+1,
                  i;
    char        **fonts;
    XFontStruct  *info;

    /* Get list of fonts matching pattern */
    for (;;) {
        if (open_instead_of_list) {
            info = XLoadQueryFont (dpy, pattern);

            if (info) {
                fonts = &pattern;
                available = 1;
                XUnloadFont (dpy, info->fid);
            } else {
                fonts = NULL;
            }
            break;
        }
            
        if (long_list == L_MEDIUM)
            fonts = XListFontsWithInfo(dpy, pattern, nnames, &available, &info);
        else
            fonts = XListFonts(dpy, pattern, nnames, &available);
        if (fonts == NULL || available < nnames)
            break;
        if (long_list == L_MEDIUM)
            XFreeFontInfo(fonts, info, available);
        else
            XFreeFontNames(fonts);
        nnames = available * 2;
    }

    if (fonts == NULL) {
        fprintf(stderr, "%s: pattern \"%s\" unmatched\n",
                program_name, pattern);
        return;
    }

    font_list = (FontList *)Realloc((char *)font_list,
            (font_cnt + available) * sizeof(FontList));
    for (i=0; i<available; i++) {
        font_list[font_cnt].name = fonts[i];
        if (long_list == L_MEDIUM)
            font_list[font_cnt].info = info + i;
        else
            font_list[font_cnt].info = NULL;
        
        font_cnt++;
    }
}
コード例 #11
0
ファイル: xfont-pagination.c プロジェクト: plonk/xfont-draw
void CleanUp()
{
    XUnloadFont(disp, font->fid);
    XFreeGC(disp, cursor_gc);
    XFreeGC(disp, margin_gc);
    XFreeGC(disp, control_gc);
    XFreeGC(disp, gc);
    XDestroyWindow(disp, win);
    XCloseDisplay(disp);
    assert(text != NULL);
    free(text);
}
コード例 #12
0
ファイル: font.c プロジェクト: 0xffffffRabbit/NextBSD-1
static void
DisposeFontSizes (DviWidget dw, DviFontSizeList *fs)
{
	DviFontSizeList	*next;

	for (; fs; fs=next) {
		next = fs->next;
		if (fs->x_name)
			XtFree (fs->x_name);
		if (fs->font && fs->font != dw->dvi.default_font) {
			XUnloadFont (XtDisplay (dw), fs->font->fid);
			XFree ((char *)fs->font);
		}
		XtFree ((char *) fs);
	}
}
コード例 #13
0
ファイル: ifr_xtext.c プロジェクト: clemej/ifrac
static void deinit_xfont(void)
{
	int i;

	for (i=0; i<2; i++)
	{
    if (FontId[i] != None)
    {   XUnloadFont(disp, FontId[i]);
				FontId[i] = None;
    }	
    if (FontName[i])
		{ XFree(FontName[i]);
	    FontName[i] = NULL;
    }
  }	
			
}
コード例 #14
0
ファイル: glc.c プロジェクト: cout/mglc
/* reloadFont() is a local function that deletes the current display list
 * and re-creates it using the font specified in current_font_list[0].
 * FIX ME!!  We should not use display lists for texture-mapped fonts (which
 * aren't supported yet anyway), and if we are to support font maps, then
 * we should be able to load more than one font at a time into the font
 * list.  As is, we can load more than one font, but we will only use the
 * first font loaded.
 */
static void reloadFont() {
	char fontbuf[2048], matbuf[256];
	int i = g->current_font_list[0], j;
	GLCfont *f = &g->fonts[i][g->font_faces[i]];

	/* If we changed scale (or changed font faces), then we need to
	 * reload the xfontinfo structure, which keeps track of the size
	 * of the current font.
	 */
	if(g->scale_change) {
		if(f->can_transform) {
			snprintf(matbuf, sizeof(matbuf), "[%f %f %f %f]",
				g->bitmap_scale[0], 0.0,
				0.0, g->bitmap_scale[1]);
			for(j = 0; matbuf[j] != 0; j++) if(matbuf[j] == '-') matbuf[j] = '~';
			snprintf(fontbuf, sizeof(fontbuf), "%s-%s-%s",
				f->xfontprefix, matbuf, f->xfontsuffix);
		} else {
			snprintf(fontbuf, sizeof(fontbuf), "%s-%d-%s",
				f->xfontprefix, (int)g->bitmap_scale[0], f->xfontsuffix);
		}
		if(f->xfontinfo) XFreeFont(g->display, f->xfontinfo);
		f->xfontinfo = XLoadQueryFont(g->display, fontbuf);
#ifdef DEBUG
		fprintf(stderr, "Reloading font info for %s\n", fontbuf);
#endif
		g->scale_change = FALSE;
	}

	/* We ALWAYS need to reload the display list (unless we are using
	 * texture-mapped fonts)
	 */
	if(f->can_transform) {
		snprintf(matbuf, sizeof(matbuf), "[%f %f %f %f]",
			g->bitmap_matrix[0], g->bitmap_matrix[1],
			g->bitmap_matrix[2], g->bitmap_matrix[3]);
		for(j = 0; matbuf[j] != 0; j++) if(matbuf[j] == '-') matbuf[j] = '~';
		snprintf(fontbuf, sizeof(fontbuf), "%s-%s-%s",
			f->xfontprefix, matbuf, f->xfontsuffix);
	}
	if(f->xfont) XUnloadFont(g->display, f->xfont);
	f->xfont = XLoadFont(g->display, fontbuf);
	glXUseXFont(f->xfont, 0, 256, g->list_base);
	g->reload_font = FALSE;

}
コード例 #15
0
ファイル: display_x_dialog.c プロジェクト: krytarowski/xjadeo
void close_x_dialog (Display *dpy) {
	if (!_dlg_mwin) {
		assert(!_dlg_swin);
		return;
	}
	XUngrabPointer (dpy, CurrentTime);
	XUngrabKeyboard (dpy, CurrentTime);
	XSync (dpy, False);

	close_x_dialog_win(dpy, &_dlg_mwin);
	close_x_dialog_win(dpy, &_dlg_swin);

	Colormap colormap = DefaultColormap (dpy, DefaultScreen (dpy));
	XFreeColors (dpy, colormap, &_c_gray1.pixel, 1, 0);
	XFreeColors (dpy, colormap, &_c_gray2.pixel, 1, 0);
	if (_dlgfont != None) XUnloadFont(dpy, _dlgfont);
	_dlgfont = None;
	force_redraw = 1;
}
コード例 #16
0
ファイル: ax.c プロジェクト: radekp/spectemu
void aX_close_one_disp(Display *disp)
{
    /*  int evt;
        event_proc_struct **curr; */
    disp_struct *dsp, *dsp_tmp;

    /*
  for(evt = 0; evt < EVENT_NUM; evt++) {
    curr = &(event_info[evt].next_proc);
    while(*curr != NULL) {
      if(disp == (*curr)->disp) {
        aX_remove_event_proc_disp((*curr)->disp, (*curr)->event_win,
                                  evt, (*curr)->event_proc);
        curr = &(event_info[evt].next_proc);      
      }
      else curr = &((*curr)->next_proc);
    }
  }

*/

    for(dsp = &disp_start; dsp->next_disp->disp != disp; dsp = dsp->next_disp)
        if(dsp->next_disp == NULL) {
            fprintf(stderr,
                    "%s: aX_close_one_disp: warning: Trying to close unopened display.\n", 
                    prog_name);
            return;
        }

    XUnloadFont(dsp->next_disp->disp, dsp->next_disp->font->fid);
    XCloseDisplay(dsp->next_disp->disp);

    dsp_tmp = dsp->next_disp;
    dsp->next_disp = dsp->next_disp->next_disp;
    free(dsp_tmp);

    disp_chain_modified = TRUE;

}
コード例 #17
0
ファイル: xtotroff.c プロジェクト: DemonFang/groff
static int MapFont(char *font_name, const char *troff_name)
{
  XFontStruct *fi;
  int count;
  char **names;
  FILE *out;
  unsigned int c;
  unsigned int attributes;
  XFontName parsed;
  int j, k;
  DviCharNameMap *char_map;
  char encoding[256];
  char *s;
  int wid;
  char name_string[2048];

  if (!XParseFontName(font_name, &parsed, &attributes)) {
    fprintf(stderr, "not a standard name: %s\n", font_name);
    return 0;
  }

  attributes &= ~(FontNamePixelSize | FontNameAverageWidth);
  attributes |= FontNameResolutionX;
  attributes |= FontNameResolutionY;
  attributes |= FontNamePointSize;
  parsed.ResolutionX = resolution;
  parsed.ResolutionY = resolution;
  parsed.PointSize = point_size * 10;
  XFormatFontName(&parsed, attributes, name_string);

  names = XListFonts(dpy, name_string, 100000, &count);
  if (count < 1) {
    fprintf(stderr, "bad font name: %s\n", font_name);
    return 0;
  }

  if (FontNamesAmbiguous(font_name, names, count))
    return 0;

  XParseFontName(names[0], &parsed, &attributes);
  sprintf(encoding, "%s-%s", parsed.CharSetRegistry,
	  parsed.CharSetEncoding);
  for (s = encoding; *s; s++)
    if (isupper(*s))
      *s = tolower(*s);
  char_map = DviFindMap(encoding);
  if (!char_map) {
    fprintf(stderr, "not a standard encoding: %s\n", encoding);
    return 0;
  }

  fi = XLoadQueryFont(dpy, names[0]);
  if (!fi) {
    fprintf(stderr, "font does not exist: %s\n", names[0]);
    return 0;
  }

  printf("%s -> %s\n", names[0], troff_name);

  {				/* Avoid race while opening file */
    int fd;
    (void) unlink(troff_name);
    fd = open(troff_name, O_WRONLY | O_CREAT | O_EXCL, 0600);
    out = fdopen(fd, "w");
  }

  if (!out) {
    perror(troff_name);
    return 0;
  }
  fprintf(out, "name %s\n", troff_name);
  if (!strcmp(char_map->encoding, "adobe-fontspecific"))
    fprintf(out, "special\n");
  if (charExists(fi, ' ')) {
    int w = charWidth(fi, ' ');
    if (w > 0)
      fprintf(out, "spacewidth %d\n", w);
  }
  fprintf(out, "charset\n");
  for (c = fi->min_char_or_byte2; c <= fi->max_char_or_byte2; c++) {
    const char *name = DviCharName(char_map, c, 0);
    if (charExists(fi, c)) {
      int param[5];

      wid = charWidth(fi, c);

      fprintf(out, "%s\t%d", name ? name : "---", wid);
      param[0] = charHeight(fi, c);
      param[1] = charDepth(fi, c);
      param[2] = 0;		/* charRBearing (fi, c) - wid */
      param[3] = 0;		/* charLBearing (fi, c) */
      param[4] = 0;		/* XXX */
      for (j = 0; j < 5; j++)
	if (param[j] < 0)
	  param[j] = 0;
      for (j = 4; j >= 0; j--)
	if (param[j] != 0)
	  break;
      for (k = 0; k <= j; k++)
	fprintf(out, ",%d", param[k]);
      fprintf(out, "\t0\t0%o\n", c);

      if (name) {
	for (k = 1; DviCharName(char_map, c, k); k++) {
	  fprintf(out, "%s\t\"\n", DviCharName(char_map, c, k));
	}
      }
    }
  }
  XUnloadFont(dpy, fi->fid);
  fclose(out);
  return 1;
}
コード例 #18
0
ファイル: gui.c プロジェクト: NgoHuy/unikey
//--------------------------------------------
void freeXResources()
{
  XUnloadFont(display, FontInfo->fid);
  XFreeGC(display, MainGC);
}
コード例 #19
0
/* Returns an XImage structure containing the string rendered in the font.
   This XImage will be 32 bits per pixel, 8 each per R, G, and B, with the
   extra byte set to 0xFF.

   Foreground and background are GL-style color specifiers: 4 floats from
   0.0-1.0.
 */
XImage *
text_to_ximage (Screen *screen, Visual *visual,
                const char *font,
                const char *text_lines,
                GLfloat *texture_fg,
                GLfloat *texture_bg)
{
  Display *dpy = DisplayOfScreen (screen);
  int width, height;
  XFontStruct *f;
  Pixmap bitmap;

  f = XLoadQueryFont(dpy, font);
  if (!f)
    {
      f = XLoadQueryFont(dpy, "fixed");
      if (f)
        fprintf (stderr, "%s: unable to load font \"%s\"; using \"fixed\".\n",
                 progname, font);
      else
        {
          fprintf (stderr, "%s: unable to load fonts \"%s\" or \"fixed\"!\n",
                   progname, font);
          exit (1);
        }
    }

  /* Parse the text, and render it to `bitmap'
   */
  {
    char *text, *text2, *line, *token;
    int lines;
    XCharStruct overall;
    XGCValues gcv;
    GC gc;

    int margin = 2;
    int fg = 1;
    int bg = 0;
    int xoff, yoff;

    text  = strdup (text_lines);
    while (*text &&
           (text[strlen(text)-1] == '\r' ||
            text[strlen(text)-1] == '\n'))
      text[strlen(text)-1] = 0;

    text2 = strdup (text);

    memset(&overall, 0, sizeof(overall));
    token = text;
    lines = 0;
    while ((line = strtok (token, "\r\n")))
      {
        XCharStruct o2;
        int ascent, descent, direction;
        token = 0;
        XTextExtents (f, line, strlen(line),
                      &direction, &ascent, &descent, &o2);
        overall.lbearing = MAX(overall.lbearing, o2.lbearing);
        overall.rbearing = MAX(overall.rbearing, o2.rbearing);
        lines++;
      }
    free (text);
    text = 0;

    width = overall.lbearing + overall.rbearing + margin + margin + 1;
    height = ((f->ascent + f->descent) * lines) + margin + margin;

    /* GL texture sizes must be powers of two. */
    {
      int w2 = to_pow2(width);
      int h2 = to_pow2(height);
      xoff = (w2 - width)  / 2;
      yoff = (h2 - height) / 2;
      width  = w2;
      height = h2;
    }

    bitmap = XCreatePixmap(dpy, RootWindowOfScreen (screen), width, height, 1);

    gcv.font = f->fid;
    gcv.foreground = bg;
    gc = XCreateGC (dpy, bitmap, (GCFont | GCForeground), &gcv);
    XFillRectangle(dpy, bitmap, gc, 0, 0, width, height);
    XSetForeground(dpy, gc, fg);

    token = text2;
    lines = 0;
    while ((line = strtok(token, "\r\n")))
      {
        XCharStruct o2;
        int ascent, descent, direction;
        token = 0;

        XTextExtents(f, line, strlen(line),
                     &direction, &ascent, &descent, &o2);
        XDrawString(dpy, bitmap, gc,
                    overall.lbearing + margin + xoff,
                    ((f->ascent * (lines + 1)) +
                     (f->descent * lines) +
                     margin +
                     yoff),
                    line, strlen(line));
        lines++;
      }
    free(text2);

    XUnloadFont(dpy, f->fid);
    XFree((XPointer) f);
    XFreeGC(dpy, gc);
  }

  /* Convert the server-side Pixmap to a client-side GL-ordered XImage.
   */
  {
    XImage *ximage1, *ximage2;
    unsigned long fg, bg;
    int x, y;

    ximage1 = XGetImage (dpy, bitmap, 0, 0, width, height, ~0L, ZPixmap);
    XFreePixmap(dpy, bitmap);
    ximage2 = XCreateImage (dpy, visual, 32, ZPixmap, 0, 0,
                            width, height, 32, 0);

    ximage2->data = (char *) malloc (height * ximage2->bytes_per_line);

    /* Translate the 1-bit image to a deep image:
       first figure out what the colors are.
     */
    {
      int rpos, gpos, bpos, apos;  /* bitfield positions */

      /* Note that unlike X, which is endianness-agnostic (since any XImage
         can have its own specific bit ordering, with the server reversing
         things as necessary) OpenGL pretends everything is client-side, so
         we need to pack things in the right order for the client machine.
       */
#if 0
    /* #### Cherub says that the little-endian case must be taken on MacOSX,
            or else the colors/alpha are the wrong way around.  How can
            that be the case?
     */
      if (bigendian())
        rpos = 24, gpos = 16, bpos =  8, apos =  0;
      else
#endif
        rpos =  0, gpos =  8, bpos = 16, apos = 24;

      fg = (((unsigned long) (texture_fg[0] * 255.0) << rpos) |
            ((unsigned long) (texture_fg[1] * 255.0) << gpos) |
            ((unsigned long) (texture_fg[2] * 255.0) << bpos) |
            ((unsigned long) (texture_fg[3] * 255.0) << apos));
      bg = (((unsigned long) (texture_bg[0] * 255.0) << rpos) |
            ((unsigned long) (texture_bg[1] * 255.0) << gpos) |
            ((unsigned long) (texture_bg[2] * 255.0) << bpos) |
            ((unsigned long) (texture_bg[3] * 255.0) << apos));
    }

    for (y = 0; y < height; y++)
      {
	int y2 = (height-1-y); /* Texture maps are upside down. */
	for (x = 0; x < width; x++)
          XPutPixel (ximage2, x, y, 
                     XGetPixel (ximage1, x, y2) ? fg : bg);
      }

    XDestroyImage (ximage1);

#if 0
    for (y = 0; y < height; y++)
      {
	int y2 = (height-1-y); /* Texture maps are upside down. */
	for (x = 0; x < width; x++)
          fputc ((XGetPixel (ximage2, x, y2) == fg ? '#' : ' '), stdout);
        fputc ('\n', stdout);
      }
    fputc ('\n', stdout);
#endif /* 0 */

    return ximage2;
  }
}
コード例 #20
0
void display_destr (void) {
	XUnloadFont(_D, font_info->fid);
	XFreeGC(_D, _gc);
	XDestroyWindow(_D, _W);
	XCloseDisplay(_D);
}
コード例 #21
0
ファイル: hello.c プロジェクト: tomby42/prg-xws
/*
 * Vstupní bod programu
 */
int main(int argc, char *argv[])
{
    XWMHints *wm_hints; /* Doporuèení pro window manager */
    XClassHint *class_hints; /* Jméno tøídy pro resource management */
    XTextProperty window_name, icon_name; /* Jména zobrazovaná window
                                               managerem */
    XSizeHints *size_hints; /* Doporuèená velikost okna */
    char *str_window_name = (char *) "Hello World";
    char *str_icon_name = (char *) "Hello Icon";
    XEvent event; /* Pro zpracování pøijatých událostí */
    static Bool window_too_small = False;
                        
    /* Inicializace */
    progname = argv[0];
    
    /* Pøipojení k X serveru */
    if(!(display = XOpenDisplay(display_name))) {
        fprintf(stderr, "%s: cannot connect to X server %s\n",
                progname, XDisplayName(display_name));
        exit(-1);
    }
    printf("Connected to X server %s\n", XDisplayName(display_name));
    screen_num = DefaultScreen(display);
    printf("Default screen number is %d\n", screen_num);
    screen_ptr = DefaultScreenOfDisplay(display);

    display_width = DisplayWidth(display, screen_num);
    display_height = DisplayHeight(display, screen_num);
    printf("Display is %u x %u pixels\n", display_width, display_height);

    /* Vytvoøení okna */
    x = y = 0; /* Okno umístí window manager */
    width = display_width/2;
    height = display_height/2;
    win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
                              x, y, width, height, border_width,
                              BlackPixel(display, screen_num),
                              WhitePixel(display, screen_num));
    printf("Created window with ID %#lx\n", win);
    
    /* Pixmapa ikony */
    icon_pixmap = XCreateBitmapFromData(display, win, hello_icon_bits,
                                        hello_icon_width, hello_icon_height);
    printf("Created pixmap with ID %#lx\n", icon_pixmap);
    
    /* Nastavení properties pro window manager */
    if(!(size_hints = XAllocSizeHints())) {
        fprintf(stderr, "Cannot allocate memory\n");
        exit(-1);
    }
    if(!(wm_hints = XAllocWMHints())) {
        fprintf(stderr, "Cannot allocate memory\n");
        exit(-1);
    }
    if(!(class_hints = XAllocClassHint())) {
        fprintf(stderr, "Cannot allocate memory\n");
        exit(-1);
    }
    /* Poloha a velikost se bere ze skuteèných hodnot okna v oka¾iku
     * namapování. PPosition | PSize øíká, ¾e hodnoty nastavil program (a
     * window manager je mù¾e mìnit podle potøeby). USSize | USPosition by
     * znamenalo, ¾e hodnoty zadal u¾ivatel (napø. na pøíkazové øádce) a
     * window manager by je nemìl mìnit. */
    size_hints->flags = PPosition | PSize | PMinSize;
    /* Window manager by nemìl okno nikdy zmen¹it na ménì ne¾
     * min_width x min_height pixelù. */
    size_hints->min_width = 300;
    size_hints->min_height = 200;
    /* Ulo¾ení jména okna a ikony */
    if(!XStringListToTextProperty(&str_window_name, 1, &window_name)) {
        fprintf(stderr, "XStringListToTextProperty() for window_name"
                " failed\n");
        exit(-1);
    }
    if(!XStringListToTextProperty(&str_icon_name, 1, &icon_name)) {
        fprintf(stderr, "XStringListToTextProperty() for icon_name"
                " failed\n");
        exit(-1);
    }
    wm_hints->initial_state = NormalState;/* Na zaèátku má být zobrazeno
                                             normální okno (ne ikona) */
    wm_hints->input = True; /* Aplikace potøebuje vstup z klávesnice */
    wm_hints->icon_pixmap = icon_pixmap;
    wm_hints->flags = StateHint | InputHint | IconPixmapHint;
    /* Jméno programu a tøídy pro hledání v resource databázi */
    class_hints->res_name = progname;
    class_hints->res_class = (char *) "HelloWorld";
    XSetWMProperties(display, win, &window_name, &icon_name, argv, argc,
                     size_hints, wm_hints, class_hints);
    
    /* Výbìr typù událostí ke zpracování */
    XSelectInput(display, win, ExposureMask | KeyPressMask |
                 ButtonPressMask | StructureNotifyMask);

    /* Nahrát font */
    load_font(&font_info);

    /* Vytvoøit graphics context pro kreslení */
    getGC(win, &gc, font_info);

    /* Namapovat okno na obrazovku (zobrazit) */
    XMapWindow(display, win);

    /* Smyèka pro pøíjem a zpracování událostí */
    while(1) {
        XNextEvent(display, &event); /* Èeká na pøíchod dal¹í události */
        switch(event.type) { /* Zpracování události */
            case Expose:
                printf("Drawing (serial=%lu send=%d count=%d x=%d y=%d "
                       "w=%d h=%d)\n",
                       event.xexpose.serial,
                       event.xexpose.send_event,
                       event.xexpose.count,
                       event.xexpose.x,
                       event.xexpose.y,
                       event.xexpose.width,
                       event.xexpose.height);
                if(event.xexpose.count == 0) {
                    if(window_too_small) { /* Pøíli¹ zmen¹ené okno */
                        printf("Drawing small\n");
                        draw_too_small(win, gc, font_info);
                    } else { /* Nakreslit obsah okna */
                        printf("Drawing normal (w=%d h=%d)\n", width, height);
                        draw_text(win, gc, font_info, width, height);
                        draw_graphics(win, gc, width, height);
                    }
                }
                break;
            case ConfigureNotify:
                /* Kdybychom nevolali XClearWindow(), tak pøi rychlé zmìnì
                 * velikosti okna my¹í postupnì window manager mìní velikost
                 * okna, co¾ má za následek smazání pøedchozího obsahu okna a
                 * vygenerování událostí ConfigureNotify a Expose. Jen¾e
                 * jestli¾e program nestihne pøekreslit okno pøed dal¹í
                 * zmìnou velikosti okna, tak X server jednou sma¾e okno, pak
                 * program nìkolikrát pøeète ConfigureNotify a Expose a
                 * nìkolikrát nakreslí obsah okna pro rùzné velikosti
                 * zji¹tìné z ConfigureNotify. Takto se pøekryje nìkolik rùznì
                 * velkých kreseb a obsah okna je ¹patný. */
		if(width != event.xconfigure.width || height != event.xconfigure.height)
		    XClearWindow(display, win);
                width = event.xconfigure.width;
                height = event.xconfigure.height;
                window_too_small = (int) width < size_hints->min_width+10 ||
                    (int) height < size_hints->min_height+10;
                printf("ConfigureNotify (serial=%lu send=%d w=%d h=%d)\n",
                       event.xconfigure.serial,
                       event.xconfigure.send_event,
                       event.xconfigure.width,
                       event.xconfigure.height);
                break;
            case ButtonPress:
            case KeyPress:
                /* Libovolná klávesa nebo tlaèítko my¹i ukonèí program */
                /* Následující dvì volání nejsou nezbytná, XCloseDisplay()
                 * uklidí v¹echny server resources alokované tímto klientem */
                XUnloadFont(display, font_info->fid);
                XFreeGC(display, gc);
                /* Odpojení od X serveru */
                XCloseDisplay(display);
                return 0;
                break;
            default:
                /* Sem se dostanou události vybrané maskou StructureNotifyMask
                 * kromì ConfigureNotify. */
                break;
        }
    }

    /* Sem se program nikdy nedostane */
    return 0;
}
コード例 #22
0
ファイル: JFont.cpp プロジェクト: neattools/neattools
 void JFont::Delete() { XUnloadFont(JUNIX::theDisplay, (Font)hnd);}
コード例 #23
0
ファイル: HelloX.c プロジェクト: SonarSource/Nemo-projects
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;
    
    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 = "Hello, X Window System!";
	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));

	    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  */
}
コード例 #24
0
ファイル: main.cpp プロジェクト: shybovycha/proc_stat
int main( int argc, char * argv[] )
{
    Window       win;
    int          x, y;
    unsigned int width, height;
    unsigned int border_width;
    char *       window_name = "Hello, X Window System!";
    char *       icon_name   = "HelloX";

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

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

    appname = argv[0];

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

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

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

    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));

    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);

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

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

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

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

    XMapWindow(display, win);


    while ( 1 ) {
        static char * message = "Hello, X Window System!";
        //static int    length;
        static int    font_height;
        //static int    msg_x, msg_y;
        static int    msg_y = 0;

        XNextEvent(display, &report);

        switch ( report.type ) {

        case Expose:

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

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

            msg_y = 0;
            QStringList list = stat();

            for (int i = 0; i < list.size(); i++)
            {
                font_height = font_info->ascent + font_info->descent;
                msg_y  += font_height + 2;

                XDrawString(display, win, gc, 10, msg_y,
                            list.at(i).toStdString().c_str(), list.at(i).length());
            }
        }
            break;


        case ConfigureNotify:
            width  = report.xconfigure.width;
            height = report.xconfigure.height;

            break;


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

        }
    }

    return 0;
}
コード例 #25
0
ファイル: gwindow.cpp プロジェクト: tokar1/mech-math
void GWindow::unloadFont(Font fontID) {
    XUnloadFont(m_Display, fontID);
}
コード例 #26
0
ファイル: allrequests.cpp プロジェクト: glegris/tiny-x-server
main()
{
      Window w2;

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Screen *scr = DefaultScreenOfDisplay(dpy);

      // CreateWindow

      Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			       CopyFromParent, CopyFromParent,
			       0, NIL);

      XDestroyWindow(dpy, w);

      // CreateWindow with arguments

      XSetWindowAttributes swa;
      swa.background_pixel = WhitePixelOfScreen(scr);
      swa.bit_gravity = NorthWestGravity;
      swa.border_pixel = BlackPixelOfScreen(scr);
      swa.colormap = DefaultColormapOfScreen(scr);
      swa.cursor = None;
      swa.win_gravity = NorthGravity;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, 
			&swa);
      
      // CreateWindow with other arguments

      XDestroyWindow(dpy, w);

      Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr));
      assert(pixmap);

      swa.background_pixmap = pixmap;
      swa.border_pixmap = pixmap;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixmap | CWBorderPixmap,
			&swa);
      
      // ChangeWindowAttributes

      swa.backing_planes = 0x1;
      swa.backing_pixel = WhitePixelOfScreen(scr);
      swa.save_under = True;
      swa.event_mask = KeyPressMask | KeyReleaseMask;
      swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask;
      swa.override_redirect = False;
      XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask
			      | CWDontPropagate | CWOverrideRedirect, &swa);

      // GetWindowAttributes

      XWindowAttributes wa;
      Status success = XGetWindowAttributes(dpy, w, &wa);

      // DestroyWindow (done)

      // DestroySubwindows

      w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XDestroySubwindows(dpy, w);

      // ChangeSaveSet

//        Display *dpy2 = XOpenDisplay(NIL);
//        assert(dpy2);
//        XAddToSaveSet(dpy2, w);
//        XCloseDisplay(dpy2);

      // ReparentWindow

      w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, 
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XReparentWindow(dpy, w2, w, 10, 5);

      // MapWindow

      XMapWindow(dpy, w);

      // MapSubwindows
      
      XMapSubwindows(dpy, w);

      // UnmapWindow
      
      XUnmapWindow(dpy, w);

      // UnmapSubwindows

      XMapWindow(dpy, w);
      XUnmapSubwindows(dpy, w2);
      XMapSubwindows(dpy, w);

      // ConfigureWindow

      Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2,
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);

      XMapWindow(dpy, w3);

      XWindowChanges wc;
      wc.x = -5;
      wc.y = -10;
      wc.width = 50;
      wc.height = 40;
      wc.border_width = 7;
      wc.sibling = w2;
      wc.stack_mode = Opposite;
      XConfigureWindow(dpy, w3, 
		       CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, 
		       &wc);

      // CirculateWindow

      XCirculateSubwindows(dpy, w, RaiseLowest);

      // GetGeometry

      Window root;
      int x, y;
      unsigned width, height, border_width, depth;
      XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth);

      // QueryTree

      Window parent;
      Window *children;
      unsigned nchildren;
      success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren);
      XFree(children);

      // InternAtom

      Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True);

      // GetAtomName

      char *string = XGetAtomName(dpy, XA_PRIMARY);
      XFree(string);

      // ChangeProperty

      XStoreName(dpy, w, "test window");

      // DeleteProperty

      XDeleteProperty(dpy, w, XA_WM_NAME);

      // GetProperty
      // TODO

      // ListProperties

      int num_prop;
      Atom *list = XListProperties(dpy, w, &num_prop);
      XFree(list);

      // SetSelectionOwner

      XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000);
      XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime);

      // GetSelectionOwner

      Window wx = XGetSelectionOwner(dpy, XA_PRIMARY);

      // ConvertSelection

      XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime);

      // SendEvent

      // GrabPointer

      std::cerr << "Grabbing" << std::endl;
      int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask,
			     GrabModeSync, GrabModeAsync, w, None, CurrentTime);
      XSync(dpy, False);
//      sleep(5);

      // UngrabPointer

      std::cerr << "Ungrabbing" << std::endl;
      XUngrabPointer(dpy, CurrentTime);

      // GrabButton

      XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      // UngrabButton

      XUngrabButton(dpy, 2, LockMask, w);

      // ChangeActivePointerGrab

      XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime);

      // GrabKeyboard

      XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000);

      // UngrabKeyboard

      XUngrabKeyboard(dpy, 13000);

      // GrabKey

      XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync,
	       GrabModeSync);

      // UngrabKey

      XUngrabKey(dpy, AnyKey, AnyModifier, w);

      // AllowEvents

      XAllowEvents(dpy, AsyncPointer, 14000);

      // GrabServer

      XGrabServer(dpy);

      // UngrabServer

      XUngrabServer(dpy);

      // QueryPointer

      Window child;
      int root_x, root_y, win_x, win_y;
      unsigned mask;
      Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask);

      // GetMotionEvents

      int nevents;
      XGetMotionEvents(dpy, w, 15000, 16000, &nevents);

      // TranslateCoordinates

      int dest_x, dest_y;

      XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child);

      // WarpPointer

      XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30);

      // SetInputFocus

      XSetInputFocus(dpy,w, RevertToPointerRoot, 17000);
      XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000);

      // GetInputFocus

      Window focus;
      int revert_to;
      XGetInputFocus(dpy, &focus, &revert_to);

      // QueryKeymap

      char keys_return[32];
      XQueryKeymap(dpy, keys_return);

      // OpenFont

      Font fid = XLoadFont(dpy, "cursor");

      // CloseFont

      XUnloadFont(dpy, fid);

      // QueryFont

      XFontStruct *fs = XLoadQueryFont(dpy, "cursor");
      assert(fs);

      // QueryTextExtents

      int direction, font_ascent, font_descent;
      XCharStruct overall;
      XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall);
      XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall);

      XChar2b c2bs;
      c2bs.byte1 = '$';
      c2bs.byte2 = 'B';
      XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall);

      XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, 
			&font_descent, &overall);

      // ListFonts

      int actual_count;
      char **fontList = XListFonts(dpy, "*", 100, &actual_count);
      XFree((char *)fontList);

      // ListFontsWithInfo

      int count;
      XFontStruct *info;
      char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info);
      XFreeFontInfo(names, info, count);

      // SetFontPath
      // GetFontPath

      int npaths;
      char **charList = XGetFontPath(dpy, &npaths);

      char **charList2 = new char *[npaths + 1];
      memcpy(charList2, charList, npaths * sizeof(char *));
      charList2[npaths] = charList2[0];

      XSetFontPath(dpy, charList2, npaths + 1);
      XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value

      XFreeFontPath(charList);
      delete [] charList2;

      // CreatePixmap

      Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr));

      // FreePixmap

      XFreePixmap(dpy, pix2);

      // CreateGC

      Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), 
					    "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4);

      XGCValues gcv;
      gcv.function = GXand;
      gcv.plane_mask = 0x1;
      gcv.foreground = WhitePixelOfScreen(scr);
      gcv.background = BlackPixelOfScreen(scr);
      gcv.line_width = 2;
      gcv.line_style = LineDoubleDash;
      gcv.cap_style = CapProjecting;
      gcv.join_style = JoinRound;
      gcv.fill_style = FillStippled;
      gcv.fill_rule = EvenOddRule;
      gcv.arc_mode = ArcPieSlice;
      gcv.tile = pixmap;
      gcv.stipple = bitmap;
      gcv.ts_x_origin = 3;
      gcv.ts_y_origin = 4;
      gcv.font = fs -> fid;
      gcv.subwindow_mode = ClipByChildren;
      gcv.graphics_exposures = True;
      gcv.clip_x_origin = 5;
      gcv.clip_y_origin = 6;
      gcv.clip_mask = bitmap;
      gcv.dash_offset = 1;
      gcv.dashes = 0xc2;
      
      GC gc = XCreateGC(dpy, w, 
			  GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth
			| GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile
			| GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode
			| GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset
			| GCDashList | GCArcMode,
			&gcv);

      // ChangeGC

      gcv.function = GXandReverse;

      // Only a few of these should appear, since the values are cached on the client side by the Xlib.

      XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv);

      // CopyGC
      
      GC gc2 = XCreateGC(dpy, w, 0, NIL);
      XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2);

      // SetDashes

      XSetDashes(dpy, gc, 3, "\001\377\001", 3);

      // SetClipRectangles

      XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } };
      XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted);

      // FreeGC

	    // done already

      // ClearArea

      XClearArea(dpy, w, 30, 10, 10, 100, False);

      // CopyArea

      XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10);

      // CopyPlane

      // This won't work if the Screen doesn't have at least 3 planes
      XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4);

      // PolyPoint

      XDrawPoint(dpy, w, gc, 1, 2);

      XPoint points[] = { { 3, 4 }, { 5, 6 } };
      XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin);

      // PolyLine

      XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious);

      // PolySegment

      XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
      XDrawSegments(dpy, w, gc, segments, SIZEOF(segments));

      // PolyRectangle

      XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyArc

      XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, 
		      { 10, 20, 30, 40, 50, -30 } };

      XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // FillPoly

      XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious);

      // PolyFillRectangle
      
      XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyFillArc
      
      XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // PutImage
      // GetImage

      XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap);
      XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30);
      XSync(dpy, False); // Make the next request starts at the beginning of a packet

      // PolyText8
      XTextItem textItems[3];
      textItems[0].chars = "toto";
      textItems[0].nchars = strlen(textItems[0].chars);
      textItems[0].delta = -3;
      textItems[0].font = fs->fid;
      textItems[1].chars = "titi";
      textItems[1].nchars = strlen(textItems[1].chars);
      textItems[1].delta = 3;
      textItems[1].font = None;
      textItems[2].chars = "tutu";
      textItems[2].nchars = strlen(textItems[2].chars);
      textItems[2].delta = 0;
      textItems[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems, 3);


      XTextItem textItems2[3];
      textItems2[0].chars = "totox";
      textItems2[0].nchars = strlen(textItems2[0].chars);
      textItems2[0].delta = -3;
      textItems2[0].font = fs->fid;
      textItems2[1].chars = "titi";
      textItems2[1].nchars = strlen(textItems2[1].chars);
      textItems2[1].delta = 3;
      textItems2[1].font = None;
      textItems2[2].chars = "tutu";
      textItems2[2].nchars = strlen(textItems2[2].chars);
      textItems2[2].delta = 0;
      textItems2[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems2, 3);

      // PolyText16

      XChar2b c2b2[] = { 0, 't', 0, 'x' };

      XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } };
      XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16));

      // ImageText8

      XDrawImageString(dpy, w, gc, 10, 10, "toto", 4);

      // ImageText16

      XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1);
      XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2);

      // CreateColormap
      // Don't forget to tell the kids how it was when we had only 8 bits per pixel.

      Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // FreeColormap

      XFreeColormap(dpy, colormap);
      colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // CopyColormapAndFree

      Colormap colormap2 = XCopyColormapAndFree(dpy, colormap);

      // InstallColormap

      XInstallColormap(dpy, colormap2);

      // UninstallColormap

      XUninstallColormap(dpy, colormap2);

      // ListInstalledColormaps

      int num;
      Colormap *colormapList = XListInstalledColormaps(dpy, w, &num);

      // AllocColor

      XColor screen;
      screen.red = 0;
      screen.green = 32767;
      screen.blue = 65535;
      screen.flags = DoRed | DoGreen | DoBlue;
      success = XAllocColor(dpy, colormap, &screen);

      // AllocNamedColor

      XColor screen2, exact;
      success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact);

      // AllocColorCells

      unsigned long plane_masks, pixels;
      success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1);

      // AllocColorPlanes

      unsigned long rmask, gmask, bmask;
      success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask);

      // FreeColors

      unsigned long pixels2[2] = { screen.pixel, screen2.pixel };
      XFreeColors(dpy, colormap, pixels2, 2, 0);

      // StoreColors

      success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2);

      // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells
      // I want my requests to be sent, however.
      if (!success) {
	    XSetErrorHandler(errorHandler);
      }

      XColor colors[2];
      colors[0] = screen;  colors[0].pixel = pixels2[0];
      colors[1] = screen2; colors[1].pixel = pixels2[1];
      XStoreColors(dpy, colormap, colors, 2);

      // StoreNamedColor

      XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue);

      XSync(dpy, False);
      XSetErrorHandler(NIL); // Restore the default handler

      // QueryColors

      screen2.pixel = WhitePixelOfScreen(scr);
      XQueryColor(dpy, colormap, &screen2);

      // LookupColor

      success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen);

      // CreateCursor

      Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10);

      // CreateGlyphCursor
      
      Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors);

      // FreeCursor
      
      XFreeCursor(dpy, cursor2);

      // RecolorCursor

      XRecolorCursor(dpy, cursor, colors, &exact);

      // QueryBestSize

      success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height);

      // QueryExtension

      int major_opcode, first_event, first_error;
      XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error);

      // ListExtensions

      int nextensions;
      char **extensionList = XListExtensions(dpy, &nextensions);
      for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl;
      XFree(extensionList);

      // ChangeKeyboardMapping
      // GetKeyboardMapping

      int min_keycodes, max_keycodes;
      XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes);

      int keysyms_per_keycode;
      KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1,
					    &keysyms_per_keycode);
      XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, 
			     max_keycodes - min_keycodes + 1);

      // ChangeKeyboardControl
      // GetKeyboardControl

      XKeyboardState keyboardState;
      XGetKeyboardControl(dpy, &keyboardState);

      XKeyboardControl keyboardValues;
      keyboardValues.key_click_percent = keyboardState.key_click_percent;
      keyboardValues.bell_percent = keyboardState.bell_percent;
      keyboardValues.bell_pitch = keyboardState.bell_pitch;
      keyboardValues.bell_duration = keyboardState.bell_duration;
      keyboardValues.led = 1;
      keyboardValues.led_mode = LedModeOn;
      keyboardValues.key = min_keycodes;
      keyboardValues.auto_repeat_mode = AutoRepeatModeDefault;
      XChangeKeyboardControl(dpy, 
			       KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration
			     | KBLed | KBLedMode | KBKey | KBAutoRepeatMode,
			     &keyboardValues);

      // Bell

      XBell(dpy, 90);

      // ChangePointerControl
      // GetPointerControl

      int accel_numerator, accel_denominator, threshold;
      XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold);

      XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold);

      // SetScreenSaver
      // GetScreenSaver

      int timeout, interval, prefer_blanking, allow_exposures;
      XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures);
      XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures);

      // ChangeHosts
      // ListHosts

      int nhosts;
      Bool state;
      XHostAddress *hostList = XListHosts(dpy, &nhosts, &state);

      XHostAddress host;
      host.family = FamilyInternet;
      host.length = 4;
      host.address = "\001\002\003\004";
      XAddHost(dpy, &host);

      // SetAccessControl

      XSetAccessControl(dpy, EnableAccess);

      // SetCloseDownMode

      XSetCloseDownMode(dpy, RetainTemporary);

      // KillClient

      XKillClient(dpy, AllTemporary);

      // RotateProperties

      Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), 
			    XInternAtom(dpy, "CUT_BUFFER1", False),
			    XInternAtom(dpy, "CUT_BUFFER2", False) };
      XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1);

      // ForceScreenSaver

      XForceScreenSaver(dpy, ScreenSaverReset);

      // SetPointerMapping
      // GetPointerMapping

      unsigned char map[64];
      int map_length = XGetPointerMapping(dpy, map, 64);
      XSetPointerMapping(dpy, map, map_length);

      // SetModifierMapping
      // GetModifierMapping

      XModifierKeymap *modmap = XGetModifierMapping(dpy);
      XSetModifierMapping(dpy, modmap);

      // NoOperation

      XNoOp(dpy);

      for(;;) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    std::cout << "Got an event of type " << e.type << std::endl;
      }
}
コード例 #27
0
ファイル: xf2pcx.c プロジェクト: AntonLanghoff/whitecatlib
int main(int argc, char *argv[])
{
   /* default values for -f, -i, -r, -c, -b, -g */
   char *fontname = "*";
   char *filename = "font.pcx";
   int start_char = 32, end_char = 255;
   int ccolor = 000000000;
   int bcolor = 255255255;
   int gcolor = 255000255;
   /* X11 variables */
   Display *display;
   int screen_number;
   int default_depth;
   Window window;
   Font font;
   GC gc, gc2;
   Pixmap pixmap;
   XImage *image;
   XCharStruct overall;
   /* misc variables */
   int bitmap_width, bitmap_height;
   int max_ascent, max_descent;
   int max_width, max_height;
   int i, opt, x, y, cx, cy, sx, sy, lines;
   unsigned long black, white;
   BITMAP *bitmap;
   RGB palette[256];

   /* show usage if no options  */
   if (argc == 1) {
      usage(argv[0]);
      exit(EXIT_SUCCESS);
   }

   /* only to access bitmap operations */
   install_allegro(SYSTEM_NONE, &errno, atexit);

   /* parse options  */
   opterr = 0;
   while ((opt = getopt(argc, argv, "f:o:z:c:b:g:r:h")) != EOF) {
      switch (opt) {
	 case 'f':
	    fontname = optarg;
	    break;
	 case 'o':
	    filename = optarg;
	    break;
	 case 'c':
	    ccolor = atol(optarg);
	    break;
	 case 'b':
	    bcolor = atol(optarg);
	    break;
	 case 'g':
	    gcolor = atol(optarg);
	    break;
	 case 'r':
	    {
	       char *str;
	       start_char = strtol(optarg, &str, 0);
	       end_char = strtol(str + 1, NULL, 0);
	       break;
	    }
	 case 'h':
	    usage(argv[0]);
	    exit(EXIT_SUCCESS);
	 default:
	    fprintf(stderr, "%s: unrecognized option -- '%c'\n", argv[0],
		    optopt);
	    fprintf(stderr, "%s: try '%s -h' for more information\n",
		    argv[0], argv[0]);
	    exit(EXIT_FAILURE);
      }
   }

   /* open display */
   display = XOpenDisplay(0);
   if (display == 0) {
      fprintf(stderr, "%s: XOpenDisplay failed\n", argv[0]);
      exit(EXIT_FAILURE);
   }

   /* default screen number and window */
   screen_number = XDefaultScreen(display);
   default_depth = XDefaultDepth(display, screen_number);
   window = XDefaultRootWindow(display);

   /* load font */
   font = XLoadFont(display, fontname);

   /* create gcs */
   {
      unsigned long val_mask;
      XGCValues val_bits;
      val_mask = GCForeground | GCBackground | GCFont | GCFunction;
      val_bits.function = GXcopy;
      val_bits.foreground = white = WhitePixel(display, screen_number);
      val_bits.background = black = BlackPixel(display, screen_number);
      val_bits.font = font;
      gc = XCreateGC(display, window, val_mask, &val_bits);
      val_mask = GCForeground;
      val_bits.foreground = black;
      gc2 = XCreateGC(display, window, val_mask, &val_bits);
   }

   /* query font ascent and descent */
   {
      XFontStruct *xfs;
      int min, max;
      xfs = XQueryFont(display, font);
      max_ascent = xfs->ascent;
      max_descent = xfs->descent;

      if (xfs->min_byte1 == 0 && xfs->max_byte1 == 0) {
	 min = xfs->min_char_or_byte2;
	 max = xfs->max_char_or_byte2;
      }
      else {
	 min = (xfs->min_byte1 << 8) + xfs->min_char_or_byte2;
	 max = (xfs->max_byte1 << 8) + xfs->max_char_or_byte2;
      }

      if (start_char < min || end_char > max)
	 fprintf(stderr,
		 "You specified characters %04x-%04x, but this font "
		 "only has the range %04x-%04x\n", start_char, end_char,
		 min, max);

      XFreeFontInfo(NULL, xfs, 0);
   }

   /* calculate bitmap width and maximum ascent and descent of characters
    * (can exceed the font ascent/descent queried above!) */
   max_width = 0;
   lines = 1 + (end_char - start_char) / 16;
   for (cy = 0; cy < lines; cy++) {

      for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) {
	 int dir, ascent, descent;
	 int width;
	 XChar2b string[2] = { {0, 0}, {0, 0} };

	 /* query character size */
	 string[0].byte1 = (start_char + cy * 16 + cx) >> 8;
	 string[0].byte2 = (start_char + cy * 16 + cx) & 255;
	 XQueryTextExtents16(display, font, string, 1, &dir, &ascent,
			     &descent, &overall);
	 width = overall.width;
	 if (width < 1)
	    width = 1;

	 if (width > max_width)
	    max_width = width;

	 if (max_ascent < overall.ascent)
	    max_ascent = overall.ascent;
	 if (max_descent < overall.descent)
	    max_descent = overall.descent;
      }

   }

   max_height = max_ascent + max_descent;

   bitmap_width = (max_width + 1) * 16 + 1;
   bitmap_height = (max_height + 1) * lines + 1;

   /* create bitmap */
   bitmap = create_bitmap(bitmap_width, bitmap_height);
   if (bitmap == 0) {
      fprintf(stderr, "%s: can not create bitmap\n", argv[0]);
      exit(EXIT_FAILURE);
   }

   /* fill with filler color */
   clear_to_color(bitmap, 255);

   /* process all characters */
   sy = 1;
   for (cy = 0; cy < lines; cy++) {

      sx = 1;
      for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) {
	 int dir, ascent, descent;
	 XChar2b string[2] = { {0, 0}, {0, 0} };

	 /* query character size */
	 string[0].byte1 = (start_char + cy * 16 + cx) >> 8;
	 string[0].byte2 = (start_char + cy * 16 + cx) & 255;
	 XQueryTextExtents16(display, font, string, 1, &dir, &ascent,
			     &descent, &overall);

	 if (overall.width < 1)
	    overall.width = 1;

	 /* create pixmap and draw character there */
	 pixmap =
	     XCreatePixmap(display, window, overall.width, max_height,
			   default_depth);
	 /* some fonts draw outside their ascent/descent, so we need to clear
	  * the pixmap before drawing the glyph */
	 XFillRectangle(display, pixmap, gc2, 0, 0, overall.width,
			max_height);
	 XDrawImageString16(display, pixmap, gc, 0, max_ascent, string, 1);

	 /* create image with pixmap contents */
	 image =
	     XGetImage(display, pixmap, 0, 0, overall.width, max_height,
		       AllPlanes, ZPixmap);
	 if (image == 0) {
	    fprintf(stderr, "%s: can not get image\n", argv[0]);
	    exit(EXIT_FAILURE);
	 }

	 /* copy image to bitmap */
	 for (y = 0; y < max_height; y++)
	    for (x = 0; x < overall.width; x++) {
	       if (XGetPixel(image, x, y) == white)
		  putpixel(bitmap, sx + x, sy + y, 1);
	       else
		  putpixel(bitmap, sx + x, sy + y, 0);
	    }

	 XDestroyImage(image);
	 XFreePixmap(display, pixmap);

	 sx += max_width + 1;
      }
      sy += max_height + 1;
   }

   /* initialize palette */
   for (i = 0; i < 256; i++)
      palette[i].r = palette[i].g = palette[i].b = 0;

#define CLAMP_COL(v) (((v / 4) > 63) ? 63 : (v / 4))
   palette[0].r = CLAMP_COL(bcolor / 1000000);
   palette[0].g = CLAMP_COL((bcolor % 1000000) / 1000);
   palette[0].b = CLAMP_COL(bcolor % 1000);
   palette[1].r = CLAMP_COL(ccolor / 1000000);
   palette[1].g = CLAMP_COL((ccolor % 1000000) / 1000);
   palette[1].b = CLAMP_COL(ccolor % 1000);
   palette[255].r = CLAMP_COL(gcolor / 1000000);
   palette[255].g = CLAMP_COL((gcolor % 1000000) / 1000);
   palette[255].b = CLAMP_COL(gcolor % 1000);
#undef CLAMP_COL
   save_pcx(filename, bitmap, palette);

   /* clean up */
   destroy_bitmap(bitmap);
   XFreeGC(display, gc);
   XFreeGC(display, gc2);
   XUnloadFont(display, font);
   XCloseDisplay(display);

   exit(EXIT_SUCCESS);
}