Added gdk_text_extents_wc()
Tue Dec 15 14:30:35 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfonts.c: Added gdk_text_extents_wc() * Patch from Jonathan Blanford <jrb@redhat.com> to add line wrapping to label. (Based on patch from Jeff Dairiki <dairiki@mac-ceope.apl.washington.edu> gtk-dairiki-971208-0) - Adds new function gtk_label_set_line_wrap() - implement GTK_JUSTIFY_FILL. - rename gtk_label_set to gtk_label_set_text() add gtk_label_set() to gtkcompat.h. * Use an internal wc representation in the label, so that we handle underlining and line breaks correctly for multi-byte strings.
This commit is contained in:
@ -503,6 +503,80 @@ gdk_text_extents (GdkFont *font,
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
gdk_text_extents_wc (GdkFont *font,
|
||||
const GdkWChar *text,
|
||||
gint text_length,
|
||||
gint *lbearing,
|
||||
gint *rbearing,
|
||||
gint *width,
|
||||
gint *ascent,
|
||||
gint *descent)
|
||||
{
|
||||
GdkFontPrivate *private;
|
||||
XCharStruct overall;
|
||||
XFontStruct *xfont;
|
||||
XFontSet fontset;
|
||||
XRectangle ink, logical;
|
||||
int direction;
|
||||
int font_ascent;
|
||||
int font_descent;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (font != NULL);
|
||||
g_return_if_fail (text != NULL);
|
||||
|
||||
private = (GdkFontPrivate*) font;
|
||||
|
||||
switch (font->type)
|
||||
{
|
||||
case GDK_FONT_FONT:
|
||||
{
|
||||
gchar *text_8bit;
|
||||
gint i;
|
||||
|
||||
xfont = (XFontStruct *) private->xfont;
|
||||
g_return_if_fail ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0));
|
||||
|
||||
text_8bit = g_new (gchar, text_length);
|
||||
for (i=0; i<text_length; i++)
|
||||
text_8bit[i] = text[i];
|
||||
|
||||
XTextExtents (xfont, text_8bit, text_length,
|
||||
&direction, &font_ascent, &font_descent,
|
||||
&overall);
|
||||
g_free (text_8bit);
|
||||
|
||||
if (lbearing)
|
||||
*lbearing = overall.lbearing;
|
||||
if (rbearing)
|
||||
*rbearing = overall.rbearing;
|
||||
if (width)
|
||||
*width = overall.width;
|
||||
if (ascent)
|
||||
*ascent = overall.ascent;
|
||||
if (descent)
|
||||
*descent = overall.descent;
|
||||
break;
|
||||
}
|
||||
case GDK_FONT_FONTSET:
|
||||
fontset = (XFontSet) private->xfont;
|
||||
XwcTextExtents (fontset, text, text_length, &ink, &logical);
|
||||
if (lbearing)
|
||||
*lbearing = ink.x;
|
||||
if (rbearing)
|
||||
*rbearing = ink.x + ink.width;
|
||||
if (width)
|
||||
*width = logical.width;
|
||||
if (ascent)
|
||||
*ascent = -ink.y;
|
||||
if (descent)
|
||||
*descent = ink.y + ink.height;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
gdk_string_extents (GdkFont *font,
|
||||
const gchar *string,
|
||||
|
||||
Reference in New Issue
Block a user