예제 #1
0
파일: thai.c 프로젝트: razvanm/mrxvt
/* EXTPROTO */
int
ThaiPixel2Col (rxvt_t* r, int page, int x, int y)
{
	int row;             /* row storing data */
	int i;               /* byte offset index */
	int xpixel;          /* dummy x pixel */
	char *str;           /* drawn_text pointer */
	XFontStruct *wf;     /* font */

	/* locate buffer storing data */
	row = Pixel2Row(y);
	MAX_IT(row, 0);
	MIN_IT(row, r->TermWin.nrow - 1);
	str = PVTS(r, page)->drawn_text[row];

	/* access to font structure */
	wf = r->TermWin.font;

	/* increase byte offset until we get to target x */
	i = 0;
	xpixel = FONT_WIDTH(wf, str[0]);
	x -= r->TermWin.int_bwidth;
	while (xpixel <= x && i < r->TermWin.ncol){
		i++;
		xpixel += FONT_WIDTH(wf, str[i]); /* wf->per_char[char_num].width;  */
	}

	MAX_IT(i, 0);
	MIN_IT(i, r->TermWin.ncol);
	return i;
}
예제 #2
0
파일: pixmap.c 프로젝트: mcgrew/lxvt
/* EXTPROTO */
int
rxvt_scale_pixmap(rxvt_t *r, int page, const char *geom)
{
    int		 flags, changed = 0;
    int		 x = 0, y = 0;
    unsigned int    w = 0, h = 0;
    unsigned int    n;
    char	   *p, *str;
    bgPixmap_t	 *bgpixmap = &(PVTS(r, page)->bg);

#define MAXLEN_GEOM	sizeof("[1000x1000+1000+1000]")

    if (geom == NULL)
	return 0;
    str = rxvt_malloc(MAXLEN_GEOM + 1);
    if (!STRCMP(geom, "?")) {
	sprintf(str, "[%dx%d+%d+%d]",	/* can't presume snprintf() ! */
	    min(bgpixmap->w, 9999), min(bgpixmap->h, 9999),
	    min(bgpixmap->x, 9999), min(bgpixmap->y, 9999));
	rxvt_xterm_seq(r, page, XTerm_title, str, CHAR_ST);
	rxvt_free(str);
	return 0;
    }

    if ((p = STRCHR(geom, ';')) == NULL)
    p = STRCHR(geom, '\0');
    n = (p - geom);
    if (n <= MAXLEN_GEOM) {
    STRNCPY(str, geom, n);
    str[n] = '\0';

    flags = XParseGeometry(str, &x, &y, &w, &h);
    if (!flags) {
	flags |= WidthValue;
	w = 0;
    }		/* default is tile */
    if (flags & WidthValue) {
	if (!(flags & XValue))
	x = 50;
	if (!(flags & HeightValue))
	h = w;
	if (w && !h) {
	w = (bgpixmap->w * w) / 100;
	h = bgpixmap->h;
	} else if (h && !w) {
	w = bgpixmap->w;
	h = (bgpixmap->h * h) / 100;
	}
	if (w > 1000)
	w = 1000;
	if (h > 1000)
	h = 1000;
	if (bgpixmap->w != (short)w) {
	bgpixmap->w = (short)w;
	changed++;
	}
	if (bgpixmap->h != (short)h) {
	bgpixmap->h = (short)h;
	changed++;
	}
    }
    if (!(flags & YValue)) {
	if (flags & XNegative)
	flags |= YNegative;
	y = x;
    }

    if (!(flags & WidthValue) && geom[0] != '=') {
	x += bgpixmap->x;
	y += bgpixmap->y;
    } else {
	if (flags & XNegative)
	x += 100;
	if (flags & YNegative)
	y += 100;
    }
    MIN_IT(x, 100);
    MIN_IT(y, 100);
    MAX_IT(x, 0);
    MAX_IT(y, 0);
    if (bgpixmap->x != x) {
	bgpixmap->x = x;
	changed++;
    }
    if (bgpixmap->y != y) {
	bgpixmap->y = y;
	changed++;
    }
    }
    rxvt_free(str);
    return changed;
}