summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-06-20 10:43:04 -0700
committerMatthias Clasen <mclasen@redhat.com>2022-07-04 11:17:21 -0400
commit50e813eed12fa59212b0c69df45d1acb7a31ff69 (patch)
tree8337ad603f44f5790d7282d4505dfcfca7b341a1
parent9138a932d9c56e70b0d62b5a11c3059149423153 (diff)
downloadpango-50e813eed12fa59212b0c69df45d1acb7a31ff69.tar.gz
Document attribute binding helpers
-rw-r--r--examples/cairoshape.c6
-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
-rw-r--r--tests/test-itemize.c1
-rw-r--r--tests/testattributes.c99
-rw-r--r--tests/testmisc.c27
17 files changed, 259 insertions, 230 deletions
diff --git a/examples/cairoshape.c b/examples/cairoshape.c
index 2fdb9c15..07f19b8c 100644
--- a/examples/cairoshape.c
+++ b/examples/cairoshape.c
@@ -111,8 +111,7 @@ get_layout (cairo_t *cr)
PangoAttribute *attr;
attr = pango_attr_font_desc_new (font_desc);
- attr->start_index = p - text;
- attr->end_index = attr->start_index + strlen (BULLET);
+ pango_attribute_set_range (attr, p - text, p - text + strlen (BULLET));
pango_attr_list_insert (attrs, attr);
}
@@ -121,8 +120,7 @@ get_layout (cairo_t *cr)
PangoAttribute *attr;
attr = pango_attr_font_desc_new (font_desc);
- attr->start_index = p - text;
- attr->end_index = attr->start_index + strlen (HEART);
+ pango_attribute_set_range (attr, p - text, p - text + strlen (HEART));
pango_attr_list_insert (attrs, attr);
}
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"
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index 07f7c850..3d04a897 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -31,6 +31,7 @@
#include <pango/pango.h>
#include "test-common.h"
+#include "pango/pango-attr-private.h"
#include "pango/pango-item-private.h"
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 1b1c8dac..136d8445 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -20,6 +20,7 @@
*/
#include <pango/pango.h>
+#include <pango/pango-attr-private.h>
static void
test_copy (PangoAttribute *attr)
@@ -122,7 +123,6 @@ test_attributes_register (void)
PangoAttrType type;
PangoAttribute *attr;
PangoAttribute *attr2;
- gpointer value = NULL;
gboolean ret;
PangoAttrList *list;
char *str;
@@ -138,15 +138,12 @@ test_attributes_register (void)
g_assert_cmpstr (pango_attr_type_get_name (type), ==, "my-attribute");
- attr = pango_attribute_new (type);
- attr->pointer_value = (gpointer)0x42;
+ attr = pango_attribute_new (type, (gpointer)0x42);
- ret = pango_attribute_get_pointer (attr, &value);
g_assert_true (ret);
- g_assert_true (value == (gpointer)0x42);
+ g_assert_true (pango_attribute_get_pointer (attr) == (gpointer)0x42);
- attr2 = pango_attribute_new (type);
- attr2->pointer_value = (gpointer)0x43;
+ attr2 = pango_attribute_new (type, (gpointer)0x43);
ret = pango_attribute_equal (attr, attr2);
g_assert_false (ret);
@@ -164,93 +161,6 @@ test_attributes_register (void)
}
static void
-test_binding (PangoAttribute *attr)
-{
- int int_value;
- gboolean boolean_value;
- PangoLanguage *lang_value;
- const char *string;
- PangoFontDescription *font_desc;
- PangoColor color;
- double double_value;
- gpointer pointer_value;
-
- switch (PANGO_ATTR_VALUE_TYPE (attr))
- {
- case PANGO_ATTR_VALUE_INT:
- g_assert_true (pango_attribute_get_int (attr, &int_value));
- break;
- case PANGO_ATTR_VALUE_BOOLEAN:
- g_assert_true (pango_attribute_get_boolean (attr, &boolean_value));
- break;
- case PANGO_ATTR_VALUE_LANGUAGE:
- g_assert_true (pango_attribute_get_language (attr, &lang_value));
- break;
- case PANGO_ATTR_VALUE_STRING:
- g_assert_true (pango_attribute_get_string (attr, &string));
- break;
- case PANGO_ATTR_VALUE_FONT_DESC:
- g_assert_true (pango_attribute_get_font_desc (attr, &font_desc));
- break;
- case PANGO_ATTR_VALUE_COLOR:
- g_assert_true (pango_attribute_get_color (attr, &color));
- break;
- case PANGO_ATTR_VALUE_FLOAT:
- g_assert_true (pango_attribute_get_float (attr, &double_value));
- break;
- case PANGO_ATTR_VALUE_POINTER:
- g_assert_true (pango_attribute_get_pointer (attr, &pointer_value));
- break;
- default:
- g_assert_not_reached ();
- }
-
- pango_attribute_destroy (attr);
-}
-
-static void
-test_binding_helpers (void)
-{
- PangoFontDescription *desc;
-
- test_binding (pango_attr_language_new (pango_language_from_string ("ja-JP")));
- test_binding (pango_attr_family_new ("Times"));
- test_binding (pango_attr_foreground_new (&(PangoColor){100, 200, 300, 400}));
- test_binding (pango_attr_background_new (&(PangoColor){100, 200, 300, 400}));
- test_binding (pango_attr_size_new (1024));
- test_binding (pango_attr_size_new_absolute (1024));
- test_binding (pango_attr_style_new (PANGO_STYLE_ITALIC));
- test_binding (pango_attr_weight_new (PANGO_WEIGHT_ULTRALIGHT));
- test_binding (pango_attr_variant_new (PANGO_VARIANT_SMALL_CAPS));
- test_binding (pango_attr_stretch_new (PANGO_STRETCH_SEMI_EXPANDED));
- desc = pango_font_description_from_string ("Computer Modern 12");
- test_binding (pango_attr_font_desc_new (desc));
- pango_font_description_free (desc);
- test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_SOLID));
- test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_DOTTED));
- test_binding (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
- test_binding (pango_attr_overline_new (PANGO_LINE_STYLE_SOLID));
- test_binding (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
- test_binding (pango_attr_strikethrough_new (TRUE));
- test_binding (pango_attr_strikethrough_color_new (&(PangoColor){100, 200, 300}));
- test_binding (pango_attr_rise_new (256));
- test_binding (pango_attr_scale_new (2.56));
- test_binding (pango_attr_fallback_new (FALSE));
- test_binding (pango_attr_letter_spacing_new (1024));
- test_binding (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
- test_binding (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
- test_binding (pango_attr_font_features_new ("csc=1"));
- test_binding (pango_attr_allow_breaks_new (FALSE));
- test_binding (pango_attr_show_new (PANGO_SHOW_SPACES));
- test_binding (pango_attr_insert_hyphens_new (FALSE));
- test_binding (pango_attr_text_transform_new (PANGO_TEXT_TRANSFORM_UPPERCASE));
- test_binding (pango_attr_line_height_new (1.5));
- test_binding (pango_attr_line_height_new_absolute (3000));
- test_binding (pango_attr_word_new ());
- test_binding (pango_attr_sentence_new ());
-}
-
-static void
assert_attributes (GSList *attrs,
const char *expected)
{
@@ -1466,7 +1376,6 @@ main (int argc, char *argv[])
g_test_add_func ("/attributes/basic", test_attributes_basic);
g_test_add_func ("/attributes/equal", test_attributes_equal);
g_test_add_func ("/attributes/register", test_attributes_register);
- g_test_add_func ("/attributes/binding-helpers", test_binding_helpers);
g_test_add_func ("/attributes/list/basic", test_list);
g_test_add_func ("/attributes/list/change", test_list_change);
g_test_add_func ("/attributes/list/change2", test_list_change2);
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 62a9daec..f1749c35 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -222,31 +222,34 @@ test_attr_list_update (void)
PangoAttribute *weight_attr;
PangoAttribute *fg_attr;
PangoAttrList *list;
+ guint start, end;
weight_attr = pango_attr_weight_new (700);
- weight_attr->start_index = 4;
- weight_attr->end_index = 6;
+ pango_attribute_set_range (weight_attr, 4, 6);
fg_attr = pango_attr_foreground_new (&(PangoColor){0, 0, 65535});
- fg_attr->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
- fg_attr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END;
+ pango_attribute_set_range (fg_attr, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING, PANGO_ATTR_INDEX_TO_TEXT_END);
list = pango_attr_list_new();
pango_attr_list_insert (list, weight_attr);
pango_attr_list_insert (list, fg_attr);
- g_assert_cmpuint (weight_attr->start_index, ==, 4);
- g_assert_cmpuint (weight_attr->end_index, ==, 6);
- g_assert_cmpuint (fg_attr->start_index, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING);
- g_assert_cmpuint (fg_attr->end_index, ==, PANGO_ATTR_INDEX_TO_TEXT_END);
+ pango_attribute_get_range (weight_attr, &start, &end);
+ g_assert_cmpuint (start, ==, 4);
+ g_assert_cmpuint (end, ==, 6);
+ pango_attribute_get_range (fg_attr, &start, &end);
+ g_assert_cmpuint (start, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING);
+ g_assert_cmpuint (end, ==, PANGO_ATTR_INDEX_TO_TEXT_END);
// Delete 1 byte at position 2
pango_attr_list_update (list, 2, 1, 0);
- g_assert_cmpuint (weight_attr->start_index, ==, 3);
- g_assert_cmpuint (weight_attr->end_index, ==, 5);
- g_assert_cmpuint (fg_attr->start_index, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING);
- g_assert_cmpuint (fg_attr->end_index, ==, PANGO_ATTR_INDEX_TO_TEXT_END);
+ pango_attribute_get_range (weight_attr, &start, &end);
+ g_assert_cmpuint (start, ==, 3);
+ g_assert_cmpuint (end, ==, 5);
+ pango_attribute_get_range (fg_attr, &start, &end);
+ g_assert_cmpuint (start, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING);
+ g_assert_cmpuint (end, ==, PANGO_ATTR_INDEX_TO_TEXT_END);
pango_attr_list_unref (list);
}