Exemple #1
0
static zr_size
font_get_text_width(zr_handle handle, float height, const char *text, zr_size len)
{
    XFont *font = (XFont*)handle.ptr;
    XRectangle r;
    if(!font || !text)
        return 0;

    UNUSED(height);
    if(font->set) {
        XmbTextExtents(font->set, (const char*)text, (int)len, NULL, &r);
        return r.width;
    } else return (zr_size)XTextWidth(font->xfont, (const char*)text, (int)len);
}
Exemple #2
0
int
textnw(DC *dc, const char *text, size_t len) {
	if(dc->font.xft_font) {
		XGlyphInfo gi;
		XftTextExtentsUtf8(dc->dpy, dc->font.xft_font,
                       (const FcChar8*)text, len, &gi);
		return gi.width;
	} else if(dc->font.set) {
		XRectangle r;
		XmbTextExtents(dc->font.set, text, len, NULL, &r);
		return r.width;
	}
	return XTextWidth(dc->font.xfont, text, len);
}
void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale,
                     const wxString& str,
                     int* width, int* height, int* ascent, int* descent)
{
    XRectangle ink, logical;
    WXFontSet fset = font.GetFontSet(scale, display);

    XmbTextExtents( (XFontSet)fset, str.mb_str(), str.length(), &ink, &logical);

    if( width ) *width = logical.width;
    if( height ) *height = logical.height;
    if( ascent ) *ascent = -logical.y;
    if( descent ) *descent = logical.height + logical.y;
}
Exemple #4
0
Fichier : drw.c Projet : bqv/dwm
void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) {
	XRectangle r;

	if(!font || !text)
		return;
	if(font->set) {
		XmbTextExtents(font->set, text, len, NULL, &r);
		tex->w = r.width;
		tex->h = r.height;
	}
	else {
		tex->h = font->ascent + font->descent;
		tex->w = XTextWidth(font->xfont, text, len);
	}
}
Exemple #5
0
static unsigned int
textnw(Fnt *font, const char *text, unsigned int len) {
#ifndef DZEN_XFT
	XRectangle r;

	if(font->set) {
		XmbTextExtents(font->set, text, len, NULL, &r);
		return r.width;
	}
	return XTextWidth(font->xfont, text, len);
#else
	XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) text, strlen(text), dzen.font.extents);
	if(dzen.font.extents->height > dzen.font.height)
		dzen.font.height = dzen.font.extents->height;
	return dzen.font.extents->xOff;
#endif
}
Exemple #6
0
uint defont_get_text_width(DEFont *font, const char *text, uint len)
{
    if(font->fontset!=NULL){
        XRectangle lext;
#ifdef CF_DE_USE_XUTF8
        if(ioncore_g.enc_utf8)
            Xutf8TextExtents(font->fontset, text, len, NULL, &lext);
        else
#endif
            XmbTextExtents(font->fontset, text, len, NULL, &lext);
        return lext.width;
    }else if(font->fontstruct!=NULL){
        return XTextWidth(font->fontstruct, text, len);
    }else{
        return 0;
    }
}
Exemple #7
0
uint defont_get_text_width(DEFont *font, const char *text, uint len)
{
#ifdef HAVE_X11_XFT
    if(font->font!=NULL){
        XGlyphInfo extents;
        if(ioncore_g.enc_utf8)
            XftTextExtentsUtf8(ioncore_g.dpy, font->font, (XftChar8*)text, len, &extents);
        else
            XftTextExtents8(ioncore_g.dpy, font->font, (XftChar8*)text, len, &extents);
        return extents.xOff;
    }
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_BMF
    if(font->fontset!=NULL){
        XRectangle lext;
#ifdef CF_DE_USE_XUTF8
        if(ioncore_g.enc_utf8)
            Xutf8TextExtents(font->fontset, text, len, NULL, &lext);
        else
#endif
            XmbTextExtents(font->fontset, text, len, NULL, &lext);
        return lext.width;
    }else if(font->fontstruct!=NULL){
        if(ioncore_g.enc_utf8){
            XChar2b *str16; int len16=0;
            uint res;

            toucs(text, len, &str16, &len16);

            res=XTextWidth16(font->fontstruct, str16, len16);

            free(str16);

            return res;
        }else{
            return XTextWidth(font->fontstruct, text, len);
        }
    }
#endif /* HAVE_X11_BMF */
    else{
        return 0;
    }
}
Exemple #8
0
static void
computeFontInfo(BALLOON)
{
	XRectangle ink;
	XRectangle logical;

	if(!ATTR(fontset))
		return;

	XmbTextExtents(ATTR(fontset), "1", 1,&ink, &logical);

	/*****
	* Collect font dimensions. Baseline offset is returned relative to the
	* *bottom* of the char, so we need to invert it.
	*****/
	ATTR(baseline)    = -logical.y;
	ATTR(font_width)  = logical.width;
	ATTR(font_height) = logical.height;
}
Exemple #9
0
void
drw_getexts(Drw *drw, const char *text, unsigned int len, Extnts *tex) {
	XRectangle r;

	if(!drw || !drw->font || !text)
		return;
	if(drw->font->set) {
		XmbTextExtents(drw->font->set, text, len, NULL, &r);
		tex->xOff = r.x;
		tex->yOff = r.y;
		tex->w = r.width;
		tex->h = r.height;
	}
	else {
		tex->h = drw->font->ascent + drw->font->descent;
		tex->w = XTextWidth(drw->font->xfont, text, len);
		tex->xOff = tex->h / 2;
		tex->yOff = (tex->h / 2) + drw->font->ascent;
	}
}
Exemple #10
0
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);
}
Exemple #11
0
/*
 * Given a font or fontset, return the extents of the text.
 */
void
CalTextExtents(
	Cal_Font	*font,
	char		*string,
	int		 nbytes,
	int		*x_return,
	int		*y_return,
	int		*width_return,
	int		*height_return)
{
	
	if (!font) return;

	if (font->cf_type == XmFONT_IS_FONT) {
		int		direction,
				ascent,
				descent;
		XCharStruct	overall;

		XTextExtents(font->f.cf_font, string, nbytes,
				&direction, &ascent, &descent, &overall);

		*x_return = overall.lbearing;
		*y_return = overall.ascent;
		*width_return = overall.width;
		*height_return = overall.ascent + overall.descent;
	} else {
		XRectangle	ink,
				logical;

		XmbTextExtents(font->f.cf_fontset, string, nbytes,
				&ink, &logical);

		*x_return = logical.x;
		*y_return = logical.y;
		*width_return = logical.width;
		*height_return = logical.height;
	}
}
Exemple #12
0
/*****
* Name: 		popupBalloon
* Return Type: 	void
* Description: 	pops up a balloon widget;
* In: 
*	client_..:	timeout client data, this is a XmBalloonWidget.
*	id:			interval id. When 0 it means this function has been called
*				directly from within the widget code. This will cause any
*				existing timeouts to be removed.
* Returns:
*	nothing.
*****/
static void
popupBalloon(XtPointer client_data, XtIntervalId *id)
{
	XmBalloonWidget balloon = (XmBalloonWidget)client_data;
	Position x, y;
	XRectangle ink, logical;

	/* remove timeout if called from within the widget code */
	if(*id == (XtIntervalId)0 && ATTR(popup_id))
		XtRemoveTimeOut(ATTR(popup_id));

	/* always remove any outstanding popdownDelay */
	if(ATTR(popdown_id))
		XtRemoveTimeOut(ATTR(popdown_id));

	ATTR(popdown_id) = (XtIntervalId)0;
	ATTR(popup_id) = (XtIntervalId)0;

	/* get dimensions for the widget (depends on the current label text) */
#if XtSpecificationRelease < 5
	{
		int dir, ascent, descent;
		XCharStruct sw;
		XTextExtents(ATTR(font), ATTR(source), ATTR(source_len),
			&dir, &ascent, &descent, &sw); 
		logical.width = sw.width;
	}
#else
	XmbTextExtents(ATTR(fontset), ATTR(source), ATTR(source_len), &ink,
		&logical);
#endif

	/* No coordinates given, query to current pointer location */
	if(ATTR(pop_x) == 0 && ATTR(pop_y) == 0)
	{
		Widget parent = XtParent((Widget)balloon);
		Display *dpy = XtDisplay(parent);
		Window w = XtWindow(parent);
		Window root, child;
		int win_x, win_y, root_x, root_y;
		unsigned int mask_return;

		/* must get pointer position relative to child window position */
		if(!XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x,
			&win_y, &mask_return))
			return;

		/*****
		* don't put x and y in the above call, win_x and win_y are int
		* whereas x and y are Position (short int)
		*****/
		x = (Position)win_x;
		y = (Position)win_y;
	}
	else /* translate local pointer position to global position */
	{
		x = ATTR(pop_x);
		y = ATTR(pop_y);
	}

	if(ATTR(shape_window))
		drawBalloonShaped((Widget)balloon, x, y, logical.width);
	else
		drawBalloonSquared((Widget)balloon, x, y, logical.width);

	/* if we have got a popdown timeout, add it */
	if(ATTR(popdown_delay))
	{
		ATTR(popdown_id) = XtAppAddTimeOut(ATTR(context),
			ATTR(popdown_delay), popdownBalloon, (XtPointer)balloon);
	}
}
/*
 * Backend for f.identify and f.version: Fills in the Info array with the
 * appropriate bits for ctwm and the window specified (if any), and
 * sizes/pops up the InfoWindow.
 *
 * Notably, the bits of Info aren't written into the window during this
 * process; that happens later as a result of the expose event.
 */
static void
Identify(TwmWindow *t)
{
	int i, n, twidth, width, height;
	int x, y;
	unsigned int wwidth, wheight, bw, depth;
	Window junk;
	int px, py, dummy;
	unsigned udummy;
	unsigned char *prop;
	unsigned long nitems, bytesafter;
	Atom actual_type;
	int actual_format;
	XRectangle inc_rect;
	XRectangle logical_rect;
	char *ctopts;

	/*
	 * Include some checking we don't blow out _LINES.  We use snprintf()
	 * exclusively to avoid blowing out _SIZE.
	 *
	 * In an ideal world, we'd probably fix this to be more dynamically
	 * allocated, but this will do for now.
	 */
	n = 0;
#define CHKN do { \
                if(n > (INFO_LINES - 3)) { \
                        fprintf(stderr, "Overflowing Info[] on line %d\n", n); \
                        sprintf(Info[n++], "(overflow)"); \
                        goto info_dismiss; \
                } \
        } while(0)

	snprintf(Info[n++], INFO_SIZE, "Twm version:  %s", TwmVersion);
	CHKN;
	if(VCSRevision) {
		snprintf(Info[n++], INFO_SIZE, "VCS Revision:  %s", VCSRevision);
		CHKN;
	}

	ctopts = ctopts_string(", ");
	snprintf(Info[n++], INFO_SIZE, "Compile time options : %s", ctopts);
	free(ctopts);
	CHKN;

	Info[n++][0] = '\0';
	CHKN;

	if(t) {
		XGetGeometry(dpy, t->w, &JunkRoot, &JunkX, &JunkY,
		             &wwidth, &wheight, &bw, &depth);
		XTranslateCoordinates(dpy, t->w, Scr->Root, 0, 0,
		                      &x, &y, &junk);
		snprintf(Info[n++], INFO_SIZE, "Name               = \"%s\"",
		         t->name);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Class.res_name     = \"%s\"",
		         t->class.res_name);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Class.res_class    = \"%s\"",
		         t->class.res_class);
		CHKN;
		Info[n++][0] = '\0';
		CHKN;
		snprintf(Info[n++], INFO_SIZE,
		         "Geometry/root (UL) = %dx%d+%d+%d (Inner: %dx%d+%d+%d)",
		         wwidth + 2 * (bw + t->frame_bw3D),
		         wheight + 2 * (bw + t->frame_bw3D) + t->title_height,
		         x - (bw + t->frame_bw3D),
		         y - (bw + t->frame_bw3D + t->title_height),
		         wwidth, wheight, x, y);
		CHKN;
		snprintf(Info[n++], INFO_SIZE,
		         "Geometry/root (LR) = %dx%d-%d-%d (Inner: %dx%d-%d-%d)",
		         wwidth + 2 * (bw + t->frame_bw3D),
		         wheight + 2 * (bw + t->frame_bw3D) + t->title_height,
		         Scr->rootw - (x + wwidth + bw + t->frame_bw3D),
		         Scr->rooth - (y + wheight + bw + t->frame_bw3D),
		         wwidth, wheight,
		         Scr->rootw - (x + wwidth), Scr->rooth - (y + wheight));
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Border width       = %d", bw);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "3D border width    = %d", t->frame_bw3D);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Depth              = %d", depth);
		CHKN;
		if(t->vs &&
		                t->vs->wsw &&
		                t->vs->wsw->currentwspc) {
			snprintf(Info[n++], INFO_SIZE, "Virtual Workspace  = %s",
			         t->vs->wsw->currentwspc->name);
			CHKN;
		}
		snprintf(Info[n++], INFO_SIZE, "OnTopPriority      = %d",
		         OtpEffectiveDisplayPriority(t));
		CHKN;

		if(t->icon != NULL) {
			int iwx, iwy;

			XGetGeometry(dpy, t->icon->w, &JunkRoot, &iwx, &iwy,
			             &wwidth, &wheight, &bw, &depth);
			Info[n++][0] = '\0';
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconGeom/root     = %dx%d+%d+%d",
			         wwidth, wheight, iwx, iwy);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconGeom/intern   = %dx%d+%d+%d",
			         t->icon->w_width, t->icon->w_height,
			         t->icon->w_x, t->icon->w_y);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconBorder width  = %d", bw);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconDepth         = %d", depth);
			CHKN;
		}

		if(XGetWindowProperty(dpy, t->w, XA_WM_CLIENT_MACHINE, 0L, 64, False,
		                      XA_STRING, &actual_type, &actual_format, &nitems,
		                      &bytesafter, &prop) == Success) {
			if(nitems && prop) {
				snprintf(Info[n++], INFO_SIZE, "Client machine     = %s",
				         (char *)prop);
				XFree(prop);
				CHKN;
			}
		}
		Info[n++][0] = '\0';
		CHKN;
	}

#undef CHKN
info_dismiss:
	snprintf(Info[n++], INFO_SIZE, "Click to dismiss....");


	/*
	 * OK, it's all built now.
	 */

	/* figure out the width and height of the info window */
	height = n * (Scr->DefaultFont.height + 2);
	width = 1;
	for(i = 0; i < n; i++) {
		XmbTextExtents(Scr->DefaultFont.font_set, Info[i],
		               strlen(Info[i]), &inc_rect, &logical_rect);

		twidth = logical_rect.width;
		if(twidth > width) {
			width = twidth;
		}
	}

	/* Unmap if it's currently up, while we muck with it */
	if(Scr->InfoWindow.mapped) {
		XUnmapWindow(dpy, Scr->InfoWindow.win);
		/* Don't really need to bother since we're about to reset, but...  */
		Scr->InfoWindow.mapped = false;
	}

	/* Stash the new number of lines */
	Scr->InfoWindow.lines = n;

	width += 10;                /* some padding */
	height += 10;               /* some padding */
	if(XQueryPointer(dpy, Scr->Root, &JunkRoot, &JunkChild,
	                 &dummy, &dummy, &px, &py, &udummy)) {
		px -= width / 2;
		py -= height / 3;
	}
	else {
		px = py = 0;
	}

	{
		RArea area = RAreaNew(px, py, width, height);
		int min_x, min_y, max_bottom, max_right;

		RLayoutFindLeftRightEdges(Scr->Layout, &area, &min_x, &max_right);
		if(px < min_x) {
			px = min_x;
		}
		else if(px + width - 1 > max_right) {
			px = max_right - width + 1;
		}

		RLayoutFindTopBottomEdges(Scr->Layout, &area, &min_y, &max_bottom);
		if(py < min_y) {
			py = min_y;
		}
		else if(py + height - 1 > max_bottom) {
			py = max_bottom - height + 1;
		}
	}
	XMoveResizeWindow(dpy, Scr->InfoWindow.win, px, py, width, height);
	XMapRaised(dpy, Scr->InfoWindow.win);
	Scr->InfoWindow.mapped = true;
	Scr->InfoWindow.width  = width;
	Scr->InfoWindow.height = height;
}