Patches for GTK 2. Puzzles already _built_ under GTK 2, but now it

builds better:
 - the GTK makefile now defines $(GTK_CONFIG) which you can
   override, so you can build for GTK 2 with no makefile-editing
   simply by running `make GTK_CONFIG="pkg_config gtk+-2.0"'
 - we use Pango to find appropriate fonts, which means the text in
   the puzzles actually (gasp!) adapts its size to the
   circumstances. Unfortunately, I've been unable to do this
   portably without depending on _either_ a Pango function that
   isn't present in older versions _or_ the underlying window system
   being X11; I'd appreciate someone doing better.

[originally from svn r5693]
This commit is contained in:
Simon Tatham
2005-04-27 19:39:20 +00:00
parent 8b31b4606c
commit 37a0c1af6a
2 changed files with 59 additions and 5 deletions

59
gtk.c
View File

@ -14,6 +14,11 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#if GTK_CHECK_VERSION(2,0,0) && !defined HAVE_SENSIBLE_ABSOLUTE_SIZE_FUNCTION
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#endif
#include "puzzles.h" #include "puzzles.h"
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -153,11 +158,59 @@ void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize,
fe->fonts[i].type = fonttype; fe->fonts[i].type = fonttype;
fe->fonts[i].size = fontsize; fe->fonts[i].size = fontsize;
#if GTK_CHECK_VERSION(2,0,0)
/* /*
* FIXME: Really I should make at least _some_ effort to * Use Pango to find the closest match to the requested
* pick the correct font. * font.
*/ */
fe->fonts[i].font = gdk_font_load("variable"); {
PangoFontDescription *fd;
fd = pango_font_description_new();
/* `Monospace' and `Sans' are meta-families guaranteed to exist */
pango_font_description_set_family(fd, fonttype == FONT_FIXED ?
"Monospace" : "Sans");
/*
* I found some online Pango documentation which
* described a function called
* pango_font_description_set_absolute_size(), which is
* _exactly_ what I want here. Unfortunately, none of
* my local Pango installations have it (presumably
* they're too old), so I'm going to have to hack round
* it by figuring out the point size myself. This
* limits me to X and probably also breaks in later
* Pango installations, so ideally I should add another
* CHECK_VERSION type ifdef and use set_absolute_size
* where available. All very annoying.
*/
#ifdef HAVE_SENSIBLE_ABSOLUTE_SIZE_FUNCTION
pango_font_description_set_absolute_size(fd, PANGO_SCALE*fontsize);
#else
{
Display *d = GDK_DISPLAY();
int s = DefaultScreen(d);
double resolution =
(PANGO_SCALE * 72.27 / 25.4) *
((double) DisplayWidthMM(d, s) / DisplayWidth (d, s));
pango_font_description_set_size(fd, resolution * fontsize);
}
#endif
fe->fonts[i].font = gdk_font_from_description(fd);
pango_font_description_free(fd);
}
if (!fe->fonts[i].font)
#endif
/*
* In GTK 1.2, I don't know of any plausible way to
* pick a suitable font, so I'm just going to be
* tedious.
*
* This is also fallback code called if the Pango
* approach fails to find an appropriate font.
*/
fe->fonts[i].font = gdk_font_load(fonttype == FONT_FIXED ?
"fixed" : "variable");
} }
/* /*

View File

@ -874,11 +874,12 @@ if (defined $makefiles{'gtk'}) {
"# You can define this path to point at your tools if you need to\n". "# You can define this path to point at your tools if you need to\n".
"# TOOLPATH = /opt/gcc/bin\n". "# TOOLPATH = /opt/gcc/bin\n".
"CC = \$(TOOLPATH)cc\n". "CC = \$(TOOLPATH)cc\n".
"GTK_CONFIG = gtk-config\n".
"\n". "\n".
&splitline("CFLAGS = -O2 -Wall -Werror -g " . &splitline("CFLAGS = -O2 -Wall -Werror -g " .
(join " ", map {"-I$dirpfx$_"} @srcdirs) . (join " ", map {"-I$dirpfx$_"} @srcdirs) .
" `gtk-config --cflags`")."\n". " `\$(GTK_CONFIG) --cflags`")."\n".
"XLDFLAGS = `gtk-config --libs`\n". "XLDFLAGS = `\$(GTK_CONFIG) --libs`\n".
"ULDFLAGS =#\n". "ULDFLAGS =#\n".
"INSTALL=install\n", "INSTALL=install\n",
"INSTALL_PROGRAM=\$(INSTALL)\n", "INSTALL_PROGRAM=\$(INSTALL)\n",