From a3c5d33f26891f02bfcfc78f024f3b87a31753d1 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sat, 13 Mar 1999 16:40:24 +0000 Subject: [PATCH] Configure now generates a gdkconfig.h file, in similar way as GLib's configure generates glibconfig.h. Currently it only defines what windowing API GDK uses, and on Unix (where configure scripts are used), it's always X11... Include gdkconfig.h in gdktypes.h. gdkconfig.h is installed in @libdir@/gtk+/include (like glibconfig.h is in @libdir@/glib/include). (This might be debatable?) Add that to gtk-config --cflags. Merge in Win32 changes to gtkfontsel.c --- ChangeLog | 23 +++- ChangeLog.pre-2-0 | 23 +++- ChangeLog.pre-2-10 | 23 +++- ChangeLog.pre-2-2 | 23 +++- ChangeLog.pre-2-4 | 23 +++- ChangeLog.pre-2-6 | 23 +++- ChangeLog.pre-2-8 | 23 +++- configure.in | 62 ++++++++++ gdk/Makefile.am | 12 ++ gdk/gdktypes.h | 22 ++++ gdk/win32/gdkconfig.h | 3 + gtk-config.in | 2 +- gtk/gtkfontsel.c | 272 ++++++++++++++++++++++++++++++++++++++---- 13 files changed, 485 insertions(+), 49 deletions(-) create mode 100644 gdk/win32/gdkconfig.h diff --git a/ChangeLog b/ChangeLog index 189e0810ec..362f67fd10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 189e0810ec..362f67fd10 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,12 +1,27 @@ 1999-03-13 Tor Lillqvist - * configure.in acconfig.h: Check for dirent.h and pwd.h. + * configure.in acconfig.h: Check for dirent.h and pwd.h. Generate + gdk/gdkconfig.h using similar mechanism as GLib's glibconfig.h. + * gtk-config.in: Add @libdir/gtk+/include (where gdkconfig.h is + installed) to CFLAGS. + + * gdk/Makefile.am: Add rules for gdkconfig.h. + + * gdk/gdktypes.h: Include gdkconfig.h. Define macros for windowing + APIs. + + * gdk/gdkfontsel.c: Don't include Xlib.h, it gets included via + gdkx.h anyway when compiling for X11. + (gtk_font_selection_create_xlfd): Use g_strdup_printf. (In + general): Merge in Win32 version. + * gtk/gtkfilesel.c: Use g_get_current_dir(). Merge in Win32 version: Use G_DIR_SEPARATOR, g_path_is_absolute, no tilde - expansion (based on HAVE_PWD_H), allow for drive letters. UNC - paths (\\server\share\...) not handled yet. Also, code from Craig - Setera's port to Win32 that uses cygwin.dll + expansion (if we don't have HAVE_PWD_H), allow for drive + letters. UNC paths (\\server\share\...) are not handled yet. Also, + included code from Craig Setera's port to Win32 (the one that uses + X11, and the cygwin dll), even if it probably will be abandoned. * gtk/gtkfilesel.c: Don't append a * to the pattern to complete if the user entered one herself. This way one can complete *.h and diff --git a/configure.in b/configure.in index 4af37b70c2..b7abc39934 100644 --- a/configure.in +++ b/configure.in @@ -512,6 +512,68 @@ AC_SUBST(GTK_DEBUG_FLAGS) AC_SUBST(GTK_XIM_FLAGS) AC_SUBST(GTK_LOCALE_FLAGS) +AC_OUTPUT_COMMANDS([ + +## Generate `gdk/gdkconfig.h' in two cases +## 1. `config.status' is run either explicitly, or via configure. +## Esp. not when it is run in `Makefile' to generate makefiles and +## config.h +## 2. CONFIG_OTHER is set explicitly +## +## Case 1 is difficult. We know that `automake' sets one of +## CONFIG_FILES or CONFIG_HEADERS to empty. This heuristic works +## only when AM_CONFIG_HEADER is set, however. + +if test -n "${CONFIG_FILES}" && test -n "${CONFIG_HEADERS}"; then + # Both CONFIG_FILES and CONFIG_HEADERS are non-empty ==> Case 1 + CONFIG_OTHER=${CONFIG_OTHER:-gdk/gdkconfig.h} +fi +case "$CONFIG_OTHER" in +*gdk/gdkconfig.h*) + echo creating gdk/gdkconfig.h + outfile=gdkconfig.h-tmp + cat > $outfile <<\_______EOF +/* gdkconfig.h + * + * This is a generated file. Please modify `configure.in' + */ + +#ifndef GDKCONFIG_H +#define GDKCONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +_______EOF + + cat >>$outfile <<_______EOF +$gdk_windowing +_______EOF + + cat >>$outfile <<_______EOF + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GDKCONFIG_H */ +_______EOF + + + if cmp -s $outfile gdk/gdkconfig.h; then + echo gdk/gdkconfig.h is unchanged + rm -f $outfile + else + mv $outfile gdk/gdkconfig.h + fi ;; +esac +],[ +# Currently we always use X11 on those systems where we run configure... +gdk_windowing=' +#define GDK_WINDOWING GDK_WINDOWING_X11' +]) + AC_OUTPUT([ gtk+.spec Makefile diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 3161727020..694753b3c3 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -2,6 +2,8 @@ gdkincludedir = $(includedir)/gdk +configincludedir = $(pkglibdir)/include + lib_LTLIBRARIES = libgdk.la INCLUDES = \ @@ -72,6 +74,16 @@ libgdk_la_LDFLAGS = \ @x_libs@ \ -lm +configinclude_DATA = \ + gdkconfig.h + +BUILT_SOURCES = stamp-gc-h #note: not gdkconfig.h +gdkconfig.h: stamp-gc-h + @: +stamp-gc-h: ../config.status + cd .. && CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=gdk/gdkconfig.h ./config.status + echo timestamp > stamp-gc-h + EXTRA_PROGRAMS = gxid bin_PROGRAMS = @xinput_progs@ diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index 16400bcee6..19406de578 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -33,6 +33,28 @@ #include +/* The system specific file gdkconfig.h contains such configuration + * settings that are needed not only when compiling GDK (or GTK) + * itself, but also occasionally when compiling programs that use GDK + * (or GTK). One such setting is what windowing API backend is in use. + */ +#include + +/* Windowing API alternatives. Note that these macros indicate just + * what windowing system is in use, not what operating system. It is + * possible to built GDK for X11 in a Win32 environment, for instance. + * + * gdkconfig.h defines GDK_WINDOWING as one of the following. In + * addition to the original X11 only the Win32 implementation exists + * yet. + */ +#define GDK_WINDOWING_X11 1 /* X11 */ +#define GDK_WINDOWING_WIN32 2 /* Win32 GDI */ +#define GDK_WINDOWING_BEOS 3 /* BeOS */ +#define GDK_WINDOWING_MACOS 4 /* MacOS */ +#define GDK_WINDOWING_GGI 5 /* Linux GGI */ + +/* some common magic values */ #define GDK_NONE 0L #define GDK_CURRENT_TIME 0L #define GDK_PARENT_RELATIVE 1L diff --git a/gdk/win32/gdkconfig.h b/gdk/win32/gdkconfig.h new file mode 100644 index 0000000000..e4221b6025 --- /dev/null +++ b/gdk/win32/gdkconfig.h @@ -0,0 +1,3 @@ +/* Handcrafted for Win32 */ + +#define GDK_WINDOWING GDK_WINDOWING_WIN32 diff --git a/gtk-config.in b/gtk-config.in index f056c3a423..7783db73a5 100644 --- a/gtk-config.in +++ b/gtk-config.in @@ -99,7 +99,7 @@ if test "$echo_cflags" = "yes"; then fi done fi - echo $includes @x_cflags@ $glib_cflags + echo -I@libdir@/gtk+/include $includes @x_cflags@ $glib_cflags fi if test "$echo_libs" = "yes"; then diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 060d56ed22..b505704afc 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -64,13 +64,12 @@ * Debugging: compile with -DFONTSEL_DEBUG for lots of debugging output. */ - #include #include #include #include -#include +#include "gdk/gdk.h" #include "gdk/gdkx.h" #include "gdk/gdkkeysyms.h" @@ -395,6 +394,13 @@ static gint gtk_font_selection_dialog_on_configure(GtkWidget *widget, GdkEventConfigure *event, GtkFontSelectionDialog *fsd); +#if GDK_WINDOWING == GDK_WINDOWING_WIN32 +static char *logfont_to_xlfd (const LOGFONT *lfp, + int size, + int res, + int avg_width); +#endif + static GtkWindowClass *font_selection_parent_class = NULL; static GtkNotebookClass *font_selection_dialog_parent_class = NULL; @@ -1803,8 +1809,10 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel) GtkStyle *style; gint text_height, new_height; gchar *text; +#if GDK_WINDOWING == GDK_WINDOWING_X11 XFontStruct *xfs; - +#endif + #ifdef FONTSEL_DEBUG g_message("In update_preview\n"); #endif @@ -1836,12 +1844,14 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel) gtk_entry_set_text(GTK_ENTRY(fontsel->preview_entry), PREVIEW_TEXT); gtk_entry_set_position(GTK_ENTRY(fontsel->preview_entry), 0); +#if GDK_WINDOWING == GDK_WINDOWING_X11 /* If this is a 2-byte font display a message to say it may not be displayed properly. */ xfs = GDK_FONT_XFONT(fontsel->font); if (xfs->min_byte1 != 0 || xfs->max_byte1 != 0) gtk_label_set_text(GTK_LABEL(fontsel->message_label), _("This is a 2-byte font and may not be displayed correctly.")); +#endif } @@ -1868,8 +1878,10 @@ gtk_font_selection_switch_page (GtkWidget *w, static void gtk_font_selection_show_font_info (GtkFontSelection *fontsel) { +#if GDK_WINDOWING == GDK_WINDOWING_X11 Atom font_atom, atom; Bool status; +#endif char *name; gchar *fontname; gchar field_buffer[XLFD_MAX_FIELD_LEN]; @@ -1898,7 +1910,7 @@ gtk_font_selection_show_font_info (GtkFontSelection *fontsel) gtk_clist_set_text(GTK_CLIST(fontsel->info_clist), i, 1, field ? field : ""); } - +#if GDK_WINDOWING == GDK_WINDOWING_X11 if (fontsel->font) { font_atom = XInternAtom(GDK_DISPLAY(), "FONT", True); @@ -1927,6 +1939,33 @@ gtk_font_selection_show_font_info (GtkFontSelection *fontsel) } } } +#elif GDK_WINDOWING == GDK_WINDOWING_WIN32 + if (fontsel->font) + { + LOGFONT logfont; + + if (GetObject (GDK_FONT_XFONT (fontsel->font), + sizeof (LOGFONT), &logfont) > 0) + { + name = logfont_to_xlfd (&logfont, logfont.lfHeight, -1, 0); + gtk_entry_set_text (GTK_ENTRY(fontsel->actual_font_name),name); + for (i = 0; i < GTK_XLFD_NUM_FIELDS; i++) + { + field = gtk_font_selection_get_xlfd_field (name, i, + field_buffer); + if (i == XLFD_SLANT) + field = gtk_font_selection_expand_slant_code(field); + else if (i == XLFD_SPACING) + field = gtk_font_selection_expand_spacing_code(field); + gtk_clist_set_text(GTK_CLIST(fontsel->info_clist), i, 2, + field ? field : ""); + } + shown_actual_fields = TRUE; + g_free (name); + } + } + +#endif if (!shown_actual_fields) { gtk_entry_set_text(GTK_ENTRY(fontsel->actual_font_name), ""); @@ -2602,6 +2641,185 @@ gtk_font_selection_filter_state (GtkFontSelection *fontsel, } +#if GDK_WINDOWING == GDK_WINDOWING_WIN32 + +static gint num_fonts; +static gint font_names_size; +static gchar **xfontnames; +static HDC hdc; + +static char * +logfont_to_xlfd (const LOGFONT *lfp, + int size, + int res, + int avg_width) +{ + const gchar *weight; + const gchar *registry, *encoding; + int point_size; + static int logpixelsy = 0; + gchar facename[LF_FACESIZE*3]; + gchar *p, *q; + + if (logpixelsy == 0) + { + HDC hdc = GetDC (NULL); + logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY); + ReleaseDC (NULL, hdc); + } + + if (lfp->lfWeight >= FW_HEAVY) + weight = "heavy"; + else if (lfp->lfWeight >= FW_EXTRABOLD) + weight = "extrabold"; + else if (lfp->lfWeight >= FW_BOLD) + weight = "bold"; + else if (lfp->lfWeight >= FW_DEMIBOLD) + weight = "demibold"; + else if (lfp->lfWeight >= FW_MEDIUM) + weight = "medium"; + else if (lfp->lfWeight >= FW_NORMAL) + weight = "normal"; + else if (lfp->lfWeight >= FW_LIGHT) + weight = "light"; + else if (lfp->lfWeight >= FW_EXTRALIGHT) + weight = "extralight"; + else if (lfp->lfWeight >= FW_THIN) + weight = "thin"; + else + weight = "regular"; + + if (lfp->lfCharSet == ANSI_CHARSET) + { + registry = "iso8859"; + encoding = "1"; + } + else + { + registry = "windows"; + if (lfp->lfCharSet == DEFAULT_CHARSET) + encoding = "default"; + else if (lfp->lfCharSet == SYMBOL_CHARSET) + encoding = "symbol"; + else if (lfp->lfCharSet == SHIFTJIS_CHARSET) + encoding = "shiftjis"; + else if (lfp->lfCharSet == GB2312_CHARSET) + encoding = "gb2312"; + else if (lfp->lfCharSet == HANGEUL_CHARSET) + encoding = "hangeul"; + else if (lfp->lfCharSet == CHINESEBIG5_CHARSET) + encoding = "chinesebig5"; + else if (lfp->lfCharSet == OEM_CHARSET) + encoding = "oem"; + else if (lfp->lfCharSet == JOHAB_CHARSET) + encoding = "johab"; + else if (lfp->lfCharSet == HEBREW_CHARSET) + encoding = "hebrew"; + else if (lfp->lfCharSet == ARABIC_CHARSET) + encoding = "arabic"; + else if (lfp->lfCharSet == GREEK_CHARSET) + encoding = "greek"; + else if (lfp->lfCharSet == TURKISH_CHARSET) + encoding = "turkish"; + else if (lfp->lfCharSet == THAI_CHARSET) + encoding = "thai"; + else if (lfp->lfCharSet == EASTEUROPE_CHARSET) + encoding = "easteurope"; + else if (lfp->lfCharSet == RUSSIAN_CHARSET) + encoding = "russian"; + else if (lfp->lfCharSet == MAC_CHARSET) + encoding = "mac"; + else if (lfp->lfCharSet == BALTIC_CHARSET) + encoding = "baltic"; + else + encoding = "unknown"; + } + + point_size = (int) (((double) size/logpixelsy) * 720.); + + if (res == -1) + res = logpixelsy; + + /* Replace illegal characters with hex escapes. */ + p = facename; + q = lfp->lfFaceName; + while (*q) + { + if (*q == '-' || *q == '*' || *q == '?' || *q == '%') + p += sprintf (p, "%%%.02x", *q); + else + *p++ = *q; + q++; + } + *p = '\0'; + + return g_strdup_printf + ("-%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-%d-%s-%s", + "unknown", + facename, + weight, + (lfp->lfItalic ? + ((lfp->lfPitchAndFamily & 0xF0) == FF_ROMAN + || (lfp->lfPitchAndFamily & 0xF0) == FF_SCRIPT ? + "i" : "o") : "r"), + "normal", + "", + size, + point_size, + res, + res, + ((lfp->lfPitchAndFamily & 0x03) == FIXED_PITCH ? "m" : "p"), + avg_width, + registry, encoding); +} + +int CALLBACK +InnerEnumFontFamExProc (const LOGFONT *lfp, + const TEXTMETRIC *metrics, + DWORD fontType, + LPARAM lParam) +{ + int size; + + if (fontType == TRUETYPE_FONTTYPE) + { + size = 0; + } + else + { + size = lfp->lfHeight; + } + + num_fonts++; + if (num_fonts == font_names_size) + { + font_names_size *= 2; + xfontnames = g_realloc (xfontnames, font_names_size * sizeof (gchar *)); + } + xfontnames[num_fonts-1] = + logfont_to_xlfd (lfp, size, 0, 0); + return 1; +} + +int CALLBACK +EnumFontFamExProc (const LOGFONT *lfp, + const TEXTMETRIC *metrics, + DWORD fontType, + LPARAM lParam) +{ + if (fontType == TRUETYPE_FONTTYPE) + { + LOGFONT lf = *lfp; + lf.lfPitchAndFamily = 0; + EnumFontFamiliesEx (hdc, &lf, InnerEnumFontFamExProc, 0, 0); + } + else + InnerEnumFontFamExProc (lfp, metrics, fontType, lParam); + return 1; +} + +#endif + /***************************************************************************** * These functions all deal with creating the main class arrays containing * the data about all available fonts. @@ -2609,11 +2827,15 @@ gtk_font_selection_filter_state (GtkFontSelection *fontsel, static void gtk_font_selection_get_fonts (void) { +#if GDK_WINDOWING == GDK_WINDOWING_X11 gchar **xfontnames; + gint num_fonts; +#elif GDK_WINDOWING == GDK_WINDOWING_WIN32 + LOGFONT logfont; +#endif GSList **fontnames; gchar *fontname; GSList * temp_list; - gint num_fonts; gint i, prop, style, size; gint npixel_sizes = 0, npoint_sizes = 0; FontInfo *font; @@ -2626,7 +2848,8 @@ gtk_font_selection_get_fonts (void) guint16 *pixel_sizes, *point_sizes, *tmp_sizes; fontsel_info = g_new (GtkFontSelInfo, 1); - + +#if GDK_WINDOWING == GDK_WINDOWING_X11 /* Get a maximum of MAX_FONTS fontnames from the X server. Use "-*" as the pattern rather than "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" since the latter may result in fonts being returned which don't actually exist. @@ -2636,6 +2859,18 @@ gtk_font_selection_get_fonts (void) if (num_fonts == MAX_FONTS) g_warning(_("MAX_FONTS exceeded. Some fonts may be missing.")); +#elif GDK_WINDOWING == GDK_WINDOWING_WIN32 + num_fonts = 0; + hdc = GetDC (NULL); + font_names_size = 100; + xfontnames = g_new (gchar *, font_names_size); + logfont.lfCharSet = DEFAULT_CHARSET; + logfont.lfFaceName[0] = '\0'; + logfont.lfPitchAndFamily = 0; + EnumFontFamiliesEx (hdc, &logfont, EnumFontFamExProc, 0, 0); + ReleaseDC (NULL, hdc); +#endif + /* The maximum size of all these tables is the number of font names returned. We realloc them later when we know exactly how many unique entries there are. */ @@ -2877,8 +3112,14 @@ gtk_font_selection_get_fonts (void) fontsel_info->point_sizes = g_realloc(fontsel_info->point_sizes, sizeof(guint16) * npoint_sizes); g_free(fontnames); + +#if GDK_WINDOWING == GDK_WINDOWING_X11 XFreeFontNames (xfontnames); - +#elif GDK_WINDOWING == GDK_WINDOWING_WIN32 + for (i = 0; i < num_fonts; i++) + g_free (xfontnames[i]); + g_free (xfontnames); +#endif /* Debugging Output */ /* This outputs all FontInfos. */ @@ -3373,7 +3614,6 @@ gtk_font_selection_create_xlfd (gint size, { gchar buffer[16]; gchar *pixel_size = "*", *point_size = "*", *fontname; - gint length; if (size <= 0) return NULL; @@ -3384,18 +3624,10 @@ gtk_font_selection_create_xlfd (gint size, else point_size = buffer; - /* Note: be careful here - don't overrun the allocated memory. */ - length = strlen(foundry) + strlen(family) + strlen(weight) + strlen(slant) - + strlen(set_width) + strlen(pixel_size) + strlen(point_size) - + strlen(spacing) + strlen(charset) - + 1 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 3 - + 1 /* for the terminating '\0'. */; - - fontname = g_new(gchar, length); - /* **NOTE**: If you change this string please change length above! */ - sprintf(fontname, "-%s-%s-%s-%s-%s-*-%s-%s-*-*-%s-*-%s", - foundry, family, weight, slant, set_width, pixel_size, - point_size, spacing, charset); + fontname = g_strdup_printf ("-%s-%s-%s-%s-%s-*-%s-%s-*-*-%s-*-%s", + foundry, family, weight, slant, + set_width, pixel_size, point_size, + spacing, charset); return fontname; }