gtk2/gdk/gdkfont.c

721 lines
16 KiB
C
Raw Normal View History

1997-11-24 22:37:52 +00:00
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
1997-11-24 22:37:52 +00:00
*/
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include "gdk.h"
#include "gdkprivate.h"
GdkFont*
gdk_font_load (const gchar *font_name)
{
GdkFont *font;
GdkFontPrivate *private;
private = g_new (GdkFontPrivate, 1);
font = (GdkFont*) private;
private->xdisplay = gdk_display;
private->xfont = XLoadQueryFont (private->xdisplay, font_name);
private->ref_count = 1;
if (!private->xfont)
{
g_free (font);
return NULL;
}
else
{
font->type = GDK_FONT_FONT;
font->ascent = ((XFontStruct *) private->xfont)->ascent;
font->descent = ((XFontStruct *) private->xfont)->descent;
}
gdk_xid_table_insert (&((XFontStruct *) private->xfont)->fid, font);
return font;
}
GdkFont*
gdk_fontset_load (gchar *fontset_name)
1997-11-24 22:37:52 +00:00
{
GdkFont *font;
GdkFontPrivate *private;
XFontSet fontset;
gint missing_charset_count;
gchar **missing_charset_list;
gchar *def_string;
private = g_new (GdkFontPrivate, 1);
font = (GdkFont*) private;
private->xdisplay = gdk_display;
fontset = XCreateFontSet (gdk_display, fontset_name,
&missing_charset_list, &missing_charset_count,
&def_string);
if (missing_charset_count)
{
gint i;
g_message ("Missing charsets in FontSet creation\n");
for (i=0;i<missing_charset_count;i++)
g_message (" %s\n", missing_charset_list[i]);
1997-11-24 22:37:52 +00:00
XFreeStringList (missing_charset_list);
}
private->ref_count = 1;
if (!fontset)
{
g_free (font);
return NULL;
}
else
{
gint num_fonts;
gint i;
XFontStruct **font_structs;
gchar **font_names;
1997-11-24 22:37:52 +00:00
private->xfont = fontset;
font->type = GDK_FONT_FONTSET;
num_fonts = XFontsOfFontSet (fontset, &font_structs, &font_names);
font->ascent = font->descent = 0;
for (i = 0; i < num_fonts; i++)
{
font->ascent = MAX (font->ascent, font_structs[i]->ascent);
font->descent = MAX (font->descent, font_structs[i]->descent);
}
1997-11-24 22:37:52 +00:00
}
return font;
}
GdkFont*
gdk_font_ref (GdkFont *font)
1997-11-24 22:37:52 +00:00
{
GdkFontPrivate *private;
g_return_val_if_fail (font != NULL, NULL);
1997-11-24 22:37:52 +00:00
private = (GdkFontPrivate*) font;
private->ref_count += 1;
return font;
1997-11-24 22:37:52 +00:00
}
void
gdk_font_unref (GdkFont *font)
1997-11-24 22:37:52 +00:00
{
GdkFontPrivate *private;
g_return_if_fail (font != NULL);
private = (GdkFontPrivate*) font;
private->ref_count -= 1;
if (private->ref_count == 0)
{
switch (font->type)
{
case GDK_FONT_FONT:
gdk_xid_table_remove (((XFontStruct *) private->xfont)->fid);
XFreeFont (private->xdisplay, (XFontStruct *) private->xfont);
break;
case GDK_FONT_FONTSET:
XFreeFontSet (private->xdisplay, (XFontSet) private->xfont);
break;
default:
g_error ("unknown font type.");
break;
}
1997-11-24 22:37:52 +00:00
g_free (font);
}
}
gint
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
gdk_font_id (const GdkFont *font)
1997-11-24 22:37:52 +00:00
{
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
const GdkFontPrivate *font_private;
1997-11-24 22:37:52 +00:00
g_return_val_if_fail (font != NULL, 0);
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
font_private = (const GdkFontPrivate*) font;
1997-11-24 22:37:52 +00:00
if (font->type == GDK_FONT_FONT)
{
return ((XFontStruct *) font_private->xfont)->fid;
}
else
{
return 0;
}
}
gint
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
gdk_font_equal (const GdkFont *fonta,
const GdkFont *fontb)
1997-11-24 22:37:52 +00:00
{
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
const GdkFontPrivate *privatea;
const GdkFontPrivate *privateb;
1997-11-24 22:37:52 +00:00
g_return_val_if_fail (fonta != NULL, FALSE);
g_return_val_if_fail (fontb != NULL, FALSE);
Removed g_object_pointer_hash, which was just g_direct_hash. Tue Jun 9 18:44:57 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkobject.c: Removed g_object_pointer_hash, which was just g_direct_hash. Mon May 25 19:54:20 1998 Owen Taylor <otaylor@gtk.org> * configure.in: x_libs=, not $x_libs=. Enough said. (Case only hit for --disable-xshm) Mon May 25 12:08:14 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Add to $CFLAGS and $LDFLAGS when testing for X libraries, don't replace them. Because the user might have specified the path to the X libraries themself before running configure. * examples/**.c: Changed all gpointer * to gpointer Sat May 23 21:54:05 1998 Owen Taylor <otaylor@gtk.org> * configure.in (LDFLAGS): Bomb out with a moderately helpful message if detection of X libraries fails. Sat May 23 18:57:06 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * gdk/gdk.h gdk/gdkcc.c gdk/gdkfont.c gtk/gtkmain.c gtk/gtksignal.c gtk/gtktext.c: Fixups for warnings from adding const to type of GHashFunc, GCompareFunc * gtk/gtkcombo.c (gtk_combo_entry_key_press): Minor style/ ansi-warnings fixups. Tue Jun 9 17:47:33 1998 Owen Taylor <otaylor@gtk.org> * glib.h: Remove #error - HP/UX. Sat May 23 19:00:01 1998 Owen Taylor <otaylor@gtk.org> [ Combination of: gtk-rrh-980412-0.patch (Raja R Harinath <harinath@cs.umn.edu>) gtk-jbuhler-980516-0 (Jeremy Buhler <jbuhler@cs.washington.edu>) ] * glib.h ghash.c gstring.c gdataset.c gutils.c: - Added new typedef g_const_pointer; expunged all incorrect uses of 'const gpointer'. - Fixed up warnings that that created, - Changed GHashFunc and GCompareFunc to take g_const_pointer arguments. (Necessary, but will cause warnings in existing code until fixed) - Added other new const in harmless positions.
1998-06-09 23:18:11 +00:00
privatea = (const GdkFontPrivate*) fonta;
privateb = (const GdkFontPrivate*) fontb;
1997-11-24 22:37:52 +00:00
if (fonta->type == GDK_FONT_FONT && fontb->type == GDK_FONT_FONT)
{
return (((XFontStruct *) privatea->xfont)->fid ==
((XFontStruct *) privateb->xfont)->fid);
}
else if (fonta->type == GDK_FONT_FONTSET && fontb->type == GDK_FONT_FONTSET)
{
/* how to compare two fontsets ?? by basename or XFontSet ?? */
return (((XFontSet) privatea->xfont) == ((XFontSet) privateb->xfont));
}
else
/* fontset != font */
return 0;
}
gint
gdk_string_width (GdkFont *font,
const gchar *string)
{
GdkFontPrivate *font_private;
gint width;
XFontStruct *xfont;
XFontSet fontset;
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (string != NULL, -1);
font_private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) font_private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
width = XTextWidth (xfont, string, strlen (string));
}
else
{
width = XTextWidth16 (xfont, (XChar2b *) string, strlen (string) / 2);
}
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) font_private->xfont;
width = XmbTextEscapement (fontset, string, strlen(string));
break;
default:
width = 0;
}
return width;
}
gint
gdk_text_width (GdkFont *font,
const gchar *text,
gint text_length)
{
GdkFontPrivate *private;
gint width;
XFontStruct *xfont;
XFontSet fontset;
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (text != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
width = XTextWidth (xfont, text, text_length);
}
else
{
width = XTextWidth16 (xfont, (XChar2b *) text, text_length / 2);
}
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) private->xfont;
width = XmbTextEscapement (fontset, text, text_length);
break;
default:
width = 0;
}
return width;
}
Destroy widgets _after_ propagating unrealize signals through the widget Mon Dec 7 10:27:09 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtkwidget.c: Destroy widgets _after_ propagating unrealize signals through the widget heirarchy. This is unpleasant, as it causes more X traffic, but is necessary, because we have to clean up our Input Contexts before destroying the X windows. (from matsu-981109-0.patch) Mon Dec 7 10:18:18 1998 Owen Taylor <otaylor@redhat.com> Applied gtk-a-higuti-981202-0 : [ a-higuti@math.sci.hokudai.ac.jp (Akira Higuchi) ] * gdk/gdk.h gdk/gdk.c (gdk_mbstowcs): New function. Nearly equals to mbstowcs, but implemented by a combination of Xlib functions, so it works even with X_LOCALE. (gdk_wcstombs): New function. (g_mbtowc): Removed. No longer needed. * gdk/gdk.h gdk/gdkfont.c gdk/gdkdraw.c: Added _wc() variants to gdk_text_width(), gdk_char_width(), gdk_draw_text(), * gdk/gdki18n.h (mblen, mbtowc, wctomb, mbstowcs, wcstombs, wcslen, wcscpy, wcsncpy): Removed. No longer needed. (iswalnum): Removed. (gdk_iswalnum): New macro. (gdk_iswspace): New macro. * gdk/gdktype.h (GdkWChar): New typedef. * gtk/gtkentry.h, gtk/gtkentry.c There are many changes according to the change of the internal representation of text, from multibyte string to wide characters. * gtk/gtkprivate.h, gtk/gtkmain.c Removed the variable gtk_use_mb and related codes. * gtk/gtkspinbutton.c Some changes according to the change of type of entry->text. * gtk/gtktext.h, gtk/gtktext.c Changed the internal representation of text. We use GdkWchar if a fontset is supplied. If not, we use guchar to save memory.
1998-12-09 06:36:57 +00:00
gint
gdk_text_width_wc (GdkFont *font,
const GdkWChar *text,
gint text_length)
{
GdkFontPrivate *private;
gint width;
XFontStruct *xfont;
XFontSet fontset;
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (text != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
gchar *text_8bit;
gint i;
text_8bit = g_new (gchar, text_length);
for (i=0; i<text_length; i++) text_8bit[i] = text[i];
width = XTextWidth (xfont, text_8bit, text_length);
g_free (text_8bit);
}
else
{
width = 0;
}
break;
case GDK_FONT_FONTSET:
if (sizeof(GdkWChar) == sizeof(wchar_t))
{
fontset = (XFontSet) private->xfont;
width = XwcTextEscapement (fontset, (wchar_t *)text, text_length);
}
else
{
wchar_t *text_wchar;
gint i;
fontset = (XFontSet) private->xfont;
text_wchar = g_new(wchar_t, text_length);
for (i=0; i<text_length; i++) text_wchar[i] = text[i];
width = XwcTextEscapement (fontset, text_wchar, text_length);
g_free (text_wchar);
}
break;
default:
width = 0;
}
return width;
}
1997-11-24 22:37:52 +00:00
/* Problem: What if a character is a 16 bits character ?? */
gint
gdk_char_width (GdkFont *font,
gchar character)
{
GdkFontPrivate *private;
XCharStruct *chars;
gint width;
guint ch = character & 0xff; /* get rid of sign-extension */
XFontStruct *xfont;
XFontSet fontset;
g_return_val_if_fail (font != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
/* only 8 bits characters are considered here */
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) &&
(xfont->max_byte1 == 0) &&
(ch >= xfont->min_char_or_byte2) &&
(ch <= xfont->max_char_or_byte2))
{
chars = xfont->per_char;
if (chars)
width = chars[ch - xfont->min_char_or_byte2].width;
else
width = xfont->min_bounds.width;
}
else
{
width = XTextWidth (xfont, &character, 1);
}
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) private->xfont;
width = XmbTextEscapement (fontset, &character, 1) ;
break;
default:
width = 0;
}
return width;
}
Destroy widgets _after_ propagating unrealize signals through the widget Mon Dec 7 10:27:09 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtkwidget.c: Destroy widgets _after_ propagating unrealize signals through the widget heirarchy. This is unpleasant, as it causes more X traffic, but is necessary, because we have to clean up our Input Contexts before destroying the X windows. (from matsu-981109-0.patch) Mon Dec 7 10:18:18 1998 Owen Taylor <otaylor@redhat.com> Applied gtk-a-higuti-981202-0 : [ a-higuti@math.sci.hokudai.ac.jp (Akira Higuchi) ] * gdk/gdk.h gdk/gdk.c (gdk_mbstowcs): New function. Nearly equals to mbstowcs, but implemented by a combination of Xlib functions, so it works even with X_LOCALE. (gdk_wcstombs): New function. (g_mbtowc): Removed. No longer needed. * gdk/gdk.h gdk/gdkfont.c gdk/gdkdraw.c: Added _wc() variants to gdk_text_width(), gdk_char_width(), gdk_draw_text(), * gdk/gdki18n.h (mblen, mbtowc, wctomb, mbstowcs, wcstombs, wcslen, wcscpy, wcsncpy): Removed. No longer needed. (iswalnum): Removed. (gdk_iswalnum): New macro. (gdk_iswspace): New macro. * gdk/gdktype.h (GdkWChar): New typedef. * gtk/gtkentry.h, gtk/gtkentry.c There are many changes according to the change of the internal representation of text, from multibyte string to wide characters. * gtk/gtkprivate.h, gtk/gtkmain.c Removed the variable gtk_use_mb and related codes. * gtk/gtkspinbutton.c Some changes according to the change of type of entry->text. * gtk/gtktext.h, gtk/gtktext.c Changed the internal representation of text. We use GdkWchar if a fontset is supplied. If not, we use guchar to save memory.
1998-12-09 06:36:57 +00:00
gint
gdk_char_width_wc (GdkFont *font,
GdkWChar character)
{
GdkFontPrivate *private;
XCharStruct *chars;
gint width;
guint ch = character & 0xff; /* get rid of sign-extension */
XFontStruct *xfont;
XFontSet fontset;
g_return_val_if_fail (font != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
/* only 8 bits characters are considered here */
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) &&
(xfont->max_byte1 == 0) &&
(ch >= xfont->min_char_or_byte2) &&
(ch <= xfont->max_char_or_byte2))
{
chars = xfont->per_char;
if (chars)
width = chars[ch - xfont->min_char_or_byte2].width;
else
width = xfont->min_bounds.width;
}
else
{
char ch2 = character;
width = XTextWidth (xfont, &ch2, 1);
}
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) private->xfont;
{
wchar_t char_wc = character;
width = XwcTextEscapement (fontset, &char_wc, 1) ;
}
break;
default:
width = 0;
}
return width;
}
1997-11-24 22:37:52 +00:00
gint
gdk_string_measure (GdkFont *font,
const gchar *string)
{
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (string != NULL, -1);
return gdk_text_measure (font, string, strlen (string));
}
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
void
gdk_text_extents (GdkFont *font,
const gchar *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;
g_return_if_fail (font != NULL);
g_return_if_fail (text != NULL);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
XTextExtents (xfont, text, text_length,
&direction, &font_ascent, &font_descent,
&overall);
}
else
{
XTextExtents16 (xfont, (XChar2b *) text, text_length / 2,
&direction, &font_ascent, &font_descent,
&overall);
}
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;
XmbTextExtents (fontset, text, text_length, &ink, &logical);
if (lbearing)
*lbearing = ink.x;
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
if (rbearing)
*rbearing = ink.x + ink.width;
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
if (width)
*width = logical.width;
if (ascent)
*ascent = -ink.y;
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
if (descent)
*descent = ink.y + ink.height;
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
break;
}
}
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;
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;
}
}
Added gdk_text/string_extents() - too calculate all the metrics at once of Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
1998-08-12 16:49:13 +00:00
void
gdk_string_extents (GdkFont *font,
const gchar *string,
gint *lbearing,
gint *rbearing,
gint *width,
gint *ascent,
gint *descent)
{
g_return_if_fail (font != NULL);
g_return_if_fail (string != NULL);
gdk_text_extents (font, string, strlen (string),
lbearing, rbearing, width, ascent, descent);
}
1997-11-24 22:37:52 +00:00
gint
gdk_text_measure (GdkFont *font,
const gchar *text,
gint text_length)
{
GdkFontPrivate *private;
XCharStruct overall;
XFontStruct *xfont;
XFontSet fontset;
XRectangle ink, log;
int direction;
int font_ascent;
int font_descent;
gint width;
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (text != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
XTextExtents (xfont, text, text_length,
&direction, &font_ascent, &font_descent,
&overall);
}
else
{
XTextExtents16 (xfont, (XChar2b *) text, text_length / 2,
&direction, &font_ascent, &font_descent,
&overall);
}
width = overall.rbearing;
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) private->xfont;
XmbTextExtents (fontset, text, text_length, &ink, &log);
width = log.width;
break;
default:
width = 0;
}
return width;
}
gint
gdk_char_measure (GdkFont *font,
gchar character)
{
g_return_val_if_fail (font != NULL, -1);
return gdk_text_measure (font, &character, 1);
}
gint
gdk_string_height (GdkFont *font,
const gchar *string)
{
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (string != NULL, -1);
return gdk_text_height (font, string, strlen (string));
}
gint
gdk_text_height (GdkFont *font,
const gchar *text,
gint text_length)
{
GdkFontPrivate *private;
XCharStruct overall;
XFontStruct *xfont;
XFontSet fontset;
XRectangle ink, log;
int direction;
int font_ascent;
int font_descent;
gint height;
g_return_val_if_fail (font != NULL, -1);
g_return_val_if_fail (text != NULL, -1);
private = (GdkFontPrivate*) font;
switch (font->type)
{
case GDK_FONT_FONT:
xfont = (XFontStruct *) private->xfont;
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
XTextExtents (xfont, text, text_length,
&direction, &font_ascent, &font_descent,
&overall);
}
else
{
XTextExtents16 (xfont, (XChar2b *) text, text_length / 2,
&direction, &font_ascent, &font_descent,
&overall);
}
height = overall.ascent + overall.descent;
break;
case GDK_FONT_FONTSET:
fontset = (XFontSet) private->xfont;
XmbTextExtents (fontset, text, text_length, &ink, &log);
height = log.height;
break;
default:
height = 0;
}
return height;
}
gint
gdk_char_height (GdkFont *font,
gchar character)
{
g_return_val_if_fail (font != NULL, -1);
return gdk_text_height (font, &character, 1);
}