2009-07-29 12:21:07 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* 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 library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:cogl-pango
|
|
|
|
* @short_description: COGL-based text rendering using Pango
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "cogl-pango.h"
|
|
|
|
#include "cogl-pango-private.h"
|
2012-05-10 07:16:03 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl/cogl-context-private.h"
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
static GQuark cogl_pango_font_map_get_priv_key (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
typedef struct _CoglPangoFontMapPriv
|
|
|
|
{
|
|
|
|
CoglContext *ctx;
|
|
|
|
PangoRenderer *renderer;
|
|
|
|
} CoglPangoFontMapPriv;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_priv (gpointer data)
|
|
|
|
{
|
|
|
|
CoglPangoFontMapPriv *priv = data;
|
|
|
|
|
|
|
|
cogl_object_unref (priv->ctx);
|
|
|
|
cogl_object_unref (priv->renderer);
|
|
|
|
|
|
|
|
g_free (priv);
|
|
|
|
}
|
2009-07-29 12:21:07 -04:00
|
|
|
|
|
|
|
PangoFontMap *
|
|
|
|
cogl_pango_font_map_new (void)
|
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoFontMap *fm = pango_cairo_font_map_new ();
|
|
|
|
CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (context, NULL);
|
|
|
|
|
|
|
|
priv->ctx = cogl_object_ref (context);
|
|
|
|
|
|
|
|
/* XXX: The public pango api doesn't let us sub-class
|
|
|
|
* PangoCairoFontMap so we attach our own private data using qdata
|
|
|
|
* for now. */
|
|
|
|
g_object_set_qdata_full (G_OBJECT (fm),
|
|
|
|
cogl_pango_font_map_get_priv_key (),
|
|
|
|
priv,
|
|
|
|
free_priv);
|
|
|
|
|
|
|
|
return fm;
|
2009-07-29 12:21:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PangoContext *
|
|
|
|
cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
|
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (COGL_PANGO_IS_FONT_MAP (fm), NULL);
|
2009-07-29 12:21:07 -04:00
|
|
|
|
|
|
|
/* 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));
|
|
|
|
}
|
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
static CoglPangoFontMapPriv *
|
|
|
|
_cogl_pango_font_map_get_priv (CoglPangoFontMap *fm)
|
2009-07-29 12:21:07 -04:00
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
return g_object_get_qdata (G_OBJECT (fm),
|
|
|
|
cogl_pango_font_map_get_priv_key ());
|
|
|
|
}
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoRenderer *
|
|
|
|
_cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
|
|
|
|
{
|
|
|
|
CoglPangoFontMapPriv *priv = _cogl_pango_font_map_get_priv (fm);
|
|
|
|
if (G_UNLIKELY (!priv->renderer))
|
|
|
|
priv->renderer = _cogl_pango_renderer_new (priv->ctx);
|
|
|
|
return priv->renderer;
|
|
|
|
}
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoRenderer *
|
|
|
|
cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
|
|
|
|
{
|
|
|
|
return _cogl_pango_font_map_get_renderer (fm);
|
|
|
|
}
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
CoglContext *
|
|
|
|
_cogl_pango_font_map_get_cogl_context (CoglPangoFontMap *fm)
|
|
|
|
{
|
|
|
|
CoglPangoFontMapPriv *priv = _cogl_pango_font_map_get_priv (fm);
|
|
|
|
return priv->ctx;
|
2009-07-29 12:21:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
|
|
|
|
double dpi)
|
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (COGL_PANGO_IS_FONT_MAP (font_map));
|
2009-07-29 12:21:07 -04:00
|
|
|
|
|
|
|
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
|
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 12:21:07 -04:00
|
|
|
|
|
|
|
_cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool value)
|
2009-07-29 12:21:07 -04:00
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
_cogl_pango_renderer_set_use_mipmapping (COGL_PANGO_RENDERER (renderer),
|
|
|
|
value);
|
2009-07-29 12:21:07 -04:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool
|
2009-07-29 12:21:07 -04:00
|
|
|
cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm)
|
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
return
|
|
|
|
_cogl_pango_renderer_get_use_mipmapping (COGL_PANGO_RENDERER (renderer));
|
2009-07-29 12:21:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GQuark
|
2012-05-10 07:16:03 -04:00
|
|
|
cogl_pango_font_map_get_priv_key (void)
|
2009-07-29 12:21:07 -04:00
|
|
|
{
|
2012-05-10 07:16:03 -04:00
|
|
|
static GQuark priv_key = 0;
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
if (G_UNLIKELY (priv_key == 0))
|
|
|
|
priv_key = g_quark_from_static_string ("CoglPangoFontMap");
|
2009-07-29 12:21:07 -04:00
|
|
|
|
2012-05-10 07:16:03 -04:00
|
|
|
return priv_key;
|
2009-07-29 12:21:07 -04:00
|
|
|
}
|