gtk2/gdk/x11/gdkpango-x11.c
Owen Taylor 3d737ee8ba Add GdkPangoRenderer, a subclass of PangoRenderer targeting GDK drawables.
Sat Nov 20 15:13:51 2004  Owen Taylor  <otaylor@redhat.com>

	* gdk/gdkpango.[ch]: Add GdkPangoRenderer, a subclass of
	PangoRenderer targeting GDK drawables. Use to implement the old
	gdk_draw_layout() and friends.

	* gdk/gdkdraw.c gdk/gdkdrawable.h gdk/gdkwindow.c gdk/gdkpixmap.c:
	Add gdk_draw_glyphs_transformed() gdk_draw_trapezoids() and
	the corresponding members of GdkDrawableClass. Add a fallback
	implementation of gdk_draw_trapezoids() in terms of pixbufs.

	* gdk/gdkwindowing.h gdk/x11/gdkg-x11.h: Add
	_gdk_windowing_gc_get_foreground() to enable the fallback
	trapezoid implementation.

	* gdk/x11/gdkdrawable-x11.c gdk/x11/gdkdisplay-x11.h: Implement
	draw_glyph_transformed,	draw_trapezoids.

	* gdk/x11/gdkdrawable-x11.[ch]: Add
	_gdk_x11_drawable_draw_xtrapezoids, _gdk_x11_drawable_draw_xft_glyphs
	for use of GdkX11Renderer.

	* gdk/x11/gdkgc-x11.c gdk/x11/gdkprivate-x11.h: Implement
	GDK_TILED, GDK_STIPPLED, GDK_OPAQUE_STIPPLED in the RENDER codepath.

	* gdk/gdkpango-x11.c: Add GdkX11Renderer... a subclass of
	PangoXftRenderer that does tiles/stipples and fallback rendering
	of trapezoids without the RENDER extension.

	* gdk/gdkpango-x11.c gdk/x11/gdkscreen-x11.[ch] _gdk_x11_renderer_get:
	Add _gdk_x11_renderer_get() to get a singleton GdkX11Renderer
	for the screen.

	* gdk/x11/gdkdrawable-x11.c (get_impl_drawable): Fix a None/NULL
	confusion.

	* gtk/gtklabel.[ch] gtk/gtk.symbols: Add gtk_label_set/get_angle(),
	and an ::angle property.

	* gtk/gtklabel.c: Remove #if 0'd dead code gtk_label_paint_word().

	* gtk/gtktextdisplay.c: Switch to using a GtkTextRenderer subclass
	of GdkPangoRenderer for drawing.

	* gtk/gtktextlayout.[ch] gtk/gtktextdisplay.c: Switch to using
	gtk_attr_shape_new_with_data() to store backreferences to
	embedded pixmaps and widgets. Leave line_display->shaped_objects
	around for backwords compatibility.

	* gdk/gdkpango.[ch] (gdk_pango_context_set_colormap): Describe
	as deprecated, remove implementation.

	* gtk/gtkwidget.c (gtk_widget_create_pango_context): Remove
	call to gdk_pango_context_set_colormap.

	* demos/gtk-demo/Makefile.am demos/gtk-demo/rotated_text.c: Add
	a demo showing drawing rotated text.

	* tests/testgtk.c: Add a rotated-label test, and also a rotated
	drawing test (differs from demos/gtk-demo/rotated_text by also
	using a tile)
2004-11-21 16:24:01 +00:00

173 lines
5.1 KiB
C

/* GDK - The GIMP Drawing Kit
* Copyright (C) 2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
#include <config.h>
#include <stdlib.h>
#include "gdkalias.h"
#include "gdkx.h"
#include "gdkdisplay-x11.h"
#include "gdkpango.h"
#include <pango/pangoxft.h>
#include <pango/pangoxft-render.h>
#include <math.h>
typedef struct _GdkX11Renderer GdkX11Renderer;
typedef struct _GdkX11RendererClass GdkX11RendererClass;
#define GDK_TYPE_X11_RENDERER (gdk_x11_renderer_get_type())
#define GDK_X11_RENDERER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_X11_RENDERER, GdkX11Renderer))
#define GDK_IS_X11_RENDERER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_X11_RENDERER))
#define GDK_X11_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_X11_RENDERER, GdkX11RendererClass))
#define GDK_IS_X11_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_X11_RENDERER))
#define GDK_X11_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_X11_RENDERER, GdkX11RendererClass))
#define MAX_RENDER_PART PANGO_RENDER_PART_STRIKETHROUGH
struct _GdkX11Renderer
{
PangoXftRenderer parent_instance;
XRenderPictFormat *mask_format;
GdkDrawable *drawable;
GdkGC *gc;
};
struct _GdkX11RendererClass
{
PangoXftRendererClass parent_class;
};
G_DEFINE_TYPE (GdkX11Renderer, gdk_x11_renderer, PANGO_TYPE_XFT_RENDERER)
static void
gdk_x11_renderer_finalize (GObject *object)
{
G_OBJECT_CLASS (gdk_x11_renderer_parent_class)->finalize (object);
}
static void
gdk_x11_renderer_composite_trapezoids (PangoXftRenderer *xftrenderer,
PangoRenderPart part,
XTrapezoid *trapezoids,
int n_trapezoids)
{
/* Because we only use this renderer for "draw_glyphs()" calls, we
* won't hit this code path much. However, it is hit for drawing
* the "unknown glyph" hex squares. We can safely ignore the part,
*/
GdkX11Renderer *x11_renderer = GDK_X11_RENDERER (xftrenderer);
_gdk_x11_drawable_draw_xtrapezoids (x11_renderer->drawable,
x11_renderer->gc,
trapezoids, n_trapezoids);
}
static void
gdk_x11_renderer_composite_glyphs (PangoXftRenderer *xftrenderer,
XftFont *xft_font,
XftGlyphSpec *glyphs,
gint n_glyphs)
{
GdkX11Renderer *x11_renderer = GDK_X11_RENDERER (xftrenderer);
_gdk_x11_drawable_draw_xft_glyphs (x11_renderer->drawable,
x11_renderer->gc,
xft_font, glyphs, n_glyphs);
}
static void
gdk_x11_renderer_init (GdkX11Renderer *renderer)
{
}
static void
gdk_x11_renderer_class_init (GdkX11RendererClass *klass)
{
PangoXftRendererClass *xftrenderer_class = PANGO_XFT_RENDERER_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
xftrenderer_class->composite_glyphs = gdk_x11_renderer_composite_glyphs;
xftrenderer_class->composite_trapezoids = gdk_x11_renderer_composite_trapezoids;
object_class->finalize = gdk_x11_renderer_finalize;
}
PangoRenderer *
_gdk_x11_renderer_get (GdkDrawable *drawable,
GdkGC *gc)
{
GdkScreen *screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen;
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
GdkX11Renderer *x11_renderer;
if (!screen_x11->renderer)
{
screen_x11->renderer = g_object_new (GDK_TYPE_X11_RENDERER,
"display", GDK_SCREEN_XDISPLAY (screen),
"screen", GDK_SCREEN_XNUMBER (screen),
NULL);
}
x11_renderer = GDK_X11_RENDERER (screen_x11->renderer);
x11_renderer->drawable = drawable;
x11_renderer->gc = gc;
return screen_x11->renderer;
}
/**
* gdk_pango_context_get_for_screen:
* @screen: the #GdkScreen for which the context is to be created.
*
* Creates a #PangoContext for @screen.
*
* The context must be freed when you're finished with it.
*
* When using GTK+, normally you should use gtk_widget_get_pango_context()
* instead of this function, to get the appropriate context for
* the widget you intend to render text onto.
*
* Return value: a new #PangoContext for @screen
*
* Since: 2.2
**/
PangoContext *
gdk_pango_context_get_for_screen (GdkScreen *screen)
{
PangoContext *context;
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
if (screen->closed)
return NULL;
context = pango_xft_get_context (GDK_SCREEN_XDISPLAY (screen),
GDK_SCREEN_X11 (screen)->screen_num);
g_object_set_data (G_OBJECT (context), "gdk-pango-screen", screen);
return context;
}