2009-07-29 16:21:07 +00:00
|
|
|
/*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Cogl
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 OpenedHand
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2009-07-29 16:21:07 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
2023-08-07 13:38:12 +00:00
|
|
|
#include "cogl-pango/cogl-pango.h"
|
|
|
|
#include "cogl-pango/cogl-pango-private.h"
|
|
|
|
#include "cogl/cogl-util.h"
|
2012-05-10 11:16:03 +00:00
|
|
|
#include "cogl/cogl-context-private.h"
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00: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);
|
2023-08-21 10:36:54 +00:00
|
|
|
g_object_unref (priv->renderer);
|
2012-05-10 11:16:03 +00:00
|
|
|
|
|
|
|
g_free (priv);
|
|
|
|
}
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
PangoFontMap *
|
|
|
|
cogl_pango_font_map_new (void)
|
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
PangoFontMap *fm = pango_cairo_font_map_new ();
|
2019-07-09 09:13:09 +00:00
|
|
|
g_autofree CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
|
2012-05-10 11:16:03 +00:00
|
|
|
|
|
|
|
_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 (),
|
2019-07-09 09:13:09 +00:00
|
|
|
g_steal_pointer (&priv),
|
2012-05-10 11:16:03 +00:00
|
|
|
free_priv);
|
|
|
|
|
|
|
|
return fm;
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PangoContext *
|
|
|
|
cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
|
|
|
|
{
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2015-06-10 14:14:30 +00:00
|
|
|
#if PANGO_VERSION_CHECK (1, 22, 0)
|
2009-07-29 16:21:07 +00:00
|
|
|
/* We can just directly use the pango context from the Cairo font
|
|
|
|
map */
|
2015-06-10 14:14:30 +00:00
|
|
|
return pango_font_map_create_context (PANGO_FONT_MAP (fm));
|
|
|
|
#else
|
2009-07-29 16:21:07 +00:00
|
|
|
return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
|
2015-06-10 14:14:30 +00:00
|
|
|
#endif
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
static CoglPangoFontMapPriv *
|
|
|
|
_cogl_pango_font_map_get_priv (CoglPangoFontMap *fm)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
return g_object_get_qdata (G_OBJECT (fm),
|
|
|
|
cogl_pango_font_map_get_priv_key ());
|
|
|
|
}
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00: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 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
PangoRenderer *
|
|
|
|
cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
|
|
|
|
{
|
|
|
|
return _cogl_pango_font_map_get_renderer (fm);
|
|
|
|
}
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00: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 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
|
|
|
|
double dpi)
|
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map));
|
2009-07-29 16:21:07 +00: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 11:16:03 +00:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
_cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean value)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
_cogl_pango_renderer_set_use_mipmapping (COGL_PANGO_RENDERER (renderer),
|
|
|
|
value);
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean
|
2009-07-29 16:21:07 +00:00
|
|
|
cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm)
|
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
return
|
|
|
|
_cogl_pango_renderer_get_use_mipmapping (COGL_PANGO_RENDERER (renderer));
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GQuark
|
2012-05-10 11:16:03 +00:00
|
|
|
cogl_pango_font_map_get_priv_key (void)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
static GQuark priv_key = 0;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
if (G_UNLIKELY (priv_key == 0))
|
|
|
|
priv_key = g_quark_from_static_string ("CoglPangoFontMap");
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-05-10 11:16:03 +00:00
|
|
|
return priv_key;
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|