示例#1
0
文件: font.c 项目: raboof/notion
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 */
    return 0;
}
示例#2
0
int4 MCOldFontlist::ctxt_textwidth(MCFontStruct *of, const char *s, uint2 l, bool p_unicode_override)
{
	MCOldFontStruct *f;
	f = static_cast<MCOldFontStruct *>(of);

	bool useUnicode = (f->max_byte1 > 0 || f->unicode) || p_unicode_override;

	if ( useUnicode )
	{
		uint2 x_l ;
		XChar2b x_s[l / 2];
		
		x_l = (l + 1) / 2;
		for(int i = 0; i < x_l; ++i)
			x_s[i] . byte1 = s[i * 2 + 1], x_s[i] . byte2 = s[i * 2];

		return XTextWidth16(f->fstruct, (const XChar2b *)x_s, x_l);
	}
	
	return XTextWidth(f->fstruct, s, l);
}
示例#3
0
static
int X11DRV_TextWidth_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count )
{
    int i;
    int width;
    int curfont;
    fontObject* pfos[X11FONT_REFOBJS_MAX+1];

    pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
    pfos[1] = pfo;
    if ( pfos[0] == NULL ) pfos[0] = pfo;

    width = 0;
    wine_tsx11_lock();
    for ( i = 0; i < count; i++ )
    {
	curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
	width += XTextWidth16( pfos[curfont]->fs, pstr, 1 );
	pstr ++;
    }
    wine_tsx11_unlock();
    return width;
}
示例#4
0
int
XUtf8UcsWidth(
        XUtf8FontStruct  *font_set,
        unsigned int            ucs)
{
	int		x;
	int 		*encodings; /* encodings array */
	XFontStruct 	**fonts; /* fonts array */
	XChar2b 	buf[8]; /* drawing buffer */
	int 		fnum; /* index of the current font in the fonts array*/
	int 		i; /* current byte in the XChar2b buffer */
	int 		first; /* first valid font index */
	int 		last_fnum; /* font index of the previous char */
	int 		nb_font;  /* quantity of fonts in the font array */
	char 		glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
	int		*ranges; /* sub range of iso10646 */

	nb_font = font_set->nb_font;
	x = 0;

	if (nb_font < 1) {
		/* there is no font in the font_set :-( */
		return x;
	}

	ranges = font_set->ranges;
	fonts = font_set->fonts;
	encodings = font_set->encodings;
	i = 0;
	fnum = 0;
	
	while(fnum < nb_font && !fonts[fnum]) fnum++;
	if (fnum >= nb_font) {
		/* there is no valid font for the X server */
		return x;
	}

	first = fnum;
	last_fnum = fnum;


	ucs = XUtf8IsNonSpacing(ucs);

	/* 
	 * find the first encoding which can be used to 	
	 * draw the glyph 				
	 */
	fnum = first;
	while (fnum < nb_font) {
		if (fonts[fnum] && 
			ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) 
		{
			if (encodings[fnum] != 0 || (ucs >= ranges[fnum * 2] &&
				ucs <= ranges[fnum * 2 + 1]))
			{
				break;
			}
		}
		fnum++;
	}
	if (fnum == nb_font) {
		/** the char is not valid in all encodings ->
		  * draw it using the first font :-( **/
		fnum = first;
		ucs2fontmap(glyph, '?', encodings[fnum]);
	}

	(*buf).byte1 = glyph[0];
	(*buf).byte2 = glyph[1];

	x += XTextWidth16(fonts[fnum], buf, 1);

	return x;
}
示例#5
0
int  
XUtf8TextWidth(
        XUtf8FontStruct 	*font_set, 
	const char 	*string,
        int 		num_bytes)
{
	int		x;
	int 		*encodings; /* encodings array */
	XFontStruct 	**fonts; /* fonts array */
	XChar2b 	buf[128]; /* drawing buffer */
	int 		fnum; /* index of the current font in the fonts array*/
	int 		i; /* current byte in the XChar2b buffer */
	int 		first; /* first valid font index */
	int 		last_fnum; /* font index of the previous char */
	int 		nb_font;  /* quantity of fonts in the font array */
	char 		glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
	int		*ranges; /* sub range of iso10646 */

	nb_font = font_set->nb_font;
	x = 0;

	if (nb_font < 1) {
		/* there is no font in the font_set :-( */
		return x;
	}

	ranges = font_set->ranges;
	fonts = font_set->fonts;
	encodings = font_set->encodings;
	i = 0;
	fnum = 0;
	
	while(fnum < nb_font && !fonts[fnum]) fnum++;
	if (fnum >= nb_font) {
		/* there is no valid font for the X server */
		return x;
	}

	first = fnum;
	last_fnum = fnum;

	while (num_bytes > 0) {
		int 		ulen; /* byte length of the UTF-8 char */
		unsigned int 	ucs;  /* Unicode value of the UTF-8 char */
		unsigned int	no_spc; /* Spacing char equivalent of a 
					   non-spacing char */

		if (i > 120) {
			/*** measure the buffer **/
			x += XTextWidth16(fonts[fnum], buf, i);
			i = 0;
		}

		ulen = XFastConvertUtf8ToUcs((unsigned char*)string, 
				num_bytes, &ucs); 

		if (ulen < 1) ulen = 1; 

		no_spc = XUtf8IsNonSpacing(ucs);
		if (no_spc) {
			ucs = no_spc;
		}

		/* 
		 * find the first encoding which can be used to 	
		 * draw the glyph 				
		 */
		fnum = first;
		while (fnum < nb_font) {
			if (fonts[fnum] && 
				ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) 
			{
				if (encodings[fnum] != 0 || 
					(ucs >= ranges[fnum * 2] &&
					ucs <= ranges[fnum * 2 + 1]))
				{
					break;
				}
			}
			fnum++;
		}
		if (fnum == nb_font) {
			/** the char is not valid in all encodings ->
			  * draw it using the first font :-( **/
			fnum = first;
			ucs2fontmap(glyph, '?', encodings[fnum]);
		}

		if (last_fnum != fnum || no_spc) {
			x += XTextWidth16(fonts[last_fnum], buf, i);
			i = 0;
			(*buf).byte1 = glyph[0];
			(*buf).byte2 = glyph[1];
			if (no_spc) {
				/* go back to draw the non-spacing char over
				 *  the previous char */
				x -= XTextWidth16(fonts[fnum], buf, 1);
			}
		} else {
			(*(buf + i)).byte1 = glyph[0];
			(*(buf + i)).byte2 = glyph[1];
		}
		last_fnum = fnum;
		i++;
		string += ulen;
		num_bytes -= ulen;
	}

	x += XTextWidth16(fonts[last_fnum], buf, i);

	return x;
}
示例#6
0
void 
XUtf8DrawRtlString(
	Display 	*display, 
	Drawable 	d,
        XUtf8FontStruct 	*font_set, 
	GC 		gc, 
	int 		x, 
	int 		y, 
	const char	*string,
        int 		num_bytes)
{
	int 		*encodings; /* encodings array */
	XFontStruct 	**fonts; /* fonts array */
	XChar2b 	buf[128]; /* drawing buffer */
	XChar2b		*ptr;	/* pointer to the drawing buffer */
	int 		fnum; /* index of the current font in the fonts array*/
	int 		i; /* current byte in the XChar2b buffer */
	int 		first; /* first valid font index */
	int 		last_fnum; /* font index of the previous char */
	int 		nb_font;  /* quantity of fonts in the font array */
	char 		glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
	int		*ranges; /* sub range of iso10646 */

	nb_font = font_set->nb_font;

	if (nb_font < 1) {
		/* there is no font in the font_set :-( */
		return;
	}
	
	ranges = font_set->ranges;
	fonts = font_set->fonts;
	encodings = font_set->encodings;
	i = 0;
	fnum = 0;
	ptr = buf + 128;
	
	while(fnum < nb_font && !fonts[fnum]) fnum++;
	if (fnum >= nb_font) {
		/* there is no valid font for the X server */
		return;
	}

	first = fnum;
	last_fnum = fnum;

	while (num_bytes > 0) {
		int 		ulen; /* byte length of the UTF-8 char */
		unsigned int 	ucs;  /* Unicode value of the UTF-8 char */
		unsigned int	no_spc; /* Spacing char equivalent of a 
					   non-spacing char */

		if (i > 120) {
			/*** draw the buffer **/
			XSetFont(display, gc, fonts[fnum]->fid);
			x -= XTextWidth16(fonts[fnum], ptr, i);
			XDrawString16(display, d, gc, x, y, ptr, i);
			i = 0;
			ptr = buf + 128;
		}

		ulen = XFastConvertUtf8ToUcs((unsigned char*)string, 
				num_bytes, &ucs); 

		if (ulen < 1) ulen = 1; 

		no_spc = XUtf8IsNonSpacing(ucs);
		if (no_spc) ucs = no_spc; 

		/* 
		 * find the first encoding which can be used to 	
		 * draw the glyph 				
		 */
		fnum = first;
		while (fnum < nb_font) {
			if (fonts[fnum] && 
				ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) 
			{
				if (encodings[fnum] != 0 || 
					(ucs >= ranges[fnum * 2] &&
					ucs <= ranges[fnum * 2 + 1]))
				{
					break;
				}
			}
			fnum++;
		}
		if (fnum == nb_font) {
			/** the char is not valid in all encodings ->
			  * draw it using the first font :-( **/
			fnum = first;
			ucs2fontmap(glyph, '?', encodings[fnum]);
		}

		if (last_fnum != fnum || no_spc) {
			XSetFont(display, gc, fonts[last_fnum]->fid);
			x -= XTextWidth16(fonts[last_fnum], ptr, i);
			XDrawString16(display, d, gc, x, y, ptr, i);
			i = 0;
			ptr = buf + 127;
			(*ptr).byte1 = glyph[0];
			(*ptr).byte2 = glyph[1];
			if (no_spc) {
				x += XTextWidth16(fonts[fnum], ptr, 1);
			}
		} else {
			ptr--;
			(*ptr).byte1 = glyph[0];
			(*ptr).byte2 = glyph[1];
		}
		last_fnum = fnum;
		i++;
		string += ulen;
		num_bytes -= ulen;
	}

	if (i < 1) return;

	XSetFont(display, gc, fonts[fnum]->fid);
	x -= XTextWidth16(fonts[last_fnum], ptr, i);
	XDrawString16(display, d, gc, x, y, ptr, i);
}
示例#7
0
/*
 * Calculate width and height of displayed text in pixels
 */
static void
SetTextWidthAndHeight(LabelWidget lw)
{
    XFontStruct	*fs = lw->label.font;
    char *nl;

    if (lw->label.pixmap != None) {
	Window root;
	int x, y;
	unsigned int width, height, bw, depth;

	if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y,
		       &width, &height, &bw, &depth)) {
	    lw->label.label_height = height;
	    lw->label.label_width = width;
	    lw->label.label_len = depth;
	    return;
	}
    }
    if (lw->simple.international == True) {
	XFontSet	fset = lw->label.fontset;
	XFontSetExtents *ext = XExtentsOfFontSet(fset);

	lw->label.label_height = ext->max_ink_extent.height;
	if (lw->label.label == NULL) {
	    lw->label.label_len = 0;
	    lw->label.label_width = 0;
	}
	else if ((nl = index(lw->label.label, '\n')) != NULL) {
	    char *label;

	    lw->label.label_len = MULTI_LINE_LABEL;
	    lw->label.label_width = 0;
	    for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) {
		int width = XmbTextEscapement(fset, label, (int)(nl - label));

		if (width > (int)lw->label.label_width)
		    lw->label.label_width = width;
		label = nl + 1;
		if (*label)
		    lw->label.label_height += ext->max_ink_extent.height;
	    }
	    if (*label) {
		int width = XmbTextEscapement(fset, label, strlen(label));

		if (width > (int)lw->label.label_width)
		    lw->label.label_width = width;
	    }
	}
	else {
	    lw->label.label_len = strlen(lw->label.label);
	    lw->label.label_width =
		XmbTextEscapement(fset, lw->label.label, lw->label.label_len);
	}
    }
    else {
	lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent;
	if (lw->label.label == NULL) {
	    lw->label.label_len = 0;
	    lw->label.label_width = 0;
	}
	else if ((nl = index(lw->label.label, '\n')) != NULL) {
	    char *label;

	    lw->label.label_len = MULTI_LINE_LABEL;
	    lw->label.label_width = 0;
	    for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) {
		int width;

		if (lw->label.encoding)
		    width = XTextWidth16(fs, (XChar2b *)label, (int)(nl - label) / 2);
		else
		    width = XTextWidth(fs, label, (int)(nl - label));
		if (width > (int)lw->label.label_width)
		    lw->label.label_width = width;
		label = nl + 1;
		if (*label)
		    lw->label.label_height +=
			fs->max_bounds.ascent + fs->max_bounds.descent;
	    }
	    if (*label) {
		int width = XTextWidth(fs, label, strlen(label));

		if (lw->label.encoding)
		    width = XTextWidth16(fs, (XChar2b *)label, strlen(label) / 2);
		else
		    width = XTextWidth(fs, label, strlen(label));
		if (width > (int) lw->label.label_width)
		    lw->label.label_width = width;
	    }
	}
	else {
	    lw->label.label_len = strlen(lw->label.label);
	    if (lw->label.encoding)
		lw->label.label_width =
		    XTextWidth16(fs, (XChar2b *)lw->label.label,
			   (int)lw->label.label_len / 2);
	    else
		lw->label.label_width =
	      XTextWidth(fs, lw->label.label, (int)lw->label.label_len);
	}
    }
}