diff options
author | Havoc Pennington <hp@redhat.com> | 2000-06-21 03:57:02 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2000-06-21 03:57:02 +0000 |
commit | 197a2a68c145d3568cd4f0f2fee3d3b55570134f (patch) | |
tree | 6089cb6806eae9126d39a71f2966a56342f8db49 /pango | |
parent | e2dc9e117648e267953d7318bd3e0093cd5ab234 (diff) | |
download | pango-197a2a68c145d3568cd4f0f2fee3d3b55570134f.tar.gz |
GTK+ should compile now... sorry about the mess...
2000-06-14 Havoc Pennington <hp@redhat.com>
* pango/pango-attributes.c (pango_attr_list_copy): Function to
copy the attribute list.
2000-06-13 Havoc Pennington <hp@redhat.com>
* pango/pango-layout.h: Convert PangoLayout to GObject
* pango/pango-context.h: Convert to
PangoContext to GObject
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-attributes.c | 36 | ||||
-rw-r--r-- | pango/pango-attributes.h | 1 | ||||
-rw-r--r-- | pango/pango-context.c | 170 | ||||
-rw-r--r-- | pango/pango-context.h | 24 | ||||
-rw-r--r-- | pango/pango-layout.c | 142 | ||||
-rw-r--r-- | pango/pango-layout.h | 23 | ||||
-rw-r--r-- | pango/pangox.c | 11 |
7 files changed, 246 insertions, 161 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 47171e01..695fa0f8 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -614,6 +614,42 @@ pango_attr_list_unref (PangoAttrList *list) } /** + * pango_attr_list_copy: + * @list: a #PangoAttrList + * + * Copy @list and return an identical, new list. + * + * Return value: new attribute list + **/ +PangoAttrList * +pango_attr_list_copy (PangoAttrList *list) +{ + PangoAttrList *new; + GSList *iter; + GSList *new_attrs; + + g_return_val_if_fail (list != NULL, NULL); + + new = pango_attr_list_new (); + + iter = list->attributes; + new_attrs = NULL; + while (iter != NULL) + { + new_attrs = g_slist_prepend (new_attrs, + pango_attribute_copy (iter->data)); + + iter = g_slist_next (iter); + } + + /* we're going to reverse the nodes, so head becomes tail */ + new->attributes_tail = new_attrs; + new->attributes = g_slist_reverse (new_attrs); + + return new; +} + +/** * pango_attr_list_insert: * @list: a #PangoAttrList * @attr: the attribute to insert. Ownership of this value is diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index e7b362c0..3e34d011 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -131,6 +131,7 @@ PangoAttribute *pango_attr_rise_new (int rise); PangoAttrList * pango_attr_list_new (void); void pango_attr_list_ref (PangoAttrList *list); void pango_attr_list_unref (PangoAttrList *list); +PangoAttrList * pango_attr_list_copy (PangoAttrList *list); void pango_attr_list_insert (PangoAttrList *list, PangoAttribute *attr); void pango_attr_list_change (PangoAttrList *list, diff --git a/pango/pango-context.c b/pango/pango-context.c index cc672383..b967000b 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -29,14 +29,19 @@ struct _PangoContext { - gint ref_count; + GObject parent_instance; char *lang; PangoDirection base_dir; PangoFontDescription *font_desc; GSList *font_maps; - GData *data; +}; + +struct _PangoContextClass +{ + GObjectClass parent_class; + }; static void add_engines (PangoContext *context, @@ -48,24 +53,48 @@ static void add_engines (PangoContext *context, PangoFont **fonts, GSList **extra_attr_lists); -/** - * pango_context_new: - * - * Creates a new #PangoContext initialized to default value. - * - * Return value: the new #PangoContext - **/ -PangoContext * -pango_context_new (void) +static void pango_context_init (PangoContext *context); +static void pango_context_class_init (PangoContextClass *klass); +static void pango_context_finalize (GObject *object); + +static gpointer parent_class; + +GType +pango_context_get_type (void) { - PangoContext *result = g_new (PangoContext, 1); - PangoFontDescription desc; + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoContextClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_context_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoContext), + 0, /* n_preallocs */ + (GInstanceInitFunc) pango_context_init, + }; + + object_type = g_type_register_static (G_TYPE_OBJECT, + "PangoContext", + &object_info); + } - result->ref_count = 1; - result->base_dir = PANGO_DIRECTION_LTR; - result->lang = NULL; - result->font_maps = NULL; - result->data = NULL; + return object_type; +} + +static void +pango_context_init (PangoContext *context) +{ + PangoFontDescription desc; + + context->base_dir = PANGO_DIRECTION_LTR; + context->lang = NULL; + context->font_maps = NULL; desc.family_name = "serif"; desc.style = PANGO_STYLE_NORMAL; @@ -73,48 +102,53 @@ pango_context_new (void) desc.weight = PANGO_WEIGHT_NORMAL; desc.stretch = PANGO_STRETCH_NORMAL; - result->font_desc = pango_font_description_copy (&desc); + context->font_desc = pango_font_description_copy (&desc); +} + +static void +pango_context_class_init (PangoContextClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); - return result; + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = pango_context_finalize; } -/** - * pango_context_ref: - * @context: a #PangoContext - * - * Increases the reference count of a #PangoContext. - **/ -void -pango_context_ref (PangoContext *context) +static void +pango_context_finalize (GObject *object) { - g_return_if_fail (context != NULL); + PangoContext *context; + + context = PANGO_CONTEXT (object); - context->ref_count++; + if (context->lang) + g_free (context->lang); + + g_slist_foreach (context->font_maps, (GFunc)g_object_unref, NULL); + g_slist_free (context->font_maps); + + G_OBJECT_CLASS (parent_class)->finalize (object); } /** - * pango_context_unref: - * @context: a #PangoContext - * - * Decreases the reference count of a #PangoContext. - * if the result is zero, destroy the context - * and free the associated memory. - */ -void -pango_context_unref (PangoContext *context) + * pango_context_new: + * + * Creates a new #PangoContext initialized to default value. + * + * Return value: the new #PangoContext + **/ +PangoContext * +pango_context_new (void) { - g_return_if_fail (context != NULL); + PangoContext *context; - context->ref_count--; - if (context->ref_count == 0) - { - if (context->lang) - g_free (context->lang); - - g_slist_foreach (context->font_maps, (GFunc)g_object_unref, NULL); - g_slist_free (context->font_maps); - } + g_type_init (); + + context = PANGO_CONTEXT (g_type_create_instance (pango_context_get_type ())); + + return context; } /** @@ -458,44 +492,6 @@ pango_context_get_base_dir (PangoContext *context) } /** - * pango_context_set_data: - * @context: a #PangoContext - * @key: the string key that identifies the data - * @data: the data to store - * @destroy_func: the function to free @data when it is no longer needed (may be %NULL) - * - * Adds user data to a #PangoContext. - **/ -void -pango_context_set_data (PangoContext *context, - const char *key, - gpointer data, - GDestroyNotify destroy_func) -{ - g_return_if_fail (context != NULL); - - g_datalist_set_data_full (&context->data, key, data, destroy_func); -} - -/** - * pango_context_get_data: - * @context: a #PangoContext - * @key: the string key that identifies the data - * - * Retrieves user data from a #PangoContext - * - * Return value: the data, if @key was found, or %NULL. - **/ -gpointer -pango_context_get_data (PangoContext *context, - const char *key) -{ - g_return_val_if_fail (context != NULL, NULL); - - return g_datalist_get_data (&context->data, key); -} - -/** * pango_itemize: * @context: a structure holding information that affects the itemization process. diff --git a/pango/pango-context.h b/pango/pango-context.h index ba2144d1..8c180e3e 100644 --- a/pango/pango-context.h +++ b/pango/pango-context.h @@ -33,11 +33,23 @@ extern "C" { /* Sort of like a GC - application set information about how * to handle scripts */ -typedef struct _PangoContext PangoContext; +typedef struct _PangoContext PangoContext; +typedef struct _PangoContextClass PangoContextClass; +#define PANGO_TYPE_CONTEXT (pango_context_get_type ()) +#define PANGO_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CONTEXT, PangoContext)) +#define PANGO_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_CONTEXT, PangoContextClass)) +#define PANGO_IS_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CONTEXT)) +#define PANGO_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CONTEXT)) +#define PANGO_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_CONTEXT, PangoContextClass)) + + +/* The PangoContext and PangoContextClass structs are private; if you + * need to create a subclass of these, mail otaylor@redhat.com + */ + +GType pango_context_get_type (void); PangoContext *pango_context_new (void); -void pango_context_ref (PangoContext *context); -void pango_context_unref (PangoContext *context); void pango_context_add_font_map (PangoContext *context, PangoFontMap *font_map); void pango_context_list_fonts (PangoContext *context, @@ -60,12 +72,6 @@ void pango_context_set_base_dir (PangoContext PangoDirection direction); PangoDirection pango_context_get_base_dir (PangoContext *context); -void pango_context_set_data (PangoContext *context, - const char *key, - gpointer data, - GDestroyNotify destroy_func); -gpointer pango_context_get_data (PangoContext *context, - const char *key); /* Break a string of Unicode characters into segments with * consistent shaping/language engine and bidrectional level. diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 0953d9a3..c1b1e514 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -28,9 +28,15 @@ typedef struct _PangoLayoutLinePrivate PangoLayoutLinePrivate; -struct _PangoLayout +struct _PangoLayoutLinePrivate { + PangoLayoutLine line; guint ref_count; +}; + +struct _PangoLayout +{ + GObject parent_instance; PangoContext *context; PangoAttrList *attrs; @@ -51,10 +57,11 @@ struct _PangoLayout GSList *lines; }; -struct _PangoLayoutLinePrivate +struct _PangoLayoutClass { - PangoLayoutLine line; - guint ref_count; + GObjectClass parent_class; + + }; static void pango_layout_clear_lines (PangoLayout *layout); @@ -71,29 +78,43 @@ static int *pango_layout_line_get_vis2log_map (PangoLayoutLine *line, static void pango_layout_get_item_properties (PangoItem *item, PangoUnderline *uline); -/** - * pango_layout_new: - * @context: a #PangoContext - * - * Create a new #PangoLayout object with attributes initialized to - * default values for a particular #PangoContext. - * - * Return value: a new #PangoLayout, with a reference count of one. - **/ -PangoLayout * -pango_layout_new (PangoContext *context) -{ - PangoLayout *layout; - - g_return_val_if_fail (context != NULL, NULL); +static void pango_layout_init (PangoLayout *layout); +static void pango_layout_class_init (PangoLayoutClass *klass); +static void pango_layout_finalize (GObject *object); - layout = g_new (PangoLayout, 1); +static gpointer parent_class; - layout->ref_count = 1; +GType +pango_layout_get_type (void) +{ + static GType object_type = 0; - layout->context = context; - pango_context_ref (context); + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoLayoutClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_layout_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoLayout), + 0, /* n_preallocs */ + (GInstanceInitFunc) pango_layout_init, + }; + + object_type = g_type_register_static (G_TYPE_OBJECT, + "PangoLayout", + &object_info); + } + return object_type; +} + +static void +pango_layout_init (PangoLayout *layout) +{ layout->attrs = NULL; layout->text = NULL; layout->length = 0; @@ -106,53 +127,62 @@ pango_layout_new (PangoContext *context) layout->log_attrs = NULL; layout->lines = NULL; - layout->tab_width = -1; + layout->tab_width = -1; +} - return layout; +static void +pango_layout_class_init (PangoLayoutClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = pango_layout_finalize; } -/** - * pango_layout_ref: - * @layout: a #PangoLayout - * - * Increase the reference count of the #PangoLayout by one. - **/ -void -pango_layout_ref (PangoLayout *layout) +static void +pango_layout_finalize (GObject *object) { - g_return_if_fail (layout != NULL); + PangoLayout *layout; + + layout = PANGO_LAYOUT (object); + + pango_layout_clear_lines (layout); + + if (layout->context) + g_object_unref (G_OBJECT (layout->context)); + + if (layout->attrs) + pango_attr_list_unref (layout->attrs); + if (layout->text) + g_free (layout->text); - layout->ref_count++; + G_OBJECT_CLASS (parent_class)->finalize (object); } + /** - * pango_layout_unref: - * @layout: + * pango_layout_new: + * @context: a #PangoContext + * + * Create a new #PangoLayout object with attributes initialized to + * default values for a particular #PangoContext. * - * Decrease the reference count of the #PangoLayout by one. If the - * result is zero, free the #PangoLayout and all associated memory. + * Return value: a new #PangoLayout, with a reference count of one. **/ -void -pango_layout_unref (PangoLayout *layout) +PangoLayout * +pango_layout_new (PangoContext *context) { - g_return_if_fail (layout != NULL); - g_return_if_fail (layout->ref_count > 0); + PangoLayout *layout; - layout->ref_count--; - if (layout->ref_count == 0) - { - pango_layout_clear_lines (layout); + g_return_val_if_fail (context != NULL, NULL); - if (layout->context) - pango_context_unref (layout->context); - - if (layout->attrs) - pango_attr_list_unref (layout->attrs); - if (layout->text) - g_free (layout->text); + layout = PANGO_LAYOUT (g_type_create_instance (pango_layout_get_type ())); - g_free (layout); - } + layout->context = context; + g_object_ref (G_OBJECT (context)); + + return layout; } /** diff --git a/pango/pango-layout.h b/pango/pango-layout.h index da3b1e1f..034794d9 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -30,9 +30,10 @@ extern "C" { #endif /* __cplusplus */ -typedef struct _PangoLayout PangoLayout; -typedef struct _PangoLayoutLine PangoLayoutLine; -typedef struct _PangoLayoutRun PangoLayoutRun; +typedef struct _PangoLayout PangoLayout; +typedef struct _PangoLayoutClass PangoLayoutClass; +typedef struct _PangoLayoutLine PangoLayoutLine; +typedef struct _PangoLayoutRun PangoLayoutRun; typedef enum { PANGO_ALIGN_LEFT, @@ -53,10 +54,20 @@ struct _PangoLayoutRun PangoGlyphString *glyphs; }; -PangoLayout *pango_layout_new (PangoContext *context); -void pango_layout_ref (PangoLayout *layout); -void pango_layout_unref (PangoLayout *layout); +#define PANGO_TYPE_LAYOUT (pango_layout_get_type ()) +#define PANGO_LAYOUT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_LAYOUT, PangoLayout)) +#define PANGO_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_LAYOUT, PangoLayoutClass)) +#define PANGO_IS_LAYOUT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_LAYOUT)) +#define PANGO_IS_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_LAYOUT)) +#define PANGO_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_LAYOUT, PangoLayoutClass)) + +/* The PangoLayout and PangoLayoutClass structs are private; if you + * need to create a subclass of these, mail otaylor@redhat.com + */ + +GType pango_layout_get_type (void); +PangoLayout *pango_layout_new (PangoContext *context); PangoContext *pango_layout_get_context (PangoLayout *layout); diff --git a/pango/pangox.c b/pango/pangox.c index b0da8d7b..b2f3ca0d 100644 --- a/pango/pangox.c +++ b/pango/pangox.c @@ -171,7 +171,9 @@ pango_x_get_context (Display *display) info = g_new (PangoXContextInfo, 1); info->get_gc_func = NULL; info->free_gc_func = NULL; - pango_context_set_data (result, "pango-x-info", info, (GDestroyNotify)g_free); + g_object_set_qdata_full (G_OBJECT (result), + g_quark_from_static_string ("pango-x-info"), + info, (GDestroyNotify)g_free); pango_context_add_font_map (result, pango_x_font_map_for_display (display)); @@ -196,7 +198,8 @@ pango_x_context_set_funcs (PangoContext *context, g_return_if_fail (context != NULL); - info = pango_context_get_data (context, "pango-x-info"); + info = g_object_get_qdata (G_OBJECT (context), + g_quark_from_static_string ("pango-x-info")); info->get_gc_func = get_gc_func; info->free_gc_func = free_gc_func; @@ -1150,7 +1153,9 @@ pango_x_render_layout_line (Display *display, PangoRectangle logical_rect; PangoRectangle ink_rect; PangoContext *context = pango_layout_get_context (line->layout); - PangoXContextInfo *info = pango_context_get_data (context, "pango-x-info"); + PangoXContextInfo *info = + g_object_get_qdata (G_OBJECT (context), + g_quark_from_static_string ("pango-x-info")); int x_off = 0; |