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; }
int main(int argc, char *argv[]) { Display *display; int screen; GC gc; Window window; XWMHints hints; Atom protocols; XEvent event; unsigned long mask; Font xfont1, xfont2; display = XOpenDisplay(""); screen = DefaultScreen(display); gc = DefaultGC(display, screen); /* * Font names are hard-coded. */ xfont1 = XLoadFont(display, "a14"); xfont2 = XLoadFont(display, "k14"); window = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, W_WIDTH, W_HEIGHT, 2, BlackPixel(display, screen), WhitePixel(display, screen)); XStoreName(display, window, "XFontStruct demo"); hints.flags = InputHint; hints.input = True; XSetWMHints(display, window, &hints); protocols = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &protocols, 1); mask = ExposureMask; XSelectInput(display, window, mask); XMapWindow(display, window); for (;;) { XNextEvent(display, &event); if (XFilterEvent(&event, window) == True) continue; switch (event.type) { case Expose: { XSetFont(display, gc, xfont1); XDrawString(display, window, gc, 10, 50, "abcdef", 6); XSetFont(display, gc, xfont2); /* JIS */ XDrawString16(display, window, gc, 10, 80, (XChar2b *) "\x24\x22\x24\x24", 4); break; } default: { break; } } } }
/* ------------------------------------------------------------------ */ int drawWinFlag(int c) { char msg[40]; theFont = XLoadFont(theDisplay, FONT18 ); XSetFont(theDisplay, theGC, theFont); sprintf(msg, "YOU WON. With only %d moves !!!", c); XDrawImageString(theDisplay, theWindow, theGC, (wW-10*strlen(msg))/2, wH/2, msg, strlen(msg) ); XFlush(theDisplay); theFont = XLoadFont(theDisplay, FONT10 ); XSetFont(theDisplay, theGC, theFont); return c; }
void do_draw_technical(EX_Drawable dr, GC gc, int a, int b, int c, int d, int bl, int br, int bt, int bb) { if (!font) font = XLoadFont(disp, "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*"); XSetFont(disp, gc, font); if (c < 3) c = 3; if (d < 3) d = 3; draw_h_arrow(dr, gc, a + bl, a + bl + c - 1, b + bt + d - 16); draw_h_arrow(dr, gc, 0, a - 1, b + bt + (d / 2)); draw_h_arrow(dr, gc, a + c + bl + br, WinGetW(VROOT) - 1, b + bt + (d / 2)); draw_v_arrow(dr, gc, b + bt, b + bt + d - 1, a + bl + 16); draw_v_arrow(dr, gc, 0, b - 1, a + bl + (c / 2)); draw_v_arrow(dr, gc, b + d + bt + bb, WinGetH(VROOT) - 1, a + bl + (c / 2)); XDrawLine(disp, dr, gc, a, 0, a, WinGetH(VROOT)); XDrawLine(disp, dr, gc, a + c + bl + br - 1, 0, a + c + bl + br - 1, WinGetH(VROOT)); XDrawLine(disp, dr, gc, 0, b, WinGetW(VROOT), b); XDrawLine(disp, dr, gc, 0, b + d + bt + bb - 1, WinGetW(VROOT), b + d + bt + bb - 1); XDrawRectangle(disp, dr, gc, a + bl + 1, b + bt + 1, c - 3, d - 3); }
HelloWorld::HelloWorld(Display* display) : _game() { _display = display; _screen = XDefaultScreenOfDisplay(display); _blackColor = BlackPixelOfScreen(_screen); _whiteColor = WhitePixelOfScreen(_screen); _font = XLoadFont(_display, WINDOW_FONT); int screenWidth = XWidthOfScreen(_screen); int screenHeight = XHeightOfScreen(_screen); int windowWidth = MIN_CELL_SIZE * 3; int windowHeight = MIN_CELL_SIZE * 3 + STRING_HEIGHT * 3; int windowX = (screenWidth + windowWidth) / 2; int windowY = (screenHeight + windowHeight) / 2; _window = XCreateSimpleWindow(_display, XRootWindowOfScreen(_screen), windowX, windowY, windowWidth, windowHeight, 1, _blackColor, _whiteColor); long eventMask = ButtonPressMask | ExposureMask | KeyPressMask; XSelectInput(_display, _window, eventMask); draw(); }
void NSInitialize(void) { if ((NSdpy = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } font = XLoadFont(NSdpy, defaultFont); }
void MAOpenGLInitCb( Widget w, XtPointer clientData, XtPointer callData) { static String xFontStr = "-*-courier-*-*-*-*-14-*-*-*-*-*-*-*"; Font xFont; WlzDVertex3 tVtx, orgVtx; Display *dpy = XtDisplay( w ); (void )HGUglwCreateCanvasGlxContext(w, NULL); HGUglwCanvasGlxMakeCurrent(w, NULL); xFont = XLoadFont(XtDisplay(w), xFontStr); if(xFont) { threeDFont = HGUglTextFontCreate(xFont); } glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); if( globals.toplDepth == 24 ){ glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_FOG); glFogf(GL_FOG_MODE, GL_LINEAR); } else { glClearIndex( (GLfloat) BlackPixelOfScreen(XtScreen(w)) ); } /* set the initial transform - should be from resources */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotated( (GLdouble) 90.0, (GLdouble) 1.0, (GLdouble) 0.0, (GLdouble) 0.0); glRotated((GLdouble) -40.0, (GLdouble) 0.0, (GLdouble) 0.0, (GLdouble) 1.0); glRotated( (GLdouble) 20.0, (GLdouble) 0.6, (GLdouble) 0.4, (GLdouble) 0.0); glGetDoublev(GL_MODELVIEW_MATRIX, &initial_rot[0][0]); /* create the default 3D display DisplayList */ globals.ref_display_list = glGenLists( (GLsizei) 1 ); glNewList( globals.ref_display_list, GL_COMPILE ); WLZ_VTX_3_SET(tVtx, 10.0, 10.0, 10.0); WLZ_VTX_3_SET(orgVtx, 5.0, 5.0, 5.0); if( globals.toplDepth == 24 ){ glColor3d((GLdouble) 1.0, (GLdouble) 1.0, (GLdouble) 1.0); } else { glIndexi( HGU_XGetColorPixel(dpy, globals.cmap, 1.0, 1.0, 1.0) ); } HGUglShapeWireCube(tVtx, orgVtx); glEndList(); WLZ_VTX_3_SET(globals.bbox_vtx, -2.0, -2.0, -2.0); WLZ_VTX_3_SET(globals.bbox_size, 14.0, 14.0, 14.0); return; }
void load_font(){ char *font_name=conf_get_string("font",FONT); Font font=XLoadFont(dpy,font_name); XSetFont(dpy,gc,font); XGCValues v; XGetGCValues(dpy,gc,GCFont,&v); sfont=XQueryFont(dpy,v.font); }
void Graphics::DrawText(const Point & p, const string & text) { this->PrepareGraphicsContext(); XTextItem xTextItem; xTextItem.chars = const_cast<char*>(text.c_str()); xTextItem.nchars = text.size(); xTextItem.font = XLoadFont(this->display, "a14"); xTextItem.delta = 0; Point newPoint = this->transform * p; XDrawText(this->display, this->window, this->gc, (int)newPoint.x, (int)newPoint.y, &xTextItem, 1); DebugDelay(string("DrawText")); }
/* ------------------------------------------------------------------ */ int drawSave(int c, int flag ) { char msg[40]; theFont = XLoadFont(theDisplay, FONT18 ); XSetFont(theDisplay, theGC, theFont); if ( !flag ) { XSetForeground(theDisplay, theGC, theMark[2].pixel); sprintf(msg, "Click \"Save\" to save the game."); } else { sprintf(msg, "The game with seed: %d is saved", c); } XDrawImageString(theDisplay, theWindow, theGC, (wW-10*strlen(msg))/2, wH/2, msg, strlen(msg) ); XFlush(theDisplay); sleep(2); XSetForeground(theDisplay, theGC,theBlack.pixel); XDrawImageString(theDisplay, theWindow, theGC, (wW-10*strlen(msg))/2, wH/2, msg, strlen(msg) ); XFlush(theDisplay); XSetForeground(theDisplay, theGC,theWhite.pixel); theFont = XLoadFont(theDisplay, FONT10 ); XSetFont(theDisplay, theGC, theFont); return c; }
// --------------------------------------------------------------------------- // --------------------------------------------------------------------------- X11GUIFactory::X11GUIFactory(const char* displayname) : xdisplay(0) , xvisualinfo(0) , xfont(0) { // Open one display connection for all RGL X11 devices xdisplay = XOpenDisplay(displayname); if (xdisplay == 0) { throw_error("unable to open X11 display"); return; } // Load System font xfont = XLoadFont(xdisplay,"fixed"); // Obtain display atoms static char* atom_names[GUI_X11_ATOM_LAST] = { "WM_DELETE_WINDOW" }; Status s = XInternAtoms(xdisplay, atom_names, sizeof(atom_names)/sizeof(char*), True, atoms); if (!s) lib::printMessage("some atoms not available"); // Query glx extension if ( glXQueryExtension(xdisplay, &errorBase, &eventBase) == False ) { throw_error("GLX extension missing on server"); return; } // Choose GLX visual static int attribList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 0, GLX_DEPTH_SIZE, 1, None }; xvisualinfo = glXChooseVisual( xdisplay, DefaultScreen(xdisplay), attribList ); if (xvisualinfo == 0) { throw_error("no suitable visual available"); return; } }
Cursor XCreateFontCursor(Display * display, unsigned int shape) { static XColor fg = { 0, 0, 0, 0}; /* black*/ static XColor bg = { 0, 65535, 65535, 65535}; /* white*/ if (_nxCursorFont == None) { _nxCursorFont = XLoadFont(display, X_CURSOR_FONT); if (_nxCursorFont == None) return 0; } return XCreateGlyphCursor(display, _nxCursorFont, _nxCursorFont, shape, shape+1, &fg, &bg); }
/* 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; }
static int text(char *s, int n, int fn) { int cx, cy; static int flg = 0, cfn = -1, ccw = -1, cch = -1; float xadj, yadj; if (n <= 0) return (0); if (fn != cfn) { ccw = cw; cch = ch; if (ch == LFCH) cfn = fn + 1; else cfn = fn; flg = 1; } if (flg || cw != ccw || ch != cch) { if (cw < ccw || ch < cch) cfn = fn - 1; else if (cw > ccw || ch > cch) cfn = fn + 1; XSetFont(display, gc, XLoadFont(display, f_name[cfn])); ccw = cw; cch = ch; flg = 0; } if (th == 0) XDrawString(display, main_window, gc, points[0].x, points[0].y, s, n); else { xadj = ccw / shrink; yadj = ((cch > FCH) ? 0.75 : 1.25) * cch / shrink; while (n) { cx = points[0].x - xadj; cy = points[0].y - yadj * --n; XDrawString(display, main_window, gc, cx, cy, s, 1); s++; } } return 0; }
//========================================= // CreateCursorFromName //----------------------------------------- Cursor CreateCursorFromName(Display* dpy, const char* name) { XColor fg, bg; int i; Font fid; char* fore_color = NULL; char* back_color = NULL; fg = NameToXColor(dpy, fore_color, BlackPixel(dpy, screen)); bg = NameToXColor(dpy, back_color, WhitePixel(dpy, screen)); i = XmuCursorNameToIndex(name); if (i == -1) return (Cursor) 0; fid = XLoadFont (dpy, "cursor"); if (!fid) return (Cursor) 0; return XCreateGlyphCursor(dpy, fid, fid, i, i+1, &fg, &bg); }
bool GFX_SelectEditFont(struct Tracker_Windows *tvisual){ int lokke; XFontStruct *xfontstruct; char *rawfontname=GFX_ReadStringFromPythonCommand("X11_Qtstuff.GFX_SelectEditFont(\"%s\")"); printf("Got -%s-\n",rawfontname); xfontstruct=XLoadQueryFont(x11_display,rawfontname); if(xfontstruct==NULL){ printf("Unable to load font \"%s\"\n",rawfontname); return false; } tvisual->os_visual->xfontstruct=xfontstruct; //max_bounds.rbearing - min_bounds.lbearing tvisual->fontwidth=tvisual->h_fontwidth=xfontstruct->max_bounds.rbearing - xfontstruct->min_bounds.lbearing; tvisual->org_fontheight=xfontstruct->max_bounds.ascent+xfontstruct->max_bounds.descent; tvisual->fontheight=tvisual->org_fontheight+2; for(lokke=0;lokke<8;lokke++){ GC gc=tvisual->os_visual->gcs[lokke]; XSetFont(x11_display,gc,tvisual->os_visual->xfontstruct->fid); } #if 0 XSetFont(display, gc, font) Display *display; GC gc; Font font; Font XLoadFont(display, name) Display *display; char *name; #endif return true; }
PetscErrorCode XiLoadFont(PetscDraw_X *XBWin,XiFont *font) { char font_name[100]; XFontStruct *FontInfo; XGCValues values ; PetscFunctionBegin; (void) sprintf(font_name,"%dx%d",font->font_w,font->font_h); font->fnt = XLoadFont(XBWin->disp,font_name); /* The font->descent may not have been set correctly; get it now that the font has been loaded */ FontInfo = XQueryFont(XBWin->disp,font->fnt); font->font_descent = FontInfo->descent; XFreeFontInfo(0,FontInfo,1); /* Set the current font in the CG */ values.font = font->fnt ; XChangeGC(XBWin->disp,XBWin->gc.set,GCFont,&values); PetscFunctionReturn(0); }
//========================================= // CreateCursorFromName //----------------------------------------- Cursor CreateCursorFromName (Display* dpy,char *name) { XColor fg, bg; int i; Font fid; fg = NameToXColor (dpy,fore_color, BlackPixel(dpy, screen)); bg = NameToXColor (dpy,back_color, WhitePixel(dpy, screen)); #if 0 if (reverse) { temp = fg; fg = bg; bg = temp; } #endif i = XmuCursorNameToIndex (name); if (i == -1) return (Cursor) 0; fid = XLoadFont (dpy, "cursor"); if (!fid) return (Cursor) 0; return XCreateGlyphCursor ( dpy, fid, fid, i, i+1, &fg, &bg ); }
/* ------------------------------------------------------------------ */ int initGraphics() { theDisplay = XOpenDisplay(XDisplayName(NULL)); if (theDisplay == NULL) { printf("You need to run the program under X-window.\n\n"); exit(1); } theScreen = XDefaultScreen(theDisplay); rootW = RootWindow(theDisplay, theScreen); theGC = XDefaultGC(theDisplay, theScreen); theCmap = XDefaultColormap(theDisplay, theScreen); theVisual = DefaultVisual(theDisplay, theScreen); theDepth = XDefaultDepth(theDisplay, theScreen); // fprintf(stderr, "Visual %x Depth %d\n", theVisual, theDepth); pScreen = XDefaultScreenOfDisplay(theDisplay); sW = XWidthOfScreen(pScreen); sH = XHeightOfScreen(pScreen); theFont = XLoadFont(theDisplay, FONT10 ); XSetFont(theDisplay, theGC, theFont); return 0; }
XFontStruct* XLoadQueryFont(Display* display, _Xconst char* name) { // https://tronche.com/gui/x/xlib/graphics/font-metrics/XLoadQueryFont.html Font fontId = XLoadFont(display, name); if (fontId == None) { return NULL; } TTF_Font* font = GET_FONT(fontId); SET_X_SERVER_REQUEST(display, X_QueryFont); XFontStruct* fontStruct = malloc(sizeof(XFontStruct)); if (fontStruct == NULL) { handleOutOfMemory(0, display, 0, 0); TTF_CloseFont(font); return NULL; } fontStruct->fid = fontId; fontStruct->ascent = TTF_FontAscent(font); fontStruct->descent = abs(TTF_FontDescent(font)); fontStruct->per_char = NULL; unsigned int numChars = 0; unsigned int i; for (i = 0; i < 65536 /* 2^16 */; i++) { if (TTF_GlyphIsProvided(font, (Uint16) i)) { if (numChars == 0) { fontStruct->min_char_or_byte2 = i; } fontStruct->max_char_or_byte2 = i; numChars++; } } // if (numChars >= 256) { // fontStruct->min_byte1 = fontStruct->min_char_or_byte2 / 256; // fontStruct->max_byte1 = fontStruct->max_char_or_byte2 / 256; // fontStruct->min_char_or_byte2 = 0; // } else { fontStruct->min_byte1 = 0; fontStruct->max_byte1 = 0; // } // TODO: This is debugging fontStruct->max_char_or_byte2 = 255; // Build per_char int monospace = TTF_FontFaceIsFixedWidth(font); XCharStruct charStruct; if (!monospace) { fontStruct->per_char = malloc(sizeof(XCharStruct) * numChars); if (fontStruct->per_char == NULL) { handleOutOfMemory(0, display, 0, 0); XFreeFont(display, fontStruct); return NULL; } charStruct = fontStruct->per_char[0]; } if (fillXCharStruct(font, fontStruct->min_char_or_byte2, &charStruct) == False) { XFreeFont(display, fontStruct); return NULL; } fontStruct->max_bounds = charStruct; fontStruct->min_bounds = charStruct; if (monospace) { fontStruct->per_char = NULL; } else { int counter = 1; for (i = fontStruct->min_char_or_byte2 + 1; i < 65536 /* 2^16 */; ++i) { if (TTF_GlyphIsProvided(font, (Uint16) i)) { charStruct = fontStruct->per_char[counter]; if (fillXCharStruct(font, i, &charStruct) == False) { XFreeFont(display, fontStruct); return NULL; } // I think rbearing (aka. advance) is the value that matters here if (fontStruct->max_bounds.rbearing < charStruct.rbearing) { fontStruct->max_bounds = charStruct; } else if (fontStruct->min_bounds.rbearing > charStruct.rbearing) { fontStruct->max_bounds = charStruct; } counter++; } } } return fontStruct; }
void initx(xxfmt *xx) { int rslt; char title[64]; xx->dpy = XOpenDisplay(NULL); if (xx->dpy == NULL) { fprintf(stderr,"X Windows failure\n"); exit(1); } /* if X Windows is not active */ assert(xx->dpy); /* get dimensions of root window */ xx->rootww = XDisplayWidth(xx->dpy,0); xx->rootwh = XDisplayHeight(xx->dpy,0); /* make display window smaller than root window */ /* allow for menu bar on top */ // xx->dpywdth = xx->rootww - 80; // xx->dpyhght = xx->rootwh - 100; xx->dpywdth = 512; /* need a power of 2 */ xx->dpyhght = 512; /* need a power of 2 */ xx->whiteColor = WhitePixel(xx->dpy, DefaultScreen(xx->dpy)); xx->blackColor = BlackPixel(xx->dpy, DefaultScreen(xx->dpy)); xx->w = XCreateSimpleWindow(xx->dpy, DefaultRootWindow(xx->dpy), 0, 0, xx->dpywdth, xx->dpyhght, 0, xx->whiteColor, xx->whiteColor); XSelectInput(xx->dpy, xx->w, StructureNotifyMask); XMapWindow(xx->dpy, xx->w); xx->gc = XCreateGC(xx->dpy, xx->w, 0, NULL); xx->fontid = (Font) XLoadFont(xx->dpy,"12x24"); XSetFont(xx->dpy,xx->gc,xx->fontid); XSetForeground(xx->dpy, xx->gc, xx->blackColor); xx->dfltscr = XDefaultScreenOfDisplay(xx->dpy); if (xx->dfltscr == NULL) { fprintf(stderr,"XDefaultScreenOfDisplay failed\n"); perror("XDefaultScreenOfDisplay failed"); exit(1); } /* if error */ xx->cmap = XDefaultColormapOfScreen(xx->dfltscr); rslt = XAllocNamedColor(xx->dpy,xx->cmap,"red", &xx->scrdef,&xx->exctdef); if (rslt < 0) { fprintf(stderr,"XAllocNamedColor failed\n"); perror("XAllocNamedColor failed"); exit(1); } /* if error */ xx->red = xx->scrdef.pixel; XSetWindowBorderWidth(xx->dpy, xx->w, 40); sprintf(title,"Random Screen"); XStoreName(xx->dpy,xx->w,title); XSetIconName(xx->dpy,xx->w,title); while(1) { XEvent e; XNextEvent(xx->dpy, &e); if (e.type == MapNotify) break; } /* wait for window initialization */ } /* initx */
static int X_init(__AA_CONST struct aa_hardware_params *p, __AA_CONST void *none,struct aa_hardware_params *dest, void **driverdata) { const char *font = "8x13bold"; static int registered; static aa_font aafont; __AA_CONST static struct aa_hardware_params def= {&aa_fontX13B, AA_DIM_MASK | AA_REVERSE_MASK | AA_NORMAL_MASK | AA_BOLD_MASK | AA_BOLDFONT_MASK | AA_EXTENDED, 0, 0, 0, 0, 80, 32, 0, 0}; struct xdriverdata *d; *dest=def; *driverdata=d=calloc(1,sizeof(*d)); d->previoust=NULL; d->previousa=NULL; d->cvisible=1; d->width=80; d->height=32; if ((d->dp = XOpenDisplay(NULL)) == NULL) return 0; d->screen = DefaultScreen(d->dp); if (getenv ("AAFont")) font = getenv ("AAFont"); d->font = XLoadFont(d->dp, font); if (!d->font) { XCloseDisplay(d->dp); return 0; } d->font_s = XQueryFont(d->dp, d->font); if (!d->font_s) { XCloseDisplay(d->dp); return 0; } d->fontheight = d->font_s->max_bounds.ascent + d->font_s->max_bounds.descent; d->fontwidth = d->font_s->max_bounds.rbearing - d->font_s->min_bounds.lbearing; d->realfontwidth = d->font_s->max_bounds.width; d->cmap = DefaultColormap(d->dp, d->screen); /*c.flags=DoRed | DoGreen | DoBlue; */ X_AllocColors (d); if (d->bold == d->normal) dest->supported &= ~AA_BOLD_MASK; if (d->dim == d->normal) dest->supported &= ~AA_DIM_MASK; d->attr.event_mask = ExposureMask; d->attr.override_redirect = False; if (p->width) d->width = p->width; if (p->height) d->height = p->height; if (p->maxwidth && d->width > p->maxwidth) d->width = p->maxwidth; if (p->minwidth && d->width < p->minwidth) d->width = p->minwidth; if (p->maxheight && d->height > p->maxheight) d->height = p->maxheight; if (p->minheight && d->height < p->minheight) d->height = p->minheight; d->wi = XCreateWindow(d->dp, RootWindow(d->dp, d->screen), 0, 0, d->width * d->realfontwidth, d->height * d->fontheight, 0, DefaultDepth(d->dp, d->screen), InputOutput, DefaultVisual(d->dp, d->screen), CWBackPixel | CWBorderPixel | CWEventMask, &d->attr); if (!registered) { d->pi = XCreatePixmap(d->dp, d->wi, d->fontwidth, d->fontheight * 256, 1); if (d->pi) { int i; unsigned char c; unsigned char *data; XImage *image; registered = 1; d->specialGC = XCreateGC(d->dp, d->pi, 0L, NULL); XSetForeground(d->dp, d->specialGC, 0); XSetBackground(d->dp, d->specialGC, 0); XFillRectangle(d->dp, d->pi, d->specialGC, 0, 0, d->fontwidth, 256 * d->fontheight); XSetForeground(d->dp, d->specialGC, 1); XSetFont(d->dp, d->specialGC, d->font); for (i = 0; i < 256; i++) { c = i; XDrawString(d->dp, d->pi, d->specialGC, 0, (i + 1) * d->fontheight - d->font_s->descent, (char *)&c, 1); } image = XGetImage(d->dp, d->pi, 0, 0, d->fontwidth, 256 * d->fontheight, 1, XYPixmap); if (image != NULL) { data = malloc(256 * d->fontheight); for (i = 0; i < 256; i++) { int y; font_error = 0; for (y = 0; y < d->fontheight; y++) { int o; o = ((mygetpixel(image, 0, i * d->fontheight + y) != 0) << 7) + ((mygetpixel(image, 1, i * d->fontheight + y) != 0) << 6) + ((mygetpixel(image, 2, i * d->fontheight + y) != 0) << 5) + ((mygetpixel(image, 3, i * d->fontheight + y) != 0) << 4) + ((mygetpixel(image, 4, i * d->fontheight + y) != 0) << 3) + ((mygetpixel(image, 5, i * d->fontheight + y) != 0) << 2) + ((mygetpixel(image, 6, i * d->fontheight + y) != 0) << 1) + ((mygetpixel(image, 7, i * d->fontheight + y) != 0) << 0); data[i * d->fontheight + y] = o; } } aafont.name = "Font used by X server"; aafont.shortname = "current"; aafont.height = d->fontheight; aafont.data = data; aa_registerfont(&aafont); dest->font = &aafont; } } } XStoreName(d->dp, d->wi, "aa for X"); XMapWindow(d->dp, d->wi); X_setinversionmode (getenv ("AAInverted") != NULL, d); d->pixelwidth = -1; d->pixelheight = -1; XSync(d->dp, 0); aa_recommendlowkbd("X11"); return 1; }
static void init( /* get view and find window */ char *pname, char *wname ) { extern Window xfindwind(); XWindowAttributes wa; XColor xc; XGCValues gcv; register int i; /* get the viewing parameters */ if (viewfile(pname, &ourview, &pres) <= 0 || setview(&ourview) != NULL) { fprintf(stderr, "%s: cannot get view from \"%s\"\n", progname, pname); exit(1); } /* open the display */ if ((theDisplay = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "%s: cannot open display; DISPLAY variable set?\n", progname); exit(1); } /* find our window */ if (wname == NULL) { /* remove directory prefix from name */ for (i = strlen(pname); i-- > 0; ) if (pname[i] == '/') break; wname = pname+i+1; i = 0; } else i = 1; gwind = xfindwind(theDisplay, rwind, wname, 4); if (gwind == None) { if (i) { fprintf(stderr, "%s: cannot find \"%s\" window\n", progname, wname); exit(2); } /* start ximage */ if (fork() == 0) { execlp(XIM, XIM, "-c", "256", pname, 0); perror(XIM); fprintf(stderr, "%s: cannot start %s\n", progname, XIM); kill(getppid(), SIGPIPE); _exit(1); } do sleep(8); while ((gwind=xfindwind(theDisplay,rwind,wname,4)) == None); } else XMapRaised(theDisplay, gwind); do { XGetWindowAttributes(theDisplay, gwind, &wa); sleep(6); } while (wa.map_state != IsViewable); if (wa.width != scanlen(&pres) || wa.height != numscans(&pres)) { fprintf(stderr, "%s: warning -- window seems to be the wrong size!\n", progname); if (pres.rt & YMAJOR) { pres.xr = wa.width; pres.yr = wa.height; } else { pres.xr = wa.height; pres.yr = wa.width; } } /* set graphics context */ gcv.font = XLoadFont(theDisplay, FONTNAME); if (gcv.font == 0) { fprintf(stderr, "%s: cannot load font \"%s\"\n", progname, FONTNAME); exit(1); } xc.red = col[0] >= 1.0 ? 65535 : (unsigned)(65536*col[0]); xc.green = col[1] >= 1.0 ? 65535 : (unsigned)(65536*col[1]); xc.blue = col[2] >= 1.0 ? 65535 : (unsigned)(65536*col[2]); xc.flags = DoRed|DoGreen|DoBlue; gcv.background = xc.green >= 32768 ? BlackPixel(theDisplay,DefaultScreen(theDisplay)) : WhitePixel(theDisplay,DefaultScreen(theDisplay)) ; if (XAllocColor(theDisplay, wa.colormap, &xc)) { gcv.foreground = xc.pixel; vecGC = XCreateGC(theDisplay,gwind, GCForeground|GCBackground|GCFont,&gcv); strGC = vecGC; } else { gcv.function = GXinvert; vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv); gcv.foreground = xc.green < 32768 ? BlackPixel(theDisplay,DefaultScreen(theDisplay)) : WhitePixel(theDisplay,DefaultScreen(theDisplay)) ; strGC = XCreateGC(theDisplay,gwind, GCForeground|GCBackground|GCFont,&gcv); } }
void xstext ( int *itxfn, float *txtsz, int *ijust, float *txsize, int *iret ) /************************************************************************ * xstext * * * * This subroutine gets the name of the hardware font to be used * * and computes the actual font size to be used. * * * * void xstext ( itxfn, txtsz, ijust, txsize, iret ) * * * * Input parameters: * * *itxfn int Number of desired font * * *txtsz float Requested text size * * *ijust int Text justification * * * * Output parameters: * * *txsize float Actual text size set * * *iret int Return code * * G_NORMAL = normal return * ** * * Log: * * J. Whistler/SSAI 7/91 * * S. Jacobs/EAI 10/92 Changed comp of font name and size * * C. Lin/EAI 9/93 Added check for loaded fonts * * S. Jacobs/NMC 7/94 General clean up * * C. Lin/EAI 7/94 Multi-window, multi-pixmap * * M. desJardins/NMC 10/94 Eliminate check for current font * * C. Lin/EAI 11/94 use XQueryTextExtents instead of * * of XQueryFont to avoid font_info, * * therefore possible memory leak. * * S. Jacobs/NCEP 6/97 Changed calculation of text point sizes * * S. Jacobs/NCEP 11/97 Added justification to calling seq * * S. Jacobs/NCEP 2/98 Changed calc of Y size of font * * S. Jacobs/NCEP 7/98 Removed calc of txszx and txszy * * S. Jacobs/NCEP 7/98 Added actual text size * * S. Jacobs/NCEP 4/00 Added point size 34 * * B. Yin/SAIC 3/04 Modified code to use iso-8859-1 * ***********************************************************************/ { char fontname[80]; int i, size, mult, iftyp1, iftyp2, nfnt; float avgsiz; Font fontid; static char *fonts[12] = { "-adobe-courier-medium-r-normal--", "-adobe-helvetica-medium-r-normal--", "-adobe-times-medium-r-normal--", "-adobe-courier-medium-o-normal--", "-adobe-helvetica-medium-o-normal--", "-adobe-times-medium-i-normal--", "-adobe-courier-bold-r-normal--", "-adobe-helvetica-bold-r-normal--", "-adobe-times-bold-r-normal--", "-adobe-courier-bold-o-normal--", "-adobe-helvetica-bold-o-normal--", "-adobe-times-bold-i-normal--" }; static int fontsz[] = { 8, 10, 12, 14, 18, 24, 34 }; static int fntmul[] = { 80, 100, 120, 140, 180, 240, 240 }; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Get valid text font and save the values. */ iftyp1 = *itxfn / 10; iftyp2 = *itxfn % 10; if ( ( iftyp1 < 0 ) || ( iftyp1 > 3 ) ) iftyp1 = 0; if ( ( iftyp2 < 1 ) || ( iftyp2 > 3 ) ) iftyp2 = 1; txfont_req = iftyp1 * 3 + iftyp2; if ( *txtsz > 0. ) { txsize_req = *txtsz; } else { txsize_req = 1.; } /* * Get the size of the font in point values. */ nfnt = sizeof(fontsz) / sizeof(fontsz[0]); size = fontsz[0]; mult = fntmul[0]; for ( i = 1; i < nfnt; i++ ) { avgsiz = ( (fontsz[i-1]/14.0) + (fontsz[i]/14.0) ) / 2.0; if ( txsize_req > avgsiz ) { size = fontsz[i]; mult = fntmul[i]; } } *txsize = size / 14.0; txsize_req = *txsize; /* * Get the name of the font. */ sprintf ( fontname, "%s%d-%d-*-*-*-*-iso8859-1", fonts[txfont_req-1], size, mult ); /* * Check if the font is already loaded. * Load the font and set the font character height and widths. */ fontid = -1; for ( i = 0; i < nfont; i++ ) { if ( strcmp ( fontname, loadfonts[i].name ) == 0 ) { fontid = loadfonts[i].id; } } if ( fontid == (Font)-1 ) { fontid = XLoadFont ( gemdisplay, fontname ); if ( nfont < MAX_LOAD_FONTS ) { strcpy ( loadfonts[nfont].name, fontname ); loadfonts[nfont].id = fontid; nfont ++; } else { xrmfnt ( 0 ); strcpy ( loadfonts[MAX_LOAD_FONTS-1].name, fontname ); loadfonts[MAX_LOAD_FONTS-1].id = fontid; nfont = MAX_LOAD_FONTS; } } XSetFont ( gemdisplay, gemwindow[current_window].gc, fontid ); txfont_set = txfont_req; txsize_set = txsize_req; /* * Save the text justification. */ kjust = *ijust; }
/*-------------------------------------------------------------------------- ** Purpose: Windows thread. ** ** Parameters: Name Description. ** ** Returns: Nothing. ** **------------------------------------------------------------------------*/ void *windowThread(void *param) { GC gc; KeySym key; KeySym modList[2]; Pixmap pixmap; XEvent event; XWMHints wmhints; int screen, depth; char text[30]; unsigned long fg, bg; int len; XWindowAttributes a; XColor b,c; static int refreshCount = 0; char str[2] = " "; DispList *curr; DispList *end; u8 oldFont = 0; Atom targetProperty; Atom retAtom; Atom wmDeleteWindow; int retFormat; int retStatus; unsigned long retRemaining; unsigned long retLength; int usageDisplayCount = 0; /* ** Open the X11 display. */ disp = XOpenDisplay(0); if (disp == (Display *) NULL) { fprintf(stderr, "Could not open display\n"); exit(1); } screen = DefaultScreen(disp); /* ** Create a window using the following hints. */ width = 1100; height = 750; bg = BlackPixel(disp, screen); fg = WhitePixel(disp, screen); window = XCreateSimpleWindow (disp, DefaultRootWindow(disp), 10, 10, width, height, 5, fg, bg); /* ** Create a pixmap for background image generation. */ depth = DefaultDepth (disp, screen); pixmap = XCreatePixmap (disp, window, width, height, depth); /* ** Set window and icon titles. */ XSetStandardProperties (disp, window, DtCyberVersion " - " DtCyberCopyright " - " DtCyberLicense, DtCyberVersion, None, NULL, 0, NULL); /* ** Create the graphics contexts for window and pixmap. */ gc = XCreateGC (disp, window, 0, 0); /* ** We don't want to get Expose events, otherwise every XCopyArea will generate one, ** and the event queue will fill up. This application will discard them anyway, but ** it is better not to generate them in the first place. */ XSetGraphicsExposures(disp, gc, FALSE); /* ** Load three Cyber fonts. */ hSmallFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-10-*-*-*-*-*-*-*\0"); hMediumFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-14-*-*-*-*-*-*-*\0"); hLargeFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-24-*-*-*-*-*-*-*\0"); /* ** Setup fore- and back-ground colors. */ XGetWindowAttributes(disp,window,&a); XAllocNamedColor(disp, a.colormap,"green",&b,&c); fg=b.pixel; bg = BlackPixel(disp, screen); XSetBackground(disp, gc, bg); XSetForeground(disp, gc, fg); /* ** Create mappings of some ALT-key combinations to strings. */ modList[0] = XK_Meta_L; XRebindKeysym(disp, '0', modList, 1, (u8 *)"$0", 2); XRebindKeysym(disp, '1', modList, 1, (u8 *)"$1", 2); XRebindKeysym(disp, '2', modList, 1, (u8 *)"$2", 2); XRebindKeysym(disp, '3', modList, 1, (u8 *)"$3", 2); XRebindKeysym(disp, '4', modList, 1, (u8 *)"$4", 2); XRebindKeysym(disp, '5', modList, 1, (u8 *)"$5", 2); XRebindKeysym(disp, '6', modList, 1, (u8 *)"$6", 2); XRebindKeysym(disp, '7', modList, 1, (u8 *)"$7", 2); XRebindKeysym(disp, '8', modList, 1, (u8 *)"$8", 2); XRebindKeysym(disp, '9', modList, 1, (u8 *)"$9", 2); XRebindKeysym(disp, 'c', modList, 1, (u8 *)"$c", 2); XRebindKeysym(disp, 'C', modList, 1, (u8 *)"$c", 2); XRebindKeysym(disp, 'e', modList, 1, (u8 *)"$e", 2); XRebindKeysym(disp, 'E', modList, 1, (u8 *)"$e", 2); XRebindKeysym(disp, 'x', modList, 1, (u8 *)"$x", 2); XRebindKeysym(disp, 'X', modList, 1, (u8 *)"$x", 2); XRebindKeysym(disp, 'p', modList, 1, (u8 *)"$p", 2); XRebindKeysym(disp, 'P', modList, 1, (u8 *)"$p", 2); /* ** Initialise input. */ wmhints.flags = InputHint; wmhints.input = True; XSetWMHints(disp, window, &wmhints); XSelectInput (disp, window, KeyPressMask | KeyReleaseMask | StructureNotifyMask); /* ** We like to be on top. */ XMapRaised (disp, window); /* ** Create atom for paste operations, */ targetProperty = XInternAtom(disp, "DtCYBER", False); /* ** Create atom for delete message and set window manager. */ wmDeleteWindow = XInternAtom(disp, "WM_DELETE_WINDOW", False); XSetWMProtocols(disp, window, &wmDeleteWindow, 1); /* ** Window thread loop. */ displayActive = TRUE; while(displayActive) { /* ** Process paste buffer one character a time. */ if (lpClipToKeyboardPtr != NULL) { if (clipToKeyboardDelay != 0) { /* ** Delay after CR. */ clipToKeyboardDelay -= 1; } else { ppKeyIn = *lpClipToKeyboardPtr++; if (ppKeyIn == 0) { /* ** All paste data has been processed - clean up. */ XFree(lpClipToKeyboard); lpClipToKeyboard = NULL; lpClipToKeyboardPtr = NULL; } else if (ppKeyIn == '\n') { /* ** Substitute to a CR to be able to handle DOS/Windows or UNIX style ** line terminators. */ ppKeyIn = '\r'; /* ** Short delay to allow PP program to process the line. This may ** require customisation. */ clipToKeyboardDelay = 30; } else if (ppKeyIn == '\r') { /* ** Ignore CR. */ ppKeyIn = 0; } } } /* ** Process any X11 events. */ while (XEventsQueued(disp, QueuedAfterReading)) { XNextEvent(disp, &event); switch (event.type) { case ClientMessage: if (event.xclient.data.l[0] == wmDeleteWindow) { /* ** Initiate display of usage note because user attempts to close the window. */ usageDisplayCount = 5 * FramesPerSecond; } break; case MappingNotify: XRefreshKeyboardMapping ((XMappingEvent *)&event); refresh = TRUE; break; case ConfigureNotify: if (event.xconfigure.width > width || event.xconfigure.height > height) { /* ** Reallocate pixmap only if it has grown. */ width = event.xconfigure.width; height = event.xconfigure.height; XFreePixmap (disp, pixmap); pixmap = XCreatePixmap (disp, window, width, height, depth); } XFillRectangle (disp, pixmap, gc, 0, 0, width, height); refresh = TRUE; break; case KeyPress: len = XLookupString ((XKeyEvent *)&event, text, 10, &key, 0); if (len == 1) { ppKeyIn = text[0]; usleep(5000); } else if (len == 2 && text[0] == '$') { switch (text[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': traceMask ^= (1 << (text[1] - '0')); break; case 'c': traceMask ^= (1 << 14); break; case 'e': traceMask ^= (1 << 15); break; case 'x': if (traceMask == 0) { traceMask = ~0; } else { traceMask = 0; } break; case 'p': if (lpClipToKeyboardPtr != NULL) { /* ** Ignore paste request when a previous one is still executing. */ break; } if (targetProperty == None) { /* ** The paste operation atom has not been created. This is bad, but ** not fatal, so we silently ignore paste requests. */ break; } /* ** Request the server to send an event to the present owner of the selection, ** asking the owner to convert the data in the selection to the required type. */ XConvertSelection(disp, XA_PRIMARY, XA_STRING, targetProperty, window, event.xbutton.time); break; } } break; case KeyRelease: len = XLookupString((XKeyEvent *)&event, text, 10, &key, 0); if (len == 1) { switch (text[0]) { default: break; } } break; case SelectionNotify: /* ** The present owner of the selection has replied. */ if (event.xselection.property != targetProperty) { /* ** The current selection is not a string, so we ignore it. */ break; } /* ** Fetch up to 1 kb from the selection. */ retStatus = XGetWindowProperty(disp, window, event.xselection.property, 0L, 1024, False, AnyPropertyType, &retAtom, &retFormat, &retLength, &retRemaining, &lpClipToKeyboard); if (retStatus == Success) { lpClipToKeyboardPtr = lpClipToKeyboard; } else { lpClipToKeyboard = NULL; lpClipToKeyboardPtr = NULL; } break; } } /* ** Process any refresh request. */ XSetForeground (disp, gc, fg); XSetFont(disp, gc, hSmallFont); oldFont = FontSmall; #if CcCycleTime { extern double cycleTime; char buf[80]; sprintf(buf, "Cycle time: %.3f", cycleTime); XDrawString(disp, pixmap, gc, 0, 10, buf, strlen(buf)); } #endif #if CcDebug == 1 { char buf[160]; /* ** Display P registers of PPUs and CPU and current trace mask. */ sprintf(buf, "Refresh: %-10d PP P-reg: %04o %04o %04o %04o %04o %04o %04o %04o %04o %04o CPU P-reg: %06o", refreshCount++, ppu[0].regP, ppu[1].regP, ppu[2].regP, ppu[3].regP, ppu[4].regP, ppu[5].regP, ppu[6].regP, ppu[7].regP, ppu[8].regP, ppu[9].regP, cpu.regP); sprintf(buf + strlen(buf), " Trace: %c%c%c%c%c%c%c%c%c%c%c%c", (traceMask >> 0) & 1 ? '0' : '_', (traceMask >> 1) & 1 ? '1' : '_', (traceMask >> 2) & 1 ? '2' : '_', (traceMask >> 3) & 1 ? '3' : '_', (traceMask >> 4) & 1 ? '4' : '_', (traceMask >> 5) & 1 ? '5' : '_', (traceMask >> 6) & 1 ? '6' : '_', (traceMask >> 7) & 1 ? '7' : '_', (traceMask >> 8) & 1 ? '8' : '_', (traceMask >> 9) & 1 ? '9' : '_', (traceMask >> 14) & 1 ? 'C' : '_', (traceMask >> 15) & 1 ? 'E' : '_'); XDrawString(disp, pixmap, gc, 0, 10, buf, strlen(buf)); } #endif if (opActive) { /* ** Display pause message. */ static char opMessage[] = "Emulation paused"; XSetFont(disp, gc, hLargeFont); oldFont = FontLarge; XDrawString(disp, pixmap, gc, 20, 256, opMessage, strlen(opMessage)); } /* ** Protect display list. */ pthread_mutex_lock(&mutexDisplay); if (usageDisplayCount != 0) { /* ** Display usage note when user attempts to close window. */ static char usageMessage1[] = "Please don't just close the window, but instead first cleanly halt the operating system and"; static char usageMessage2[] = "then use the 'shutdown' command in the operator interface to terminate the emulation."; XSetFont(disp, gc, hMediumFont); oldFont = FontMedium; XDrawString(disp, pixmap, gc, 20, 256, usageMessage1, strlen(usageMessage1)); XDrawString(disp, pixmap, gc, 20, 275, usageMessage2, strlen(usageMessage2)); listEnd = 0; usageDisplayCount -= 1; } /* ** Draw display list in pixmap. */ curr = display; end = display + listEnd; for (curr = display; curr < end; curr++) { /* ** Setup new font if necessary. */ if (oldFont != curr->fontSize) { oldFont = curr->fontSize; switch (oldFont) { case FontSmall: XSetFont(disp, gc, hSmallFont); break; case FontMedium: XSetFont(disp, gc, hMediumFont); break; case FontLarge: XSetFont(disp, gc, hLargeFont); break; } } /* ** Draw dot or character. */ if (curr->fontSize == FontDot) { XDrawPoint(disp, pixmap, gc, curr->xPos, (curr->yPos * 14) / 10 + 20); } else { str[0] = curr->ch; XDrawString(disp, pixmap, gc, curr->xPos, (curr->yPos * 14) / 10 + 20, str, 1); } } listEnd = 0; currentX = -1; currentY = -1; refresh = FALSE; /* ** Release display list. */ pthread_mutex_unlock (&mutexDisplay); /* ** Update display from pixmap. */ XCopyArea(disp, pixmap, window, gc, 0, 0, width, height, 0, 0); /* ** Erase pixmap for next round. */ XSetForeground (disp, gc, bg); XFillRectangle (disp, pixmap, gc, 0, 0, width, height); /* ** Make sure the updates make it to the X11 server. */ XSync(disp, 0); /* ** Give other threads a chance to run. This may require customisation. */ usleep(FrameTime); } XSync(disp, 0); XFreeGC (disp, gc); XFreePixmap (disp, pixmap); XDestroyWindow (disp, window); XCloseDisplay (disp); pthread_exit(NULL); }
static UnixFtFont * InitFont( Tk_Window tkwin, FcPattern *pattern, UnixFtFont *fontPtr) { FcFontSet *set; FcCharSet *charset; FcResult result; XftFont *ftFont; int i; if (!fontPtr) { fontPtr = (UnixFtFont *) ckalloc(sizeof(UnixFtFont)); } FcConfigSubstitute(0, pattern, FcMatchPattern); XftDefaultSubstitute(Tk_Display(tkwin), Tk_ScreenNumber(tkwin), pattern); /* * Generate the list of fonts */ set = FcFontSort(0, pattern, FcTrue, NULL, &result); if (!set) { FcPatternDestroy(pattern); ckfree((char *)fontPtr); return NULL; } fontPtr->fontset = set; fontPtr->pattern = pattern; fontPtr->faces = (UnixFtFace *) ckalloc(set->nfont * sizeof(UnixFtFace)); fontPtr->nfaces = set->nfont; /* * Fill in information about each returned font */ for (i = 0; i < set->nfont; i++) { fontPtr->faces[i].ftFont = 0; fontPtr->faces[i].source = set->fonts[i]; if (FcPatternGetCharSet(set->fonts[i], FC_CHARSET, 0, &charset) == FcResultMatch) { fontPtr->faces[i].charset = FcCharSetCopy(charset); } else { fontPtr->faces[i].charset = 0; } } fontPtr->display = Tk_Display(tkwin); fontPtr->screen = Tk_ScreenNumber(tkwin); fontPtr->ftDraw = 0; fontPtr->color.color.red = 0; fontPtr->color.color.green = 0; fontPtr->color.color.blue = 0; fontPtr->color.color.alpha = 0xffff; fontPtr->color.pixel = 0xffffffff; /* * Fill in platform-specific fields of TkFont. */ ftFont = GetFont(fontPtr, 0); fontPtr->font.fid = XLoadFont(Tk_Display(tkwin), "fixed"); GetTkFontAttributes(ftFont, &fontPtr->font.fa); GetTkFontMetrics(ftFont, &fontPtr->font.fm); return fontPtr; }
/*--------------------------------------------------------*/ void open_gwindow_( ) { /* * create new graphics window on first entry.... */ int font,black,white; int scr_width,scr_height; int j; unsigned long valuemask; static int depth; /* number of planes */ static Visual *visual; /*VISUAL TYPE */ static XSizeHints win_position; /*position and size for window manager.*/ /* * initialize display id and screen id.... */ disp_id = XOpenDisplay(0); if (!disp_id) { printf("Display not opened!\n"); exit(-1); } /* * next instruction for debugging only.... */ /* XSynchronize(disp_id, 1); */ screen_id = XDefaultScreenOfDisplay(disp_id); root_win_id = XRootWindowOfScreen(screen_id); black = XBlackPixelOfScreen(screen_id); white = XWhitePixelOfScreen(screen_id); scr_width = XWidthOfScreen(screen_id); scr_height = XHeightOfScreen(screen_id); depth = XDefaultDepthOfScreen(screen_id); visual = XDefaultVisualOfScreen(screen_id); /* * set up backing store.... */ valuemask = CWBitGravity | CWBackingStore | CWBackPixel; setwinattr.bit_gravity = SouthWestGravity; setwinattr.backing_store = Always; setwinattr.background_pixel = white; /* * create the window.... */ win_id = XCreateWindow(disp_id, root_win_id, scr_width - win_width - 15, scr_height - win_height - 35, win_width, win_height, 10, depth, InputOutput, visual, valuemask, &setwinattr); /* WMHints structure */ win_position.x = scr_width - win_width - 15; win_position.y = scr_height - win_height - 35; win_position.width = win_width; win_position.height = win_height; win_position.flags=USPosition|USSize; XSetWMNormalHints(disp_id, win_id, &win_position); XStoreName(disp_id, win_id, WINDNAME); /* * get named color values.... */ color[1] = define_color_("BLUE"); color[2] = define_color_("DEEP SKY BLUE"); color[3] = define_color_("LIGHT SKY BLUE"); color[4] = define_color_("SEA GREEN"); color[5] = define_color_("MEDIUM SEA GREEN"); color[6] = define_color_("GREEN"); color[7] = define_color_("BROWN"); color[8] = define_color_("CHOCOLATE"); color[9] = define_color_("SANDY BROWN"); color[10] = define_color_("RED"); color[11] = define_color_("CORAL"); color[12] = define_color_("ORANGE"); color[13] = define_color_("YELLOW3"); color[14] = define_color_("YELLOW2"); color[15] = define_color_("YELLOW"); color[16] = define_color_("PEACH PUFF"); color[17] = define_color_("PAPAYA WHIP"); color[18] = define_color_("OLD LACE"); color[19] = white; color[20] = black; color[21] = black; /* * create graphics context.... */ xgcvl.background = color[19]; xgcvl.foreground = color[20]; gc_id = XCreateGC(disp_id, win_id, GCForeground | GCBackground, &xgcvl); xgcvl.function = GXinvert; gc_comp_id = XCreateGC(disp_id, win_id, GCFunction, &xgcvl); /* * load the font for text writing.... */ font = XLoadFont(disp_id, FONTNAME); XSetFont(disp_id, gc_id, font); /* Map the window.... */ XSelectInput(disp_id,win_id,ExposureMask|VisibilityChangeMask); XMapRaised(disp_id,win_id); /* * Wait for the window to be raised. Some X servers do not * generate an initial expose event, so also check the visibility * event. */ XMaskEvent(disp_id,ExposureMask|VisibilityChangeMask,&event); XSelectInput(disp_id,win_id,0); XSync(disp_id,1); }
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; } }
int main (int argc, char **argv) { /* Variables used for XWindow. */ Display *my_display; /* Display unit. */ Window root_id; /* Root window. */ Window my_window; /* First window opened. */ Window wind_pic; /* Window with picture. */ Window wind_exit; /* Exit window. */ Window wind_scale; /* Color scale window. */ GC my_gc; /* Gc for my_window. */ XSizeHints window_hints; /* Hints for 1st window. */ XEvent event_received; /* Events. */ long input_event_mask; /* Input event mask that are to * be responded to. */ unsigned long black; /* Black pixel value. */ unsigned long white; /* White pixel value. */ int screen=0; /* Used for getting colors. */ XColor colval[MAXCOL]; /* Color values. */ XRectangle rect[MAXARR]; /* Array for drawing rectangles. */ char **a=(char **)NULL; /* Place holder for XSetStandard Properties. */ const char winttl[] = "SEE"; /* Window title. */ const char quit[] = "QUIT"; /* Exit label. */ Font font; /* Structure for setting font. */ /* Other variables. */ FILE *fpr; /* Used to read a file. */ FILE *fpw; /* Used to write a file. */ char file[MAXFIL]; /* File to be read. */ char line[151]; /* Used to read one line of a file. */ size_t main_w, main_h; /* Width & height of main window. */ size_t wide, high; /* Width and height of picture window. */ double pixval[MAXPIX][MAXPIX];/* Pixel value (width, height). */ double min=0.0, max=0.0; /* Minimum & maximum pixel values. */ int i, j, k, m; /* Loop counters. */ double r; /* Temporary variable. */ double dcol; /* Color step. */ double pixbin[MAXCOL + 1]; /* Pixel bins. */ double dpix; /* Delta between pixel bins. */ int color[MAXPIX][MAXPIX]; /* Indicates color. */ int icol; /* Indicates color shading. */ double check; /* Used for finding colors. */ char string[11]; /* Used to write a label. */ int flag=0; /* Color flag. */ int lstarr; /* Last color array. */ int flag_pix; /* 0=>no pix file written, 1=>pix file written. */ char file_pix[MAXFIL]; /* Pix file name. */ unsigned char c; /* Used to write pix file. */ int ret; int ch; struct colstr *array = NULL; /* Array for color information. */ bu_opterr = 0; while ((ch = bu_getopt(argc, argv, "h?")) != -1) { if (bu_optopt == '?') ch = 'h'; switch (ch) { case 'h': fprintf(stderr,"ir-X is interactive; sample session in 'man' page\n"); bu_exit(1,NULL); default: break; } } fprintf(stderr," Program continues running:\n"); array = (struct colstr *)bu_calloc(MAXCOL + EXTRA, sizeof(struct colstr), "allocate colstr array"); /* Get file name to be read. */ printf("Enter name of file to be read (%d char max).\n\t", MAXFIL); (void)fflush(stdout); ret = scanf("%25s", file); if (ret == 0) perror("scanf"); /* Find what color shading to use. */ printf("Indicate type of color shading to use.\n"); printf("\t0 - gray\n"); printf("\t1 - red\n"); printf("\t2 - black-blue-cyan-green-yellow-white\n"); printf("\t3 - black-blue-magenta-red-yellow-white\n"); (void)fflush(stdout); ret = scanf("%d", &icol); if (ret == 0) perror("scanf"); if ((icol != 1) && (icol != 2) && (icol != 3)) icol = 0; /* Determine if a pix file is to be written. */ flag_pix = 0; printf("Do you wish to create a pix file (0-no, 1-yes)?\n\t"); (void)fflush(stdout); ret = scanf("%d", &flag_pix); if (ret == 0) perror("scanf"); if (flag_pix != 1) flag_pix = 0; else { printf("Enter name of the pix file to be created "); printf("(%d char max).\n\t", MAXFIL); (void)fflush(stdout); ret = scanf("%25s", file_pix); if (ret == 0) perror("scanf"); } printf("Zeroing color info array "); (void)fflush(stdout); /* Zero color info array. */ for (i=0; i<(MAXCOL + EXTRA); i++) { array[i].cnt = 0; array[i].more = 0; } lstarr = MAXCOL; printf("- finished zeroing\n"); (void)fflush(stdout); printf("Setting up color scale "); (void)fflush(stdout); /* Set up color scale. */ dcol = (65535.0 + 1.0) / MAXCOL; if (icol == 0) { /* Shades of gray. */ printf("-shades of gray "); (void)fflush(stdout); for (i=0; i<MAXCOL; i++) { colval[i].red = (unsigned short)((double)i * dcol); colval[i].green = (unsigned short)((double)i * dcol); colval[i].blue = (unsigned short)((double)i * dcol); } } else if (icol == 1) { /* Shades of red. */ printf("- shades of red "); (void)fflush(stdout); for (i=0; i<MAXCOL; i++) { colval[i].red = (unsigned short)((double)i * dcol); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)0; } } else if (icol == 2) { /* Black-blue-cyan-green-yellow-white. */ printf("- black-blue-cyan-green-yellow-white "); (void)fflush(stdout); if (MAXCOL > 1280.0) { printf("Maximum number of colors, %d, is ", MAXCOL); printf("greater than 1280.\n"); printf("This may create problems.\n"); } /* Color step. */ dcol = 1280. / MAXCOL; i = 0; /* Colors (0, 0, 0) to (0, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } /* Colors (0, 0, 255) to (0, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)(check * 256.0); colval[i].blue = (unsigned short)(255 * 256); check += dcol; i++; } /* Colors (0, 255, 255) to (0, 255, 0). */ check = 255.0; while ((check >= 0.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check -= dcol; i++; } /* Colors (0, 255, 0) to (255, 255, 0). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(check * 256.0); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)0; check += dcol; i++; } /* Colors (255, 255, 0) to (255, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } } else if (icol == 3) { /* Black-blue-magenta-red-yellow-white. */ printf("- black-blue-magenta-red-yellow-white "); (void)fflush(stdout); if (MAXCOL > 1280.0) { printf("Maximum number of colors, %d, is ", MAXCOL); printf("greater than 1280.\n"); printf("This may create problems.\n"); } /* Color step. */ dcol = 1280. / MAXCOL; i = 0; /* Colors (0, 0, 0) to (0, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } /* Colors (0, 0, 255) to (255, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(check * 256.0); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(255 * 256); check += dcol; i++; } /* Colors (255, 0, 255) to (255, 0, 0). */ check = 255.0; while ((check >= 0.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check -= dcol; i++; } /* Colors (255, 0, 0) to (255, 255, 0). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(check * 256.0); colval[i].blue = (unsigned short)0; check += dcol; i++; } /* Colors (255, 255, 0) to (255, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } } printf("- finished.\n"); (void)fflush(stdout); printf("Reading file "); (void)fflush(stdout); /* Open file for reading. */ fpr = fopen(file, "rb"); /* Check for non-existent file. */ while (fpr == NULL) { printf("\nThis file does not exist, please try again.\n"); (void)fflush(stdout); ret = scanf("%25s", file); if (ret == 0) { bu_exit(EXIT_FAILURE, "ir-X - scanf failure - no file to work with!!\n"); } fpr = fopen(file, "rb"); } /* Read width and height of window. */ (void)bu_fgets(line, 150, fpr); { unsigned long w, h; sscanf(line, "%lu %lu", &w, &h); wide = w; high = h; } /* Check that width and height are not too big. */ if (wide > (size_t)MAXPIX) { printf("The width of the window, %lu, is greater\n", (unsigned long)wide); printf("than the maximum for width, %lu. Press\n", (unsigned long)MAXPIX); printf("delete to end program.\n"); (void)fflush(stdout); } if (high > MAXPIX) { printf("The height of the window, %lu, is greater\n", (unsigned long)wide); printf("than the maximum for height, %lu. Press\n", (unsigned long)MAXPIX); printf("delete to end program.\n"); (void)fflush(stdout); } /* Read pixel values. */ for (i=0; i<(int)high; i++) { for (j=0; j<(int)wide; j++) { (void)bu_fgets(line, 150, fpr); sscanf(line, "%lf", &pixval[j][i]); } } /* Close file. */ (void)fclose(fpr); printf("- file read.\n"); (void)fflush(stdout); /* Print out width and height of window. */ printf("Width: %lu\n", (unsigned long)wide); printf("Height: %lu\n", (unsigned long)high); (void)fflush(stdout); printf("Finding min & max.\n"); (void)fflush(stdout); /* Find minimum and maximum of pixel values. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { if ((j==0) && (i==0)) { min = pixval[j][i]; max = pixval[j][i]; } V_MIN(min, pixval[j][i]); V_MAX(max, pixval[j][i]); } } /* Write minimum and maximum pixel values. */ printf("Minimum: %f\n", min); printf("Maximum: %f\n", max); (void)fflush(stdout); printf("Finding pixel bins "); (void)fflush(stdout); /* Find pixel bins. */ dpix = (max - min) / MAXCOL; pixbin[0] = min; for (i=1; i<MAXCOL; i++) { pixbin[i] = pixbin[i-1] + dpix; } pixbin[MAXCOL] = max; /* Find the color for each pixel. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { /* Determine the color associated with pixval[j][i]. */ m = 0; k = 0; color[j][i] = 0; while ((m == 0) && (k < MAXCOL)) { if ((pixval[j][i] > pixbin[k]) && (pixval[j][i] <= pixbin[k + 1])) { color[j][i] = k; m = 1; } k++; } } } printf("- found pixel bins.\n"); (void)fflush(stdout); printf("Putting color info in arrays "); (void)fflush(stdout); /* Put color info in arrays. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { if (array[color[j][i]].cnt < MAXARR) { array[color[j][i]].x1[array[color[j][i]].cnt] = j; array[color[j][i]].y1[array[color[j][i]].cnt] = i; array[color[j][i]].cnt++; } else { if (array[color[j][i]].more == 0) { if (lstarr < (MAXCOL + EXTRA)) { array[color[j][i]].more = lstarr; k = lstarr; lstarr++; array[k].x1[array[k].cnt] = j; array[k].y1[array[k].cnt] = i; array[k].cnt++; } else { flag = 1; } } else { k = array[color[j][i]].more; if (array[k].cnt < MAXARR) { array[k].x1[array[k].cnt] = j; array[k].y1[array[k].cnt] = i; array[k].cnt++; } else { flag = 1; } } } } } printf("- color info in arrays.\n"); (void)fflush(stdout); if (flag != 0) { printf("There too many pixels of one color. Note that\n"); printf("this means there is something wrong with the\n"); printf("picture!\n"); (void)fflush(stdout); } /* Set up window to be the size that was read. */ /* Open display. */ my_display = XOpenDisplay(NULL); /* Get id of parent (root is parent). */ root_id = DefaultRootWindow(my_display); /* Find value for black & white. */ black = BlackPixel(my_display, DefaultScreen(my_display)); white = WhitePixel(my_display, DefaultScreen(my_display)); /* Create a window & find its id. */ main_w = wide + (unsigned int)150; main_h = high + (unsigned int)150; my_window = XCreateSimpleWindow(my_display, root_id, 0, 0, main_w, main_h, 50, white, black); /* Set appropriate fields in window hits structure. */ /* This is only done for the first window created. */ window_hints.width = (int)main_w; window_hints.height = (int)main_h; window_hints.flags = PSize; /* Inform window manager of hints. */ /* Set XSetStandarProperties instead of XSetNormalHints. */ XSetStandardProperties(my_display, my_window, winttl, winttl, None, a, 0, &window_hints); /* Create picture window & find its id. */ wind_pic = XCreateSimpleWindow(my_display, my_window, 20, 20, wide, high, 5, white, black); /* Create exit window & find its id. */ wind_exit = XCreateSimpleWindow(my_display, my_window, (wide + 30), (high + 65), 80, 30, 5, white, black); /* Create color scale window & find its id. */ wind_scale = XCreateSimpleWindow(my_display, my_window, 10, (high + 50), (2 * MAXCOL), 60, 5, white, black); /* Select input event masks that are to be responded to (exposure). */ input_event_mask = ExposureMask | ButtonPressMask; /* Notify server about input event masks. */ XSelectInput(my_display, my_window, ExposureMask); XSelectInput(my_display, wind_pic, ExposureMask); XSelectInput(my_display, wind_exit, input_event_mask); XSelectInput(my_display, wind_scale, input_event_mask); /* Map window to display so that it will show up. */ XMapWindow(my_display, my_window); /* Map picture window, exit window, & color scale window to display */ /* so that they will show up. */ XMapWindow(my_display, wind_pic); XMapWindow(my_display, wind_exit); XMapWindow(my_display, wind_scale); /* Create graphics context (gc) for my window. */ my_gc = XCreateGC(my_display, my_window, None, NULL); /* Create a loop so that events will occur. */ for (;;) { XNextEvent(my_display, &event_received); switch (event_received.type) { /* Do the following when an expose occurs. */ case Expose: /* Code for expose event. */ /* Draw the picture if the picture window is exposed. */ if (event_received.xexpose.window == wind_pic) { /* START # 1 */ /* Send groups of color to screen. */ for (k=0; k<MAXCOL; k++) { if (array[k].cnt > 0) { for (i=0; i<array[k].cnt; i++) { rect[i].x = array[k].x1[i]; rect[i].y = array[k].y1[i]; rect[i].width = 1; rect[i].height = 1; } m = array[k].cnt; XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[k]); XSetForeground(my_display, my_gc, colval[k].pixel); XFillRectangles(my_display, wind_pic, my_gc, rect, m); /* Send extra array if there is a lot of that color. */ if (array[k].more > 0) { j = array[k].more; for (i=0; i<array[j].cnt; i++) { rect[i].x = array[j].x1[i]; rect[i].y = array[j].y1[i]; rect[i].width = 1; rect[i].height = 1; } m = array[j].cnt; XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[k]); XSetForeground(my_display, my_gc, colval[k].pixel); XFillRectangles(my_display, wind_pic, my_gc, rect, m); } } } } /* END # 1 */ /* If exit window is exposed write label. */ else if (event_received.xexpose.window == wind_exit) { /* START # 2 */ XSetForeground(my_display, my_gc, white); font = XLoadFont(my_display, "8x13bold"); XSetFont(my_display, my_gc, font); XDrawString(my_display, wind_exit, my_gc, 25, 20, quit, strlen(quit)); } /* END # 2 */ /* If color scale window is exposed put up color scale. */ else if (event_received.xexpose.window == wind_scale) { for (i=0; i<MAXCOL; i++) { XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[i]); XSetForeground(my_display, my_gc, colval[i].pixel); XFillRectangle(my_display, wind_scale, my_gc, (i * 2), 0, 2, 30); } /* Write label. */ XSetForeground(my_display, my_gc, white); font = XLoadFont(my_display, "8x13bold"); XSetFont(my_display, my_gc, font); (void)sprintf(string, "%.0f", min); XDrawString(my_display, wind_scale, my_gc, 2, 45, string, strlen(string)); r = min + (max - min) / 4.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 / 4 - 8), 45, string, strlen(string)); r = min + (max - min) / 2.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 / 2 - 8), 45, string, strlen(string)); r = min + (max - min) * 3. / 4.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 * 3 / 4 - 8), 45, string, strlen(string)); (void)sprintf(string, "%.0f", max); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 - 16), 45, string, strlen(string)); } break; /* Do the following if a mouse press occurs. */ case ButtonPress: if (event_received.xbutton.window == wind_exit) { XCloseDisplay(my_display); /* Create pix file if necessary. */ if (flag_pix == 1) { /* START # 1. */ /* Open pix file to be written to. */ fpw = fopen(file_pix, "wb"); /* Write colors to file. */ for (i=high; i>0; i--) { /* START # 2. */ for (j=0; (size_t)j<wide; j++) { /* START # 3. */ c = (unsigned char)((int)(colval[color[j][i-1]].red / 256)); putc(c, fpw); c = (unsigned char)((int) (colval[color[j][i-1]].green / 256)); putc(c, fpw); c = (unsigned char)((int)(colval[color[j][i-1]].blue / 256)); putc(c, fpw); } /* END # 3. */ } /* END # 2. */ /* Close file. */ (void)fclose(fpw); printf("Pix file, %s, has been written.\n", file_pix); (void)fflush(stdout); } /* END # 1. */ bu_free(array, "free colstr array"); return 0; } break; } } bu_free(array, "free colstr array"); return 0; }
/* Beginning with the first element of the GLC master list, find the first * master whose string attribute GLC_FAMILY equals inFamily. We do not * implement masters, so we simulate this behaviour using the X font server's * list of fonts as our list of masters. Return fontnum on success, or * zero otherwise. */ GLint glcNewFontFromFamily(GLint fontnum, const char *s) { char **xfontlist; int fontlen = strlen(s); char *fontname; int num_fonts; int font, our_font[NUM_GLC_STYLES]; int i, j; char *t; int font_can_transform = TRUE; #ifdef DEBUG fprintf(stderr, "glcNewFontFromFamily(%d, \"%s\")\n", fontnum, s); #endif if(currentGlcContext == 0) { last_error = GLC_STATE_ERROR; return 0; } /* Get a list of fonts from the X server that match this font family, * giving precedence to adobe fonts. */ fontname = (char*)malloc(fontlen+1024); sprintf(fontname, "-adobe-%s-*-*-*-*-[1 0 0 1]-0-*-*-*-*-*-*", s); xfontlist = XListFonts(g->display, fontname, 1000, &num_fonts); if(num_fonts == 0) { sprintf(fontname, "-*-%s-*-*-*-*-[1 0 0 1]-0-*-*-*-*-*-*", s); xfontlist = XListFonts(g->display, fontname, 1000, &num_fonts); if(num_fonts == 0) { font_can_transform = FALSE; sprintf(fontname, "-*-%s-*-*-*-*-0-0-*-*-*-*-*-*", s); xfontlist = XListFonts(g->display, fontname, 1000, &num_fonts); if(num_fonts == 0) { for(j = 0; j < NUM_GLC_STYLES; j++) g->fonts[fontnum][j].isFont = FALSE; #ifdef DEBUG fprintf(stderr, "No X fonts found for request %s.\n", fontname); #endif free(fontname); return 0; } } } free(fontname); /* Determine which fonts in this family have the faces we are looking * for. We search the structure upside-down, because fonts that * come first should take precedence. */ for(j = 0; j < NUM_GLC_STYLES; j++) our_font[j] = INT_MAX; for(font = num_fonts-1; font >= 0; font--) { if(strstr(xfontlist[font], "medium-r")) { our_font[GLC_STYLE_NORMAL] = font; } else if(strstr(xfontlist[font], "bold-r")) { our_font[GLC_STYLE_BOLD] = font; } else if(strstr(xfontlist[font], "medium-i")) { our_font[GLC_STYLE_ITALIC] = font; } else if(strstr(xfontlist[font], "bold-i")) { our_font[GLC_STYLE_BOLD_ITALIC] = font; } } /* Set the font information in the GLC context */ for(j = 0; j < NUM_GLC_STYLES; j++) { if(our_font[j] != INT_MAX) { if(g->fonts[fontnum][j].isFont) glcDeleteFont(fontnum); g->fonts[fontnum][j].xfont = XLoadFont(g->display, xfontlist[our_font[j]]); g->fonts[fontnum][j].isFont = TRUE; g->fonts[fontnum][j].name = strdup(s); g->fonts[fontnum][j].xfontprefix = strdup(xfontlist[our_font[j]]); for(t = g->fonts[fontnum][j].xfontprefix,i=0; *t != 0 && i < 7; t++) if(*t == '-') i++; if(*t != 0) { *(t-1) = 0; for(t++; *t != 0 && i < 8; t++) if(*t == '-') i++; } g->fonts[fontnum][j].xfontsuffix = t; g->fonts[fontnum][j].can_transform = font_can_transform; g->fonts[fontnum][j].xfontinfo = NULL; g->fonts[fontnum][j].xfont = 0; #ifdef DEBUG fprintf(stderr, "Using font %s-[1 0 0 1]-%s\n", g->fonts[fontnum][j].xfontprefix, g->fonts[fontnum][j].xfontsuffix); #endif } else { g->fonts[fontnum][j].isFont = FALSE; #ifdef DEBUG fprintf(stderr, "Not using font style %d.\n", j); #endif } } /* Free the list of fonts and return */ XFreeFontNames(xfontlist); return fontnum; }