[pango/wip/matthiasc/alpha: 2/4] Add alpha support to PangoRenderer
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/wip/matthiasc/alpha: 2/4] Add alpha support to PangoRenderer
- Date: Wed, 12 Aug 2015 00:41:53 +0000 (UTC)
commit 884db27321c7eb381fbec23fa445cc481bf546b7
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 11 15:35:21 2015 -0400
Add alpha support to PangoRenderer
Add pango_renderer_get/set_alpha to allow associating alpha
values with the various colors. The alpha is stored as a value
between 0 and 65536, with 0 meaning 'unset'.
docs/pango-sections.txt | 2 +
pango/pango-renderer.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++
pango/pango-renderer.h | 6 ++++
3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index fa45b24..ec6a2fb 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -687,6 +687,8 @@ pango_renderer_deactivate
pango_renderer_part_changed
pango_renderer_set_color
pango_renderer_get_color
+pango_renderer_set_alpha
+pango_renderer_get_alpha
pango_renderer_set_matrix
pango_renderer_get_matrix
pango_renderer_get_layout
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index d7dfa03..a2f6ea4 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -53,6 +53,7 @@ struct _PangoRendererPrivate
{
PangoColor color[N_RENDER_PARTS];
gboolean color_set[N_RENDER_PARTS];
+ guint16 alpha[N_RENDER_PARTS];
PangoLayoutLine *line;
LineState *line_state;
@@ -1143,6 +1144,7 @@ pango_renderer_deactivate (PangoRenderer *renderer)
* @color: (allow-none): the new color or %NULL to unset the current color
*
* Sets the color for part of the rendering.
+ * Also see pango_renderer_set_alpha().
*
* Since: 1.8
**/
@@ -1201,6 +1203,59 @@ pango_renderer_get_color (PangoRenderer *renderer,
}
/**
+ * pango_renderer_set_alpha:
+ * @renderer: a #PangoRenderer
+ * @part: the part to set the alpha for
+ * @alpha: an alpha value between 1 and 65536, or 0 to unset the alpha
+ *
+ * Sets the alpha for part of the rendering.
+ * Note that the alpha may only be used if a color is
+ * specified for @part as well.
+ *
+ * Since: 1.38
+ */
+void
+pango_renderer_set_alpha (PangoRenderer *renderer,
+ PangoRenderPart part,
+ guint16 alpha)
+{
+ g_return_if_fail (PANGO_IS_RENDERER_FAST (renderer));
+ g_return_if_fail (IS_VALID_PART (part));
+
+ if ((!alpha && !renderer->priv->alpha[part]) ||
+ (alpha && renderer->priv->alpha[part] &&
+ renderer->priv->alpha[part] == alpha))
+ return;
+
+ pango_renderer_part_changed (renderer, part);
+
+ renderer->priv->alpha[part] = alpha;
+}
+
+/**
+ * pango_renderer_get_alpha:
+ * @renderer: a #PangoRenderer
+ * @part: the part to get the alpha for
+ *
+ * Gets the current alpha for the specified part.
+ *
+ * Return value: the alpha for the specified part,
+ * or 0 if it hasn't been set and should be
+ * inherited from the environment.
+ *
+ * Since: 1.38
+ */
+guint16
+pango_renderer_get_alpha (PangoRenderer *renderer,
+ PangoRenderPart part)
+{
+ g_return_val_if_fail (PANGO_IS_RENDERER_FAST (renderer), NULL);
+ g_return_val_if_fail (IS_VALID_PART (part), NULL);
+
+ return renderer->priv->alpha[part];
+}
+
+/**
* pango_renderer_part_changed:
* @renderer: a #PangoRenderer
* @part: the part for which rendering has changed.
@@ -1261,6 +1316,8 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
PangoColor *bg_color = NULL;
PangoColor *underline_color = NULL;
PangoColor *strikethrough_color = NULL;
+ guint16 fg_alpha = 0;
+ guint16 bg_alpha = 0;
GSList *l;
renderer->underline = PANGO_UNDERLINE_NONE;
@@ -1296,6 +1353,14 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
strikethrough_color = &((PangoAttrColor *)attr)->color;
break;
+ case PANGO_ATTR_FOREGROUND_ALPHA:
+ fg_alpha = ((PangoAttrInt *)attr)->value;
+ break;
+
+ case PANGO_ATTR_BACKGROUND_ALPHA:
+ bg_alpha = ((PangoAttrInt *)attr)->value;
+ break;
+
default:
break;
}
@@ -1311,6 +1376,11 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
pango_renderer_set_color (renderer, PANGO_RENDER_PART_BACKGROUND, bg_color);
pango_renderer_set_color (renderer, PANGO_RENDER_PART_UNDERLINE, underline_color);
pango_renderer_set_color (renderer, PANGO_RENDER_PART_STRIKETHROUGH, strikethrough_color);
+
+ pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_FOREGROUND, fg_alpha);
+ pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_BACKGROUND, bg_alpha);
+ pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_UNDERLINE, fg_alpha);
+ pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_STRIKETHROUGH, fg_alpha);
}
/**
diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h
index 63d9e65..2127a4c 100644
--- a/pango/pango-renderer.h
+++ b/pango/pango-renderer.h
@@ -248,6 +248,12 @@ void pango_renderer_set_color (PangoRenderer *renderer,
PangoColor *pango_renderer_get_color (PangoRenderer *renderer,
PangoRenderPart part);
+void pango_renderer_set_alpha (PangoRenderer *renderer,
+ PangoRenderPart part,
+ guint16 alpha);
+guint16 pango_renderer_get_alpha (PangoRenderer *renderer,
+ PangoRenderPart part);
+
void pango_renderer_set_matrix (PangoRenderer *renderer,
const PangoMatrix *matrix);
const PangoMatrix *pango_renderer_get_matrix (PangoRenderer *renderer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]