mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
Bug #919 - Replacement pango renderer (Neil Roberts) * clutter/clutter-backend.h: * clutter/clutter-backend.c: (clutter_backend_set_font_options), (clutter_backend_get_font_options): Add the ability to set the cairo_font_options_t* for the backend at construction time, so that backend implementations can have their own options. * clutter/clutter-color.c: Include pango/pango-attributes.h for the pango_color_parse() function. * clutter/clutter-label.c: (clutter_label_ensure_layout), (clutter_label_init), (clutter_label_set_text), (clutter_label_set_font_name), (clutter_label_set_ellipsize), (clutter_label_set_use_markup): Ensure that the cache is always primed when the Label changes; this makes sure that the cache is rebuilt outside the paint run, which should make the painting perform better especially on embedded devices. * clutter/clutter-entry.c: (clutter_entry_ensure_layout), (clutter_entry_init), (clutter_entry_set_text), (clutter_entry_set_font_name): Ditto as above. * clutter/clutter-private.h: * clutter/clutter-main.[ch]: Create the font-map inside the main context; add two new functions: clutter_clear_glyph_cache() clutter_set_use_mipmapped_text() that control the glyphs cache. * clutter/pango/Makefile.am: * clutter/pango/pangoclutter-fontmap.c: * clutter/pango/pangoclutter-private.h: * clutter/pango/pangoclutter-render.c: * clutter/pango/pangoclutter.h: Rewrite the Pango renderer using a PangoCairo context and saving the glyphs inside a more efficient cache. * configure.ac: Depend on pangocairo instead of pangoft2.
This commit is contained in:
parent
a0747e8c2d
commit
f20cfeadb4
49
ChangeLog
49
ChangeLog
@ -1,3 +1,52 @@
|
||||
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
|
||||
|
||||
Bug #919 - Replacement pango renderer (Neil Roberts)
|
||||
|
||||
* clutter/clutter-backend.h:
|
||||
* clutter/clutter-backend.c:
|
||||
(clutter_backend_set_font_options),
|
||||
(clutter_backend_get_font_options): Add the ability to set
|
||||
the cairo_font_options_t* for the backend at construction
|
||||
time, so that backend implementations can have their own
|
||||
options.
|
||||
|
||||
* clutter/clutter-color.c: Include pango/pango-attributes.h
|
||||
for the pango_color_parse() function.
|
||||
|
||||
* clutter/clutter-label.c:
|
||||
(clutter_label_ensure_layout),
|
||||
(clutter_label_init), (clutter_label_set_text),
|
||||
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
|
||||
(clutter_label_set_use_markup): Ensure that the cache is
|
||||
always primed when the Label changes; this makes sure that
|
||||
the cache is rebuilt outside the paint run, which should
|
||||
make the painting perform better especially on embedded
|
||||
devices.
|
||||
|
||||
* clutter/clutter-entry.c:
|
||||
(clutter_entry_ensure_layout),
|
||||
(clutter_entry_init), (clutter_entry_set_text),
|
||||
(clutter_entry_set_font_name): Ditto as above.
|
||||
|
||||
* clutter/clutter-private.h:
|
||||
* clutter/clutter-main.[ch]: Create the font-map inside the
|
||||
main context; add two new functions:
|
||||
|
||||
clutter_clear_glyph_cache()
|
||||
clutter_set_use_mipmapped_text()
|
||||
|
||||
that control the glyphs cache.
|
||||
|
||||
* clutter/pango/Makefile.am:
|
||||
* clutter/pango/pangoclutter-fontmap.c:
|
||||
* clutter/pango/pangoclutter-private.h:
|
||||
* clutter/pango/pangoclutter-render.c:
|
||||
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
|
||||
using a PangoCairo context and saving the glyphs inside a
|
||||
more efficient cache.
|
||||
|
||||
* configure.ac: Depend on pangocairo instead of pangoft2.
|
||||
|
||||
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
|
||||
|
||||
Bug 882 - Allow child properties for containers implementing the
|
||||
|
@ -41,10 +41,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "clutter-fixed.h"
|
||||
#include "clutter-backend.h"
|
||||
#include "clutter-private.h"
|
||||
#include "clutter-debug.h"
|
||||
#include "clutter-fixed.h"
|
||||
#include "clutter-private.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
|
||||
|
||||
@ -58,6 +58,8 @@ struct _ClutterBackendPrivate
|
||||
guint double_click_distance;
|
||||
|
||||
ClutterFixed resolution;
|
||||
|
||||
cairo_font_options_t *font_options;
|
||||
};
|
||||
|
||||
static void
|
||||
@ -74,6 +76,8 @@ clutter_backend_dispose (GObject *gobject)
|
||||
clutter_context->events_queue = NULL;
|
||||
}
|
||||
|
||||
clutter_backend_set_font_options (CLUTTER_BACKEND (gobject), NULL);
|
||||
|
||||
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
||||
}
|
||||
|
||||
@ -382,6 +386,10 @@ clutter_backend_set_resolution (ClutterBackend *backend,
|
||||
fixed_dpi = CLUTTER_FLOAT_TO_FIXED (dpi);
|
||||
if (priv->resolution != fixed_dpi)
|
||||
priv->resolution = fixed_dpi;
|
||||
|
||||
if (CLUTTER_CONTEXT ()->font_map)
|
||||
pango_clutter_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map,
|
||||
CLUTTER_FIXED_TO_FLOAT (fixed_dpi));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,3 +411,49 @@ clutter_backend_get_resolution (ClutterBackend *backend)
|
||||
|
||||
return CLUTTER_FIXED_TO_FLOAT (backend->priv->resolution);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_backend_set_font_options (ClutterBackend *backend,
|
||||
cairo_font_options_t *options)
|
||||
{
|
||||
ClutterBackendPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
||||
|
||||
priv = backend->priv;
|
||||
|
||||
if (priv->font_options != options)
|
||||
{
|
||||
if (priv->font_options)
|
||||
cairo_font_options_destroy (priv->font_options);
|
||||
|
||||
if (options)
|
||||
priv->font_options = cairo_font_options_copy (options);
|
||||
else
|
||||
priv->font_options = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_font_options_t *
|
||||
clutter_backend_get_font_options (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
||||
|
||||
priv = backend->priv;
|
||||
|
||||
if (G_LIKELY (priv->font_options))
|
||||
return priv->font_options;
|
||||
|
||||
priv->font_options = cairo_font_options_create ();
|
||||
|
||||
cairo_font_options_set_hint_style (priv->font_options,
|
||||
CAIRO_HINT_STYLE_NONE);
|
||||
cairo_font_options_set_subpixel_order (priv->font_options,
|
||||
CAIRO_SUBPIXEL_ORDER_DEFAULT);
|
||||
cairo_font_options_set_antialias (priv->font_options,
|
||||
CAIRO_ANTIALIAS_DEFAULT);
|
||||
|
||||
return priv->font_options;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#ifndef __CLUTTER_BACKEND_H__
|
||||
#define __CLUTTER_BACKEND_H__
|
||||
|
||||
#include <cairo.h>
|
||||
#include <glib-object.h>
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-stage.h>
|
||||
@ -80,15 +81,18 @@ GType clutter_backend_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterBackend *clutter_get_default_backend (void);
|
||||
|
||||
void clutter_backend_set_resolution (ClutterBackend *backend,
|
||||
gdouble dpi);
|
||||
gdouble clutter_backend_get_resolution (ClutterBackend *backend);
|
||||
void clutter_backend_set_double_click_time (ClutterBackend *backend,
|
||||
guint msec);
|
||||
guint clutter_backend_get_double_click_time (ClutterBackend *backend);
|
||||
void clutter_backend_set_double_click_distance (ClutterBackend *backend,
|
||||
guint distance);
|
||||
guint clutter_backend_get_double_click_distance (ClutterBackend *backend);
|
||||
void clutter_backend_set_resolution (ClutterBackend *backend,
|
||||
gdouble dpi);
|
||||
gdouble clutter_backend_get_resolution (ClutterBackend *backend);
|
||||
void clutter_backend_set_double_click_time (ClutterBackend *backend,
|
||||
guint msec);
|
||||
guint clutter_backend_get_double_click_time (ClutterBackend *backend);
|
||||
void clutter_backend_set_double_click_distance (ClutterBackend *backend,
|
||||
guint distance);
|
||||
guint clutter_backend_get_double_click_distance (ClutterBackend *backend);
|
||||
void clutter_backend_set_font_options (ClutterBackend *backend,
|
||||
cairo_font_options_t *options);
|
||||
cairo_font_options_t *clutter_backend_get_font_options (ClutterBackend *backend);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <pango/pango-attributes.h>
|
||||
|
||||
#include "clutter-main.h"
|
||||
#include "clutter-color.h"
|
||||
#include "clutter-private.h"
|
||||
|
@ -56,7 +56,6 @@
|
||||
G_DEFINE_TYPE (ClutterEntry, clutter_entry, CLUTTER_TYPE_ACTOR);
|
||||
|
||||
/* Probably move into main */
|
||||
static PangoClutterFontMap *_font_map = NULL;
|
||||
static PangoContext *_context = NULL;
|
||||
|
||||
enum
|
||||
@ -289,6 +288,9 @@ clutter_entry_ensure_layout (ClutterEntry *entry, gint width)
|
||||
pango_layout_set_width (priv->layout, width * PANGO_SCALE);
|
||||
else
|
||||
pango_layout_set_width (priv->layout, -1);
|
||||
|
||||
/* Prime the cache for the layout */
|
||||
pango_clutter_ensure_glyph_cache_for_layout (priv->layout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,9 +860,17 @@ clutter_entry_init (ClutterEntry *self)
|
||||
|
||||
if (G_UNLIKELY (_context == NULL))
|
||||
{
|
||||
_font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
|
||||
pango_clutter_font_map_set_resolution (_font_map, resolution);
|
||||
_context = pango_clutter_font_map_create_context (_font_map);
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
PangoClutterFontMap *font_map = CLUTTER_CONTEXT ()->font_map;
|
||||
gdouble resolution;
|
||||
cairo_font_options_t *font_options;
|
||||
|
||||
_context = pango_clutter_font_map_create_context (font_map);
|
||||
|
||||
pango_cairo_context_set_resolution (_context, resolution);
|
||||
|
||||
font_options = clutter_backend_get_font_options (backend);
|
||||
pango_cairo_context_set_font_options (_context, font_options);
|
||||
}
|
||||
|
||||
priv->alignment = PANGO_ALIGN_LEFT;
|
||||
@ -1040,6 +1050,8 @@ clutter_entry_set_text (ClutterEntry *entry,
|
||||
|
||||
clutter_entry_clear_layout (entry);
|
||||
clutter_entry_clear_cursor_position (entry);
|
||||
/* Recreate the layout so the glyph cache will be primed */
|
||||
clutter_entry_ensure_layout (entry, -1);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
||||
@ -1123,6 +1135,8 @@ clutter_entry_set_font_name (ClutterEntry *entry,
|
||||
if (entry->priv->text && entry->priv->text[0] != '\0')
|
||||
{
|
||||
clutter_entry_clear_layout (entry);
|
||||
/* Recreate the layout so the glyph cache will be primed */
|
||||
clutter_entry_ensure_layout (entry, -1);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
||||
|
@ -48,7 +48,6 @@
|
||||
G_DEFINE_TYPE (ClutterLabel, clutter_label, CLUTTER_TYPE_ACTOR)
|
||||
|
||||
/* Probably move into main */
|
||||
static PangoClutterFontMap *_font_map = NULL;
|
||||
static PangoContext *_context = NULL;
|
||||
|
||||
enum
|
||||
@ -268,6 +267,9 @@ clutter_label_ensure_layout (ClutterLabel *label)
|
||||
else
|
||||
pango_layout_set_width (priv->layout, raw_width > 0 ? CLUTTER_UNITS_TO_PANGO_UNIT (raw_width)
|
||||
: -1);
|
||||
|
||||
/* Prime the glyph cache */
|
||||
pango_clutter_ensure_glyph_cache_for_layout (priv->layout);
|
||||
}
|
||||
|
||||
CLUTTER_NOTE (ACTOR, "Label width set to %d pixels", width);
|
||||
@ -637,17 +639,18 @@ clutter_label_init (ClutterLabel *self)
|
||||
|
||||
if (G_UNLIKELY (_context == NULL))
|
||||
{
|
||||
ClutterBackend *backend;
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
PangoClutterFontMap *font_map = CLUTTER_CONTEXT ()->font_map;
|
||||
gdouble resolution;
|
||||
cairo_font_options_t *font_options;
|
||||
|
||||
_context = pango_clutter_font_map_create_context (font_map);
|
||||
|
||||
backend = clutter_get_default_backend ();
|
||||
resolution = clutter_backend_get_resolution (backend);
|
||||
if (resolution < 0)
|
||||
resolution = 96.0;
|
||||
pango_cairo_context_set_resolution (_context, resolution);
|
||||
|
||||
_font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
|
||||
pango_clutter_font_map_set_resolution (_font_map, resolution);
|
||||
_context = pango_clutter_font_map_create_context (_font_map);
|
||||
font_options = clutter_backend_get_font_options (backend);
|
||||
pango_cairo_context_set_font_options (_context, font_options);
|
||||
}
|
||||
|
||||
priv->alignment = PANGO_ALIGN_LEFT;
|
||||
@ -769,6 +772,9 @@ clutter_label_set_text (ClutterLabel *label,
|
||||
priv->text = g_strdup (text);
|
||||
|
||||
clutter_label_clear_layout (label);
|
||||
/* Recreate the layout now so that the glyph cache will be primed
|
||||
outside of the paint run */
|
||||
clutter_label_ensure_layout (label);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR(label)))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
|
||||
@ -847,7 +853,10 @@ clutter_label_set_font_name (ClutterLabel *label,
|
||||
if (label->priv->text && label->priv->text[0] != '\0')
|
||||
{
|
||||
clutter_label_clear_layout (label);
|
||||
|
||||
/* Recreate the layout now so that the glyph cache will be
|
||||
primed outside of the paint run */
|
||||
clutter_label_ensure_layout (label);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (label))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (label));
|
||||
}
|
||||
@ -947,6 +956,9 @@ clutter_label_set_ellipsize (ClutterLabel *label,
|
||||
priv->ellipsize = mode;
|
||||
|
||||
clutter_label_clear_layout (label);
|
||||
/* Recreate the layout now so that the glyph cache will be
|
||||
primed outside of the paint run */
|
||||
clutter_label_ensure_layout (label);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR(label)))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
|
||||
@ -1214,6 +1226,9 @@ clutter_label_set_use_markup (ClutterLabel *label,
|
||||
|
||||
priv->use_markup = setting;
|
||||
clutter_label_clear_layout (label);
|
||||
/* Recreate the layout now so that the glyph cache will be
|
||||
primed outside of the paint run */
|
||||
clutter_label_ensure_layout (label);
|
||||
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (label)))
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (label));
|
||||
|
@ -367,6 +367,9 @@ clutter_context_free (ClutterMainContext *context)
|
||||
clutter_id_pool_free (context->id_pool);
|
||||
context->id_pool = NULL;
|
||||
|
||||
g_object_unref (context->font_map);
|
||||
context->font_map = NULL;
|
||||
|
||||
/* XXX: The cleaning up of the event queue should be moved here from
|
||||
the backend base class. */
|
||||
|
||||
@ -877,8 +880,9 @@ clutter_context_get_default (void)
|
||||
if (G_UNLIKELY(!ClutterCntx))
|
||||
{
|
||||
ClutterMainContext *ctx;
|
||||
gdouble resolution;
|
||||
|
||||
ctx = g_new0 (ClutterMainContext, 1);
|
||||
ClutterCntx = ctx = g_new0 (ClutterMainContext, 1);
|
||||
ctx->backend = g_object_new (_clutter_backend_impl_get_type (), NULL);
|
||||
|
||||
ctx->is_initialized = FALSE;
|
||||
@ -889,7 +893,12 @@ clutter_context_get_default (void)
|
||||
g_timer_start (ctx->timer);
|
||||
#endif
|
||||
|
||||
ClutterCntx = ctx;
|
||||
ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
|
||||
|
||||
resolution = clutter_backend_get_resolution (ctx->backend);
|
||||
pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
|
||||
|
||||
pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
|
||||
}
|
||||
|
||||
return ClutterCntx;
|
||||
@ -983,8 +992,6 @@ pre_parse_hook (GOptionContext *context,
|
||||
|
||||
clutter_context = clutter_context_get_default ();
|
||||
|
||||
clutter_context->font_map = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
|
||||
pango_ft2_font_map_set_resolution (clutter_context->font_map, 96.0, 96.0);
|
||||
clutter_context->id_pool = clutter_id_pool_new (256);
|
||||
|
||||
backend = clutter_context->backend;
|
||||
@ -2071,3 +2078,38 @@ clutter_set_motion_events_frequency (guint frequency)
|
||||
/* never allow the motion events to exceed the default frame rate */
|
||||
context->motion_frequency = CLAMP (frequency, 1, clutter_default_fps);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_clear_glyph_cache:
|
||||
*
|
||||
* Clears the internal cache of glyphs used by the Pango
|
||||
* renderer. This will free up some memory and GL texture
|
||||
* resources. The cache will be automatically refilled as more text is
|
||||
* drawn.
|
||||
*
|
||||
* Since: 0.8
|
||||
*/
|
||||
void
|
||||
clutter_clear_glyph_cache (void)
|
||||
{
|
||||
if (CLUTTER_CONTEXT ()->font_map)
|
||||
pango_clutter_font_map_clear_glyph_cache (CLUTTER_CONTEXT ()->font_map);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_set_use_mipmapped_text:
|
||||
* @value: %TRUE to enable mipmapping or %FALSE to disable.
|
||||
*
|
||||
* Sets whether subsequent text rendering operations will use
|
||||
* mipmapped textures or not. Using mipmapped textures will improve
|
||||
* the quality for scaled down text but will use more texture memory.
|
||||
*
|
||||
* Since: 0.8
|
||||
*/
|
||||
void
|
||||
clutter_set_use_mipmapped_text (gboolean value)
|
||||
{
|
||||
if (CLUTTER_CONTEXT ()->font_map)
|
||||
pango_clutter_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
|
||||
value);
|
||||
}
|
||||
|
@ -127,6 +127,9 @@ void clutter_grab_keyboard (ClutterActor *actor);
|
||||
void clutter_ungrab_keyboard (void);
|
||||
ClutterActor * clutter_get_keyboard_grab (void);
|
||||
|
||||
void clutter_clear_glyph_cache (void);
|
||||
void clutter_set_use_mipmapped_text (gboolean value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _HAVE_CLUTTER_MAIN_H */
|
||||
|
@ -38,8 +38,6 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <pango/pangoft2.h>
|
||||
|
||||
#include "clutter-backend.h"
|
||||
#include "clutter-event.h"
|
||||
#include "clutter-feature.h"
|
||||
@ -47,6 +45,7 @@
|
||||
#include "clutter-stage-manager.h"
|
||||
#include "clutter-stage-window.h"
|
||||
#include "clutter-stage.h"
|
||||
#include "pango/pangoclutter.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -77,7 +76,6 @@ struct _ClutterMainContext
|
||||
system backend */
|
||||
ClutterStageManager *stage_manager; /* stages */
|
||||
GQueue *events_queue; /* the main event queue */
|
||||
PangoFT2FontMap *font_map;
|
||||
|
||||
guint is_initialized : 1;
|
||||
GTimer *timer; /* Used for debugging scheduler */
|
||||
@ -110,6 +108,7 @@ or enter/leave events */
|
||||
gint fb_r_mask, fb_g_mask, fb_b_mask;
|
||||
gint fb_r_mask_used, fb_g_mask_used, fb_b_mask_used;
|
||||
|
||||
PangoClutterFontMap *font_map; /* Global font map */
|
||||
};
|
||||
|
||||
#define CLUTTER_CONTEXT() (clutter_context_get_default ())
|
||||
|
@ -1,16 +1,17 @@
|
||||
source_c = pangoclutter-font.c \
|
||||
pangoclutter-fontmap.c \
|
||||
pangoclutter-render.c
|
||||
source_c = pangoclutter-fontmap.c \
|
||||
pangoclutter-render.c \
|
||||
pangoclutter-glyph-cache.c
|
||||
|
||||
source_h = pangoclutter.h
|
||||
|
||||
source_h_priv = pangoclutter-private.h
|
||||
source_h_priv = pangoclutter-private.h \
|
||||
pangoclutter-glyph-cache.h
|
||||
|
||||
noinst_LTLIBRARIES = libpangoclutter.la
|
||||
|
||||
libpangoclutter_la_SOURCES = $(source_c) \
|
||||
$(source_h) \
|
||||
$(source_h_priv)
|
||||
$(source_h) \
|
||||
$(source_h_priv)
|
||||
|
||||
INCLUDES = \
|
||||
@GCC_FLAGS@ @CLUTTER_CFLAGS@ \
|
||||
|
@ -1,241 +1,124 @@
|
||||
/* Pango
|
||||
* Clutter fonts handling
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* Copyright (C) 2000 Red Hat Software
|
||||
* Copyright (C) 2000 Tor Lillqvist
|
||||
* Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2008 OpenedHand
|
||||
*
|
||||
* 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 file is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
* 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 Library General Public
|
||||
* 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 <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/* This is needed to get the Pango headers to export stuff needed to
|
||||
subclass */
|
||||
#ifndef PANGO_ENABLE_BACKEND
|
||||
#define PANGO_ENABLE_BACKEND 1
|
||||
#endif
|
||||
|
||||
#include <pango/pango-fontmap.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <pango/pango-renderer.h>
|
||||
|
||||
#include "pangoclutter.h"
|
||||
#include "pangoclutter-private.h"
|
||||
|
||||
|
||||
#include <pango/pangofc-font.h>
|
||||
#include <pango/pangofc-fontmap.h>
|
||||
|
||||
struct _PangoClutterFontMap
|
||||
{
|
||||
PangoFcFontMap parent_instance;
|
||||
|
||||
FT_Library library;
|
||||
|
||||
double dpi;
|
||||
|
||||
/* Function to call on prepared patterns to do final
|
||||
* config tweaking.
|
||||
*/
|
||||
PangoClutterSubstituteFunc substitute_func;
|
||||
gpointer substitute_data;
|
||||
GDestroyNotify substitute_destroy;
|
||||
|
||||
PangoRenderer *renderer;
|
||||
};
|
||||
|
||||
struct _PangoClutterFontMapClass
|
||||
{
|
||||
PangoFcFontMapClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PangoClutterFontMap, pango_clutter_font_map, PANGO_TYPE_FC_FONT_MAP)
|
||||
|
||||
static void
|
||||
pango_clutter_font_map_finalize (GObject *object)
|
||||
{
|
||||
PangoClutterFontMap *fontmap = PANGO_CLUTTER_FONT_MAP (object);
|
||||
|
||||
if (fontmap->renderer)
|
||||
g_object_unref (fontmap->renderer);
|
||||
|
||||
if (fontmap->substitute_destroy)
|
||||
fontmap->substitute_destroy (fontmap->substitute_data);
|
||||
|
||||
FT_Done_FreeType (fontmap->library);
|
||||
|
||||
G_OBJECT_CLASS (pango_clutter_font_map_parent_class)->finalize (object);
|
||||
}
|
||||
static GQuark pango_clutter_font_map_get_renderer_key (void) G_GNUC_CONST;
|
||||
|
||||
PangoFontMap *
|
||||
pango_clutter_font_map_new (void)
|
||||
{
|
||||
PangoClutterFontMap *fontmap;
|
||||
FT_Error error;
|
||||
|
||||
/* Make sure that the type system is initialized */
|
||||
g_type_init ();
|
||||
|
||||
fontmap = g_object_new (PANGO_TYPE_CLUTTER_FONT_MAP, NULL);
|
||||
|
||||
error = FT_Init_FreeType (&fontmap->library);
|
||||
if (error != FT_Err_Ok)
|
||||
g_critical ("pango_clutter_font_map_new: Could not initialize freetype");
|
||||
|
||||
return (PangoFontMap *)fontmap;
|
||||
return pango_cairo_font_map_new ();
|
||||
}
|
||||
|
||||
void
|
||||
pango_clutter_font_map_set_default_substitute (PangoClutterFontMap *fontmap,
|
||||
PangoClutterSubstituteFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
if (fontmap->substitute_destroy)
|
||||
fontmap->substitute_destroy (fontmap->substitute_data);
|
||||
|
||||
fontmap->substitute_func = func;
|
||||
fontmap->substitute_data = data;
|
||||
fontmap->substitute_destroy = notify;
|
||||
|
||||
pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
|
||||
}
|
||||
|
||||
/**
|
||||
* pango_clutter_font_map_substitute_changed:
|
||||
* @fontmap: a #PangoClutterFontmap
|
||||
*
|
||||
* Call this function any time the results of the
|
||||
* default substitution function set with
|
||||
* pango_clutter_font_map_set_default_substitute() change.
|
||||
* That is, if your subsitution function will return different
|
||||
* results for the same input pattern, you must call this function.
|
||||
*
|
||||
* Since: 1.2
|
||||
**/
|
||||
void
|
||||
pango_clutter_font_map_substitute_changed (PangoClutterFontMap *fontmap)
|
||||
{
|
||||
pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
|
||||
}
|
||||
|
||||
/**
|
||||
* pango_clutter_font_map_create_context:
|
||||
* @fontmap: a #PangoClutterFontmap
|
||||
*
|
||||
* Create a #PangoContext for the given fontmap.
|
||||
*
|
||||
* Return value: the newly created context; free with g_object_unref().
|
||||
*
|
||||
* Since: 1.2
|
||||
**/
|
||||
PangoContext *
|
||||
pango_clutter_font_map_create_context (PangoClutterFontMap *fontmap)
|
||||
pango_clutter_font_map_create_context (PangoClutterFontMap *fm)
|
||||
{
|
||||
g_return_val_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap), NULL);
|
||||
|
||||
return pango_fc_font_map_create_context (PANGO_FC_FONT_MAP (fontmap));
|
||||
g_return_val_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fm), NULL);
|
||||
|
||||
/* We can just directly use the pango context from the Cairo font
|
||||
map */
|
||||
return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
|
||||
}
|
||||
|
||||
FT_Library
|
||||
_pango_clutter_font_map_get_library (PangoFontMap *fontmap_)
|
||||
PangoRenderer *
|
||||
_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fm)
|
||||
{
|
||||
PangoClutterFontMap *fontmap = (PangoClutterFontMap *)fontmap_;
|
||||
|
||||
return fontmap->library;
|
||||
PangoRenderer *renderer;
|
||||
|
||||
/* We want to keep a cached pointer to the renderer from the font
|
||||
map instance but as we don't have a proper subclass we have to
|
||||
store it in the object data instead */
|
||||
|
||||
renderer = g_object_get_qdata (G_OBJECT (fm),
|
||||
pango_clutter_font_map_get_renderer_key ());
|
||||
|
||||
if (G_UNLIKELY (renderer == NULL))
|
||||
{
|
||||
renderer = g_object_new (PANGO_CLUTTER_TYPE_RENDERER, NULL);
|
||||
g_object_set_qdata_full (G_OBJECT (fm),
|
||||
pango_clutter_font_map_get_renderer_key (),
|
||||
renderer,
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void
|
||||
pango_clutter_font_map_set_resolution (PangoClutterFontMap *fontmap,
|
||||
double dpi)
|
||||
pango_clutter_font_map_set_resolution (PangoClutterFontMap *font_map,
|
||||
double dpi)
|
||||
{
|
||||
g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap));
|
||||
g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
|
||||
|
||||
fontmap->dpi = dpi;
|
||||
|
||||
pango_clutter_font_map_substitute_changed (fontmap);
|
||||
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
|
||||
}
|
||||
|
||||
/**
|
||||
* _pango_clutter_font_map_get_renderer:
|
||||
* @fontmap: a #PangoClutterFontmap
|
||||
*
|
||||
* Gets the singleton PangoClutterRenderer for this fontmap.
|
||||
*
|
||||
* Return value:
|
||||
**/
|
||||
PangoRenderer *
|
||||
_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fontmap)
|
||||
void
|
||||
pango_clutter_font_map_clear_glyph_cache (PangoClutterFontMap *fm)
|
||||
{
|
||||
if (!fontmap->renderer)
|
||||
fontmap->renderer = g_object_new (PANGO_TYPE_CLUTTER_RENDERER, NULL);
|
||||
PangoRenderer *renderer;
|
||||
|
||||
return fontmap->renderer;
|
||||
renderer = _pango_clutter_font_map_get_renderer (fm);
|
||||
|
||||
_pango_clutter_renderer_clear_glyph_cache (PANGO_CLUTTER_RENDERER (renderer));
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_font_map_default_substitute (PangoFcFontMap *fcfontmap,
|
||||
FcPattern *pattern)
|
||||
void
|
||||
pango_clutter_font_map_set_use_mipmapping (PangoClutterFontMap *fm,
|
||||
gboolean value)
|
||||
{
|
||||
PangoClutterFontMap *fontmap = PANGO_CLUTTER_FONT_MAP (fcfontmap);
|
||||
PangoClutterRenderer *renderer;
|
||||
|
||||
FcConfigSubstitute (NULL, pattern, FcMatchPattern);
|
||||
renderer = PANGO_CLUTTER_RENDERER (_pango_clutter_font_map_get_renderer (fm));
|
||||
|
||||
if (fontmap->substitute_func)
|
||||
fontmap->substitute_func (pattern, fontmap->substitute_data);
|
||||
|
||||
#if 0
|
||||
FcValue v;
|
||||
if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch)
|
||||
FcPatternAddDouble (pattern, FC_DPI, fontmap->dpi_y);
|
||||
#endif
|
||||
|
||||
/* Turn off hinting, since we most of the time are not using the glyphs
|
||||
* from our cache at their nativly rendered resolution
|
||||
*/
|
||||
FcPatternDel (pattern, FC_HINTING);
|
||||
FcPatternAddBool (pattern, FC_HINTING, FALSE);
|
||||
|
||||
FcDefaultSubstitute (pattern);
|
||||
_pango_clutter_renderer_set_use_mipmapping (renderer, value);
|
||||
}
|
||||
|
||||
static PangoFcFont *
|
||||
pango_clutter_font_map_new_font (PangoFcFontMap *fcfontmap,
|
||||
FcPattern *pattern)
|
||||
static GQuark
|
||||
pango_clutter_font_map_get_renderer_key (void)
|
||||
{
|
||||
return (PangoFcFont *)_pango_clutter_font_new (PANGO_CLUTTER_FONT_MAP (fcfontmap), pattern);
|
||||
}
|
||||
static GQuark renderer_key = 0;
|
||||
|
||||
static double
|
||||
pango_clutter_font_map_get_resolution (PangoFcFontMap *fcfontmap,
|
||||
PangoContext *context)
|
||||
{
|
||||
return ((PangoClutterFontMap *)fcfontmap)->dpi;
|
||||
}
|
||||
if (G_UNLIKELY (renderer_key == 0))
|
||||
renderer_key = g_quark_from_static_string ("PangoClutterFontMap");
|
||||
|
||||
static void
|
||||
pango_clutter_font_map_class_init (PangoClutterFontMapClass *class)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
||||
PangoFcFontMapClass *fcfontmap_class = PANGO_FC_FONT_MAP_CLASS (class);
|
||||
|
||||
gobject_class->finalize = pango_clutter_font_map_finalize;
|
||||
fcfontmap_class->default_substitute = pango_clutter_font_map_default_substitute;
|
||||
fcfontmap_class->new_font = pango_clutter_font_map_new_font;
|
||||
fcfontmap_class->get_resolution = pango_clutter_font_map_get_resolution;
|
||||
return renderer_key;
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_font_map_init (PangoClutterFontMap *fontmap)
|
||||
{
|
||||
fontmap->library = NULL;
|
||||
fontmap->dpi = 96.0;
|
||||
}
|
||||
|
||||
|
@ -1,147 +1,42 @@
|
||||
/* Pango
|
||||
* pangoclutter-private.h: private symbols for Clutter backend
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* Copyright (C) 2006 Matthew Allum <mallum@o-hand.com>
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2008 OpenedHand
|
||||
*
|
||||
* 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 file is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
* 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 Library General Public
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __PANGOCLUTTER_PRIVATE_H__
|
||||
#define __PANGOCLUTTER_PRIVATE_H__
|
||||
|
||||
#ifndef _HAVE_PANGO_CLUTTER_PRIVATE_H
|
||||
#define _HAVE_PANGO_CLUTTER_PRIVATE_H
|
||||
|
||||
#include "pangoclutter.h"
|
||||
#include <pango/pango-renderer.h>
|
||||
#include <glib-object.h>
|
||||
#include <pango/pangofc-decoder.h>
|
||||
|
||||
/* Defines duped - fun,fun.. */
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifndef PANGO_GLYPH_EMPTY
|
||||
#define PANGO_GLYPH_EMPTY ((PangoGlyph)0x0FFFFFFF)
|
||||
#endif
|
||||
#ifndef PANGO_GLYPH_UNKNOWN_FLAG
|
||||
#define PANGO_GLYPH_UNKNOWN_FLAG ((PangoGlyph)0x10000000)
|
||||
#endif
|
||||
#ifndef PANGO_UNKNOWN_GLYPH_WIDTH
|
||||
#define PANGO_UNKNOWN_GLYPH_WIDTH 10
|
||||
#endif
|
||||
#ifndef PANGO_UNKNOWN_GLYPH_HEIGHT
|
||||
#define PANGO_UNKNOWN_GLYPH_HEIGHT 14
|
||||
#endif
|
||||
PangoRenderer *_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fm);
|
||||
|
||||
#define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6))
|
||||
void _pango_clutter_renderer_clear_glyph_cache (PangoClutterRenderer *renderer);
|
||||
|
||||
/* We only use the PANGO_SCALE_26_6 macro for scaling font size.
|
||||
* Font sizes are normally given in points with at most one single
|
||||
* decimal place fraction. If we do not do the rounding here, we will
|
||||
* be suffering from an error < 0.016pt, which is entirely negligeable
|
||||
* as far as font sizes are concerned.
|
||||
*/
|
||||
#if 0
|
||||
#define PANGO_PIXELS_26_6(d) \
|
||||
(((d) >= 0) ? \
|
||||
((d) + PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6 : \
|
||||
((d) - PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6)
|
||||
#else
|
||||
#define PANGO_PIXELS_26_6(d) \
|
||||
(d / PANGO_SCALE_26_6)
|
||||
#endif
|
||||
void _pango_clutter_renderer_set_use_mipmapping (PangoClutterRenderer *renderer,
|
||||
gboolean value);
|
||||
|
||||
#define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d))
|
||||
G_END_DECLS
|
||||
|
||||
#define PANGO_TYPE_CLUTTER_FONT (pango_clutter_font_get_type ())
|
||||
|
||||
#define PANGO_CLUTTER_FONT(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((object), \
|
||||
PANGO_TYPE_CLUTTER_FONT, \
|
||||
PangoClutterFont))
|
||||
#define PANGO_CLUTTER_IS_FONT(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_FONT))
|
||||
|
||||
typedef struct _PangoClutterFont PangoClutterFont;
|
||||
typedef struct _PangoClutterGlyphInfo PangoClutterGlyphInfo;
|
||||
|
||||
struct _PangoClutterFont
|
||||
{
|
||||
PangoFcFont font;
|
||||
FT_Face face;
|
||||
int load_flags;
|
||||
int size;
|
||||
GSList *metrics_by_lang;
|
||||
GHashTable *glyph_info;
|
||||
GDestroyNotify glyph_cache_destroy;
|
||||
};
|
||||
|
||||
struct _PangoClutterGlyphInfo
|
||||
{
|
||||
PangoRectangle logical_rect;
|
||||
PangoRectangle ink_rect;
|
||||
void *cached_glyph;
|
||||
};
|
||||
|
||||
PangoGlyph
|
||||
pango_clutter_get_unknown_glyph (PangoFont *font);
|
||||
|
||||
GType pango_clutter_font_get_type (void);
|
||||
|
||||
PangoClutterFont *
|
||||
_pango_clutter_font_new (PangoClutterFontMap *fontmap,
|
||||
FcPattern *pattern);
|
||||
FT_Face
|
||||
pango_clutter_font_get_face (PangoFont *font);
|
||||
|
||||
FT_Library
|
||||
_pango_clutter_font_map_get_library (PangoFontMap *fontmap);
|
||||
|
||||
void *
|
||||
_pango_clutter_font_get_cache_glyph_data (PangoFont *font,
|
||||
int glyph_index);
|
||||
void
|
||||
_pango_clutter_font_set_cache_glyph_data (PangoFont *font,
|
||||
int glyph_index,
|
||||
void *cached_glyph);
|
||||
void
|
||||
_pango_clutter_font_set_glyph_cache_destroy (PangoFont *font,
|
||||
GDestroyNotify destroy_notify);
|
||||
|
||||
/* Renderer */
|
||||
|
||||
typedef struct _PangoClutterRenderer PangoClutterRenderer;
|
||||
|
||||
#define PANGO_TYPE_CLUTTER_RENDERER (pango_clutter_renderer_get_type())
|
||||
|
||||
#define PANGO_CLUTTER_RENDERER(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((object), \
|
||||
PANGO_TYPE_CLUTTER_RENDERER, \
|
||||
PangoClutterRenderer))
|
||||
|
||||
#define PANGO_IS_CLUTTER_RENDERER(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_RENDERER))
|
||||
|
||||
GType pango_clutter_renderer_get_type (void);
|
||||
|
||||
PangoRenderer *
|
||||
_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fontmap);
|
||||
|
||||
|
||||
/* HACK make this public to avoid a mass of re-implementation*/
|
||||
void
|
||||
pango_fc_font_get_raw_extents (PangoFcFont *font,
|
||||
FT_Int32 load_flags,
|
||||
PangoGlyph glyph,
|
||||
PangoRectangle *ink_rect,
|
||||
PangoRectangle *logical_rect);
|
||||
|
||||
#endif
|
||||
#endif /* _HAVE_PANGO_CLUTTER_H */
|
||||
|
@ -1,22 +1,23 @@
|
||||
/* Pango
|
||||
* Rendering routines to Clutter
|
||||
/*
|
||||
* 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
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2008 OpenedHand
|
||||
*
|
||||
* 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 file is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
* 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 Library General Public
|
||||
* 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.
|
||||
@ -26,372 +27,102 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#ifndef PANGO_ENABLE_BACKEND
|
||||
#define PANGO_ENABLE_BACKEND 1
|
||||
#endif
|
||||
|
||||
#include <pango/pango-fontmap.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <pango/pango-renderer.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
||||
#include "pangoclutter.h"
|
||||
#include "pangoclutter-private.h"
|
||||
#include "pangoclutter-glyph-cache.h"
|
||||
#include "../clutter-debug.h"
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
/*
|
||||
* Texture cache support code
|
||||
*/
|
||||
|
||||
#define TC_WIDTH 256
|
||||
#define TC_HEIGHT 256
|
||||
#define TC_ROUND 4
|
||||
|
||||
typedef struct {
|
||||
CoglHandle cogl_tex;
|
||||
int x, y, w, h;
|
||||
} tc_area;
|
||||
|
||||
typedef struct tc_texture {
|
||||
struct tc_texture *next;
|
||||
CoglHandle cogl_tex;
|
||||
int avail;
|
||||
} tc_texture;
|
||||
|
||||
typedef struct tc_slice {
|
||||
CoglHandle cogl_tex;
|
||||
int avail, y;
|
||||
} tc_slice;
|
||||
|
||||
static int tc_generation = 0;
|
||||
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--; )
|
||||
slices [i].cogl_tex = COGL_INVALID_HANDLE;
|
||||
|
||||
while (first_texture)
|
||||
{
|
||||
tc_texture *next = first_texture->next;
|
||||
cogl_texture_unref (first_texture->cogl_tex);
|
||||
g_slice_free (tc_texture, first_texture);
|
||||
first_texture = next;
|
||||
}
|
||||
|
||||
++tc_generation;
|
||||
}
|
||||
|
||||
static void
|
||||
tc_get (tc_area *area, int width, int height)
|
||||
{
|
||||
int slice_height;
|
||||
tc_slice *slice;
|
||||
|
||||
area->w = width;
|
||||
area->h = height;
|
||||
|
||||
/* 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;
|
||||
|
||||
width = MIN (width, TC_WIDTH);
|
||||
|
||||
if (slice->cogl_tex == COGL_INVALID_HANDLE || slice->avail < width)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
CLUTTER_NOTE (PANGO, "creating new texture %i x %i",
|
||||
TC_WIDTH, TC_HEIGHT);
|
||||
|
||||
match = g_slice_new (tc_texture);
|
||||
match->next = first_texture;
|
||||
first_texture = match;
|
||||
match->avail = TC_HEIGHT;
|
||||
|
||||
match->cogl_tex = cogl_texture_new_with_size (TC_WIDTH, TC_HEIGHT, 0, TRUE,
|
||||
COGL_PIXEL_FORMAT_A_8);
|
||||
|
||||
/* We use mipmapping instead of just CGL_LINEAR here
|
||||
* which allows rendering of glyphs to look nice even at
|
||||
* scales far below 50%.
|
||||
*/
|
||||
cogl_texture_set_filters (match->cogl_tex,
|
||||
CGL_LINEAR_MIPMAP_LINEAR,
|
||||
CGL_LINEAR);
|
||||
}
|
||||
|
||||
match->avail -= slice_height;
|
||||
|
||||
slice->cogl_tex = match->cogl_tex;
|
||||
slice->avail = TC_WIDTH;
|
||||
slice->y = match->avail;
|
||||
}
|
||||
|
||||
slice->avail -= width;
|
||||
|
||||
area->cogl_tex = slice->cogl_tex;
|
||||
area->x = slice->avail;
|
||||
area->y = slice->y;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* The color to draw the glyphs with */
|
||||
ClutterColor color;
|
||||
|
||||
/* Two caches of glyphs as textures, one with mipmapped textures and
|
||||
one without */
|
||||
PangoClutterGlyphCache *glyph_cache;
|
||||
PangoClutterGlyphCache *mipmapped_glyph_cache;
|
||||
|
||||
gboolean use_mipmapping;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PangoClutterRenderer, \
|
||||
pango_clutter_renderer, \
|
||||
PANGO_TYPE_RENDERER)
|
||||
|
||||
typedef struct
|
||||
struct _PangoClutterRendererClass
|
||||
{
|
||||
guint8 *bitmap;
|
||||
int width, stride, height, top, left;
|
||||
} Glyph;
|
||||
PangoRendererClass class_instance;
|
||||
};
|
||||
|
||||
static void *
|
||||
temp_buffer (size_t size)
|
||||
static void pango_clutter_renderer_finalize (GObject *object);
|
||||
static void pango_clutter_renderer_draw_glyph (PangoRenderer *renderer,
|
||||
PangoFont *font,
|
||||
PangoGlyph glyph,
|
||||
double x,
|
||||
double y);
|
||||
static void pango_clutter_renderer_draw_rectangle (PangoRenderer *renderer,
|
||||
PangoRenderPart part,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
static void pango_clutter_renderer_draw_trapezoid (PangoRenderer *renderer,
|
||||
PangoRenderPart part,
|
||||
double y1,
|
||||
double x11,
|
||||
double x21,
|
||||
double y2,
|
||||
double x12,
|
||||
double x22);
|
||||
static void pango_clutter_renderer_prepare_run (PangoRenderer *renderer,
|
||||
PangoLayoutRun *run);
|
||||
|
||||
static GObjectClass *parent_class = NULL;
|
||||
|
||||
G_DEFINE_TYPE (PangoClutterRenderer, pango_clutter_renderer,
|
||||
PANGO_TYPE_RENDERER);
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_init (PangoClutterRenderer *priv)
|
||||
{
|
||||
static char *buffer;
|
||||
static size_t alloc;
|
||||
|
||||
if (size > alloc)
|
||||
{
|
||||
size = (size + 4095) & ~4095;
|
||||
g_free (buffer);
|
||||
alloc = size;
|
||||
buffer = g_malloc (size);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
priv->glyph_cache = pango_clutter_glyph_cache_new (FALSE);
|
||||
priv->mipmapped_glyph_cache = pango_clutter_glyph_cache_new (TRUE);
|
||||
priv->use_mipmapping = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
render_box (Glyph *glyph, int width, int height, int top)
|
||||
pango_clutter_renderer_class_init (PangoClutterRendererClass *klass)
|
||||
{
|
||||
int i;
|
||||
int left = 0;
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
|
||||
|
||||
if (height > 2)
|
||||
{
|
||||
height -= 2;
|
||||
top++;
|
||||
}
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
if (width > 2)
|
||||
{
|
||||
width -= 2;
|
||||
left++;
|
||||
}
|
||||
object_class->finalize = pango_clutter_renderer_finalize;
|
||||
|
||||
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--; )
|
||||
glyph->bitmap [i]
|
||||
= glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff;
|
||||
|
||||
for (i = height; i--; )
|
||||
glyph->bitmap [i * glyph->stride]
|
||||
= glyph->bitmap [i * glyph->stride + (width - 1)] = 0xff;
|
||||
renderer_class->draw_glyph = pango_clutter_renderer_draw_glyph;
|
||||
renderer_class->draw_rectangle = pango_clutter_renderer_draw_rectangle;
|
||||
renderer_class->draw_trapezoid = pango_clutter_renderer_draw_trapezoid;
|
||||
renderer_class->prepare_run = pango_clutter_renderer_prepare_run;
|
||||
}
|
||||
|
||||
static void
|
||||
font_render_glyph (Glyph *glyph, PangoFont *font, int glyph_index)
|
||||
pango_clutter_renderer_finalize (GObject *object)
|
||||
{
|
||||
FT_Face face;
|
||||
PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (object);
|
||||
|
||||
if (glyph_index & PANGO_GLYPH_UNKNOWN_FLAG)
|
||||
{
|
||||
PangoFontMetrics *metrics;
|
||||
pango_clutter_glyph_cache_free (priv->mipmapped_glyph_cache);
|
||||
pango_clutter_glyph_cache_free (priv->glyph_cache);
|
||||
|
||||
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);
|
||||
|
||||
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:
|
||||
render_box (glyph, PANGO_UNKNOWN_GLYPH_WIDTH,
|
||||
PANGO_UNKNOWN_GLYPH_HEIGHT, PANGO_UNKNOWN_GLYPH_HEIGHT);
|
||||
}
|
||||
|
||||
typedef struct glyph_info
|
||||
{
|
||||
tc_area tex;
|
||||
int left, top;
|
||||
int generation;
|
||||
}
|
||||
glyph_info;
|
||||
|
||||
static void
|
||||
free_glyph_info (glyph_info *g)
|
||||
{
|
||||
tc_put (&g->tex);
|
||||
g_slice_free (glyph_info, g);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_glyph (PangoRenderer *renderer_,
|
||||
PangoFont *font,
|
||||
PangoGlyph glyph,
|
||||
double xd,
|
||||
double yd)
|
||||
{
|
||||
glyph_info *g;
|
||||
gint x = (gint)xd, y = (gint)yd;
|
||||
ClutterFixed fx, fy;
|
||||
|
||||
if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
|
||||
{
|
||||
glyph = pango_clutter_get_unknown_glyph (font);
|
||||
|
||||
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);
|
||||
|
||||
if (bm.width < 1 || bm.height < 1 || bm.bitmap == NULL)
|
||||
{
|
||||
/* Safety on */
|
||||
if (g)
|
||||
{
|
||||
x += g->left;
|
||||
y -= g->top;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (bm.height > TC_HEIGHT)
|
||||
{
|
||||
g_warning ("%s: Glyph too large for cache, increase TC_HEIGHT",
|
||||
G_STRLOC);
|
||||
}
|
||||
|
||||
if (g)
|
||||
g->generation = tc_generation;
|
||||
else
|
||||
{
|
||||
g = g_slice_new0 (glyph_info);
|
||||
|
||||
_pango_clutter_font_set_glyph_cache_destroy
|
||||
(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;
|
||||
|
||||
CLUTTER_NOTE (PANGO, "cache fail; subimage2d %i", glyph);
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
CLUTTER_NOTE (PANGO, "cache success %i\n", glyph);
|
||||
|
||||
x += g->left;
|
||||
y -= g->top;
|
||||
|
||||
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);
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
void
|
||||
@ -401,17 +132,19 @@ pango_clutter_render_layout_subpixel (PangoLayout *layout,
|
||||
ClutterColor *color,
|
||||
int flags)
|
||||
{
|
||||
PangoContext *context;
|
||||
PangoFontMap *fontmap;
|
||||
PangoRenderer *renderer;
|
||||
PangoContext *context;
|
||||
PangoFontMap *font_map;
|
||||
PangoRenderer *renderer;
|
||||
PangoClutterRenderer *priv;
|
||||
|
||||
context = pango_layout_get_context (layout);
|
||||
fontmap = pango_context_get_font_map (context);
|
||||
font_map = pango_context_get_font_map (context);
|
||||
g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
|
||||
renderer = _pango_clutter_font_map_get_renderer
|
||||
(PANGO_CLUTTER_FONT_MAP (fontmap));
|
||||
(PANGO_CLUTTER_FONT_MAP (font_map));
|
||||
priv = PANGO_CLUTTER_RENDERER (renderer);
|
||||
|
||||
memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
|
||||
color, sizeof(ClutterColor));
|
||||
priv->color = *color;
|
||||
|
||||
pango_renderer_draw_layout (renderer, layout, x, y);
|
||||
}
|
||||
@ -423,80 +156,310 @@ pango_clutter_render_layout (PangoLayout *layout,
|
||||
ClutterColor *color,
|
||||
int flags)
|
||||
{
|
||||
pango_clutter_render_layout_subpixel (layout,
|
||||
x * PANGO_SCALE,
|
||||
y * PANGO_SCALE,
|
||||
color,
|
||||
flags);
|
||||
return pango_clutter_render_layout_subpixel (layout,
|
||||
x * PANGO_SCALE,
|
||||
y * PANGO_SCALE,
|
||||
color, flags);
|
||||
}
|
||||
|
||||
void
|
||||
pango_clutter_render_layout_line (PangoLayoutLine *line,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color)
|
||||
pango_clutter_render_layout_line (PangoLayoutLine *line,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color)
|
||||
{
|
||||
PangoContext *context;
|
||||
PangoFontMap *fontmap;
|
||||
PangoRenderer *renderer;
|
||||
PangoContext *context;
|
||||
PangoFontMap *font_map;
|
||||
PangoRenderer *renderer;
|
||||
PangoClutterRenderer *priv;
|
||||
|
||||
context = pango_layout_get_context (line->layout);
|
||||
fontmap = pango_context_get_font_map (context);
|
||||
font_map = pango_context_get_font_map (context);
|
||||
g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
|
||||
renderer = _pango_clutter_font_map_get_renderer
|
||||
(PANGO_CLUTTER_FONT_MAP (fontmap));
|
||||
(PANGO_CLUTTER_FONT_MAP (font_map));
|
||||
priv = PANGO_CLUTTER_RENDERER (renderer);
|
||||
|
||||
memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
|
||||
color, sizeof(ClutterColor));
|
||||
priv->color = *color;
|
||||
|
||||
pango_renderer_draw_layout_line (renderer, line, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
pango_clutter_render_clear_caches (void)
|
||||
_pango_clutter_renderer_clear_glyph_cache (PangoClutterRenderer *renderer)
|
||||
{
|
||||
tc_clear();
|
||||
pango_clutter_glyph_cache_clear (renderer->glyph_cache);
|
||||
pango_clutter_glyph_cache_clear (renderer->mipmapped_glyph_cache);
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_init (PangoClutterRenderer *renderer)
|
||||
void
|
||||
_pango_clutter_renderer_set_use_mipmapping (PangoClutterRenderer *renderer,
|
||||
gboolean value)
|
||||
{
|
||||
memset (&renderer->color, 0xff, sizeof(ClutterColor));
|
||||
renderer->use_mipmapping = value;
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_run (PangoRenderer *renderer, PangoLayoutRun *run)
|
||||
static PangoClutterGlyphCacheValue *
|
||||
pango_clutter_renderer_get_cached_glyph (PangoRenderer *renderer,
|
||||
PangoFont *font,
|
||||
PangoGlyph glyph)
|
||||
{
|
||||
PangoClutterRenderer *glrenderer = (PangoClutterRenderer *)renderer;
|
||||
PangoColor *fg = 0;
|
||||
GSList *l;
|
||||
ClutterColor col;
|
||||
PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (renderer);
|
||||
PangoClutterGlyphCacheValue *value;
|
||||
PangoClutterGlyphCache *glyph_cache;
|
||||
|
||||
renderer->underline = PANGO_UNDERLINE_NONE;
|
||||
renderer->strikethrough = FALSE;
|
||||
glyph_cache = priv->use_mipmapping
|
||||
? priv->mipmapped_glyph_cache : priv->glyph_cache;
|
||||
|
||||
for (l = run->item->analysis.extra_attrs; l; l = l->next)
|
||||
if ((value = pango_clutter_glyph_cache_lookup (glyph_cache,
|
||||
font,
|
||||
glyph)) == NULL)
|
||||
{
|
||||
PangoAttribute *attr = l->data;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
cairo_scaled_font_t *scaled_font;
|
||||
PangoRectangle ink_rect;
|
||||
cairo_glyph_t cairo_glyph;
|
||||
|
||||
pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
|
||||
pango_extents_to_pixels (&ink_rect, NULL);
|
||||
|
||||
surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
|
||||
ink_rect.width,
|
||||
ink_rect.height);
|
||||
cr = cairo_create (surface);
|
||||
|
||||
scaled_font = pango_cairo_font_get_scaled_font (PANGO_CAIRO_FONT (font));
|
||||
cairo_set_scaled_font (cr, scaled_font);
|
||||
|
||||
cairo_glyph.x = -ink_rect.x;
|
||||
cairo_glyph.y = -ink_rect.y;
|
||||
/* The PangoCairo glyph numbers directly map to Cairo glyph
|
||||
numbers */
|
||||
cairo_glyph.index = glyph;
|
||||
cairo_show_glyphs (cr, &cairo_glyph, 1);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_flush (surface);
|
||||
|
||||
/* Copy the glyph to the cache */
|
||||
value = pango_clutter_glyph_cache_set
|
||||
(glyph_cache, font, glyph,
|
||||
cairo_image_surface_get_data (surface),
|
||||
cairo_image_surface_get_width (surface),
|
||||
cairo_image_surface_get_height (surface),
|
||||
cairo_image_surface_get_stride (surface),
|
||||
ink_rect.x, ink_rect.y);
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
CLUTTER_NOTE (PANGO, "cache fail %i", glyph);
|
||||
}
|
||||
else
|
||||
CLUTTER_NOTE (PANGO, "cache success %i", glyph);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
pango_clutter_ensure_glyph_cache_for_layout (PangoLayout *layout)
|
||||
{
|
||||
PangoContext *context;
|
||||
PangoFontMap *fontmap;
|
||||
PangoRenderer *renderer;
|
||||
PangoLayoutIter *iter;
|
||||
|
||||
g_return_if_fail (PANGO_IS_LAYOUT (layout));
|
||||
|
||||
context = pango_layout_get_context (layout);
|
||||
fontmap = pango_context_get_font_map (context);
|
||||
g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap));
|
||||
renderer = _pango_clutter_font_map_get_renderer
|
||||
(PANGO_CLUTTER_FONT_MAP (fontmap));
|
||||
|
||||
if ((iter = pango_layout_get_iter (layout)) == NULL)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
PangoLayoutLine *line;
|
||||
GSList *l;
|
||||
|
||||
line = pango_layout_iter_get_line_readonly (iter);
|
||||
|
||||
for (l = line->runs; l; l = l->next)
|
||||
{
|
||||
PangoLayoutRun *run = l->data;
|
||||
PangoGlyphString *glyphs = run->glyphs;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < glyphs->num_glyphs; i++)
|
||||
{
|
||||
PangoGlyphInfo *gi = &glyphs->glyphs[i];
|
||||
|
||||
pango_clutter_renderer_get_cached_glyph (renderer,
|
||||
run->item->analysis.font,
|
||||
gi->glyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (pango_layout_iter_next_line (iter));
|
||||
|
||||
pango_layout_iter_free (iter);
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_draw_box (int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
cogl_path_rectangle (CLUTTER_INT_TO_FIXED (x),
|
||||
CLUTTER_INT_TO_FIXED (y - height),
|
||||
CLUTTER_INT_TO_FIXED (width),
|
||||
CLUTTER_INT_TO_FIXED (height));
|
||||
cogl_path_stroke ();
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_draw_rectangle (PangoRenderer *renderer,
|
||||
PangoRenderPart part,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
float x1, x2, y1, y2;
|
||||
const PangoMatrix *matrix;
|
||||
|
||||
if ((matrix = pango_renderer_get_matrix (renderer)))
|
||||
{
|
||||
/* Convert user-space coords to device coords */
|
||||
x1 = (x * matrix->xx + y * matrix->xy) / PANGO_SCALE + matrix->x0;
|
||||
x2 = ((x + width) * matrix->xx + (y + height) * matrix->xy)
|
||||
/ PANGO_SCALE + matrix->x0;
|
||||
y1 = (y * matrix->yy + x * matrix->yx) / PANGO_SCALE + matrix->y0;
|
||||
y2 = ((y + height) * matrix->yy + (x + width) * matrix->yx)
|
||||
/ PANGO_SCALE + matrix->y0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x / PANGO_SCALE;
|
||||
x2 = (x + width) / PANGO_SCALE;
|
||||
y1 = y / PANGO_SCALE;
|
||||
y2 = (y + height) / PANGO_SCALE;
|
||||
}
|
||||
|
||||
cogl_rectangle (x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_draw_trapezoid (PangoRenderer *renderer,
|
||||
PangoRenderPart part,
|
||||
double y1,
|
||||
double x11,
|
||||
double x21,
|
||||
double y2,
|
||||
double x12,
|
||||
double x22)
|
||||
{
|
||||
ClutterFixed points[8];
|
||||
|
||||
points[0] = CLUTTER_FLOAT_TO_FIXED (x11);
|
||||
points[1] = CLUTTER_FLOAT_TO_FIXED (y1);
|
||||
points[2] = CLUTTER_FLOAT_TO_FIXED (x12);
|
||||
points[3] = CLUTTER_FLOAT_TO_FIXED (y2);
|
||||
points[4] = CLUTTER_FLOAT_TO_FIXED (x22);
|
||||
points[5] = points[3];
|
||||
points[6] = CLUTTER_FLOAT_TO_FIXED (x21);
|
||||
points[7] = points[1];
|
||||
|
||||
cogl_path_polygon (points, 4);
|
||||
cogl_path_fill ();
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_draw_glyph (PangoRenderer *renderer,
|
||||
PangoFont *font,
|
||||
PangoGlyph glyph,
|
||||
double xd,
|
||||
double yd)
|
||||
{
|
||||
PangoClutterGlyphCacheValue *cache_value;
|
||||
ClutterFixed x = CLUTTER_FLOAT_TO_FIXED ((float) xd);
|
||||
ClutterFixed y = CLUTTER_FLOAT_TO_FIXED ((float) yd);
|
||||
|
||||
if ((glyph & PANGO_GLYPH_UNKNOWN_FLAG))
|
||||
{
|
||||
PangoFontMetrics *metrics;
|
||||
|
||||
if (font == NULL
|
||||
|| (metrics = pango_font_get_metrics (font, NULL)) == NULL)
|
||||
pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
|
||||
CLUTTER_FIXED_TO_INT (y),
|
||||
PANGO_UNKNOWN_GLYPH_WIDTH,
|
||||
PANGO_UNKNOWN_GLYPH_HEIGHT);
|
||||
else
|
||||
{
|
||||
pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
|
||||
CLUTTER_FIXED_TO_INT (y),
|
||||
metrics->approximate_char_width
|
||||
/ PANGO_SCALE,
|
||||
metrics->ascent / PANGO_SCALE);
|
||||
|
||||
pango_font_metrics_unref (metrics);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the texture containing the glyph. This will create the cache
|
||||
entry if there isn't already one */
|
||||
cache_value = pango_clutter_renderer_get_cached_glyph (renderer, font, glyph);
|
||||
|
||||
if (cache_value == NULL)
|
||||
{
|
||||
pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
|
||||
CLUTTER_FIXED_TO_INT (y),
|
||||
PANGO_UNKNOWN_GLYPH_WIDTH,
|
||||
PANGO_UNKNOWN_GLYPH_HEIGHT);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
x += CLUTTER_INT_TO_FIXED (cache_value->draw_x);
|
||||
y += CLUTTER_INT_TO_FIXED (cache_value->draw_y);
|
||||
|
||||
/* Render the glyph from the texture */
|
||||
cogl_texture_rectangle (cache_value->texture, x, y,
|
||||
x + CLUTTER_INT_TO_FIXED (cache_value->draw_width),
|
||||
y + CLUTTER_INT_TO_FIXED (cache_value->draw_height),
|
||||
cache_value->tx1, cache_value->ty1,
|
||||
cache_value->tx2, cache_value->ty2);
|
||||
}
|
||||
|
||||
static void
|
||||
pango_clutter_renderer_prepare_run (PangoRenderer *renderer,
|
||||
PangoLayoutRun *run)
|
||||
{
|
||||
GSList *node;
|
||||
PangoColor *fg = NULL;
|
||||
ClutterColor col;
|
||||
PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (renderer);
|
||||
|
||||
for (node = run->item->analysis.extra_attrs; node; node = node->next)
|
||||
{
|
||||
PangoAttribute *attr = node->data;
|
||||
|
||||
switch (attr->klass->type)
|
||||
{
|
||||
case PANGO_ATTR_UNDERLINE:
|
||||
renderer->underline = ((PangoAttrInt *)attr)->value;
|
||||
break;
|
||||
|
||||
case PANGO_ATTR_STRIKETHROUGH:
|
||||
renderer->strikethrough = ((PangoAttrInt *)attr)->value;
|
||||
break;
|
||||
|
||||
case PANGO_ATTR_FOREGROUND:
|
||||
fg = &((PangoAttrColor *)attr)->color;
|
||||
break;
|
||||
fg = &((PangoAttrColor *) attr)->color;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fg)
|
||||
if (fg)
|
||||
{
|
||||
col.red = (fg->red * 255) / 65535;
|
||||
col.green = (fg->green * 255) / 65535;
|
||||
@ -504,41 +467,15 @@ prepare_run (PangoRenderer *renderer, PangoLayoutRun *run)
|
||||
}
|
||||
else
|
||||
{
|
||||
col.red = glrenderer->color.red;
|
||||
col.green = glrenderer->color.green;
|
||||
col.blue = glrenderer->color.blue;
|
||||
col.red = priv->color.red;
|
||||
col.green = priv->color.green;
|
||||
col.blue = priv->color.blue;
|
||||
}
|
||||
|
||||
col.alpha = glrenderer->color.alpha;
|
||||
col.alpha = priv->color.alpha;
|
||||
|
||||
if (glrenderer->flags & FLAG_INVERSE)
|
||||
{
|
||||
col.red ^= 0xffU;
|
||||
col.green ^= 0xffU;
|
||||
col.blue ^= 0xffU;
|
||||
}
|
||||
cogl_color (&col);
|
||||
|
||||
cogl_color(&col);
|
||||
/* Chain up */
|
||||
(* PANGO_RENDERER_CLASS (parent_class)->prepare_run) (renderer, run);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,105 +1,109 @@
|
||||
/* Pango
|
||||
* pangoclutter.h: Clutter/Freetype2 backend
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* Copyright (C) 1999 Red Hat Software
|
||||
* Copyright (C) 2000 Tor Lillqvist
|
||||
* Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2008 OpenedHand
|
||||
*
|
||||
* 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 file is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
* 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 Library General Public
|
||||
* 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.
|
||||
*/
|
||||
#ifndef PANGOCLUTTER_H__
|
||||
#define PANGOCLUTTER_H__
|
||||
|
||||
#define PANGO_ENABLE_BACKEND
|
||||
|
||||
/* we always want to disable cast checks */
|
||||
#ifndef G_DISABLE_CAST_CHECKS
|
||||
#define G_DISABLE_CAST_CHECKS
|
||||
#endif
|
||||
#ifndef _HAVE_PANGO_CLUTTER_H
|
||||
#define _HAVE_PANGO_CLUTTER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango.h>
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <clutter/clutter-color.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PANGO_TYPE_CLUTTER_FONT_MAP \
|
||||
(pango_clutter_font_map_get_type ())
|
||||
/* It's too difficult to actually subclass the pango cairo font
|
||||
map. Instead we just make a fake set of macros that actually just
|
||||
directly use the original type */
|
||||
#define PANGO_CLUTTER_TYPE_FONT_MAP PANGO_TYPE_CAIRO_FONT_MAP
|
||||
|
||||
#define PANGO_CLUTTER_FONT_MAP(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((object), \
|
||||
PANGO_TYPE_CLUTTER_FONT_MAP, \
|
||||
PangoClutterFontMap))
|
||||
#define PANGO_CLUTTER_FONT_MAP(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
PANGO_CLUTTER_TYPE_FONT_MAP, \
|
||||
PangoClutterFontMap))
|
||||
#define PANGO_CLUTTER_IS_FONT_MAP(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
PANGO_CLUTTER_TYPE_FONT_MAP))
|
||||
|
||||
#define PANGO_CLUTTER_IS_FONT_MAP(object) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_FONT_MAP))
|
||||
typedef PangoCairoFontMap PangoClutterFontMap;
|
||||
|
||||
typedef struct _PangoClutterFontMap PangoClutterFontMap;
|
||||
typedef struct _PangoClutterFontMapClass PangoClutterFontMapClass;
|
||||
PangoFontMap *pango_clutter_font_map_new (void);
|
||||
|
||||
typedef void (*PangoClutterSubstituteFunc) (FcPattern *pattern, gpointer data);
|
||||
PangoContext *pango_clutter_font_map_create_context (PangoClutterFontMap *fm);
|
||||
|
||||
GType pango_clutter_font_map_get_type (void);
|
||||
void pango_clutter_font_map_set_resolution (PangoClutterFontMap *font_map,
|
||||
double dpi);
|
||||
|
||||
PangoFontMap*
|
||||
pango_clutter_font_map_new (void);
|
||||
void pango_clutter_font_map_clear_glyph_cache (PangoClutterFontMap *fm);
|
||||
|
||||
void
|
||||
pango_clutter_font_map_set_default_substitute
|
||||
(PangoClutterFontMap *fontmap,
|
||||
PangoClutterSubstituteFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
void pango_clutter_font_map_set_use_mipmapping (PangoClutterFontMap *fm,
|
||||
gboolean value);
|
||||
|
||||
void
|
||||
pango_clutter_font_map_set_resolution (PangoClutterFontMap *fontmap,
|
||||
double dpi);
|
||||
void pango_clutter_ensure_glyph_cache_for_layout (PangoLayout *layout);
|
||||
|
||||
void
|
||||
pango_clutter_font_map_substitute_changed (PangoClutterFontMap *fontmap);
|
||||
#define PANGO_CLUTTER_TYPE_RENDERER (pango_clutter_renderer_get_type ())
|
||||
|
||||
PangoContext *
|
||||
pango_clutter_font_map_create_context (PangoClutterFontMap *fontmap);
|
||||
#define PANGO_CLUTTER_RENDERER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
PANGO_CLUTTER_TYPE_RENDERER, \
|
||||
PangoClutterRenderer))
|
||||
#define PANGO_CLUTTER_RENDERER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||
PANGO_CLUTTER_TYPE_RENDERER, \
|
||||
PangoClutterRendererClass))
|
||||
#define PANGO_CLUTTER_IS_RENDERER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
PANGO_CLUTTER_TYPE_RENDERER))
|
||||
#define PANGO_CLUTTER_IS_RENDERER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||
PANGO_CLUTTER_TYPE_RENDERER))
|
||||
#define PANGO_CLUTTER_RENDERER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
PANGO_CLUTTER_TYPE_RENDERER, \
|
||||
PangoClutterRendererClass))
|
||||
|
||||
#define FLAG_INVERSE 1
|
||||
#define FLAG_OUTLINE 2 // not yet implemented
|
||||
typedef struct _PangoClutterRenderer PangoClutterRenderer;
|
||||
typedef struct _PangoClutterRendererClass PangoClutterRendererClass;
|
||||
|
||||
void
|
||||
pango_clutter_render_layout_subpixel (PangoLayout *layout,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color,
|
||||
int flags);
|
||||
void
|
||||
pango_clutter_render_layout (PangoLayout *layout,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color,
|
||||
int flags);
|
||||
GType pango_clutter_renderer_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void
|
||||
pango_clutter_render_layout_line (PangoLayoutLine *line,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color);
|
||||
void pango_clutter_render_layout_subpixel (PangoLayout *layout,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color,
|
||||
int flags);
|
||||
|
||||
void
|
||||
pango_clutter_render_clear_caches ();
|
||||
void pango_clutter_render_layout (PangoLayout *layout,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color,
|
||||
int flags);
|
||||
|
||||
void pango_clutter_render_layout_line (PangoLayoutLine *line,
|
||||
int x,
|
||||
int y,
|
||||
ClutterColor *color);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
#endif /* _HAVE_PANGO_CLUTTER_H */
|
||||
|
@ -448,7 +448,7 @@ fi
|
||||
AC_SUBST(JSON_PREFIX)
|
||||
AM_CONDITIONAL(LOCAL_JSON_GLIB, test "x$have_json" = "xno")
|
||||
|
||||
CLUTTER_REQUIRES="pangoft2 glib-2.0 >= 2.14 gobject-2.0 gthread-2.0 gmodule-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC"
|
||||
CLUTTER_REQUIRES="pangocairo glib-2.0 >= 2.14 gobject-2.0 gthread-2.0 gmodule-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC"
|
||||
|
||||
if test "x$imagebackend" = "xgdk-pixbuf"; then
|
||||
CLUTTER_REQUIRES="$CLUTTER_REQUIRES gdk-pixbuf-2.0"
|
||||
|
Loading…
Reference in New Issue
Block a user