summaryrefslogtreecommitdiff
path: root/pango/pango-coverage.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-02-16 22:05:43 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-02-16 22:05:43 +0000
commit7f846326d416e9ab3eadca9f02b9a0129095f30b (patch)
tree4b2812b858cd830ca1282e3697d029ca347df24a /pango/pango-coverage.c
parent4f335d6e4a3f5b4e6ddd1cd78f919aa80c990262 (diff)
downloadpango-7f846326d416e9ab3eadca9f02b9a0129095f30b.tar.gz
Make refcounted.
Wed Feb 16 16:39:46 2000 Owen Taylor <otaylor@redhat.com> * libpango/pango-coverage.c (pango_coverage_get): Make refcounted. * libpango/modules.c (struct _PangoEnginePair): Since we don't currently unload engines, cache loaded engines. (Not really quite satisfactory, but should work OK) * libpango/pango-context.c (pango_context_get_font_description): Added a global font description. * libpango/modules.c (_pango_find_map): Allow NULL language tags. * libpango/pango-context.c (pango_itemize) examples/viewer.c: Switch itemize over to take a PangoAttrList. * examples/viewer.c: Conform to changes in itemization interface * libpango/font.[ch]: Add a compare function for FontDescription * libpango/pango-attributes.[ch]: Change the iteration iterface to be more convenient. * libpango/pango-context.[ch]: Add the ability to set a default font. * libpango/pango-context.[ch]: Take the font for itemization from the attributes on the text. * libpango/pangox.c: Cache currently loaded fonts, and cache coverages.
Diffstat (limited to 'pango/pango-coverage.c')
-rw-r--r--pango/pango-coverage.c51
1 files changed, 40 insertions, 11 deletions
diff --git a/pango/pango-coverage.c b/pango/pango-coverage.c
index d6ce8812..cc9ca246 100644
--- a/pango/pango-coverage.c
+++ b/pango/pango-coverage.c
@@ -39,6 +39,7 @@ struct _PangoBlockInfo
struct _PangoCoverage
{
+ guint ref_count;
int n_blocks;
int data_size;
@@ -50,7 +51,8 @@ struct _PangoCoverage
*
* Create a new #PangoCoverage
*
- * Return value: a new PangoCoverage object, initialized to PANGO_COVERAGE_NONE
+ * Return value: a new PangoCoverage object, initialized to %PANGO_COVERAGE_NONE
+ * with a reference count of 0.
**/
PangoCoverage *
pango_coverage_new (void)
@@ -60,6 +62,7 @@ pango_coverage_new (void)
coverage->n_blocks = N_BLOCKS_INCREMENT;
coverage->blocks = g_new (PangoBlockInfo, coverage->n_blocks);
+ coverage->ref_count = 1;
for (i=0; i<coverage->n_blocks; i++)
{
@@ -74,9 +77,11 @@ pango_coverage_new (void)
* pango_coverage_copy:
* @coverage: a #PangoCoverage
*
- * Copy an existing #PangoCoverage
+ * Copy an existing #PangoCoverage. (This function may now be unecessary
+ * since we refcount the structure. Mail otaylor@redhat.com if you
+ * use it.)
*
- * Return value: a copy of @coverage
+ * Return value: a copy of @coverage with a reference count of 1
**/
PangoCoverage *
pango_coverage_copy (PangoCoverage *coverage)
@@ -88,6 +93,7 @@ pango_coverage_copy (PangoCoverage *coverage)
result->n_blocks = coverage->n_blocks;
result->blocks = g_new (PangoBlockInfo, coverage->n_blocks);
+ result->ref_count = 1;
for (i=0; i<coverage->n_blocks; i++)
{
@@ -106,24 +112,47 @@ pango_coverage_copy (PangoCoverage *coverage)
}
/**
- * pango_coverage_destroy:
+ * pango_coverage_ref:
* @coverage: a #PangoCoverage
*
- * Destroy a #PangoCoverage object, freeing associated memory
+ * Increase the reference count on the #PangoCoverage by one
**/
-void pango_coverage_destroy (PangoCoverage *coverage)
+void
+pango_coverage_ref (PangoCoverage *coverage)
+{
+ g_return_if_fail (coverage != NULL);
+
+ coverage->ref_count++;
+}
+
+/**
+ * pango_coverage_unref:
+ * @coverage: a #PangoCoverage
+ *
+ * Increase the reference count on the #PangoCoverage by one.
+ * if the result is zero, free the coverage and all associated memory.
+ **/
+void
+pango_coverage_unref (PangoCoverage *coverage)
{
int i;
g_return_if_fail (coverage != NULL);
+ g_return_if_fail (coverage->ref_count > 0);
- for (i=0; i<coverage->n_blocks; i++)
+ coverage->ref_count--;
+
+ if (coverage->ref_count == 0)
{
- if (coverage->blocks[i].data)
- g_free (coverage->blocks[i].data);
+ for (i=0; i<coverage->n_blocks; i++)
+ {
+ if (coverage->blocks[i].data)
+ g_free (coverage->blocks[i].data);
+ }
+
+ g_free (coverage->blocks);
+ g_free (coverage);
}
-
- g_free (coverage);
}
/**