[cairo-commit] 2 commits - src/cairo-scaled-font-subsets.c src/cairo-scaled-font-subsets-private.h

Carl Worth cworth at kemper.freedesktop.org
Wed May 10 19:09:34 PDT 2006


 src/cairo-scaled-font-subsets-private.h |  109 +++++++++++++++++++++++++++++++-
 src/cairo-scaled-font-subsets.c         |    2 
 2 files changed, 108 insertions(+), 3 deletions(-)

New commits:
diff-tree 1ba537be18316154781e36fb66545f82afb3c3a0 (from 7bd3a037daadaed5b720d9590a479320de533af5)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 10 19:01:40 2006 -0700

    Fix memory leak in _cairo_scaled_font_subsets_foreach

diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 12eda92..4d8f4bb 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -379,5 +379,7 @@ _cairo_scaled_font_subsets_foreach (cair
     _cairo_hash_table_foreach (font_subsets->sub_fonts,
 			       _cairo_sub_font_collect, &collection);
 
+    free (collection.glyphs);
+
     return CAIRO_STATUS_SUCCESS;
 }
diff-tree 7bd3a037daadaed5b720d9590a479320de533af5 (from 7c137b7e2ccbe76bb7870756a8fd29458b571a71)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 10 18:52:36 2006 -0700

    Add documentation for the _cairo_scaled_font_subsets interface.

diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h
index 2c5c0dc..d4137d4 100644
--- a/src/cairo-scaled-font-subsets-private.h
+++ b/src/cairo-scaled-font-subsets-private.h
@@ -53,24 +53,127 @@ typedef struct _cairo_scaled_font_subset
     int num_glyphs;
 } cairo_scaled_font_subset_t;
 
+/**
+ * _cairo_scaled_font_subsets_create:
+ * @max_glyphs_per_subset: the maximum number of glyphs that should
+ * appear in any subset. A value of 0 indicates that there is no limit
+ * to the number of glyphs per subset.
+ * 
+ * Create a new #cairo_scaled_font_subsets_t object which can be used
+ * to create subsets of any number of cairo_scaled_font_t
+ * objects. This allows the (arbitrarily large and sparse) glyph
+ * indices of a cairo_scaled_font to be mapped to one or more font
+ * subsets with glyph indices packed into the range
+ * [0 .. max_glyphs_per_subset).
+ * 
+ * Return value: a pointer to the newly creates font subsets. The
+ * caller owns this object and should call
+ * _cairo_scaled_font_subsets_destroy() when done with it.
+ **/
 cairo_private cairo_scaled_font_subsets_t *
 _cairo_scaled_font_subsets_create (int max_glyphs_per_subset);
 
+/**
+ * _cairo_scaled_font_subsets_destroy:
+ * @font_subsets: a #cairo_scaled_font_subsets_t object to be destroyed
+ * 
+ * Destroys @font_subsets and all resources associated with it.
+ **/
 cairo_private void
 _cairo_scaled_font_subsets_destroy (cairo_scaled_font_subsets_t *font_subsets);
 
+/**
+ * _cairo_scaled_font_subsets_map_glyph:
+ * @font_subsets: a #cairo_scaled_font_subsets_t
+ * @scaled_font: the font of the glyph to be mapped
+ * @scaled_font_glyph_index: the index of the glyph to be mapped
+ * @font_id_ret: return value giving the font ID of the mapped glyph
+ * @subset_id_ret: return value giving the subset ID of the mapped glyph within the @font_id_ret
+ * @subset_glyph_index_ret: return value giving the index of the mapped glyph within the @subset_id_ret subset
+ * 
+ * Map a glyph from a #cairo_scaled_font to a new index within a
+ * subset of that font. The mapping performed is from the tuple:
+ *
+ *	(scaled_font, scaled_font_glyph_index)
+ *
+ * to the tuple:
+ *
+ *	(font_id, subset_id, subset_glyph_index)
+ *
+ * This mapping is 1:1. If the input tuple has previously mapped, the
+ * the output tuple previously returned will be returned again.
+ *
+ * Otherwise, the return tuple will be constructed as follows:
+ *
+ * 1) There is a 1:1 correspondence between the input scaled_font
+ *    value and the output font_id value. If no mapping has been
+ *    previously performed with the scaled_font value then the
+ *    smallest unused font_id value will be returned.
+ *
+ * 2) Within the set of output tuples of the same font_id value the
+ *    smallest value of subset_id will be returned such that
+ *    subset_glyph_index does not exceed max_glyphs_per_subset (as
+ *    passed to _cairo_scaled_font_subsets_create()) and that the
+ *    resulting tuple is unique.
+ *
+ * 3) The smallest value of subset_glyph_index is returned such that
+ *    the resulting tuple is unique.
+ *
+ * The net result is that any #cairo_scaled_font_t will be represented
+ * by one or more font subsets. Each subset is effectively a tuple of
+ * (scaled_font, font_id, subset_id) and within each subset there
+ * exists a mapping of scaled_glyph_font_index to subset_glyph_index.
+ *
+ * This final description of a font subset is the same representation
+ * used by #cairo_scaled_font_subset_t as provided by
+ * _cairo_scaled_font_subsets_foreach.
+ *
+ * Return value: CAIRO_STATUS_SUCCESS if successful, or a non-zero
+ * value indicating an error. Possible errors include
+ * CAIRO_STATUS_NO_MEMORY.
+ **/
 cairo_private cairo_status_t
 _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*font_subsets,
 				      cairo_scaled_font_t		*scaled_font,
 				      unsigned long			 scaled_font_glyph_index,
-				      unsigned int			*font_id,
-				      unsigned int			*subset_id,
-				      unsigned int			*subset_glyph_index);
+				      unsigned int			*font_id_ret,
+				      unsigned int			*subset_id_ret,
+				      unsigned int			*subset_glyph_index_ret);
 
 typedef cairo_status_t
 (*cairo_scaled_font_subset_callback_func_t) (cairo_scaled_font_subset_t	*font_subset,
 					     void			*closure);
 
+/**
+ * _cairo_scaled_font_subsets_foreach:
+ * @font_subsets: a #cairo_scaled_font_subsets_t
+ * @font_subset_callback: a function to be called for each font subset
+ * @closure: closure data for the callback function
+ * 
+ * Iterate over each unique font subset as created by calls to
+ * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by
+ * unique pairs of (font_id, subset_id) as returned by
+ * _cairo_scaled_font_subsets_map_glyph().
+ *
+ * For each subset, @font_subset_callback will be called and will be
+ * provided with both a #cairo_scaled_font_subset_t object containing
+ * all the glyphs in the subset as well as the value of @closure.
+ *
+ * The #cairo_scaled_font_subset_t object contains the scaled_font,
+ * the font_id, and the subset_id corresponding to all glyphs
+ * belonging to the subset. In addition, it contains an array providing
+ * a mapping between subset glyph indices and the original scaled font
+ * glyph indices.
+ *
+ * The index of the array corresponds to subset_glyph_index values
+ * returned by _cairo_scaled_font_subsets_map_glyph() while the
+ * values of the array correspond to the scaled_font_glyph_index
+ * values passed as input to the same function.
+ * 
+ * Return value: CAIRO_STATUS_SUCCESS if successful, or a non-zero
+ * value indicating an error. Possible errors include
+ * CAIRO_STATUS_NO_MEMORY.
+ **/
 cairo_private cairo_status_t
 _cairo_scaled_font_subsets_foreach (cairo_scaled_font_subsets_t			*font_subsets,
 				    cairo_scaled_font_subset_callback_func_t	 font_subset_callback,


More information about the cairo-commit mailing list