summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-05-28 01:23:41 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-05-28 01:23:41 +0000
commit2c10e7197f33eb1bf6d8771de13b241263dc041b (patch)
treee3b713a250de056d23ff2410bdcccb8ee8df623a /pango
parent1a23b2c124df6830bc8a8027bd8b38ccc2c75531 (diff)
downloadpango-2c10e7197f33eb1bf6d8771de13b241263dc041b.tar.gz
s/pango_font_set_data/g_object_set_qdata/
Sat May 27 21:06:13 2000 Owen Taylor <otaylor@redhat.com> * modules/thai/thai.c modules/basic/basic: s/pango_font_set_data/g_object_set_qdata/ * pango/*.c: s/pango_font_[un]ref/g_object_un[ref] * pango/pango-font.h fonts.c: GObject'ify PangoFont.
Diffstat (limited to 'pango')
-rw-r--r--pango/fonts.c122
-rw-r--r--pango/pango-context.c8
-rw-r--r--pango/pango-font.h37
-rw-r--r--pango/pango-fontmap.c17
-rw-r--r--pango/pango-item.c4
-rw-r--r--pango/pango-layout.c2
-rw-r--r--pango/pangox-fontmap.c6
-rw-r--r--pango/pangox-private.h4
-rw-r--r--pango/pangox.c165
9 files changed, 146 insertions, 219 deletions
diff --git a/pango/fonts.c b/pango/fonts.c
index bfe022fd..4914c6f0 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -361,102 +361,32 @@ pango_font_description_to_string (const PangoFontDescription *desc)
return str;
}
-/**
- * pango_font_init:
- * @font: a #PangoFont
- *
- * Initialize a #PangoFont structure. This should
- * only be called from the "new" routine of code which
- * is implementing a "subclass" of #PangoFont
- */
-void
-pango_font_init (PangoFont *font)
+GType
+pango_font_get_type (void)
{
- g_return_if_fail (font != NULL);
-
- g_datalist_init (&font->data);
- font->ref_count = 1;
-}
+ static GType object_type = 0;
-/**
- * pango_font_ref:
- * @font: a #PangoFont
- *
- * Increase the reference count of a #PangoFont.
- */
-void
-pango_font_ref (PangoFont *font)
-{
- g_return_if_fail (font != NULL);
-
- font->ref_count++;
-}
-
-
-/**
- * pango_font_unref:
- * @font: a #PangoFont
- *
- * Decrease the reference count of a #PangoFont.
- * if the result is zero, destroy the font
- * and free the associated memory.
- */
-void
-pango_font_unref (PangoFont *font)
-{
- g_return_if_fail (font != NULL);
- g_return_if_fail (font->ref_count > 0);
-
- font->ref_count--;
- if (font->ref_count == 0)
+ if (!object_type)
{
- g_datalist_clear (&font->data);
- font->klass->destroy (font);
+ static const GTypeInfo object_info =
+ {
+ sizeof (PangoFontClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ NULL, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (PangoFont),
+ 0, /* n_preallocs */
+ NULL /* init */
+ };
+
+ object_type = g_type_register_static (G_TYPE_OBJECT,
+ "PangoFont",
+ &object_info);
}
-}
-
-/**
- * pango_font_set_data:
- * @font: a #PangoFont
- * @key: a string identifying the type of user data.
- * @data: the data to store. If %NULL, the current
- * data for the key will be removed.
- * @destroy_func: a function to call when the data is no
- * longer stored, either because the font has
- * been destroyed, or because the data has
- * been replaced. This can be %NULL, in which
- * case no function will be called.
- *
- * Associate user data, tagged with a string id, with a particular
- * font.
- */
-void
-pango_font_set_data (PangoFont *font,
- const gchar *key,
- gpointer data,
- GDestroyNotify destroy_func)
-{
- g_return_if_fail (font != NULL);
-
- g_datalist_set_data_full (&font->data, key, data, destroy_func);
-}
-
-/**
- * pango_font_get_data:
- * @font: a #PangoFont
- * @key: a string identifying the type of user data.
- *
- * Look up user data tagged with a particular key.
- *
- * Returns the data, or NULL if that key does not exist.
- */
-gpointer
-pango_font_get_data (PangoFont *font,
- const gchar *key)
-{
- g_return_val_if_fail (font != NULL, NULL);
-
- return g_datalist_get_data (&font->data, key);
+
+ return object_type;
}
/**
@@ -474,7 +404,7 @@ pango_font_get_coverage (PangoFont *font,
{
g_return_val_if_fail (font != NULL, NULL);
- return font->klass->get_coverage (font, lang);
+ return PANGO_FONT_GET_CLASS (font)->get_coverage (font, lang);
}
/**
@@ -495,7 +425,7 @@ pango_font_find_shaper (PangoFont *font,
{
g_return_val_if_fail (font != NULL, NULL);
- return font->klass->find_shaper (font, lang, ch);
+ return PANGO_FONT_GET_CLASS (font)->find_shaper (font, lang, ch);
}
/**
@@ -523,7 +453,7 @@ pango_font_get_glyph_extents (PangoFont *font,
{
g_return_if_fail (font != NULL);
- font->klass->get_glyph_extents (font, glyph, ink_rect, logical_rect);
+ PANGO_FONT_GET_CLASS (font)->get_glyph_extents (font, glyph, ink_rect, logical_rect);
}
/**
@@ -547,5 +477,5 @@ pango_font_get_metrics (PangoFont *font,
{
g_return_if_fail (font != NULL);
- font->klass->get_metrics (font, lang, metrics);
+ PANGO_FONT_GET_CLASS (font)->get_metrics (font, lang, metrics);
}
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 60a54a7d..e34262b1 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -618,7 +618,7 @@ pango_itemize (PangoContext *context,
result = g_list_prepend (result, item);
}
else
- pango_font_unref (fonts[i]);
+ g_object_unref (G_OBJECT (fonts[i]));
item->length = (next - text) - item->offset;
item->num_chars++;
@@ -662,7 +662,7 @@ get_font (PangoFont **fonts,
}
if (result)
- pango_font_ref (result);
+ g_object_ref (G_OBJECT (result));
return result;
}
@@ -748,7 +748,7 @@ add_engines (PangoContext *context,
{
if (current_fonts[j])
{
- pango_font_unref (current_fonts[j]);
+ g_object_unref (G_OBJECT (current_fonts[j]));
pango_coverage_unref (current_coverages[j]);
}
}
@@ -795,7 +795,7 @@ add_engines (PangoContext *context,
{
if (current_fonts[j])
{
- pango_font_unref (current_fonts[j]);
+ g_object_unref (G_OBJECT (current_fonts[j]));
pango_coverage_unref (current_coverages[j]);
}
}
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 62d18e44..eefae335 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -29,8 +29,9 @@ extern "C" {
#include <pango/pango-coverage.h>
#include <pango/pango-types.h>
+#include <glib-object.h>
+
typedef struct _PangoFontDescription PangoFontDescription;
-typedef struct _PangoFontClass PangoFontClass;
typedef struct _PangoFontMetrics PangoFontMetrics;
typedef enum {
@@ -92,18 +93,25 @@ char * pango_font_description_to_string (const PangoFontDescrip
/* Logical fonts
*/
+
+typedef struct _PangoFontClass PangoFontClass;
+
+#define PANGO_TYPE_FONT (pango_font_get_type ())
+#define PANGO_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FONT, PangoFont))
+#define PANGO_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONT, PangoFontClass))
+#define PANGO_IS_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_FONT))
+#define PANGO_IS_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_FONT))
+#define PANGO_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_FONT, PangoFontClass))
+
struct _PangoFont
{
- PangoFontClass *klass;
-
- /*< private >*/
- gint ref_count;
- GData *data;
+ GObject parent_instance;
};
struct _PangoFontClass
{
- void (*destroy) (PangoFont *font);
+ GObjectClass parent_class;
+
PangoFontDescription *(*describe) (PangoFont *font);
PangoCoverage * (*get_coverage) (PangoFont *font,
const char *lang);
@@ -119,16 +127,7 @@ struct _PangoFontClass
PangoFontMetrics *metrics);
};
-void pango_font_init (PangoFont *font);
-void pango_font_ref (PangoFont *font);
-void pango_font_unref (PangoFont *font);
-gpointer pango_font_get_data (PangoFont *font,
- const gchar *key);
-void pango_font_set_data (PangoFont *font,
- const gchar *key,
- gpointer data,
- GDestroyNotify destroy_func);
-
+GType pango_font_get_type (void);
PangoFontDescription *pango_font_describe (PangoFont *font);
PangoCoverage * pango_font_get_coverage (PangoFont *font,
@@ -144,10 +143,6 @@ void pango_font_get_glyph_extents (PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
-/*
- * Font Map
- */
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index c5cadec3..58a9eee7 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -21,9 +21,6 @@
#include "pango-fontmap.h"
-static void pango_font_map_init (PangoFontMap *fontmap);
-static void pango_font_map_class_init (PangoFontMapClass *class);
-
GType
pango_font_map_get_type (void)
{
@@ -36,12 +33,12 @@ pango_font_map_get_type (void)
sizeof (PangoFontMapClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) pango_font_map_class_init,
+ NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (PangoFontMap),
0, /* n_preallocs */
- (GInstanceInitFunc) pango_font_map_init,
+ NULL /* init */
};
object_type = g_type_register_static (G_TYPE_OBJECT,
@@ -52,16 +49,6 @@ pango_font_map_get_type (void)
return object_type;
}
-static void
-pango_font_map_init (PangoFontMap *fontmap)
-{
-}
-
-static void
-pango_font_map_class_init (PangoFontMapClass *class)
-{
-}
-
/**
* pango_font_map_load_font:
* @fontmap: a #PangoFontMap
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 826552f8..d3e0dbd9 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -66,7 +66,7 @@ pango_item_copy (PangoItem *item)
result->extra_attrs = g_slist_reverse (extra_attrs);
result->analysis = item->analysis;
- pango_font_ref (result->analysis.font);
+ g_object_ref (G_OBJECT (result->analysis.font));
return result;
}
@@ -83,7 +83,7 @@ pango_item_free (PangoItem *item)
if (item->extra_attrs)
g_slist_foreach (item->extra_attrs, (GFunc)pango_attribute_destroy, NULL);
- pango_font_unref (item->analysis.font);
+ g_object_unref (G_OBJECT (item->analysis.font));
g_free (item);
}
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9cfa39f8..80a9d824 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -2153,7 +2153,7 @@ pango_layout_line_get_empty_extents (PangoLayoutLine *line,
logical_rect->y = - metrics.ascent;
logical_rect->height = metrics.ascent + metrics.descent;
- pango_font_unref (font);
+ g_object_unref (G_OBJECT (font));
}
else
{
diff --git a/pango/pangox-fontmap.c b/pango/pangox-fontmap.c
index 49cbfb06..4b4f0463 100644
--- a/pango/pangox-fontmap.c
+++ b/pango/pangox-fontmap.c
@@ -466,7 +466,7 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
if (xfont->size == description->size)
{
result = (PangoFont *)xfont;
- pango_font_ref (result);
+ g_object_ref (G_OBJECT (result));
break;
}
tmp_list = tmp_list->next;
@@ -474,7 +474,7 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
if (!result)
{
- result = pango_x_load_font_with_size (xfontmap->display, best_match->xlfd, description->size);
+ result = (PangoFont *)pango_x_font_new (xfontmap->display, best_match->xlfd, description->size);
((PangoXFont *)result)->entry = best_match;
best_match->cached_fonts = g_slist_prepend (best_match->cached_fonts, result);
}
@@ -482,7 +482,7 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
/* HORRIBLE performance hack until some better caching scheme is arrived at
*/
if (result)
- pango_font_ref (result);
+ g_object_ref (G_OBJECT (result));
}
}
diff --git a/pango/pangox-private.h b/pango/pangox-private.h
index 345213d5..e627bd44 100644
--- a/pango/pangox-private.h
+++ b/pango/pangox-private.h
@@ -54,8 +54,8 @@ struct _PangoXFont
PangoXFontEntry *entry; /* Used to remove cached fonts */
};
-PangoFont * pango_x_load_font_with_size (Display *display,
- char *spec,
+PangoXFont * pango_x_font_new (Display *display,
+ const char *spec,
int size);
PangoMap * pango_x_get_shaper_map (const char *lang);
char * pango_x_make_matching_xlfd (PangoFontMap *fontmap,
diff --git a/pango/pangox.c b/pango/pangox.c
index 407aa574..c08d26aa 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -32,8 +32,15 @@
#include <config.h>
+#define PANGO_TYPE_X_FONT (pango_x_font_get_type ())
+#define PANGO_X_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_X_FONT, PangoXFont))
+#define PANGO_X_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_X_FONT, PangoXFontClass))
+#define PANGO_IS_X_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_X_FONT))
+#define PANGO_IS_X_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_X_FONT))
+#define PANGO_X_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_X_FONT, PangoXFontClass))
+
+typedef struct _PangoXFontClass PangoXFontClass;
typedef struct _PangoXMetricsInfo PangoXMetricsInfo;
-
typedef struct _PangoXContextInfo PangoXContextInfo;
struct _PangoXSubfontInfo
@@ -57,7 +64,15 @@ struct _PangoXContextInfo
PangoFreeGCFunc free_gc_func;
};
-static void pango_x_font_destroy (PangoFont *font);
+struct _PangoXFontClass
+{
+ PangoFontClass parent_class;
+};
+
+static void pango_x_font_class_init (PangoXFontClass *class);
+static void pango_x_font_init (PangoXFont *xfont);
+static void pango_x_font_finalize (GObject *object);
+
static PangoFontDescription *pango_x_font_describe (PangoFont *font);
static PangoCoverage * pango_x_font_get_coverage (PangoFont *font,
const char *lang);
@@ -91,15 +106,6 @@ static void pango_x_get_item_properties (PangoItem *item,
PangoAttrColor *bg_color,
gboolean *bg_set);
-PangoFontClass pango_x_font_class = {
- pango_x_font_destroy,
- pango_x_font_describe,
- pango_x_font_get_coverage,
- pango_x_font_find_shaper,
- pango_x_font_get_glyph_extents,
- pango_x_font_get_metrics
-};
-
static inline PangoXSubfontInfo *
pango_x_find_subfont (PangoFont *font,
PangoXSubfont subfont_index)
@@ -190,95 +196,105 @@ pango_x_context_set_funcs (PangoContext *context,
info->free_gc_func = free_gc_func;
}
-/**
- * pango_x_load_font:
- * @display: the X display
- * @spec: a comma-separated list of XLFD's
- *
- * Loads up a logical font based on a "fontset" style
- * text specification.
- *
- * Returns a new #PangoFont
- */
-PangoFont *
-pango_x_load_font (Display *display,
- char *spec)
+static GType
+pango_x_font_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type)
+ {
+ static const GTypeInfo object_info =
+ {
+ sizeof (PangoXFontClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) pango_x_font_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (PangoXFont),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) pango_x_font_init,
+ };
+
+ object_type = g_type_register_static (PANGO_TYPE_FONT,
+ "PangoXFont",
+ &object_info);
+ }
+
+ return object_type;
+}
+
+static void
+pango_x_font_init (PangoXFont *xfont)
+{
+ xfont->subfonts_by_charset = g_hash_table_new (g_str_hash, g_str_equal);
+ xfont->subfonts = g_new (PangoXSubfontInfo *, 1);
+
+ xfont->n_subfonts = 0;
+ xfont->max_subfonts = 1;
+
+ xfont->metrics_by_lang = NULL;
+
+ xfont->size = -1;
+ xfont->entry = NULL;
+}
+
+static void
+pango_x_font_class_init (PangoXFontClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PangoFontClass *font_class = PANGO_FONT_CLASS (class);
+
+ object_class->finalize = pango_x_font_finalize;
+ font_class->describe = pango_x_font_describe;
+ font_class->get_coverage = pango_x_font_get_coverage;
+ font_class->find_shaper = pango_x_font_find_shaper;
+ font_class->get_glyph_extents = pango_x_font_get_glyph_extents;
+ font_class->get_metrics = pango_x_font_get_metrics;
+}
+
+PangoXFont *
+pango_x_font_new (Display *display, const char *spec, int size)
{
PangoXFont *result;
g_return_val_if_fail (display != NULL, NULL);
g_return_val_if_fail (spec != NULL, NULL);
-
- result = g_new (PangoXFont, 1);
+ result = (PangoXFont *)g_type_create_instance (PANGO_TYPE_X_FONT);
+
result->display = display;
- pango_font_init (&result->font);
- result->font.klass = &pango_x_font_class;
-
result->fonts = g_strsplit(spec, ",", -1);
-
for (result->n_fonts = 0; result->fonts[result->n_fonts]; result->n_fonts++)
; /* Nothing */
- result->subfonts_by_charset = g_hash_table_new (g_str_hash, g_str_equal);
- result->subfonts = g_new (PangoXSubfontInfo *, 1);
-
- result->n_subfonts = 0;
- result->max_subfonts = 1;
-
- result->metrics_by_lang = NULL;
+ result->size = size;
- result->size = -1;
- result->entry = NULL;
-
- return (PangoFont *)result;
+ return result;
}
-
+
/**
- * pango_x_load_font_with_size:
+ * pango_x_load_font:
* @display: the X display
- * @spec: a comma-separated list of XLFD's, unsized
- * @size: the size at which to load the font
+ * @spec: a comma-separated list of XLFD's
*
- * Load up a logical font based on a "fontset" style
+ * Loads up a logical font based on a "fontset" style
* text specification.
*
* Returns a new #PangoFont
*/
PangoFont *
-pango_x_load_font_with_size (Display *display,
- char *spec,
- int size)
+pango_x_load_font (Display *display,
+ char *spec)
{
PangoXFont *result;
g_return_val_if_fail (display != NULL, NULL);
g_return_val_if_fail (spec != NULL, NULL);
- result = g_new (PangoXFont, 1);
-
- result->display = display;
+ result = pango_x_font_new (display, spec, -1);
- pango_font_init (&result->font);
- result->font.klass = &pango_x_font_class;
-
- result->fonts = g_strsplit(spec, ",", -1);
-
- for (result->n_fonts = 0; result->fonts[result->n_fonts]; result->n_fonts++)
- ; /* Nothing */
-
- result->subfonts_by_charset = g_hash_table_new (g_str_hash, g_str_equal);
- result->subfonts = g_new (PangoXSubfontInfo *, 1);
-
- result->n_subfonts = 0;
- result->max_subfonts = 1;
-
- result->metrics_by_lang = NULL;
-
- result->size = size;
- result->entry = NULL;
-
return (PangoFont *)result;
}
@@ -847,9 +863,9 @@ subfonts_foreach (gpointer key, gpointer value, gpointer data)
}
static void
-pango_x_font_destroy (PangoFont *font)
+pango_x_font_finalize (GObject *object)
{
- PangoXFont *xfont = (PangoXFont *)font;
+ PangoXFont *xfont = (PangoXFont *)object;
int i;
for (i=0; i<xfont->n_subfonts; i++)
@@ -872,10 +888,9 @@ pango_x_font_destroy (PangoFont *font)
g_slist_free (xfont->metrics_by_lang);
if (xfont->entry)
- pango_x_font_entry_remove (xfont->entry, font);
+ pango_x_font_entry_remove (xfont->entry, (PangoFont *)xfont);
g_strfreev (xfont->fonts);
- g_free (font);
}
static PangoFontDescription *