[goffice] GOString: avoid confusing prototype for go_string_new_rich
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOString: avoid confusing prototype for go_string_new_rich
- Date: Thu, 3 Nov 2011 16:57:38 +0000 (UTC)
commit 1e9e00aa4b6ed535525432c4c70e8d70e0490b09
Author: Morten Welinder <terra gnome org>
Date: Thu Nov 3 12:56:58 2011 -0400
GOString: avoid confusing prototype for go_string_new_rich
ChangeLog | 3 ++
goffice/graph/gog-axis.c | 5 +--
goffice/graph/gog-label.c | 16 +++++---
goffice/graph/gog-legend.c | 4 +-
goffice/graph/gog-renderer.c | 4 +-
goffice/graph/gog-series-labels.c | 4 +-
goffice/utils/go-string.c | 67 ++++++++++++++++++++++++++-----------
goffice/utils/go-string.h | 5 ++-
8 files changed, 72 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d63e51d..675e2d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2011-11-03 Morten Welinder <terra gnome org>
+ * goffice/utils/go-string.c (go_string_new_rich_nocopy): New function.
+ (go_string_new_rich): Drop "copy" argument. All callers changed.
+
* goffice/graph/gog-axis.c (map_discrete_calc_ticks): Plug leak.
* goffice/utils/go-string.c (go_string_new_rich): Plug leak.
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index 6c21ad5..0fa9f3b 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -126,7 +126,7 @@ static void
gog_axis_ticks_set_markup (GogAxisTick *ticks, char const *str, PangoAttrList *l)
{
go_string_unref (ticks->str);
- ticks->str = go_string_new_rich (str, -1, TRUE, l, NULL);
+ ticks->str = go_string_new_rich (str, -1, l, NULL);
}
static GogAxisTick *
@@ -187,8 +187,7 @@ axis_format_value (GogAxis *axis, double val, GOString **str)
*str = go_string_new ("#####");
else {
*str = go_string_new_rich
- (g_strdup (pango_layout_get_text (layout)),
- -1, FALSE,
+ (pango_layout_get_text (layout), -1,
pango_attr_list_ref
(pango_layout_get_attributes (layout)),
NULL);
diff --git a/goffice/graph/gog-label.c b/goffice/graph/gog-label.c
index 2e03a1a..9eea342 100644
--- a/goffice/graph/gog-label.c
+++ b/goffice/graph/gog-label.c
@@ -576,9 +576,11 @@ gog_text_view_size_request (GogView *v,
req->w = req->h = 0.;
if (str != NULL) {
- GOString *gostr = pl? go_string_new_rich (str, -1, FALSE,
- gog_text_get_markup (text),
- NULL): NULL;
+ GOString *gostr = pl
+ ? go_string_new_rich (str, -1,
+ gog_text_get_markup (text),
+ NULL)
+ : NULL;
GOStyle *style = go_style_dup (text->base.base.style);
double rot = fabs (style->text_layout.angle / 180 * M_PI);
if (text->rotate_frame)
@@ -614,9 +616,11 @@ gog_text_view_render (GogView *view, GogViewAllocation const *bbox)
gog_renderer_push_style (view->renderer, style);
if (str != NULL) {
- GOString *gostr = pl? go_string_new_rich (str, -1, FALSE,
- gog_text_get_markup (text),
- NULL): NULL;
+ GOString *gostr = pl
+ ? go_string_new_rich (str, -1,
+ gog_text_get_markup (text),
+ NULL)
+ : NULL;
double outline = gog_renderer_line_size (view->renderer,
goo->base.style->line.width);
if (style->fill.type != GO_STYLE_FILL_NONE || outline > 0.) {
diff --git a/goffice/graph/gog-legend.c b/goffice/graph/gog-legend.c
index adbdef1..504a827 100644
--- a/goffice/graph/gog-legend.c
+++ b/goffice/graph/gog-legend.c
@@ -278,7 +278,7 @@ cb_size_elements (unsigned i, GOStyle const *style,
GOGeometryAABR aabr;
if (l) {
- GOString *str = go_string_new_rich (name, -1, TRUE, l, NULL);
+ GOString *str = go_string_new_rich (name, -1, l, NULL);
gog_renderer_get_gostring_AABR (view->renderer, str, &aabr);
go_string_unref (str);
} else
@@ -519,7 +519,7 @@ cb_render_elements (unsigned index, GOStyle const *base_style, char const *name,
pos.y = data->y + glv->element_height / 2.0;
pos.w = pos.h = -1;
if (l) {
- GOString *str = go_string_new_rich (name, -1, TRUE, l, NULL);
+ GOString *str = go_string_new_rich (name, -1, l, NULL);
gog_renderer_draw_gostring (view->renderer, str, &pos, GO_ANCHOR_W);
go_string_unref (str);
} else
diff --git a/goffice/graph/gog-renderer.c b/goffice/graph/gog-renderer.c
index 4b19214..eb5d9ec 100644
--- a/goffice/graph/gog-renderer.c
+++ b/goffice/graph/gog-renderer.c
@@ -949,7 +949,7 @@ gog_renderer_draw_text (GogRenderer *rend, char const *text,
if (use_markup && pango_parse_markup (text, -1, 0,
&attr_list, &m_text,
NULL, NULL))
- str = go_string_new_rich (m_text, -1, FALSE, attr_list, NULL);
+ str = go_string_new_rich_nocopy (m_text, -1, attr_list, NULL);
else
str = go_string_new (text);
gog_renderer_draw_gostring (rend, str, pos, anchor);
@@ -1033,7 +1033,7 @@ gog_renderer_get_text_OBR (GogRenderer *rend, char const *text,
if (use_markup && pango_parse_markup (text, -1, 0,
&attr_list, &m_text,
NULL, NULL))
- str = go_string_new_rich (m_text, -1, FALSE, attr_list, NULL);
+ str = go_string_new_rich_nocopy (m_text, -1, attr_list, NULL);
else
str = go_string_new (text);
gog_renderer_get_gostring_OBR (rend, str, obr);
diff --git a/goffice/graph/gog-series-labels.c b/goffice/graph/gog-series-labels.c
index 076090d..7a03ca1 100644
--- a/goffice/graph/gog-series-labels.c
+++ b/goffice/graph/gog-series-labels.c
@@ -837,7 +837,7 @@ gog_data_label_update (GogObject *obj)
format = next;
}
}
- lbl->element.str = go_string_new_rich (g_string_free (str, FALSE), -1, FALSE, markup, NULL);
+ lbl->element.str = go_string_new_rich_nocopy (g_string_free (str, FALSE), -1, markup, NULL);
}
static void
@@ -1275,7 +1275,7 @@ gog_series_labels_update (GogObject *obj)
format = next;
}
}
- labels->elements[i].str = go_string_new_rich (g_string_free (str, FALSE), -1, FALSE, markup, NULL);
+ labels->elements[i].str = go_string_new_rich_nocopy (g_string_free (str, FALSE), -1, markup, NULL);
}
}
} else
diff --git a/goffice/utils/go-string.c b/goffice/utils/go-string.c
index 84ba42d..6aefa0c 100644
--- a/goffice/utils/go-string.c
+++ b/goffice/utils/go-string.c
@@ -201,22 +201,12 @@ go_string_new_nocopy (char *str)
return str ? go_string_new_nocopy_len (str, strlen (str)) : NULL;
}
-/**
- * go_string_new_rich :
- * @str : string.
- * @byte_len : < 0 will call strlen.
- * @copy : %TRUE @str should be copied when adding to the string table.
- * @markup : optionally %NULL list, GOString steals the ref.
- * @phonetic : optionally %NULL list of phonetic extensions, GOString steals the ref.
- *
- * Returns: a string.
- **/
-GOString *
-go_string_new_rich (char const *str,
- int byte_len,
- gboolean copy,
- PangoAttrList *markup,
- GOStringPhonetic *phonetic)
+static GOString *
+go_string_new_rich_impl (char *str,
+ int byte_len,
+ gboolean take_ownership,
+ PangoAttrList *markup,
+ GOStringPhonetic *phonetic)
{
GOStringImpl *base;
GOStringRichImpl *rich;
@@ -241,11 +231,12 @@ go_string_new_rich (char const *str,
rich->phonetic = phonetic;
base = g_hash_table_lookup (go_strings_base, rich);
if (NULL == base) {
- if (copy) rich->base.base.str = g_strndup (str, byte_len);
+ if (!take_ownership)
+ rich->base.base.str = g_strndup (str, byte_len);
g_hash_table_insert (go_strings_base, rich, rich);
} else {
go_string_ref (&base->base);
- if (!copy)
+ if (take_ownership)
g_free (str);
rich->base.base.str = base->base.str;
rich->base.flags |= GO_STRING_IS_DEPENDENT;
@@ -263,6 +254,43 @@ go_string_new_rich (char const *str,
return &rich->base.base;
}
+/**
+ * go_string_new_rich :
+ * @str : string.
+ * @byte_len : < 0 will call strlen.
+ * @markup : optionally %NULL list, GOString steals the ref.
+ * @phonetic : optionally %NULL list of phonetic extensions, GOString steals the ref.
+ *
+ * Returns: a string.
+ **/
+GOString *
+go_string_new_rich (char const *str,
+ int byte_len,
+ PangoAttrList *markup,
+ GOStringPhonetic *phonetic)
+{
+ return go_string_new_rich_impl ((char *)str, byte_len, FALSE,
+ markup, phonetic);
+}
+
+/**
+ * go_string_new_rich_nocopy :
+ * @str : string; GOString takes ownership
+ * @byte_len : < 0 will call strlen.
+ * @markup : optionally %NULL list, GOString steals the ref.
+ * @phonetic : optionally %NULL list of phonetic extensions, GOString steals the ref.
+ *
+ * Returns: a string.
+ **/
+GOString *
+go_string_new_rich_nocopy (char *str,
+ int byte_len,
+ PangoAttrList *markup,
+ GOStringPhonetic *phonetic)
+{
+ return go_string_new_rich_impl (str, byte_len, TRUE, markup, phonetic);
+}
+
GOString *
go_string_ref (GOString *gstr)
{
@@ -715,6 +743,5 @@ go_string_trim (GOString *gstr, gboolean internal)
go_string_unref (gstr);
- return go_string_new_rich (text, -1, FALSE, attrs, NULL);
+ return go_string_new_rich_nocopy (text, -1, attrs, NULL);
}
-
diff --git a/goffice/utils/go-string.h b/goffice/utils/go-string.h
index 8391d08..eea3a9e 100644
--- a/goffice/utils/go-string.h
+++ b/goffice/utils/go-string.h
@@ -42,7 +42,10 @@ GOString *go_string_new_nocopy (char *str);
GOString *go_string_new_nocopy_len (char *str, guint32 len);
GOString *go_string_new_rich (char const *str,
int byte_len,
- gboolean copy,
+ PangoAttrList *markup,
+ GOStringPhonetic *phonetic);
+GOString *go_string_new_rich_nocopy (char *str,
+ int byte_len,
PangoAttrList *markup,
GOStringPhonetic *phonetic);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]