2006-10-03 21:59:30 +00:00
|
|
|
/* Pango
|
|
|
|
* Rendering routines to Clutter
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Matthew Allum <mallum@o-hand.com>
|
|
|
|
* Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
|
|
|
|
* Copyright (C) 2004 Red Hat Software
|
|
|
|
* Copyright (C) 2000 Tor Lillqvist
|
|
|
|
*
|
|
|
|
* This file 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 file 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.
|
|
|
|
*/
|
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "pangoclutter.h"
|
|
|
|
#include "pangoclutter-private.h"
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#include "../clutter-debug.h"
|
2006-10-03 21:59:30 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
#include "cogl/cogl.h"
|
2007-04-27 21:13:06 +00:00
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
/*
|
2006-10-03 21:59:30 +00:00
|
|
|
* Texture cache support code
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TC_WIDTH 256
|
|
|
|
#define TC_HEIGHT 256
|
|
|
|
#define TC_ROUND 4
|
|
|
|
|
|
|
|
typedef struct {
|
2008-04-25 13:37:36 +00:00
|
|
|
CoglHandle cogl_tex;
|
2006-10-03 21:59:30 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
} tc_area;
|
|
|
|
|
|
|
|
typedef struct tc_texture {
|
|
|
|
struct tc_texture *next;
|
2008-04-25 13:37:36 +00:00
|
|
|
CoglHandle cogl_tex;
|
2006-10-03 21:59:30 +00:00
|
|
|
int avail;
|
|
|
|
} tc_texture;
|
|
|
|
|
|
|
|
typedef struct tc_slice {
|
2008-04-25 13:37:36 +00:00
|
|
|
CoglHandle cogl_tex;
|
2006-10-03 21:59:30 +00:00
|
|
|
int avail, y;
|
|
|
|
} tc_slice;
|
|
|
|
|
2007-09-27 21:38:38 +00:00
|
|
|
static int tc_generation = 0;
|
2006-10-03 21:59:30 +00:00
|
|
|
static tc_slice slices[TC_HEIGHT / TC_ROUND];
|
|
|
|
static tc_texture *first_texture;
|
|
|
|
|
|
|
|
static void
|
|
|
|
tc_clear ()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = TC_HEIGHT / TC_ROUND; i--; )
|
2008-04-25 13:37:36 +00:00
|
|
|
slices [i].cogl_tex = COGL_INVALID_HANDLE;
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
while (first_texture)
|
|
|
|
{
|
|
|
|
tc_texture *next = first_texture->next;
|
2008-04-25 13:37:36 +00:00
|
|
|
cogl_texture_unref (first_texture->cogl_tex);
|
2006-10-03 21:59:30 +00:00
|
|
|
g_slice_free (tc_texture, first_texture);
|
|
|
|
first_texture = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
++tc_generation;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tc_get (tc_area *area, int width, int height)
|
|
|
|
{
|
2007-12-19 16:16:10 +00:00
|
|
|
int slice_height;
|
2007-10-16 19:14:52 +00:00
|
|
|
tc_slice *slice;
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
area->w = width;
|
|
|
|
area->h = height;
|
|
|
|
|
2007-10-16 19:14:52 +00:00
|
|
|
/* Provide for blank rows/columns of pixels between adjecant glyphs in the
|
|
|
|
* texture cache to avoid bilinear interpolation spillage at edges of glyphs.
|
|
|
|
*/
|
|
|
|
width += 1;
|
|
|
|
height += 1;
|
|
|
|
|
|
|
|
slice_height = MIN (height + TC_ROUND - 1, TC_HEIGHT) & ~(TC_ROUND - 1);
|
|
|
|
slice = slices + slice_height / TC_ROUND;
|
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
width = MIN (width, TC_WIDTH);
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
if (slice->cogl_tex == COGL_INVALID_HANDLE || slice->avail < width)
|
2006-10-03 21:59:30 +00:00
|
|
|
{
|
|
|
|
/* try to find a texture with enough space */
|
|
|
|
tc_texture *tex, *match = 0;
|
|
|
|
|
|
|
|
for (tex = first_texture; tex; tex = tex->next)
|
|
|
|
if (tex->avail >= slice_height && (!match || match->avail > tex->avail))
|
|
|
|
match = tex;
|
|
|
|
|
|
|
|
/* create a new texture if necessary */
|
|
|
|
if (!match)
|
|
|
|
{
|
2007-10-12 09:39:41 +00:00
|
|
|
CLUTTER_NOTE (PANGO, "creating new texture %i x %i",
|
|
|
|
TC_WIDTH, TC_HEIGHT);
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
match = g_slice_new (tc_texture);
|
|
|
|
match->next = first_texture;
|
|
|
|
first_texture = match;
|
|
|
|
match->avail = TC_HEIGHT;
|
|
|
|
|
2008-05-07 16:12:54 +00:00
|
|
|
match->cogl_tex = cogl_texture_new_with_size (TC_WIDTH, TC_HEIGHT, 0, TRUE,
|
|
|
|
COGL_PIXEL_FORMAT_A_8);
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2008-05-07 16:12:54 +00:00
|
|
|
/* We use mipmapping instead of just CGL_LINEAR here
|
|
|
|
* which allows rendering of glyphs to look nice even at
|
|
|
|
* scales far below 50%.
|
2008-04-25 13:37:36 +00:00
|
|
|
*/
|
2008-05-07 16:12:54 +00:00
|
|
|
cogl_texture_set_filters (match->cogl_tex,
|
|
|
|
CGL_LINEAR_MIPMAP_LINEAR,
|
|
|
|
CGL_LINEAR);
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match->avail -= slice_height;
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
slice->cogl_tex = match->cogl_tex;
|
|
|
|
slice->avail = TC_WIDTH;
|
|
|
|
slice->y = match->avail;
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
slice->avail -= width;
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
area->cogl_tex = slice->cogl_tex;
|
|
|
|
area->x = slice->avail;
|
|
|
|
area->y = slice->y;
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tc_put (tc_area *area)
|
|
|
|
{
|
|
|
|
/* our management is too primitive to support this operation yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
|
|
|
|
#define PANGO_CLUTTER_RENDERER_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
|
|
|
PANGO_TYPE_CLUTTER_RENDERER, \
|
|
|
|
PangoClutterRendererClass))
|
|
|
|
|
|
|
|
#define PANGO_IS_CLUTTER_RENDERER_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CLUTTER_RENDERER))
|
|
|
|
|
|
|
|
#define PANGO_CLUTTER_RENDERER_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
|
|
|
PANGO_TYPE_CLUTTER_RENDERER, \
|
|
|
|
PangoClutterRendererClass))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PangoRendererClass parent_class;
|
|
|
|
} PangoClutterRendererClass;
|
|
|
|
|
|
|
|
struct _PangoClutterRenderer
|
|
|
|
{
|
|
|
|
PangoRenderer parent_instance;
|
|
|
|
ClutterColor color;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (PangoClutterRenderer, \
|
|
|
|
pango_clutter_renderer, \
|
|
|
|
PANGO_TYPE_RENDERER)
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint8 *bitmap;
|
|
|
|
int width, stride, height, top, left;
|
|
|
|
} Glyph;
|
|
|
|
|
|
|
|
static void *
|
|
|
|
temp_buffer (size_t size)
|
|
|
|
{
|
|
|
|
static char *buffer;
|
|
|
|
static size_t alloc;
|
|
|
|
|
|
|
|
if (size > alloc)
|
|
|
|
{
|
|
|
|
size = (size + 4095) & ~4095;
|
2007-12-19 16:16:10 +00:00
|
|
|
g_free (buffer);
|
2006-10-03 21:59:30 +00:00
|
|
|
alloc = size;
|
2007-12-19 16:16:10 +00:00
|
|
|
buffer = g_malloc (size);
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_box (Glyph *glyph, int width, int height, int top)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int left = 0;
|
|
|
|
|
|
|
|
if (height > 2)
|
|
|
|
{
|
|
|
|
height -= 2;
|
|
|
|
top++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > 2)
|
|
|
|
{
|
|
|
|
width -= 2;
|
|
|
|
left++;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyph->stride = (width + 3) & ~3;
|
|
|
|
glyph->width = width;
|
|
|
|
glyph->height = height;
|
|
|
|
glyph->top = top;
|
|
|
|
glyph->left = left;
|
|
|
|
|
|
|
|
glyph->bitmap = temp_buffer (width * height);
|
|
|
|
memset (glyph->bitmap, 0, glyph->stride * height);
|
|
|
|
|
|
|
|
for (i = width; i--; )
|
2007-10-12 09:39:41 +00:00
|
|
|
glyph->bitmap [i]
|
2006-10-03 21:59:30 +00:00
|
|
|
= glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff;
|
|
|
|
|
|
|
|
for (i = height; i--; )
|
2007-10-12 09:39:41 +00:00
|
|
|
glyph->bitmap [i * glyph->stride]
|
2006-10-03 21:59:30 +00:00
|
|
|
= glyph->bitmap [i * glyph->stride + (width - 1)] = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
font_render_glyph (Glyph *glyph, PangoFont *font, int glyph_index)
|
|
|
|
{
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
if (glyph_index & PANGO_GLYPH_UNKNOWN_FLAG)
|
|
|
|
{
|
|
|
|
PangoFontMetrics *metrics;
|
|
|
|
|
|
|
|
if (!font)
|
|
|
|
goto generic_box;
|
|
|
|
|
|
|
|
metrics = pango_font_get_metrics (font, NULL);
|
|
|
|
if (!metrics)
|
|
|
|
goto generic_box;
|
|
|
|
|
|
|
|
render_box (glyph, PANGO_PIXELS (metrics->approximate_char_width),
|
|
|
|
PANGO_PIXELS (metrics->ascent + metrics->descent),
|
|
|
|
PANGO_PIXELS (metrics->ascent));
|
|
|
|
|
|
|
|
pango_font_metrics_unref (metrics);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
face = pango_clutter_font_get_face (font);
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
if (face)
|
|
|
|
{
|
|
|
|
PangoClutterFont *glfont = (PangoClutterFont *)font;
|
|
|
|
|
|
|
|
FT_Load_Glyph (face, glyph_index, glfont->load_flags);
|
|
|
|
FT_Render_Glyph (face->glyph, ft_render_mode_normal);
|
|
|
|
|
|
|
|
glyph->width = face->glyph->bitmap.width;
|
|
|
|
glyph->stride = face->glyph->bitmap.pitch;
|
|
|
|
glyph->height = face->glyph->bitmap.rows;
|
|
|
|
glyph->top = face->glyph->bitmap_top;
|
|
|
|
glyph->left = face->glyph->bitmap_left;
|
|
|
|
glyph->bitmap = face->glyph->bitmap.buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
generic_box:
|
2007-10-12 09:39:41 +00:00
|
|
|
render_box (glyph, PANGO_UNKNOWN_GLYPH_WIDTH,
|
2006-10-03 21:59:30 +00:00
|
|
|
PANGO_UNKNOWN_GLYPH_HEIGHT, PANGO_UNKNOWN_GLYPH_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
typedef struct glyph_info
|
2006-10-03 21:59:30 +00:00
|
|
|
{
|
|
|
|
tc_area tex;
|
|
|
|
int left, top;
|
|
|
|
int generation;
|
2007-10-12 09:39:41 +00:00
|
|
|
}
|
2006-10-03 21:59:30 +00:00
|
|
|
glyph_info;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_glyph_info (glyph_info *g)
|
|
|
|
{
|
|
|
|
tc_put (&g->tex);
|
|
|
|
g_slice_free (glyph_info, g);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-12 09:39:41 +00:00
|
|
|
draw_glyph (PangoRenderer *renderer_,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyph glyph,
|
2007-12-05 21:41:43 +00:00
|
|
|
double xd,
|
|
|
|
double yd)
|
2006-10-03 21:59:30 +00:00
|
|
|
{
|
|
|
|
glyph_info *g;
|
2007-12-05 21:41:43 +00:00
|
|
|
gint x = (gint)xd, y = (gint)yd;
|
2008-04-25 13:37:36 +00:00
|
|
|
ClutterFixed fx, fy;
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
|
|
|
|
{
|
|
|
|
glyph = pango_clutter_get_unknown_glyph (font);
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
if (glyph == PANGO_GLYPH_EMPTY)
|
|
|
|
glyph = PANGO_GLYPH_UNKNOWN_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
g = _pango_clutter_font_get_cache_glyph_data (font, glyph);
|
|
|
|
|
|
|
|
if (!g || g->generation != tc_generation)
|
|
|
|
{
|
|
|
|
Glyph bm;
|
|
|
|
font_render_glyph (&bm, font, glyph);
|
|
|
|
|
2008-02-06 14:39:04 +00:00
|
|
|
if (bm.width < 1 || bm.height < 1 || bm.bitmap == NULL)
|
|
|
|
{
|
2008-02-15 20:22:08 +00:00
|
|
|
/* Safety on */
|
|
|
|
if (g)
|
|
|
|
{
|
|
|
|
x += g->left;
|
|
|
|
y -= g->top;
|
|
|
|
}
|
2008-02-06 14:39:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:42:22 +00:00
|
|
|
if (bm.height > TC_HEIGHT)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Glyph too large for cache, increase TC_HEIGHT",
|
|
|
|
G_STRLOC);
|
|
|
|
}
|
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
if (g)
|
|
|
|
g->generation = tc_generation;
|
|
|
|
else
|
|
|
|
{
|
2008-03-04 11:16:05 +00:00
|
|
|
g = g_slice_new0 (glyph_info);
|
2006-10-03 21:59:30 +00:00
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
_pango_clutter_font_set_glyph_cache_destroy
|
2006-10-03 21:59:30 +00:00
|
|
|
(font, (GDestroyNotify)free_glyph_info);
|
|
|
|
_pango_clutter_font_set_cache_glyph_data (font, glyph, g);
|
|
|
|
}
|
|
|
|
|
|
|
|
tc_get (&g->tex, bm.width, bm.height);
|
|
|
|
|
|
|
|
g->left = bm.left;
|
|
|
|
g->top = bm.top;
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
CLUTTER_NOTE (PANGO, "cache fail; subimage2d %i", glyph);
|
2006-10-03 21:59:30 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
cogl_texture_set_region (g->tex.cogl_tex,
|
|
|
|
0, 0,
|
|
|
|
g->tex.x, g->tex.y,
|
|
|
|
bm.width, bm.height,
|
|
|
|
bm.width, bm.height,
|
|
|
|
COGL_PIXEL_FORMAT_A_8,
|
|
|
|
bm.stride,
|
|
|
|
bm.bitmap);
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
2008-04-25 13:37:36 +00:00
|
|
|
else
|
|
|
|
CLUTTER_NOTE (PANGO, "cache success %i\n", glyph);
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
x += g->left;
|
|
|
|
y -= g->top;
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
fx = CLUTTER_INT_TO_FIXED (g->tex.x) / TC_WIDTH;
|
|
|
|
fy = CLUTTER_INT_TO_FIXED (g->tex.y) / TC_HEIGHT;
|
|
|
|
|
|
|
|
cogl_texture_rectangle (g->tex.cogl_tex,
|
|
|
|
CLUTTER_INT_TO_FIXED (x),
|
|
|
|
CLUTTER_INT_TO_FIXED (y),
|
|
|
|
CLUTTER_INT_TO_FIXED (x + g->tex.w),
|
|
|
|
CLUTTER_INT_TO_FIXED (y + g->tex.h),
|
|
|
|
fx, fy,
|
|
|
|
CLUTTER_INT_TO_FIXED (g->tex.w) / TC_WIDTH + fx,
|
|
|
|
CLUTTER_INT_TO_FIXED (g->tex.h) / TC_WIDTH + fy);
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
void
|
2008-04-25 13:37:36 +00:00
|
|
|
pango_clutter_render_layout_subpixel (PangoLayout *layout,
|
2007-10-12 09:39:41 +00:00
|
|
|
int x,
|
2006-10-03 21:59:30 +00:00
|
|
|
int y,
|
|
|
|
ClutterColor *color,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
PangoFontMap *fontmap;
|
|
|
|
PangoRenderer *renderer;
|
|
|
|
|
|
|
|
context = pango_layout_get_context (layout);
|
|
|
|
fontmap = pango_context_get_font_map (context);
|
2007-10-12 09:39:41 +00:00
|
|
|
renderer = _pango_clutter_font_map_get_renderer
|
2006-10-03 21:59:30 +00:00
|
|
|
(PANGO_CLUTTER_FONT_MAP (fontmap));
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
|
2006-10-03 21:59:30 +00:00
|
|
|
color, sizeof(ClutterColor));
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
pango_renderer_draw_layout (renderer, layout, x, y);
|
|
|
|
}
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
void
|
2006-10-03 21:59:30 +00:00
|
|
|
pango_clutter_render_layout (PangoLayout *layout,
|
2007-10-12 09:39:41 +00:00
|
|
|
int x,
|
2006-10-03 21:59:30 +00:00
|
|
|
int y,
|
|
|
|
ClutterColor *color,
|
|
|
|
int flags)
|
|
|
|
{
|
2007-10-12 09:39:41 +00:00
|
|
|
pango_clutter_render_layout_subpixel (layout,
|
|
|
|
x * PANGO_SCALE,
|
|
|
|
y * PANGO_SCALE,
|
2006-10-03 21:59:30 +00:00
|
|
|
color,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
void
|
2006-10-03 21:59:30 +00:00
|
|
|
pango_clutter_render_layout_line (PangoLayoutLine *line,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
ClutterColor *color)
|
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
PangoFontMap *fontmap;
|
|
|
|
PangoRenderer *renderer;
|
|
|
|
|
|
|
|
context = pango_layout_get_context (line->layout);
|
|
|
|
fontmap = pango_context_get_font_map (context);
|
2007-10-12 09:39:41 +00:00
|
|
|
renderer = _pango_clutter_font_map_get_renderer
|
2006-10-03 21:59:30 +00:00
|
|
|
(PANGO_CLUTTER_FONT_MAP (fontmap));
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
|
2006-10-03 21:59:30 +00:00
|
|
|
color, sizeof(ClutterColor));
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
pango_renderer_draw_layout_line (renderer, line, x, y);
|
|
|
|
}
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
void
|
2006-10-03 21:59:30 +00:00
|
|
|
pango_clutter_render_clear_caches (void)
|
|
|
|
{
|
|
|
|
tc_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pango_clutter_renderer_init (PangoClutterRenderer *renderer)
|
|
|
|
{
|
|
|
|
memset (&renderer->color, 0xff, sizeof(ClutterColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prepare_run (PangoRenderer *renderer, PangoLayoutRun *run)
|
|
|
|
{
|
|
|
|
PangoClutterRenderer *glrenderer = (PangoClutterRenderer *)renderer;
|
|
|
|
PangoColor *fg = 0;
|
|
|
|
GSList *l;
|
2007-04-27 21:13:06 +00:00
|
|
|
ClutterColor col;
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
renderer->underline = PANGO_UNDERLINE_NONE;
|
|
|
|
renderer->strikethrough = FALSE;
|
|
|
|
|
|
|
|
for (l = run->item->analysis.extra_attrs; l; l = l->next)
|
|
|
|
{
|
|
|
|
PangoAttribute *attr = l->data;
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
switch (attr->klass->type)
|
|
|
|
{
|
|
|
|
case PANGO_ATTR_UNDERLINE:
|
|
|
|
renderer->underline = ((PangoAttrInt *)attr)->value;
|
|
|
|
break;
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
case PANGO_ATTR_STRIKETHROUGH:
|
|
|
|
renderer->strikethrough = ((PangoAttrInt *)attr)->value;
|
|
|
|
break;
|
2007-10-12 09:39:41 +00:00
|
|
|
|
2006-10-03 21:59:30 +00:00
|
|
|
case PANGO_ATTR_FOREGROUND:
|
|
|
|
fg = &((PangoAttrColor *)attr)->color;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fg)
|
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
col.red = (fg->red * 255) / 65535;
|
|
|
|
col.green = (fg->green * 255) / 65535;
|
|
|
|
col.blue = (fg->blue * 255) / 65535;
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
2007-10-12 09:39:41 +00:00
|
|
|
else
|
2006-10-03 21:59:30 +00:00
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
col.red = glrenderer->color.red;
|
|
|
|
col.green = glrenderer->color.green;
|
|
|
|
col.blue = glrenderer->color.blue;
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
col.alpha = glrenderer->color.alpha;
|
2006-10-03 21:59:30 +00:00
|
|
|
|
|
|
|
if (glrenderer->flags & FLAG_INVERSE)
|
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
col.red ^= 0xffU;
|
|
|
|
col.green ^= 0xffU;
|
|
|
|
col.blue ^= 0xffU;
|
2007-10-12 09:39:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_color(&col);
|
2006-10-03 21:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_begin (PangoRenderer *renderer_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_end (PangoRenderer *renderer_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pango_clutter_renderer_class_init (PangoClutterRendererClass *klass)
|
|
|
|
{
|
|
|
|
PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
renderer_class->draw_glyph = draw_glyph;
|
|
|
|
renderer_class->prepare_run = prepare_run;
|
|
|
|
renderer_class->begin = draw_begin;
|
|
|
|
renderer_class->end = draw_end;
|
|
|
|
}
|
|
|
|
|