summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
Diffstat (limited to 'pango')
-rw-r--r--pango/break.c1
-rw-r--r--pango/ellipsize.c1
-rw-r--r--pango/itemize.c1
-rw-r--r--pango/pango-attr-private.h17
-rw-r--r--pango/pango-attr.c240
-rw-r--r--pango/pango-attr.h89
-rw-r--r--pango/pango-item.c1
-rw-r--r--pango/pango-line-breaker.c1
-rw-r--r--pango/pango-line.c1
-rw-r--r--pango/pango-markup.c1
-rw-r--r--pango/pango-renderer.c1
-rw-r--r--pango/pango-run.c1
-rw-r--r--pango/shape.c1
13 files changed, 237 insertions, 119 deletions
diff --git a/pango/break.c b/pango/break.c
index a4e60267..f8b5e5b4 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -25,6 +25,7 @@
#include "pango-script-private.h"
#include "pango-emoji-private.h"
#include "pango-attributes.h"
+#include "pango-attr-private.h"
#include "pango-attr-list-private.h"
#include "pango-attr-iterator-private.h"
#include "pango-break-table.h"
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index 4269fc17..97d78c74 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -26,6 +26,7 @@
#include "pango-glyph-item.h"
#include "pango-font-private.h"
#include "pango-attributes-private.h"
+#include "pango-attr-private.h"
#include "pango-attr-list-private.h"
#include "pango-attr-iterator-private.h"
#include "pango-impl-utils.h"
diff --git a/pango/itemize.c b/pango/itemize.c
index 874c1d57..f1b4fd8d 100644
--- a/pango/itemize.c
+++ b/pango/itemize.c
@@ -32,6 +32,7 @@
#include "pango-script-private.h"
#include "pango-emoji-private.h"
#include "pango-attr-iterator-private.h"
+#include "pango-attr-private.h"
#include "pango-item-private.h"
#include "pango-bidi-private.h"
diff --git a/pango/pango-attr-private.h b/pango/pango-attr-private.h
index 4dea6545..6d93bdd1 100644
--- a/pango/pango-attr-private.h
+++ b/pango/pango-attr-private.h
@@ -21,4 +21,21 @@
#include <pango/pango-attr.h>
+struct _PangoAttribute
+{
+ guint type;
+ guint start_index;
+ guint end_index;
+ union {
+ char *str_value;
+ int int_value;
+ gboolean boolean_value;
+ double double_value;
+ PangoColor color_value;
+ PangoLanguage *lang_value;
+ PangoFontDescription *font_value;
+ gpointer pointer_value;
+ };
+};
+
char * pango_attr_value_serialize (PangoAttribute *attr);
diff --git a/pango/pango-attr.c b/pango/pango-attr.c
index 211d8232..8f6f5980 100644
--- a/pango/pango-attr.c
+++ b/pango/pango-attr.c
@@ -464,6 +464,7 @@ pango_attribute_equal (const PangoAttribute *attr1,
/**
* pango_attribute_new:
* @type: the attribute type
+ * @value: pointer to the value to be copied, must be of the right type
*
* Creates a new attribute for the given type.
*
@@ -471,27 +472,72 @@ pango_attribute_equal (const PangoAttribute *attr1,
* have been registered with [func@Pango.AttrType.register].
*
* Pango will initialize @start_index and @end_index to an
- * all-inclusive range of `[0,G_MAXUINT]`. The caller is
- * responsible for filling the proper value field with the
- * desired value.
+ * all-inclusive range of `[0,G_MAXUINT]`. The value is copied.
*
* Return value: (transfer full): the newly allocated
* `PangoAttribute`, which should be freed with
* [method@Pango.Attribute.destroy]
*/
PangoAttribute *
-pango_attribute_new (guint type)
+pango_attribute_new (guint type,
+ gconstpointer value)
{
- PangoAttribute *attr;
+ PangoAttribute attr;
g_return_val_if_fail (is_valid_attr_type (type), NULL);
- attr = g_slice_new0 (PangoAttribute);
- attr->type = type;
- attr->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
- attr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END;
+ attr.type = type;
+ attr.start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
+ attr.end_index = PANGO_ATTR_INDEX_TO_TEXT_END;
- return attr;
+ switch (PANGO_ATTR_TYPE_VALUE_TYPE (type))
+ {
+ case PANGO_ATTR_VALUE_STRING:
+ attr.str_value = (char *)value;
+ break;
+ case PANGO_ATTR_VALUE_INT:
+ attr.int_value = *(int *)value;
+ break;
+ case PANGO_ATTR_VALUE_BOOLEAN:
+ attr.boolean_value = *(gboolean *)value;
+ break;
+ case PANGO_ATTR_VALUE_FLOAT:
+ attr.double_value = *(double *)value;
+ break;
+ case PANGO_ATTR_VALUE_COLOR:
+ attr.color_value = *(PangoColor *)value;
+ break;
+ case PANGO_ATTR_VALUE_LANGUAGE:
+ attr.lang_value = (PangoLanguage *)value;
+ break;
+ case PANGO_ATTR_VALUE_FONT_DESC:
+ attr.font_value = (PangoFontDescription *)value;
+ break;
+ case PANGO_ATTR_VALUE_POINTER:
+ attr.pointer_value = (gpointer)value;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ /* Copy the value */
+ return pango_attribute_copy (&attr);
+}
+
+/**
+ * pango_attribute_type:
+ * @attribute: a `PangoAttribute`
+ *
+ * Returns the type of @attribute, either a
+ * value from the [enum@Pango.AttrType] enumeration
+ * or a registered custom type.
+ *
+ * Return value: the type of `PangoAttribute`
+ */
+guint
+pango_attribute_type (const PangoAttribute *attribute)
+{
+ return attribute->type;
}
/* }}} */
@@ -527,92 +573,174 @@ pango_attr_value_serialize (PangoAttribute *attr)
/* }}} */
/* {{{ Binding Helpers */
-gboolean
-pango_attribute_get_string (PangoAttribute *attribute,
- const char **value)
+/**
+ * pango_attribute_set_range:
+ * @attribute: a `PangoAttribute`
+ * @start_index: start index
+ * @end_index: end index
+ *
+ * Sets the range of the attribute.
+ */
+void
+pango_attribute_set_range (PangoAttribute *attribute,
+ guint start_index,
+ guint end_index)
+{
+ attribute->start_index = start_index;
+ attribute->end_index = end_index;
+}
+
+/**
+ * pango_attribute_get_range:
+ * @attribute: a `PangoAttribute`
+ * @start_index: (out caller-allocates): return location for start index
+ * @end_index: (out caller-allocates): return location for end index
+ *
+ * Gets the range of the attribute.
+ */
+void
+pango_attribute_get_range (PangoAttribute *attribute,
+ guint *start_index,
+ guint *end_index)
+{
+ *start_index = attribute->start_index;
+ *end_index = attribute->end_index;
+}
+
+/**
+ * pango_attribute_get_string:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is string.
+ *
+ * Returns: (nullable): the string value
+ */
+const char *
+pango_attribute_get_string (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_STRING)
- return FALSE;
+ return NULL;
- *value = attribute->str_value;
- return TRUE;
+ return attribute->str_value;
}
-gboolean
-pango_attribute_get_language (PangoAttribute *attribute,
- PangoLanguage **value)
+/**
+ * pango_attribute_get_language:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `PangoLanguage`.
+ *
+ * Returns: (nullable): the language value
+ */
+PangoLanguage *
+pango_attribute_get_language (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_LANGUAGE)
- return FALSE;
+ return NULL;
- *value = attribute->lang_value;
- return TRUE;
+ return attribute->lang_value;
}
-gboolean
-pango_attribute_get_int (PangoAttribute *attribute,
- int *value)
+/**
+ * pango_attribute_get_int:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `int`.
+ *
+ * Returns: the integer value, or 0
+ */
+int
+pango_attribute_get_int (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_INT)
- return FALSE;
+ return 0;
- *value = attribute->int_value;
- return TRUE;
+ return attribute->int_value;
}
+/**
+ * pango_attribute_get_boolean:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `gboolean`.
+ *
+ * Returns: the boolean value, or `FALSE`
+ */
gboolean
-pango_attribute_get_boolean (PangoAttribute *attribute,
- int *value)
+pango_attribute_get_boolean (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_BOOLEAN)
return FALSE;
- *value = attribute->boolean_value;
- return TRUE;
+ return attribute->boolean_value;
}
-gboolean
-pango_attribute_get_float (PangoAttribute *attribute,
- double *value)
+/**
+ * pango_attribute_get_float:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `double`.
+ *
+ * Returns: the float value, or 0
+ */
+double
+pango_attribute_get_float (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_FLOAT)
- return FALSE;
+ return 0.;
- *value = attribute->double_value;
- return TRUE;
+ return attribute->double_value;
}
-gboolean
-pango_attribute_get_color (PangoAttribute *attribute,
- PangoColor *value)
+/**
+ * pango_attribute_get_color:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `PangoColor`.
+ *
+ * Returns: (nullable): pointer to the color value
+ */
+PangoColor *
+pango_attribute_get_color (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_COLOR)
- return FALSE;
+ return NULL;
- *value = attribute->color_value;
- return TRUE;
+ return &attribute->color_value;
}
-gboolean
-pango_attribute_get_font_desc (PangoAttribute *attribute,
- PangoFontDescription **value)
+/**
+ * pango_attribute_get_font_desc:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `PangoFontDescription`.
+ *
+ * Returns: (nullable): the font description
+ */
+PangoFontDescription *
+pango_attribute_get_font_desc (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_FONT_DESC)
- return FALSE;
+ return NULL;
- *value = attribute->font_value;
- return TRUE;
+ return attribute->font_value;
}
-gboolean
-pango_attribute_get_pointer (PangoAttribute *attribute,
- gpointer *value)
+/**
+ * pango_attribute_get_pointer:
+ * @attribute: a `PangoAttribute`
+ *
+ * Gets the value of an attribute whose value type is `gpointer`.
+ *
+ * Returns: (nullable): the pointer value
+ */
+gpointer
+pango_attribute_get_pointer (PangoAttribute *attribute)
{
if (PANGO_ATTR_VALUE_TYPE (attribute) != PANGO_ATTR_VALUE_POINTER)
- return FALSE;
+ return NULL;
- *value = attribute->pointer_value;
- return TRUE;
+ return attribute->pointer_value;
}
/* }}} */
diff --git a/pango/pango-attr.h b/pango/pango-attr.h
index 1fbbd63a..abb57130 100644
--- a/pango/pango-attr.h
+++ b/pango/pango-attr.h
@@ -127,7 +127,7 @@ typedef enum
*
* Obtains the `PangoAttrValueType of a `PangoAttribute`.
*/
-#define PANGO_ATTR_VALUE_TYPE(attr) PANGO_ATTR_TYPE_VALUE_TYPE ((attr)->type)
+#define PANGO_ATTR_VALUE_TYPE(attr) PANGO_ATTR_TYPE_VALUE_TYPE (pango_attribute_type (attr))
/**
* PANGO_ATTR_AFFECTS:
@@ -135,7 +135,7 @@ typedef enum
*
* Obtains the `PangoAttrAffects` flags of a `PangoAttribute`.
*/
-#define PANGO_ATTR_AFFECTS(attr) PANGO_ATTR_TYPE_AFFECTS ((attr)->type)
+#define PANGO_ATTR_AFFECTS(attr) PANGO_ATTR_TYPE_AFFECTS (pango_attribute_type (attr))
/**
* PANGO_ATTR_MERGE:
@@ -143,7 +143,7 @@ typedef enum
*
* Obtains the `PangoAttrMerge` flags of a `PangoAttribute`.
*/
-#define PANGO_ATTR_MERGE(attr) PANGO_ATTR_TYPE_MERGE ((attr)->type)
+#define PANGO_ATTR_MERGE(attr) PANGO_ATTR_TYPE_MERGE (pango_attribute_type (attr))
/**
* PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING:
@@ -162,49 +162,6 @@ typedef enum
#define PANGO_ATTR_INDEX_TO_TEXT_END ((guint)(G_MAXUINT + 0))
/**
- * PangoAttribute:
- * @type: the type of the attribute
- * @start_index: the start index of the range (in bytes).
- * @end_index: end index of the range (in bytes). The character at this index
- * is not included in the range.
- * @str_value: the string value
- * @int_value: the integer value
- * @boolean_value: the boolean value
- * @double_value: the double value
- * @color_value: the `PangoColor` value
- * @lang_value: the `PangoLanguage` value
- * @font_value: the `PangoFontDescription` value
- * @pointer_value: a custom value
- *
- * The `PangoAttribute` structure contains information for a single
- * attribute.
- *
- * The common portion of the attribute holds the range to which
- * the value in the type-specific part of the attribute applies.
- * By default, an attribute will have an all-inclusive range of
- * `[0,G_MAXUINT]`.
- *
- * Which of the values is used depends on the value type of the
- * attribute, which can be obtained with `PANGO_ATTR_VALUE_TYPE()`.
- */
-struct _PangoAttribute
-{
- guint type;
- guint start_index;
- guint end_index;
- union {
- char *str_value;
- int int_value;
- gboolean boolean_value;
- double double_value;
- PangoColor color_value;
- PangoLanguage *lang_value;
- PangoFontDescription *font_value;
- gpointer pointer_value;
- };
-};
-
-/**
* PangoAttrDataCopyFunc:
* @value: value to copy
*
@@ -248,33 +205,39 @@ gboolean pango_attribute_equal (const PangoAttr
const PangoAttribute *attr2) G_GNUC_PURE;
PANGO_AVAILABLE_IN_ALL
-PangoAttribute * pango_attribute_new (guint type);
+PangoAttribute * pango_attribute_new (guint type,
+ gconstpointer value);
+
+PANGO_AVAILABLE_IN_ALL
+guint pango_attribute_type (const PangoAttribute *attribute);
+
+PANGO_AVAILABLE_IN_ALL
+void pango_attribute_set_range (PangoAttribute *attribute,
+ guint start_index,
+ guint end_index);
+
+PANGO_AVAILABLE_IN_ALL
+void pango_attribute_get_range (PangoAttribute *attribute,
+ guint *start_index,
+ guint *end_index);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_string (PangoAttribute *attribute,
- const char **value);
+const char * pango_attribute_get_string (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_language (PangoAttribute *attribute,
- PangoLanguage **value);
+PangoLanguage * pango_attribute_get_language (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_int (PangoAttribute *attribute,
- int *value);
+int pango_attribute_get_int (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_boolean (PangoAttribute *attribute,
- gboolean *value);
+gboolean pango_attribute_get_boolean (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_float (PangoAttribute *attribute,
- double *value);
+double pango_attribute_get_float (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_color (PangoAttribute *attribute,
- PangoColor *value);
+PangoColor * pango_attribute_get_color (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_font_desc (PangoAttribute *attribute,
- PangoFontDescription **value);
+PangoFontDescription * pango_attribute_get_font_desc (PangoAttribute *attribute);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_attribute_get_pointer (PangoAttribute *attribute,
- gpointer *value);
+gpointer pango_attribute_get_pointer (PangoAttribute *attribute);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(PangoAttribute, pango_attribute_destroy)
diff --git a/pango/pango-item.c b/pango/pango-item.c
index f5c9df85..3c878b4d 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -21,6 +21,7 @@
#include "config.h"
#include "pango-attributes.h"
+#include "pango-attr-private.h"
#include "pango-item-private.h"
#include "pango-impl-utils.h"
diff --git a/pango/pango-line-breaker.c b/pango/pango-line-breaker.c
index 442870d0..76d125cc 100644
--- a/pango/pango-line-breaker.c
+++ b/pango/pango-line-breaker.c
@@ -6,6 +6,7 @@
#include "pango-tabs.h"
#include "pango-impl-utils.h"
#include "pango-attributes-private.h"
+#include "pango-attr-private.h"
#include "pango-attr-list-private.h"
#include "pango-attr-iterator-private.h"
#include "pango-item-private.h"
diff --git a/pango/pango-line.c b/pango/pango-line.c
index 10661e90..64b10867 100644
--- a/pango/pango-line.c
+++ b/pango/pango-line.c
@@ -5,6 +5,7 @@
#include "pango-tabs.h"
#include "pango-impl-utils.h"
#include "pango-attributes-private.h"
+#include "pango-attr-private.h"
#include "pango-attr-list-private.h"
#include "pango-attr-iterator-private.h"
#include "pango-item-private.h"
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index fb23a7d1..6b1a3398 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -27,6 +27,7 @@
#include "pango-markup.h"
#include "pango-attributes.h"
+#include "pango-attr-private.h"
#include "pango-font.h"
#include "pango-enum-types.h"
#include "pango-impl-utils.h"
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 28c8dd4b..f857bd78 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -25,6 +25,7 @@
#include "pango-renderer.h"
#include "pango-impl-utils.h"
#include "pango-layout.h"
+#include "pango-attr-private.h"
#include "pango-run-private.h"
#include "pango-line-private.h"
#include "pango-attributes-private.h"
diff --git a/pango/pango-run.c b/pango/pango-run.c
index d3138cb6..eb8dafe5 100644
--- a/pango/pango-run.c
+++ b/pango/pango-run.c
@@ -1,6 +1,7 @@
#include "config.h"
#include "pango-run-private.h"
+#include "pango-attr-private.h"
#include "pango-item-private.h"
#include "pango-impl-utils.h"
#include "pango-font-metrics-private.h"
diff --git a/pango/shape.c b/pango/shape.c
index aed65f45..79a9417e 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -28,6 +28,7 @@
#include "pango-impl-utils.h"
#include "pango-glyph.h"
+#include "pango-attr-private.h"
#include "pango-item-private.h"
#include "pango-font-private.h"
#include "pango-userfont-private.h"