Commit 26307a1d authored by Nalin Dahyabhai's avatar Nalin Dahyabhai

add specific checks for PangoX and glX. add drawing method using freetype

* configure.in: add specific checks for PangoX and glX.
* src/vteft2.c, src/vteft2.h: add drawing method using freetype and GdkRGB.
* src/vteglyph.c, src/vteglyph.h: add.
* src/vtepangox.c, src/vtepangox.h: add drawing method using PangoX.
* src/vtergb.c, src/vtergb.h: add.
* src/vtegl.c, src/vtegl.h: add placeholder drawing method using freetype and
	glX.
* src/Makefile.am: add newly-added source files to libvte.la target.
* src/vtedraw.c, src/vtedraw.h: add get_visual and get_colormap methods so that
	drawing methods can override the default visual and colormap.  Rename
	get_text_base() to get_text_ascent(), which is more correct.  Remove
	scroll(), which would just wrap gdk_window_scroll().
* src/vte.c: fix logic for choosing alternate render methods when VTE_USE_XFT
	is "0".
* src/vteapp.c: add -- option to stop parsing options with getopt.
* src/vtefc.c: fix incorrect DPI read due to type mismatch (#109513).
parent f947682a
2003-04-09 nalin
* configure.in: add specific checks for PangoX and glX.
* src/vteft2.c, src/vteft2.h: add drawing method using freetype and
GdkRGB.
* src/vteglyph.c, src/vteglyph.h: add.
* src/vtepangox.c, src/vtepangox.h: add drawing method using PangoX.
* src/vtergb.c, src/vtergb.h: add.
* src/vtegl.c, src/vtegl.h: add placeholder drawing method using
freetype and glX.
* src/Makefile.am: add newly-added source files to libvte.la target.
* src/vtedraw.c, src/vtedraw.h: add get_visual and get_colormap
methods so that drawing methods can override the default visual and
colormap. Rename get_text_base() to get_text_ascent(), which is more
correct. Remove scroll(), which would just wrap gdk_window_scroll().
* src/vte.c: fix logic for choosing alternate render methods when
VTE_USE_XFT is "0".
* src/vteapp.c: add -- option to stop parsing options with getopt.
* src/vtefc.c: fix incorrect DPI read due to type mismatch (#109513).
2003-03-31 Laurent Dhima <laurenti@alblinux.net>
* configure.in: Added "sq" to ALL_LINGUAS.
......
......@@ -17,23 +17,64 @@ AM_GLIB_GNU_GETTEXT
# X_PRE_LIBS and X_EXTRA_LIBS to add even more libraries, and add -lX11 to
# the list of libraries for grins.
AC_PATH_XTRA
HAVE_XFT=no
X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
PKG_CHECK_MODULES(GOBJECT,[glib-2.0 gobject-2.0])
X_LIBS=
if test $with_x = yes ; then
X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
fi
savelibs="$LIBS"
LIBS="$X_LIBS $LIBS"
PKG_CHECK_MODULES(GLIB,glib-2.0)
PKG_CHECK_MODULES(GOBJECT,[glib-2.0 gobject-2.0])
PKG_CHECK_MODULES(GTK,[glib-2.0 gobject-2.0 gtk+-2.0])
# Require GTK+ 2.0 and fontconfig.
wantedmodules="glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 fontconfig"
# Use Xft2 if Pango has Xft2 support.
if pkg-config --exists pangoxft '>=' 1.1.0 ; then
AC_DEFINE(HAVE_XFT2,1,[Whether we have Xft2])
wantedmodules="$wantedmodules xft"
else
AC_MSG_WARN([Xft2 not detected])
wantedmodules="glib-2.0 gobject-2.0 gtk+-2.0 fontconfig"
# Use Xft2 if Pango has Xft2 support and it isn't disabled.
AC_ARG_WITH(xft2,[ --with-xft2 enable drawing using Xft2],with_xft2=$withval,with_xft2=yes)
if test $with_xft2 = yes ; then
if pkg-config --exists pangoxft '>=' 1.1.0 ; then
AC_DEFINE(HAVE_XFT2,1,[Whether we have Xft2])
wantedmodules="$wantedmodules pangoxft >= 1.1.0 xft >= 2.0"
else
AC_MSG_WARN([Xft2 not detected])
fi
fi
# Use PangoX if we have it and it isn't disabled.
AC_ARG_WITH(pangox,[ --with-pangox enable drawing using PangoX],with_pangox=$withval,with_pangox=yes)
if test $with_pangox = yes ; then
if pkg-config --exists pangox ; then
AC_DEFINE(HAVE_PANGOX,1,[Whether we have PangoX])
wantedmodules="$wantedmodules pangox"
else
AC_MSG_WARN([PangoX not detected])
fi
fi
# Use glX if we have it and it isn't disabled.
AC_ARG_WITH(glX,[ --with-glX enable drawing using glX],with_glx=$withval,with_glx=yes)
if test $with_glx = yes ; then
have_gl=0
have_libgl=0
AC_CHECK_HEADERS(GL/glx.h)
if test $ac_cv_header_GL_glx_h = yes ; then
AC_CHECK_FUNC(glXQueryExtension,[have_gl=1],AC_CHECK_LIB(GL,glXQueryExtension,[have_gl=1;have_libgl=1]))
fi
if test $have_gl = 1 ; then
AC_DEFINE(HAVE_GL,1,[Whether we have GL and glX.])
fi
if test $have_libgl = 1 ; then
LIBS="-lGLU -lGL $LIBS"
fi
fi
# Search for the required modules.
PKG_CHECK_MODULES(VTE,[$wantedmodules])
NEEDEDPACKAGES="$wantedmodules"
AC_SUBST(NEEDEDPACKAGES)
# Require Freetype2. We use our local copy of the macro because packages of
# freetype's development files don't always include the proper macro.
......@@ -53,24 +94,28 @@ AC_CHECK_DECLS(FT_RENDER_MODE_MONO,,,[
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECLS(FT_LOAD_NO_HINTING,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECLS(FT_RENDER_MODE_LIGHT,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECLS(FT_RENDER_MODE_NORMAL,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
CFLAGS="$savecflags"
CPPFLAGS="$savecppflags"
......@@ -84,6 +129,7 @@ AC_EGREP_CPP(glibc,
#endif
],
AC_DEFINE(_GNU_SOURCE,1,[Use all features.]))
AC_DEFINE(G_DISABLE_DEPRECATED,1,[Disable deprecated GLib features.])
AC_DEFINE(GDK_DISABLE_DEPRECATED,1,[Disable deprecated GDK features.])
AC_DEFINE(GDK_PIXBUF_DISABLE_DEPRECATED,1,[Disable deprecated gdk-pixbuf features.])
......@@ -110,7 +156,7 @@ fi
if test x$have_socketpair = x1 ; then
AC_DEFINE(HAVE_SOCKETPAIR,1,[Define if you have the socketpair function.])
fi
AC_CHECK_FUNC(floor,,AC_CHECK_LIB(m,floor,LIBS=["$LIBS -lm"]))
# Look for ncurses or curses or termcap.
AC_CHECK_HEADER(ncurses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES,1,[Define if you have ncurses.h and libncurses])])])])
......
......@@ -60,8 +60,18 @@ libvte_la_SOURCES = \
vtedraw.h \
vtefc.c \
vtefc.h \
vteft2.c \
vteft2.h \
vtegl.c \
vtegl.h \
vteglyph.c \
vteglyph.h \
vtepango.c \
vtepango.h \
vtepangox.c \
vtepangox.h \
vtergb.c \
vtergb.h \
vteskel.c \
vteskel.h \
vtexft.c \
......@@ -98,7 +108,7 @@ else
REFLECT_ZVT =
endif
interpret_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ @VTE_CFLAGS@ -DINTERPRET_MAIN
interpret_CFLAGS = @CFLAGS@ @GTK_CFLAGS@ -DINTERPRET_MAIN
interpret_SOURCES = \
buffer.c \
buffer.h \
......@@ -119,7 +129,7 @@ interpret_SOURCES = \
interpret.c
interpret_LDADD = @LDFLAGS@ @GOBJECT_LIBS@
iso2022_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ @VTE_CFLAGS@ -DISO2022_MAIN
iso2022_CFLAGS = @CFLAGS@ @GTK_CFLAGS@ -DISO2022_MAIN
iso2022_SOURCES = \
debug.c \
debug.h \
......@@ -146,22 +156,22 @@ utf8echo_SOURCES = \
utf8echo.c
utf8echo_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
nativeecho_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DNATIVEECHO_MAIN
nativeecho_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -DNATIVEECHO_MAIN
nativeecho_SOURCES = \
nativeecho.c
nativeecho_LDADD = @LDFLAGS@ @LIBS@
ring_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DRING_MAIN
ring_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -DRING_MAIN
ring_SOURCES = \
debug.c \
debug.h \
ring.c \
ring.h
ring_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
ring_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
slowcat_SOURCES = \
slowcat.c
slowcat_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
slowcat_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
table_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DTABLE_MAIN
table_SOURCES = \
......@@ -189,23 +199,23 @@ trie_SOURCES = \
trie.h
trie_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
termcap_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DTERMCAP_MAIN
termcap_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -DTERMCAP_MAIN
termcap_SOURCES = \
debug.c \
debug.h \
termcap.c \
termcap.h
termcap_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
termcap_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
pty_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DPTY_MAIN
pty_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -DPTY_MAIN
pty_SOURCES = \
debug.c \
debug.h \
pty.c \
pty.h
pty_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
pty_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
reaper_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ @VTE_CFLAGS@ -DREAPER_MAIN
reaper_CFLAGS = @CFLAGS@ @GTK_CFLAGS@ -DREAPER_MAIN
reaper_SOURCES = \
debug.c \
debug.h \
......@@ -215,19 +225,19 @@ reaper_SOURCES = \
reaper.h
reaper_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
buffer_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@ -DBUFFER_MAIN
buffer_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -DBUFFER_MAIN
buffer_SOURCES = buffer.c
buffer_LDADD = @LDFLAGS@ @GOBJECT_LIBS@
buffer_LDADD = @LDFLAGS@ @GLIB_LIBS@
dumpkeys_SOURCES = dumpkeys.c
dumpkeys_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
dumpkeys_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
mev_SOURCES = mev.c
mev_LDADD = @LDFLAGS@ @LIBS@ @GOBJECT_LIBS@
mev_LDADD = @LDFLAGS@ @LIBS@ @GLIB_LIBS@
ssfe_SOURCES = ssfe.c
ssfe_LDADD = @LDFLAGS@ @OTHERLIBS@
xticker_CFLAGS = @CFLAGS@ @GOBJECT_CFLAGS@
xticker_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@
xticker_SOURCES = xticker.c
xticker_LDADD = @LIBS@ @GOBJECT_LIBS@
xticker_LDADD = @LIBS@ @GLIB_LIBS@
......@@ -10856,9 +10856,9 @@ vte_terminal_open_font(VteTerminal *terminal)
vte_terminal_apply_metrics(terminal,
_vte_draw_get_text_width(draw),
_vte_draw_get_text_height(draw),
_vte_draw_get_text_base(draw),
_vte_draw_get_text_ascent(draw),
_vte_draw_get_text_height(draw) -
_vte_draw_get_text_base(draw));
_vte_draw_get_text_ascent(draw));
break;
#ifdef HAVE_XFT2
case VteRenderXft2:
......@@ -11585,13 +11585,14 @@ vte_terminal_init(VteTerminal *terminal, gpointer *klass)
render_max = VteRenderXft1;
}
}
if ((render_max >= VteRenderXft1) &&
if ((render_max == VteRenderXft1) &&
(getenv("VTE_USE_XFT") != NULL)) {
if (atol(getenv("VTE_USE_XFT")) == 0) {
render_max = VteRenderPango;
}
}
if ((render_max >= VteRenderXft1) &&
if (((render_max == VteRenderXft2) ||
(render_max == VteRenderXft1)) &&
(getenv("GDK_USE_XFT") != NULL)) {
if (atol(getenv("GDK_USE_XFT")) == 0) {
render_max = VteRenderPango;
......@@ -11851,12 +11852,6 @@ static void
vte_terminal_unrealize(GtkWidget *widget)
{
VteTerminal *terminal;
Display *display;
GdkColormap *gcolormap;
Colormap colormap;
GdkVisual *gvisual;
Visual *visual;
int i;
#ifdef VTE_DEBUG
if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
......@@ -12277,8 +12272,8 @@ vte_terminal_realize(GtkWidget *widget)
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual(widget);
attributes.colormap = gtk_widget_get_colormap(widget);
attributes.visual = _vte_draw_get_visual(terminal->pvt->draw);
attributes.colormap = _vte_draw_get_colormap(terminal->pvt->draw);
attributes.event_mask = gtk_widget_get_events(widget) |
GDK_EXPOSURE_MASK |
GDK_VISIBILITY_NOTIFY_MASK |
......@@ -12291,8 +12286,8 @@ vte_terminal_realize(GtkWidget *widget)
attributes.cursor = terminal->pvt->mouse_default_cursor;
attributes_mask = GDK_WA_X |
GDK_WA_Y |
GDK_WA_VISUAL |
GDK_WA_COLORMAP |
(attributes.visual ? GDK_WA_VISUAL : 0) |
(attributes.colormap ? GDK_WA_COLORMAP : 0) |
GDK_WA_CURSOR;
widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
&attributes,
......
......@@ -434,8 +434,10 @@ main(int argc, char **argv)
}
argv2[i] = NULL;
g_assert(i < (g_list_length(args) + 2));
/* Parse some command-line options. */
while ((opt = getopt(argc, argv, "B:CDT2abc:df:ghn:st:w:")) != -1) {
while ((opt = getopt(argc, argv, "B:CDT2abc:df:ghn:st:w:-")) != -1) {
gboolean bail = FALSE;
switch (opt) {
case 'B':
background = optarg;
......@@ -485,12 +487,18 @@ main(int argc, char **argv)
case 'w':
working_directory = optarg;
break;
case '-':
bail = TRUE;
break;
case 'h':
default:
g_print(usage, argv[0]);
exit(1);
break;
}
if (bail) {
break;
}
}
gtk_init(&argc, &argv);
......
......@@ -27,17 +27,27 @@
#include <gtk/gtk.h>
#include "debug.h"
#include "vtedraw.h"
#include "vteft2.h"
#include "vtegl.h"
#include "vtepango.h"
#include "vtepangox.h"
#include "vteskel.h"
#include "vtexft.h"
struct _vte_draw_impl
*_vte_draw_impls[] = {
&_vte_draw_skel,
#ifdef HAVE_GL
/* &_vte_draw_gl, */
#endif
#ifdef HAVE_XFT2
&_vte_draw_xft,
#endif
&_vte_draw_ft2,
&_vte_draw_pango,
#ifdef HAVE_PANGOX
&_vte_draw_pango_x,
#endif
};
struct _vte_draw *
......@@ -98,6 +108,22 @@ _vte_draw_free(struct _vte_draw *draw)
g_free(draw);
}
GdkVisual *
_vte_draw_get_visual(struct _vte_draw *draw)
{
g_return_val_if_fail(draw->impl != NULL, NULL);
g_return_val_if_fail(draw->impl->get_visual != NULL, NULL);
return draw->impl->get_visual(draw);
}
GdkColormap *
_vte_draw_get_colormap(struct _vte_draw *draw)
{
g_return_val_if_fail(draw->impl != NULL, NULL);
g_return_val_if_fail(draw->impl->get_colormap != NULL, NULL);
return draw->impl->get_colormap(draw);
}
void
_vte_draw_start(struct _vte_draw *draw)
{
......@@ -169,11 +195,11 @@ _vte_draw_get_text_height(struct _vte_draw *draw)
}
int
_vte_draw_get_text_base(struct _vte_draw *draw)
_vte_draw_get_text_ascent(struct _vte_draw *draw)
{
g_return_val_if_fail(draw->impl != NULL, 1);
g_return_val_if_fail(draw->impl->get_text_base != NULL, 1);
return draw->impl->get_text_base(draw);
g_return_val_if_fail(draw->impl->get_text_ascent != NULL, 1);
return draw->impl->get_text_ascent(draw);
}
void
......@@ -184,8 +210,7 @@ _vte_draw_text(struct _vte_draw *draw,
g_return_if_fail(draw->started == TRUE);
g_return_if_fail(draw->impl != NULL);
g_return_if_fail(draw->impl->draw_text != NULL);
draw->impl->draw_text(draw, requests, n_requests,
color, alpha);
draw->impl->draw_text(draw, requests, n_requests, color, alpha);
}
void
......@@ -210,15 +235,6 @@ _vte_draw_draw_rectangle(struct _vte_draw *draw,
draw->impl->draw_rectangle(draw, x, y, width, height, color, alpha);
}
gboolean
_vte_draw_scroll(struct _vte_draw *draw, gint dx, gint dy)
{
g_return_val_if_fail(draw->started == TRUE, FALSE);
g_return_val_if_fail(draw->impl != NULL, FALSE);
g_return_val_if_fail(draw->impl->scroll != NULL, FALSE);
return draw->impl->scroll(draw, dx, dy);
}
void
_vte_draw_set_scroll(struct _vte_draw *draw, gint x, gint y)
{
......
......@@ -47,6 +47,8 @@ struct _vte_draw_impl {
gboolean (*check)(struct _vte_draw *draw, GtkWidget *widget);
void (*create)(struct _vte_draw *draw, GtkWidget *widget);
void (*destroy)(struct _vte_draw *draw);
GdkVisual* (*get_visual)(struct _vte_draw *draw);
GdkColormap* (*get_colormap)(struct _vte_draw *draw);
void (*start)(struct _vte_draw *draw);
void (*end)(struct _vte_draw *draw);
void (*set_background_color)(struct _vte_draw *, GdkColor *);
......@@ -55,7 +57,7 @@ struct _vte_draw_impl {
void (*set_text_font)(struct _vte_draw *, const PangoFontDescription *);
int (*get_text_width)(struct _vte_draw *);
int (*get_text_height)(struct _vte_draw *);
int (*get_text_base)(struct _vte_draw *);
int (*get_text_ascent)(struct _vte_draw *);
void (*draw_text)(struct _vte_draw *,
struct _vte_draw_text_request *, gsize,
GdkColor *, guchar);
......@@ -65,20 +67,21 @@ struct _vte_draw_impl {
void (*fill_rectangle)(struct _vte_draw *,
gint, gint, gint, gint,
GdkColor *, guchar);
gboolean (*scroll)(struct _vte_draw *, gint, gint);
void (*set_scroll)(struct _vte_draw *, gint, gint);
};
struct _vte_draw {
GtkWidget *widget;
gboolean started;
gint width, height, base;
gint width, height, ascent;
struct _vte_draw_impl *impl;
gpointer impl_data;
};
struct _vte_draw *_vte_draw_new(GtkWidget *widget);
void _vte_draw_free(struct _vte_draw *draw);
GdkVisual *_vte_draw_get_visual(struct _vte_draw *draw);
GdkColormap *_vte_draw_get_colormap(struct _vte_draw *draw);
void _vte_draw_start(struct _vte_draw *draw);
void _vte_draw_end(struct _vte_draw *draw);
......@@ -91,7 +94,7 @@ void _vte_draw_set_text_font(struct _vte_draw *draw,
const PangoFontDescription *fontdesc);
int _vte_draw_get_text_width(struct _vte_draw *draw);
int _vte_draw_get_text_height(struct _vte_draw *draw);
int _vte_draw_get_text_base(struct _vte_draw *draw);
int _vte_draw_get_text_ascent(struct _vte_draw *draw);
void _vte_draw_text(struct _vte_draw *draw,
struct _vte_draw_text_request *requests, gsize n_requests,
GdkColor *color, guchar alpha);
......@@ -102,7 +105,6 @@ void _vte_draw_fill_rectangle(struct _vte_draw *draw,
void _vte_draw_draw_rectangle(struct _vte_draw *draw,
gint x, gint y, gint width, gint height,
GdkColor *color, guchar alpha);
gboolean _vte_draw_scroll(struct _vte_draw *draw, gint dx, gint dy);
void _vte_draw_set_scroll(struct _vte_draw *draw, gint x, gint y);
G_END_DECLS
......
......@@ -17,6 +17,7 @@
*/
#include "../config.h"
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <pango/pango.h>
......@@ -82,8 +83,8 @@ _vte_fc_transcribe_from_pango_font_description(FcPattern *pattern,
/* Set the font size for the pattern, or use a sensible default. */
if (pango_mask & PANGO_FONT_MASK_SIZE) {
size = (double) pango_font_description_get_size(font_desc);
size /= (double) PANGO_SCALE;
size = pango_font_description_get_size(font_desc);
size /= PANGO_SCALE;
}
FcPatternAddDouble(pattern, FC_SIZE, size);
......@@ -114,14 +115,16 @@ static void
_vte_fc_defaults_from_gtk(FcPattern *pattern)
{
GtkSettings *settings;
GdkScreen *screen;
GObjectClass *klass;
int i, antialias = -1, hinting = -1;
double d, dpi = -1;
int i, antialias = -1, hinting = -1, dpi = -1;
double d;
char *rgba = NULL, *hintstyle = NULL;
FcResult result;
/* Add any defaults configured for GTK+. */
settings = gtk_settings_get_for_screen(gdk_screen_get_default());
screen = gdk_screen_get_default();
settings = gtk_settings_get_for_screen(screen);
if (settings == NULL) {
return;
}
......
/*
* Copyright (C) 2003 Red Hat, Inc.
*
* This 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 program 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
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "../config.h"
#include <sys/param.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <fontconfig/fontconfig.h>
#include "debug.h"
#include "vtedraw.h"
#include "vtefc.h"
#include "vteglyph.h"
#include "vtergb.h"
#define FONT_INDEX_FUDGE 10
#define CHAR_WIDTH_FUDGE 10
struct _vte_ft2_data
{
struct _vte_glyph_cache *cache;
struct _vte_rgb_buffer *rgb;
GdkColor color;
GdkPixbuf *pixbuf;
gint scrollx, scrolly;
gint left, right, top, bottom;
};
static gboolean
_vte_ft2_check(struct _vte_draw *draw, GtkWidget *widget)
{
/* We can draw onto any widget. */
return TRUE;
}
static void
_vte_ft2_create(struct _vte_draw *draw, GtkWidget *widget)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) g_malloc0(sizeof(struct _vte_ft2_data));
draw->impl_data = data;
data->rgb = NULL;
memset(&data->color, 0, sizeof(data->color));
data->pixbuf = NULL;
data->scrollx = data->scrolly = 0;
}
static void
_vte_ft2_destroy(struct _vte_draw *draw)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) draw->impl_data;
if (data->cache != NULL) {
_vte_glyph_cache_free(data->cache);
data->cache = NULL;
}
if (data->rgb != NULL) {
_vte_rgb_buffer_free(data->rgb);
}
memset(&data->color, 0, sizeof(data->color));
if (GDK_IS_PIXBUF(data->pixbuf)) {
g_object_unref(G_OBJECT(data->pixbuf));
data->pixbuf = NULL;
}
data->scrollx = data->scrolly = 0;
g_free(data);
}
static GdkVisual *
_vte_ft2_get_visual(struct _vte_draw *draw)
{
return gtk_widget_get_visual(draw->widget);
}
static GdkColormap *
_vte_ft2_get_colormap(struct _vte_draw *draw)
{
return gtk_widget_get_colormap(draw->widget);
}
static void
_vte_ft2_start(struct _vte_draw *draw)
{
struct _vte_ft2_data *data;
guint width, height;
data = (struct _vte_ft2_data*) draw->impl_data;
gdk_window_get_geometry(draw->widget->window,
NULL, NULL, &width, &height, NULL);
if (data->rgb == NULL) {
data->rgb = _vte_rgb_buffer_new(width, height);
} else {
_vte_rgb_buffer_resize(data->rgb, width, height);
}
data->left = data->right = data->top = data->bottom = -1;
}
static void
_vte_ft2_end(struct _vte_draw *draw)
{
struct _vte_ft2_data *data;
guint width, height;
GtkWidget *widget;
GtkStateType state;
data = (struct _vte_ft2_data*) draw->impl_data;
widget = draw->widget;
gdk_window_get_geometry(widget->window,
NULL, NULL, &width, &height, NULL);
gtk_widget_ensure_style(widget);
state = GTK_WIDGET_STATE(widget);
if ((data->left == -1) &&
(data->right == -1) &&
(data->top == -1) &&
(data->bottom == -1)) {
_vte_rgb_draw_on_drawable(widget->window,
widget->style->fg_gc[state],
0, 0,
width, height,
data->rgb,
0, 0);
} else {
_vte_rgb_draw_on_drawable(widget->window,
widget->style->fg_gc[state],
data->left, data->top,
data->right - data->left + 1,
data->bottom - data->top + 1,
data->rgb,
data->left, data->top);
}
}
static void
_vte_ft2_set_background_color(struct _vte_draw *draw, GdkColor *color)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) draw->impl_data;
data->color = *color;
}
static void
_vte_ft2_set_background_pixbuf(struct _vte_draw *draw, GdkPixbuf *pixbuf)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) draw->impl_data;
if (GDK_IS_PIXBUF(data->pixbuf)) {
g_object_unref(G_OBJECT(data->pixbuf));
}
data->pixbuf = pixbuf;
if (GDK_IS_PIXBUF(data->pixbuf)) {
g_object_ref(G_OBJECT(data->pixbuf));
}
}
static void
update_bbox(struct _vte_ft2_data *data, gint x, gint y, gint width, gint height)
{
data->left = (data->left == -1) ?
x : MIN(data->left, x);
data->right = (data->right == -1) ?
x + width - 1 : MAX(data->right, x + width - 1);
data->top = (data->top == -1) ?
y : MIN(data->top, y);
data->bottom = (data->bottom == -1) ?
y + height - 1 : MAX(data->bottom, y + height - 1);
}
static void
_vte_ft2_clear(struct _vte_draw *draw,
gint x, gint y, gint width, gint height)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) draw->impl_data;
if (GDK_IS_PIXBUF(data->pixbuf)) {
/* Tile a pixbuf in. */
_vte_rgb_draw_pixbuf(data->rgb, x, y, width, height,
data->pixbuf,
data->scrollx + x, data->scrolly + y);
} else {
/* The simple case is a solid color. */
_vte_rgb_draw_color(data->rgb, x, y, width, height,
&data->color);
}
update_bbox(data, x, y, width, height);
}
static void
_vte_ft2_set_text_font(struct _vte_draw *draw,
const PangoFontDescription *fontdesc)
{
struct _vte_ft2_data *data;
data = (struct _vte_ft2_data*) draw->impl_data;
if (data->