1
0
Fork 0

2008-10-31 Emmanuele Bassi <ebassi@linux.intel.com>

* clutter/pango/cogl-pango-fontmap.c:
	* clutter/pango/cogl-pango-render.c: Whitespace fixes and code
	duplication removal. Plus, start documenting the CoglPango API.
This commit is contained in:
Emmanuele Bassi 2008-10-31 17:48:24 +00:00
parent 52c6f0ab98
commit 745d7bed2a
3 changed files with 219 additions and 101 deletions

View file

@ -1,3 +1,9 @@
2008-10-31 Emmanuele Bassi <ebassi@linux.intel.com>
* clutter/pango/cogl-pango-fontmap.c:
* clutter/pango/cogl-pango-render.c: Whitespace fixes and code
duplication removal. Plus, start documenting the CoglPango API.
2008-10-31 Matthew Allum <mallum@openedhand.com> 2008-10-31 Matthew Allum <mallum@openedhand.com>
* clutter/clutter-texture.c: (clutter_texture_set_filter_quality), * clutter/clutter-texture.c: (clutter_texture_set_filter_quality),

View file

@ -21,6 +21,14 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**
* SECTION:cogl-pango
* @short_description: COGL-based text rendering using Pango
*
* FIXME
*
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -40,12 +48,31 @@
static GQuark cogl_pango_font_map_get_renderer_key (void) G_GNUC_CONST; static GQuark cogl_pango_font_map_get_renderer_key (void) G_GNUC_CONST;
/**
* cogl_pango_font_map_new:
*
* Creates a new font map.
*
* Return value: the newly created #PangoFontMap
*
* Since: 1.0
*/
PangoFontMap * PangoFontMap *
cogl_pango_font_map_new (void) cogl_pango_font_map_new (void)
{ {
return pango_cairo_font_map_new (); return pango_cairo_font_map_new ();
} }
/**
* cogl_pango_font_map_create_context:
* @fm: a #CoglPangoFontMap
*
* Creates a new #PangoContext from the passed font map.
*
* Return value: the newly created #PangoContext
*
* Since: 1.0
*/
PangoContext * PangoContext *
cogl_pango_font_map_create_context (CoglPangoFontMap *fm) cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
{ {
@ -56,6 +83,16 @@ cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm)); return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
} }
/**
* cogl_pango_font_map_get_renderer:
* @fm: a #CoglPangoFontMap
*
* Retrieves the #CoglPangoRenderer for the passed font map.
*
* Return value: a #PangoRenderer
*
* Since: 1.0
*/
PangoRenderer * PangoRenderer *
cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm) cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
{ {
@ -82,6 +119,15 @@ cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
return renderer; return renderer;
} }
/**
* cogl_pango_font_map_set_resolution:
* @font_map: a #CoglPangoFontMap
* @dpi: DPI to set
*
* Sets the resolution to be used by @font_map at @dpi.
*
* Since: 1.0
*/
void void
cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map, cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
double dpi) double dpi)
@ -91,6 +137,14 @@ cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi); pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
} }
/**
* cogl_pango_font_map_clear_glyph_cache:
* @fm: a #CoglPangoFontMap
*
* Clears the glyph cache for @fm.
*
* Since: 1.0
*/
void void
cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm) cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
{ {
@ -101,6 +155,16 @@ cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
_cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer)); _cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer));
} }
/**
* cogl_pango_font_map_set_use_mipmapping:
* @fm: a #CoglPangoFontMap
* @value: %TRUE to enable the use of mipmapping
*
* Sets whether the renderer for the passed font map should use
* mipmapping when rendering a #PangoLayout.
*
* Since: 1.0
*/
void void
cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm, cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
gboolean value) gboolean value)
@ -112,6 +176,17 @@ cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
_cogl_pango_renderer_set_use_mipmapping (renderer, value); _cogl_pango_renderer_set_use_mipmapping (renderer, value);
} }
/**
* cogl_pango_font_map_get_use_mipmapping:
* @fm: a #CoglPangoFontMap
*
* Retrieves whether the #CoglPangoRenderer used by @fm will
* use mipmapping when rendering the glyphs.
*
* Return value: %TRUE if mipmapping is used, %FALSE otherwise.
*
* Since: 1.0
*/
gboolean gboolean
cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm) cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm)
{ {

View file

@ -62,29 +62,26 @@ struct _CoglPangoRendererClass
static void cogl_pango_renderer_finalize (GObject *object); static void cogl_pango_renderer_finalize (GObject *object);
static void cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer, static void cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer,
PangoFont *font, PangoFont *font,
PangoGlyphString *glyphs, PangoGlyphString *glyphs,
int x, int x,
int y); int y);
static void cogl_pango_renderer_draw_rectangle (PangoRenderer *renderer, static void cogl_pango_renderer_draw_rectangle (PangoRenderer *renderer,
PangoRenderPart part, PangoRenderPart part,
int x, int x,
int y, int y,
int width, int width,
int height); int height);
static void cogl_pango_renderer_draw_trapezoid (PangoRenderer *renderer, static void cogl_pango_renderer_draw_trapezoid (PangoRenderer *renderer,
PangoRenderPart part, PangoRenderPart part,
double y1, double y1,
double x11, double x11,
double x21, double x21,
double y2, double y2,
double x12, double x12,
double x22); double x22);
static GObjectClass *parent_class = NULL; G_DEFINE_TYPE (CoglPangoRenderer, cogl_pango_renderer, PANGO_TYPE_RENDERER);
G_DEFINE_TYPE (CoglPangoRenderer, cogl_pango_renderer,
PANGO_TYPE_RENDERER);
static void static void
cogl_pango_renderer_init (CoglPangoRenderer *priv) cogl_pango_renderer_init (CoglPangoRenderer *priv)
@ -100,8 +97,6 @@ cogl_pango_renderer_class_init (CoglPangoRendererClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass); PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = cogl_pango_renderer_finalize; object_class->finalize = cogl_pango_renderer_finalize;
renderer_class->draw_glyphs = cogl_pango_renderer_draw_glyphs; renderer_class->draw_glyphs = cogl_pango_renderer_draw_glyphs;
@ -117,68 +112,112 @@ cogl_pango_renderer_finalize (GObject *object)
cogl_pango_glyph_cache_free (priv->mipmapped_glyph_cache); cogl_pango_glyph_cache_free (priv->mipmapped_glyph_cache);
cogl_pango_glyph_cache_free (priv->glyph_cache); cogl_pango_glyph_cache_free (priv->glyph_cache);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (cogl_pango_renderer_parent_class)->finalize (object);
} }
static CoglPangoRenderer *
cogl_pango_get_renderer_from_context (PangoContext *context)
{
PangoFontMap *font_map;
PangoRenderer *renderer;
CoglPangoFontMap *font_map_priv;
font_map = pango_context_get_font_map (context);
g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (font_map), NULL);
font_map_priv = COGL_PANGO_FONT_MAP (font_map);
renderer = cogl_pango_font_map_get_renderer (font_map_priv);
g_return_val_if_fail (COGL_PANGO_IS_RENDERER (renderer), NULL);
return COGL_PANGO_RENDERER (renderer);
}
/**
* cogl_pango_render_layout_subpixel:
* @layout: a #PangoLayout
* @x: FIXME
* @y: FIXME
* @color: color to use when rendering the layout
* @flags: flags to pass to the renderer
*
* FIXME
*
* Since: 1.0
*/
void void
cogl_pango_render_layout_subpixel (PangoLayout *layout, cogl_pango_render_layout_subpixel (PangoLayout *layout,
int x, int x,
int y, int y,
const CoglColor *color, const CoglColor *color,
int flags) int flags)
{ {
PangoContext *context; PangoContext *context;
PangoFontMap *font_map;
PangoRenderer *renderer;
CoglPangoRenderer *priv; CoglPangoRenderer *priv;
context = pango_layout_get_context (layout); context = pango_layout_get_context (layout);
font_map = pango_context_get_font_map (context); priv = cogl_pango_get_renderer_from_context (context);
g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map)); if (G_UNLIKELY (!priv))
renderer = cogl_pango_font_map_get_renderer return;
(COGL_PANGO_FONT_MAP (font_map));
priv = COGL_PANGO_RENDERER (renderer);
priv->color = *color; priv->color = *color;
pango_renderer_draw_layout (renderer, layout, x, y); pango_renderer_draw_layout (PANGO_RENDERER (priv), layout, x, y);
} }
/**
* cogl_pango_render_layout:
* @layout: a #PangoLayout
* @x: X coordinate to render the layout at
* @y: Y coordinate to render the layout at
* @color: color to use when rendering the layout
* @flags: flags to pass to the renderer
*
* Renders @layout.
*
* Since: 1.0
*/
void void
cogl_pango_render_layout (PangoLayout *layout, cogl_pango_render_layout (PangoLayout *layout,
int x, int x,
int y, int y,
const CoglColor *color, const CoglColor *color,
int flags) int flags)
{ {
cogl_pango_render_layout_subpixel (layout, cogl_pango_render_layout_subpixel (layout,
x * PANGO_SCALE, x * PANGO_SCALE,
y * PANGO_SCALE, y * PANGO_SCALE,
color, color,
flags); flags);
} }
/**
* cogl_pango_render_layout_line:
* @line: a #PangoLayoutLine
* @x: X coordinate to render the line at
* @y: Y coordinate to render the line at
* @color: color to use when rendering the line
*
* Renders @line at the given coordinates using the given color.
*
* Since: 1.0
*/
void void
cogl_pango_render_layout_line (PangoLayoutLine *line, cogl_pango_render_layout_line (PangoLayoutLine *line,
int x, int x,
int y, int y,
const CoglColor *color) const CoglColor *color)
{ {
PangoContext *context; PangoContext *context;
PangoFontMap *font_map;
PangoRenderer *renderer;
CoglPangoRenderer *priv; CoglPangoRenderer *priv;
context = pango_layout_get_context (line->layout); context = pango_layout_get_context (line->layout);
font_map = pango_context_get_font_map (context); priv = cogl_pango_get_renderer_from_context (context);
g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map)); if (G_UNLIKELY (!priv))
renderer = cogl_pango_font_map_get_renderer return;
(COGL_PANGO_FONT_MAP (font_map));
priv = COGL_PANGO_RENDERER (renderer);
priv->color = *color; priv->color = *color;
pango_renderer_draw_layout_line (renderer, line, x, y); pango_renderer_draw_layout_line (PANGO_RENDERER (priv), line, x, y);
} }
void void
@ -203,19 +242,18 @@ _cogl_pango_renderer_get_use_mipmapping (CoglPangoRenderer *renderer)
static CoglPangoGlyphCacheValue * static CoglPangoGlyphCacheValue *
cogl_pango_renderer_get_cached_glyph (PangoRenderer *renderer, cogl_pango_renderer_get_cached_glyph (PangoRenderer *renderer,
PangoFont *font, PangoFont *font,
PangoGlyph glyph) PangoGlyph glyph)
{ {
CoglPangoRenderer *priv = COGL_PANGO_RENDERER (renderer); CoglPangoRenderer *priv = COGL_PANGO_RENDERER (renderer);
CoglPangoGlyphCacheValue *value; CoglPangoGlyphCacheValue *value;
CoglPangoGlyphCache *glyph_cache; CoglPangoGlyphCache *glyph_cache;
glyph_cache = priv->use_mipmapping glyph_cache = priv->use_mipmapping ? priv->mipmapped_glyph_cache
? priv->mipmapped_glyph_cache : priv->glyph_cache; : priv->glyph_cache;
if ((value = cogl_pango_glyph_cache_lookup (glyph_cache, value = cogl_pango_glyph_cache_lookup (glyph_cache, font, glyph);
font, if (value == NULL)
glyph)) == NULL)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
@ -245,13 +283,13 @@ cogl_pango_renderer_get_cached_glyph (PangoRenderer *renderer,
cairo_surface_flush (surface); cairo_surface_flush (surface);
/* Copy the glyph to the cache */ /* Copy the glyph to the cache */
value = cogl_pango_glyph_cache_set value =
(glyph_cache, font, glyph, cogl_pango_glyph_cache_set (glyph_cache, font, glyph,
cairo_image_surface_get_data (surface), cairo_image_surface_get_data (surface),
cairo_image_surface_get_width (surface), cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface), cairo_image_surface_get_height (surface),
cairo_image_surface_get_stride (surface), cairo_image_surface_get_stride (surface),
ink_rect.x, ink_rect.y); ink_rect.x, ink_rect.y);
cairo_surface_destroy (surface); cairo_surface_destroy (surface);
@ -267,21 +305,18 @@ void
cogl_pango_ensure_glyph_cache_for_layout (PangoLayout *layout) cogl_pango_ensure_glyph_cache_for_layout (PangoLayout *layout)
{ {
PangoContext *context; PangoContext *context;
PangoFontMap *fontmap;
PangoRenderer *renderer; PangoRenderer *renderer;
PangoLayoutIter *iter; PangoLayoutIter *iter;
g_return_if_fail (PANGO_IS_LAYOUT (layout)); 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 (COGL_PANGO_IS_FONT_MAP (fontmap));
renderer = cogl_pango_font_map_get_renderer
(COGL_PANGO_FONT_MAP (fontmap));
if ((iter = pango_layout_get_iter (layout)) == NULL) if ((iter = pango_layout_get_iter (layout)) == NULL)
return; return;
context = pango_layout_get_context (layout);
renderer =
PANGO_RENDERER (cogl_pango_get_renderer_from_context (context));
do do
{ {
PangoLayoutLine *line; PangoLayoutLine *line;
@ -300,8 +335,8 @@ cogl_pango_ensure_glyph_cache_for_layout (PangoLayout *layout)
PangoGlyphInfo *gi = &glyphs->glyphs[i]; PangoGlyphInfo *gi = &glyphs->glyphs[i];
cogl_pango_renderer_get_cached_glyph (renderer, cogl_pango_renderer_get_cached_glyph (renderer,
run->item->analysis.font, run->item->analysis.font,
gi->glyph); gi->glyph);
} }
} }
} }
@ -368,34 +403,36 @@ cogl_pango_renderer_get_device_units (PangoRenderer *renderer,
} }
static void static void
cogl_pango_renderer_draw_rectangle (PangoRenderer *renderer, cogl_pango_renderer_draw_rectangle (PangoRenderer *renderer,
PangoRenderPart part, PangoRenderPart part,
int x, int x,
int y, int y,
int width, int width,
int height) int height)
{ {
CoglFixed x1, x2, y1, y2; CoglFixed x1, x2, y1, y2;
cogl_pango_renderer_set_color_for_part (renderer, part); cogl_pango_renderer_set_color_for_part (renderer, part);
cogl_pango_renderer_get_device_units (renderer, x, y, cogl_pango_renderer_get_device_units (renderer,
&x1, &y1); x, y,
cogl_pango_renderer_get_device_units (renderer, x + width, y + height, &x1, &y1);
&x2, &y2); cogl_pango_renderer_get_device_units (renderer,
x + width, y + height,
&x2, &y2);
cogl_rectanglex (x1, y1, x2 - x1, y2 - y1); cogl_rectanglex (x1, y1, x2 - x1, y2 - y1);
} }
static void static void
cogl_pango_renderer_draw_trapezoid (PangoRenderer *renderer, cogl_pango_renderer_draw_trapezoid (PangoRenderer *renderer,
PangoRenderPart part, PangoRenderPart part,
double y1, double y1,
double x11, double x11,
double x21, double x21,
double y2, double y2,
double x12, double x12,
double x22) double x22)
{ {
CoglFixed points[8]; CoglFixed points[8];
@ -416,10 +453,10 @@ cogl_pango_renderer_draw_trapezoid (PangoRenderer *renderer,
static void static void
cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer, cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer,
PangoFont *font, PangoFont *font,
PangoGlyphString *glyphs, PangoGlyphString *glyphs,
int xi, int xi,
int yi) int yi)
{ {
CoglPangoGlyphCacheValue *cache_value; CoglPangoGlyphCacheValue *cache_value;
int i; int i;