void TStatusPanel_STD::update(Status_Pack * sp) { TIMC * imc = sp->imc; XClearWindow(TWinMan::get_display(), id()); uint16_t x = 2; uint16_t y = fontset->ascent() + 2; if (imc == NULL){ im_desc.copy(sp->im_desc[0]); #ifdef MDK_PATCH char dummy[10]; im_desc.tombs(dummy, 4); XmbDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, dummy, strlen(dummy)); #else XwcDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, &im_desc[0], 1); #endif return; } if (!imc->enabled()){ #ifdef MDK_PATCH XmbDrawImageString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, "En", 2); #else XwcDrawImageString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, L"En", 2); #endif return; } if (imc->is_mb_input()){ //XFillArc(display, stat_win, stat_gc, space_width, space_heigth, font_width * 2, font_height, 0, (360 * 64)); XFillRectangle(TWinMan::get_display(), id(), stat_gc->id(), 2, 2, fontset->width() * 2 + 1, fontset->height() + 1); }else{ XPoint p[3]; p[0].x = 2; p[0].y = 2; p[1].x = fontset->width() * 2 + 3; p[1].y = 2; p[2].x = 2; p[2].y = fontset->height() + 3; //XFillArc(display, stat_win, stat_gc, space_width, space_heigth, font_width * 2, font_height, (45 * 64), (225 * 64)); XFillPolygon(TWinMan::get_display(), id(), stat_gc->id(), p, 3, Convex,CoordModeOrigin); } im_desc.copy(sp->im_desc[0]); #ifdef MDK_PATCH char dummy[10]; im_desc.tombs(dummy, 4); XmbDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, dummy, strlen(dummy)); #else XwcDrawString(TWinMan::get_display(), id(), fontset->id(), gc->id(), x, y, &im_desc[0], 1); #endif }
void win_draw_bar(win_t *win) { int len, olen, x, y, w, tw; char rest[3]; const char *dots = "..."; win_env_t *e; if (win == NULL || win->xwin == None || win->pm == None) return; e = &win->env; y = win->h + font.ascent + V_TEXT_PAD; w = win->w; XSetForeground(e->dpy, gc, win->bar.bgcol); XFillRectangle(e->dpy, win->pm, gc, 0, win->h, win->w, win->bar.h); XSetForeground(e->dpy, gc, win->bar.fgcol); XSetBackground(e->dpy, gc, win->bar.bgcol); if ((len = strlen(win->bar.r)) > 0) { if ((tw = win_textwidth(win->bar.r, len, true)) > w) return; x = win->w - tw + H_TEXT_PAD; w -= tw; if (font.set) XmbDrawString(e->dpy, win->pm, font.set, gc, x, y, win->bar.r, len); else XDrawString(e->dpy, win->pm, gc, x, y, win->bar.r, len); } if ((len = strlen(win->bar.l)) > 0) { olen = len; while (len > 0 && (tw = win_textwidth(win->bar.l, len, true)) > w) len--; if (len > 0) { if (len != olen) { w = strlen(dots); if (len <= w) return; memcpy(rest, win->bar.l + len - w, w); memcpy(win->bar.l + len - w, dots, w); } x = H_TEXT_PAD; if (font.set) XmbDrawString(e->dpy, win->pm, font.set, gc, x, y, win->bar.l, len); else XDrawString(e->dpy, win->pm, gc, x, y, win->bar.l, len); if (len != olen) memcpy(win->bar.l + len - w, rest, w); } } }
/*----------------------------------------------------------------------------*/ void VKDrawFontDialog() { static char *titles[2] = {"Select interface font", "Chọn font giao dien"}; static char *mesages[] = {"Press a key group:", "Nhấn một nhóm phím:"}; char *S = mesages[vk_interface]; char *T = titles[vk_interface]; int i, fa = vk_text_ascent; #ifdef USE_XFT XftDraw *draw; draw = XftDrawCreate(display, fnt.window, visual, colormap); #else #define draw #endif XClearWindow(display, fnt.window); VKSetColor(display, fnt.gc, clBackground); XFillRectangle(display, fnt.window, fnt.gc, 0, 0, fnt.width, fnt.height); VKSetColor(display, fnt.gc, clBorder); XDrawRectangle(display, fnt.window, fnt.gc, 1, 1, fnt.width-3, fnt.height-3); XFillRectangle(display, fnt.window, fnt.gc, 1, 1, fnt.width-3, vk_text_height+6); XDrawLine(display, fnt.window, fnt.gc, 1, fnt.ly, fnt.width-3, fnt.ly); for( i=0; i<3; i++ ) { VKDrawLabel((VKLabel *)fc[i]); } #ifdef USE_XFT XftDrawStringUtf8(draw, &clBlack, vk_font, 11, fa+5+1, (XftChar8*)T, strlen(T)); XftDrawStringUtf8(draw, &clWhite, vk_font, 10, fa+5, (XftChar8*)T, strlen(T)); XftDrawStringUtf8(draw, &clGray, vk_font, fnt.tx+1, fnt.ty+1, (XftChar8*)S, strlen(S)); XftDrawStringUtf8(draw, &clBlack, vk_font, fnt.tx, fnt.ty, (XftChar8*)S, strlen(S)); XftDrawDestroy(draw); #else #undef draw VKSetColor(display, fnt.gc, clBlack); XmbDrawString(display, fnt.window, vk_fontset, fnt.gc, 11, fa+5+1, T, strlen(T)); VKSetColor(display, fnt.gc, clWhite); XmbDrawString(display, fnt.window, vk_fontset, fnt.gc, 10, fa+5, T, strlen(T)); VKSetColor(display, fnt.gc, clGray); XmbDrawString(display, fnt.window, vk_fontset, fnt.gc, fnt.tx+1, fnt.ty+1, S, strlen(S)); VKSetColor(display, fnt.gc, clBlack); XmbDrawString(display, fnt.window, vk_fontset, fnt.gc, fnt.tx, fnt.ty, S, strlen(S)); #endif }
void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, Bool invert) { char buf[256]; int i, tx, ty, len, olen; Extnts tex; if(!drw || !drw->fg || !drw->bg) return; XSetForeground(drw->dpy, drw->gc, invert ? drw->fg->rgb : drw->bg->rgb); XFillRectangle(drw->dpy, drw->drwable, drw->gc, x, y, w, h); if(!text || !drw->font) return; olen = strlen(text); drw_getexts(drw, text, olen, &tex); ty = y + (h / 2) - tex.yOff; tx = x + tex.xOff; /* shorten text if necessary */ for(len = MIN(olen, sizeof buf); len && tex.w > w - tex.h; len--) drw_getexts(drw, text, len, &tex); if(!len) return; memcpy(buf, text, len); if(len < olen) for(i = len; i && i > len - 3; buf[--i] = '.'); XSetForeground(drw->dpy, drw->gc, invert ? drw->bg->rgb : drw->fg->rgb); if(drw->font->set) XmbDrawString(drw->dpy, drw->drwable, drw->font->set, drw->gc, tx, ty, buf, len); else XDrawString(drw->dpy, drw->drwable, drw->gc, tx, ty, buf, len); }
static agsurface_t *get_drawn_glyph(const char *str, int w) { XImage *src; agsurface_t *dst; XSetForeground(x11_display, gc_pix_glyph, 0); XFillRectangle(x11_display, pix_glyph, gc_pix_glyph, 0, 0, GLYPH_PIXMAP_WIDTH, GLYPH_PIXMAP_HEIGHT); XSetForeground(x11_display, gc_pix_glyph, 1); XmbDrawString(x11_display, pix_glyph, fontset, gc_pix_glyph, 0, font_ascent, str, strlen(str)); src = XGetImage(x11_display, pix_glyph, 0, 0, w, font_ascent + font_descent, AllPlanes, ZPixmap); dst = g_new(agsurface_t, 1); dst->width = w; dst->height = font_ascent + font_descent; dst->bytes_per_line = src->bytes_per_line; dst->pixel = (BYTE *)src->data; dst->bytes_per_pixel = x11_workinfo->cimg.bytes_per_pixel; src->data = NULL; XDestroyImage(src); return dst; }
static int font_x11_draw_glyph(int x, int y, unsigned char *str, int col) { int w; BYTE *conv; /* convert string code from sjis to euc (or LANG) */ conv = sjis2lang(str); w = XmbTextEscapement(fontset, conv, strlen(conv)); if (w == 0) { free(conv); return 0; } if (!x11_dibinfo->shared) { /* 一度 Pixmap に書いてからイメージを取得してDIBへ */ agsurface_t *dst = get_drawn_glyph(conv, w); if (DIB_DEPTH == dib_depth_candidate) { image_getGlyphImage(DIB, dst, x, y, PAL2PIC(col)); } else { image_getGlyphImageNto8(DIB, dst, x, y, col); } g_free(dst); } else { Xcore_setForeground(col); XmbDrawString(x11_display, x11_pixmap, fontset, x11_gc_pix, x, y + font_ascent, conv, strlen(conv)); x11_needSync = TRUE; } return w; }
void drawtext(int x, int y, char *str, int len) { if (dc.font.set) XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, str, len); else XDrawString(dpy, dc.drawable, dc.gc, x, y, str, len); }
void debrush_do_draw_string_default_bmf( DEBrush *brush, int x, int y, const char *str, int len, bool needfill, DEColourGroup *colours) { GC gc=brush->d->normal_gc; if(brush->d->font==NULL) return; XSetForeground(ioncore_g.dpy, gc, PIXEL(colours->fg)); if(!needfill){ if(brush->d->font->fontset!=NULL){ #ifdef CF_DE_USE_XUTF8 if(ioncore_g.enc_utf8) Xutf8DrawString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); else #endif XmbDrawString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); }else if(brush->d->font->fontstruct!=NULL){ if(ioncore_g.enc_utf8){ XChar2b *str16; int len16=0; toucs(str, len, &str16, &len16); XDrawString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16); free(str16); }else{ XDrawString(ioncore_g.dpy, brush->win, gc, x, y, str, len); } } }else{ XSetBackground(ioncore_g.dpy, gc, PIXEL(colours->bg)); if(brush->d->font->fontset!=NULL){ #ifdef CF_DE_USE_XUTF8 if(ioncore_g.enc_utf8) Xutf8DrawImageString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); else #endif XmbDrawImageString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); }else if(brush->d->font->fontstruct!=NULL){ if(ioncore_g.enc_utf8){ XChar2b *str16; int len16=0; toucs(str, len, &str16, &len16); XDrawImageString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16); free(str16); }else{ XDrawImageString(ioncore_g.dpy, brush->win, gc, x, y, str, len); } } } }
void draw_desk(Window win, unsigned int barcolor, unsigned int gc, unsigned int x, char *string, unsigned int len) { XSetWindowBackground(dis, win, theme[barcolor].barcolor); XClearWindow(dis, win); if(font.fontset) XmbDrawString(dis, win, font.fontset, theme[gc].gc, x, font.fh, string, len); else XDrawString(dis, win, theme[gc].gc, x, font.fh, string, len); }
/************************************************************************** Draw at x = left of string, y = top of string. **************************************************************************/ static void draw_shadowed_string(struct canvas *pcanvas, XFontSet fontset, GC font_gc, struct color *foreground, struct color *shadow, int x, int y, const char *string) { size_t len = strlen(string); y -= XExtentsOfFontSet(fontset)->max_logical_extent.y; if (foreground->color.pixel != shadow->color.pixel) { XSetForeground(display, font_gc, shadow->color.pixel); XmbDrawString(display, pcanvas->pixmap, fontset, font_gc, x + 1, y + 1, string, len); } XSetForeground(display, font_gc, foreground->color.pixel); XmbDrawString(display, pcanvas->pixmap, fontset, font_gc, x, y, string, len); }
int main () { #if defined(I18N_MB) XmbDrawString (theDisplay, man ->theWindow, man ->ButtonFontset, man ->hiContext[button_state], g .text_x, g .text_base, b ->drawn_state .display_string, strlen (b ->drawn_state .display_string)); #endif #if !defined(I18N_MB) XDrawString (theDisplay, man ->theWindow, man ->hiContext[button_state], g .text_x, g .text_base, b ->drawn_state .display_string, strlen (b ->drawn_state .display_string)); #endif }
int main () { #if defined(I18N_MB) XmbDrawString (dpy, tmp_win ->icon_w, tmp_win ->icon_font .fontset, Scr .TitleGC, x, (tmp_win ->icon_g .height - tmp_win ->icon_font .height + tmp_win ->icon_font .y - 3), tmp_win ->icon_name, strlen (tmp_win ->icon_name)); #endif #if !defined(I18N_MB) XDrawString (dpy, tmp_win ->icon_w, Scr .TitleGC, x, (tmp_win ->icon_g .height - tmp_win ->icon_font .height + tmp_win ->icon_font .y - 3), tmp_win ->icon_name, strlen (tmp_win ->icon_name)); #endif }
int main () { #if defined(I18N_MB) XmbDrawString (theDisplay, man ->theWindow, man ->ButtonFontset, man ->hiContext[state], g .text_x, g .text_base, man ->titlename, len); #endif #if !defined(I18N_MB) XDrawString (theDisplay, man ->theWindow, man ->hiContext[state], g .text_x, g .text_base, man ->titlename, len); #endif }
void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) { int x = dc->x + dc->font.height/2; int y = dc->y + dc->font.ascent+1; XSetForeground(dc->dpy, dc->gc, FG(dc, col)); if(dc->font.set) XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n); else { XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid); XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n); } }
static void fontset_draw (Lisp_Font *f, char *string, size_t length, Window id, GC gc, Lisp_Color *fg, int x, int y) { XGCValues gcv; gcv.foreground = fg->pixel; XChangeGC (dpy, gc, GCForeground, &gcv); #ifdef X_HAVE_UTF8_STRING Xutf8DrawString (dpy, id, f->font, gc, x, y, string, length); #else XmbDrawString (dpy, id, f->font, gc, x, y, string, length); #endif }
static void drawText(Display *dpy, XmBalloonWidget balloon, Drawable drawable, GC gc, int x_offset, int y_offset) { /* draw the text in the window */ #if XtSpecificationRelease < 5 XDrawString(dpy, drawable, gc, ATTR(margin_width) + x_offset, ATTR(margin_height) + ATTR(baseline) + y_offset, ATTR(source), ATTR(source_len)); #else XmbDrawString(dpy, drawable, ATTR(fontset), gc, ATTR(margin_width) + x_offset, ATTR(margin_height) + ATTR(baseline) + y_offset, ATTR(source), ATTR(source_len)); #endif }
void drawtextn(DC *dc, const char *text, size_t n, ColorSet *col) { int x = dc->x + dc->font.height/2; int y = dc->y + dc->font.ascent+1; XSetForeground(dc->dpy, dc->gc, col->FG); if(dc->font.xft_font) { if (!dc->xftdraw) eprintf("error, xft drawable does not exist"); XftDrawStringUtf8(dc->xftdraw, &col->FG_xft, dc->font.xft_font, x, y, (unsigned char*)text, n); } else if(dc->font.set) { XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n); } else { XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid); XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n); } }
void draw_string(drawable_type dw, const nana::point& pos, const nana::char_t * str, std::size_t len) { #if defined(NANA_WINDOWS) ::TextOut(dw->context, pos.x, pos.y, str, static_cast<int>(len)); #elif defined(NANA_X11) auto disp = ::nana::detail::platform_spec::instance().open_display(); #if defined(NANA_UNICODE) /* std::string utf8str = nana::charset(nana::string(str, len)); XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle); ::XftDrawStringUtf8(dw->xftdraw, &(dw->xft_fgcolor), fs, pos.x, pos.y + fs->ascent, reinterpret_cast<XftChar8*>(const_cast<char*>(utf8str.c_str())), utf8str.size()); */ auto fs = reinterpret_cast<XftFont*>(dw->font->handle); //Fixed missing array declaration by dareg std::unique_ptr<FT_UInt[]> glyphs_ptr(new FT_UInt[len]); auto glyphs = glyphs_ptr.get(); const auto endstr = str + len; for(auto chr = str; chr != endstr; ++chr) { (*glyphs++) = XftCharIndex(disp, fs, *chr); } XftDrawGlyphs(dw->xftdraw, &(dw->xft_fgcolor), fs, pos.x, pos.y + fs->ascent, glyphs_ptr.get(), len); #else XFontSet fs = reinterpret_cast<XFontSet>(dw->font->handle); XFontSetExtents * ext = ::XExtentsOfFontSet(fs); XFontStruct ** fontstructs; char ** font_names; int size = ::XFontsOfFontSet(fs, &fontstructs, &font_names); unsigned ascent = 0; unsigned descent = 0; XFontStruct **fontstructs_end = fontstructs + size; for(XFontStruct** i = fontstructs; i < fontstructs_end; ++i) { if(ascent < (*i)->ascent) ascent = (*i)->ascent; if(descent < (*i)->descent) descent = (*i)->descent; } XmbDrawString(display, dw->pixmap, reinterpret_cast<XFontSet>(dw->font->handle), dw->context, pos.x, pos.y + ascent + descent, buf, len); #endif #endif }
void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) { char buf[256]; int i, tx, ty, th, len, olen; Extnts tex; if(!drw || !drw->scheme) return; XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->rgb : drw->scheme->bg->rgb); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); if(!text || !drw->font) return; olen = strlen(text); drw_font_getexts(drw->font, text, olen, &tex); th = drw->font->ascent + drw->font->descent; ty = y + (h / 2) - (th / 2) + drw->font->ascent; if(draw_with_border == 1) { tx = x + (h / 2); } else { tx = x; } /* shorten text if necessary */ if(draw_with_border == 1) { for(len = MIN(olen, sizeof buf); len && (tex.w > w + tex.h|| w < tex.h); len--) drw_font_getexts(drw->font, text, len, &tex); } else { for(len = MIN(olen, sizeof buf); len && (tex.w > w || w < 0); len--) drw_font_getexts(drw->font, text, len, &tex); } if(!len) return; memcpy(buf, text, len); if(len < olen) for(i = len; i && i > len - 3; buf[--i] = '.'); XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb); if(drw->font->set) XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len); else XDrawString(drw->dpy, drw->drawable, drw->gc, tx, ty, buf, len); }
/* * And the routine to actually write the text into the InfoWindow. This * gets called from events.c as a result of Expose events on the window. */ void draw_info_window(void) { int i; const int height = Scr->DefaultFont.height + 2; Draw3DBorder(Scr->InfoWindow.win, 0, 0, Scr->InfoWindow.width, Scr->InfoWindow.height, 2, Scr->DefaultC, off, true, false); FB(Scr->DefaultC.fore, Scr->DefaultC.back); for(i = 0; i < Scr->InfoWindow.lines ; i++) { XmbDrawString(dpy, Scr->InfoWindow.win, Scr->DefaultFont.font_set, Scr->NormalGC, 5, (i * height) + Scr->DefaultFont.y + 5, Info[i], strlen(Info[i])); } }
/* * Given a font or fontset, render the text. */ void CalDrawString( Display *dpy, Drawable draw, Cal_Font *font, GC gc, int x, int y, char *string, int length) { if (font->cf_type == XmFONT_IS_FONT) { XSetFont(dpy, gc, font->f.cf_font->fid); XDrawString(dpy, draw, gc, x, y, string, length); } else { XmbDrawString(dpy, draw, font->f.cf_fontset, gc, x, y, string, length); } }
static void surface_draw_text(XSurface *surf, zr_short x, zr_short y, zr_ushort w, zr_ushort h, const char *text, size_t len, XFont *font, struct zr_color cbg, struct zr_color cfg) { int tx, ty, th; unsigned long bg = color_from_byte(&cbg.r); unsigned long fg = color_from_byte(&cfg.r); XSetForeground(surf->dpy, surf->gc, bg); XFillRectangle(surf->dpy, surf->drawable, surf->gc, (int)x, (int)y, (unsigned)w, (unsigned)h); if(!text || !font || !len) return; tx = (int)x; th = font->ascent + font->descent; ty = (int)y + ((int)h / 2) - (th / 2) + font->ascent; XSetForeground(surf->dpy, surf->gc, fg); if(font->set) XmbDrawString(surf->dpy,surf->drawable,font->set,surf->gc,tx,ty,(const char*)text,(int)len); else XDrawString(surf->dpy, surf->drawable, surf->gc, tx, ty, (const char*)text, (int)len); }
Cursor MakeStringCursor(char *string) { Cursor cursor; XColor black, white; Pixmap bitmap; unsigned int width, height, middle; GC gc; Colormap cmap = Scr->RootColormaps.cwins[0]->colormap->c; MyFont myfont = Scr->TitleBarFont; XRectangle inc_rect; XRectangle logical_rect; black.pixel = Scr->Black; XQueryColor(dpy, cmap, &black); white.pixel = Scr->White; XQueryColor(dpy, cmap, &white); XmbTextExtents(myfont.font_set, string, strlen(string), &inc_rect, &logical_rect); width = logical_rect.width + 4; height = logical_rect.height + 2; middle = myfont.ascent; /*XQueryBestCursor (dpy, Scr->Root, width, height, &rwidth, &rheight);*/ bitmap = XCreatePixmap(dpy, Scr->Root, width, height, 1); gc = XCreateGC(dpy, bitmap, 0L, NULL); XSetForeground(dpy, gc, 0L); XFillRectangle(dpy, bitmap, gc, 0, 0, width, height); XSetForeground(dpy, gc, 1L); XDrawRectangle(dpy, bitmap, gc, 0, 0, width - 1, height - 1); XmbDrawString(dpy, bitmap, myfont.font_set, gc, 2, middle, string, strlen(string)); cursor = XCreatePixmapCursor(dpy, bitmap, None, &black, &white, 0, 0); XFreePixmap(dpy, bitmap); XFreeGC(dpy, gc); return (cursor); }
/* gdk_x11_draw_text * * Modified by Li-Da Lho to draw 16 bits and Multibyte strings * * Interface changed: add "GdkFont *font" to specify font or fontset explicitely */ static void gdk_x11_draw_text (GdkDrawable *drawable, GdkFont *font, GdkGC *gc, gint x, gint y, const gchar *text, gint text_length) { GdkDrawableImplX11 *impl; Display *xdisplay; impl = GDK_DRAWABLE_IMPL_X11 (drawable); xdisplay = GDK_SCREEN_XDISPLAY (impl->screen); if (font->type == GDK_FONT_FONT) { XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT (font); XSetFont(xdisplay, GDK_GC_GET_XGC (gc), xfont->fid); if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) { XDrawString (xdisplay, impl->xid, GDK_GC_GET_XGC (gc), x, y, text, text_length); } else { XDrawString16 (xdisplay, impl->xid, GDK_GC_GET_XGC (gc), x, y, (XChar2b *) text, text_length / 2); } } else if (font->type == GDK_FONT_FONTSET) { XFontSet fontset = (XFontSet) GDK_FONT_XFONT (font); XmbDrawString (xdisplay, impl->xid, fontset, GDK_GC_GET_XGC (gc), x, y, text, text_length); } else g_error("undefined font type\n"); }
void drawentry(Entry *e) { int x, y, h, len; XRectangle r = { e->x, e->y, e->w, e->h }; const char *l; ulong *col; if(e->pressed) col = dc.press; else if(e->highlighted) col = dc.high; else col = dc.norm; XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, dc.norm[ColFG]); r.height -= 1; r.width -= 1; XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, col[ColFG]); l = e->label; len = strlen(l); h = dc.font.height; y = e->y + (e->h / 2) - (h / 2) + dc.font.ascent; x = e->x + (e->w / 2) - (textnw(l, len) / 2); if(dc.font.set) { XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, l, len); } else XDrawString(dpy, dc.drawable, dc.gc, x, y, l, len); XCopyArea(dpy, dc.drawable, win, dc.gc, e->x, e->y, e->w, e->h, e->x, e->y); }
void rp_draw_string (rp_screen *s, Drawable d, int style, int x, int y, char *string, int length) { if (length < 0) length = strlen (string); #ifdef USE_XFT_FONT if (s->xft_font) { XftDraw *draw; draw = XftDrawCreate (dpy, d, DefaultVisual (dpy, s->screen_num), DefaultColormap (dpy, s->screen_num)); if (draw) { XftDrawString8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color:&s->xft_bg_color, s->xft_font, x, y, (FcChar8*) string, length); XftDrawDestroy (draw); } else PRINT_ERROR(("Failed to allocate XftDraw object\n")); } else #endif XmbDrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? s->normal_gc:s->inverse_gc, x, y, string, length); }
int main(int argc, char **argv) { Display *display; int screen_num; Window win; //窗口ID unsigned int width, height; //窗口尺寸 unsigned int border_width = 4; //边界空白 unsigned int display_width, display_height;//屏幕尺寸 XEvent report; GC gc; unsigned long valuemask = 0; XGCValues values; char *display_name = NULL; Atom protocols; //edit int len = 127; unsigned char string[128], s_tab[ROW][127]; KeySym keysym; int row = 0, col = 0; int i, count = 0; Status status; //字体集 XFontSet fontset; char **missing_charsets; int num_missing_charsets; char *default_string; XFontSetExtents *fs_ext; int dec; //XIM XIM im; XIC ic; //overspot XRectangle spot, s_rect; XVaNestedList preedit_attr, status_attr; //设置locale if((setlocale(LC_ALL, "")) == NULL){ printf("cannot set locale\n"); exit(1); } //判断X是否支持locale if(!XSupportsLocale()){ printf("X does not support current locale\n"); exit(1); } //设置locale修饰 if(XSetLocaleModifiers(NULL)){ printf("Cannot set locale modifiers\n"); exit(1); } // 和X 服务器连接 if ( (display=XOpenDisplay(display_name)) == NULL ) { printf("Cannot connect to X server %s\n", XDisplayName(display_name)); exit(-1); } //获得缺省的 screen_num screen_num = DefaultScreen(display); //获得屏幕的宽度和高度 display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); //建立字体集 fontset = XCreateFontSet(display, "8x16,-*-song-medium-r-normal--16-*-*-*-*-*-gb2312.1980-0", &missing_charsets, &num_missing_charsets, &default_string); if(num_missing_charsets > 0){ int i; printf("Following charsets are missing:\n"); for(i=0; i<num_missing_charsets; i++){ printf("Missing %d: %s\n", i, missing_charsets[i]); } printf("\nDefault string:%s\n", default_string); XFreeStringList(missing_charsets); } //字体的Extents fs_ext = XExtentsOfFontSet(fontset); dec = fs_ext->max_logical_extent.height + fs_ext->max_logical_extent.y; width = W_WIDTH; height = W_HEIGHT + dec; //建立窗口 win = XCreateSimpleWindow(display, //display RootWindow(display,screen_num), //父窗口 0, 0, width, height, //位置和大小 border_width, //边界宽度 BlackPixel(display,screen_num), //前景色 WhitePixel(display,screen_num));//背景色 //选择窗口感兴趣的事件掩码 XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); //建立GC gc = XCreateGC(display, win, valuemask, &values); protocols = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, win, &protocols, 1); //显示窗口 XMapWindow(display, win); //联接输入服务器 if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){ printf("Error : XOpenIM !\n"); exit(1); } //设置输入服务器的位置 spot.x = F_SIZE / 2 * col; spot.y = F_SIZE * (row + 1) - dec; preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, XNFontSet, fontset, NULL); s_rect.x = 0; s_rect.y = F_SIZE * ROW + dec + 2; s_rect.width = W_WIDTH; s_rect.height = F_SIZE; status_attr = XVaCreateNestedList(0, XNArea, &s_rect, XNFontSet, fontset, NULL); //建立IC if((ic = XCreateIC(im, XNInputStyle, XIMPreeditPosition | XIMStatusNothing, XNClientWindow, win, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL)) == NULL){ printf("Error : XCreateIC() ! \n"); XCloseIM(im); exit(0); } //释放内存 XFree(preedit_attr); XFree(status_attr); //写屏缓冲区初始化 for(i = 0; i < ROW; i++)s_tab[i][0] = 0; //进入事件循环 while (1) { //取得队列中的事件 XNextEvent(display, &report); //过滤事件 if(XFilterEvent(&report, None) == True) continue; switch (report.type) { //聚焦发声变化 case FocusIn: XSetICFocus(ic); break; case FocusOut: XUnsetICFocus(ic); break; //曝光事件, 窗口应重绘 case Expose: //取得最后一个曝光事件 if (report.xexpose.count != 0) break; for ( i=0; i < ROW; i++) XmbDrawString(display, win, fontset,gc, 0, F_SIZE * (i +1), s_tab[i], strlen(s_tab[i])); break; //窗口尺寸改变, 重新取得窗口的宽度和高度 case ConfigureNotify: width = report.xconfigure.width; height = report.xconfigure.height; break; //鼠标点击或有按键, 释放资源则退出 case KeyPress: count = XmbLookupString(ic, (XKeyPressedEvent *) &report, string, len, &keysym, &status); string[count] = 0; if (status == XLookupBoth&&keysym == XK_Return){ row = (++row) % ROW; col = 0; s_tab[row][0] = 0; XClearArea(display, win, 0, F_SIZE * row + dec, W_WIDTH, F_SIZE, False); } else if (status = XLookupChars || status == XLookupBoth){ XmbDrawString(display, win, fontset, gc, F_SIZE / 2 * col, F_SIZE * (row + 1), string, count); for (i = 0; i < count && col < len && string[i]; i++, col++) s_tab[row][col] = string[i]; s_tab[row][col] = 0; } //更新输入服务器位置 spot.x = F_SIZE / 2 * col; spot.y = F_SIZE * (row + 1); preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); XSetICValues(ic, XNPreeditAttributes, preedit_attr, NULL); XFree(preedit_attr); break; case ClientMessage: if (report.xclient.data.l[0] == protocols) { XDestroyIC(ic); XCloseIM(im); XDestroyWindow(display, win); XCloseDisplay(display); exit(0); } break; default: break; } } }
void draw_text(Window win, unsigned int gc, unsigned int x, char *string, unsigned int len) { if(font.fontset) XmbDrawString(dis, win, font.fontset, theme[gc].gc, x, font.fh, string, len); else XDrawString(dis, win, theme[gc].gc, x, font.fh, string, len); }
static void PaintItemName(Widget w, int item) { char *str; GC gc; int x, y, str_y; ListWidget lw = (ListWidget)w; XFontSetExtents *ext = XExtentsOfFontSet(lw->list.fontset); if (!XtIsRealized(w) || item > lw->list.nitems) return; if (lw->list.vertical_cols) { x = lw->list.col_width * (item / lw->list.nrows) + lw->list.internal_width; y = lw->list.row_height * (item % lw->list.nrows) + lw->list.internal_height; } else { x = lw->list.col_width * (item % lw->list.ncols) + lw->list.internal_width; y = lw->list.row_height * (item / lw->list.ncols) + lw->list.internal_height; } if ( lw->simple.international == True ) str_y = y + XawAbs(ext->max_ink_extent.y); else str_y = y + lw->list.font->max_bounds.ascent; if (item == lw->list.is_highlighted) { if (item == lw->list.highlight) { gc = lw->list.revgc; HighlightBackground(w, x, y, lw->list.normgc); } else { if (XtIsSensitive(w)) gc = lw->list.normgc; else gc = lw->list.graygc; HighlightBackground(w, x, y, lw->list.revgc); lw->list.is_highlighted = NO_HIGHLIGHT; } } else { if (item == lw->list.highlight) { gc = lw->list.revgc; HighlightBackground(w, x, y, lw->list.normgc); lw->list.is_highlighted = item; } else { if (XtIsSensitive(w)) gc = lw->list.normgc; else gc = lw->list.graygc; } } /* List's overall width contains the same number of inter-column column_space's as columns. There should thus be a half column_width margin on each side of each column. The row case is symmetric */ x += lw->list.column_space >> 1; str_y += lw->list.row_space >> 1; str = lw->list.list[item]; /* draw it */ ClipToShadowInteriorAndLongest(lw, &gc, x); if (lw->simple.international == True) XmbDrawString(XtDisplay(w), XtWindow(w), lw->list.fontset, gc, x, str_y, str, strlen(str)); else XDrawString(XtDisplay(w), XtWindow(w), gc, x, str_y, str, strlen(str)); XSetClipMask(XtDisplay(w), gc, None); }
/* ARGSUSED */ static void XawSmeBSBRedisplay(Widget w, XEvent *event, Region region) { GC gc; SmeBSBObject entry = (SmeBSBObject)w; int font_ascent, font_descent, y_loc; int fontset_ascent, fontset_descent; XFontSetExtents *ext = XExtentsOfFontSet(entry->sme_bsb.fontset); font_ascent = font_descent = fontset_ascent = fontset_descent = 0; entry->sme_bsb.set_values_area_cleared = False; if (entry->sme.international == True) { fontset_ascent = XawAbs(ext->max_ink_extent.y); fontset_descent = ext->max_ink_extent.height - fontset_ascent; } else { font_ascent = entry->sme_bsb.font->max_bounds.ascent; font_descent = entry->sme_bsb.font->max_bounds.descent; } y_loc = XtY(entry); if (XtIsSensitive(w) && XtIsSensitive(XtParent(w))) { if (w == XawSimpleMenuGetActiveEntry(XtParent(w))) { XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), entry->sme_bsb.norm_gc, XtX(w), y_loc, XtWidth(entry), XtHeight(entry)); gc = entry->sme_bsb.rev_gc; } else gc = entry->sme_bsb.norm_gc; } else gc = entry->sme_bsb.norm_gray_gc; if (entry->sme_bsb.label != NULL) { int x_loc = entry->sme_bsb.left_margin; int len = strlen(entry->sme_bsb.label); char *label = entry->sme_bsb.label; int width, t_width; switch(entry->sme_bsb.justify) { case XtJustifyCenter: if (entry->sme.international == True) { t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, len); width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); } else { t_width = XTextWidth(entry->sme_bsb.font, label, len); width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); } x_loc += (width - t_width) >> 1; break; case XtJustifyRight: if (entry->sme.international == True) { t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, len); x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + t_width); } else { t_width = XTextWidth(entry->sme_bsb.font, label, len); x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + t_width); } break; case XtJustifyLeft: /*FALLTHROUGH*/ default: break; } /* this will center the text in the gadget top-to-bottom */ if (entry->sme.international == True) { y_loc += ((XtHeight(entry) - (fontset_ascent + fontset_descent)) >> 1) + fontset_ascent; XmbDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), entry->sme_bsb.fontset, gc, XtX(w) + x_loc, y_loc, label, len); }