[librsvg] RsvgNodeChars: Make private; provide an accessor rsvg_node_chars_get_string()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] RsvgNodeChars: Make private; provide an accessor rsvg_node_chars_get_string()
- Date: Wed, 6 Dec 2017 01:51:18 +0000 (UTC)
commit e4a3de8455d944346c1062895a97d3186e2e9cb2
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 5 17:44:21 2017 -0600
RsvgNodeChars: Make private; provide an accessor rsvg_node_chars_get_string()
rsvg-base.c | 16 ++++++++++++++++
rsvg-private.h | 6 ++----
rsvg-text.c | 34 ++++++++++++++++++++++++++--------
3 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index a845553..cde82a4 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -882,6 +882,10 @@ rsvg_end_element (void *data, const xmlChar * xmlname)
}
}
+typedef struct {
+ GString *contents;
+} RsvgNodeChars;
+
static void
rsvg_node_chars_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, RsvgPropertyBag * atts)
{
@@ -947,6 +951,18 @@ rsvg_new_node_chars (RsvgNode *parent)
return node;
}
+void
+rsvg_node_chars_get_string (RsvgNode *node, const char **out_str, gsize *out_len)
+{
+ RsvgNodeChars *chars;
+
+ g_assert (rsvg_node_get_type (node) == RSVG_NODE_TYPE_CHARS);
+ chars = rsvg_rust_cnode_get_impl (node);
+
+ *out_str = chars->contents->str;
+ *out_len = chars->contents->len;
+}
+
static gboolean
find_last_chars_node (RsvgNode *node, gpointer data)
{
diff --git a/rsvg-private.h b/rsvg-private.h
index 0af0b49..f2bb025 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -53,7 +53,6 @@ typedef struct _RsvgState RsvgState;
typedef struct _RsvgDefs RsvgDefs;
typedef struct _RsvgNode RsvgNode;
typedef struct _RsvgFilter RsvgFilter;
-typedef struct _RsvgNodeChars RsvgNodeChars;
/* prepare for gettext */
#ifndef _
@@ -425,9 +424,8 @@ void rsvg_node_foreach_child (RsvgNode *node, RsvgNodeForeachChildFn fn, gpointe
G_GNUC_INTERNAL
void rsvg_node_draw_children (RsvgNode *node, RsvgDrawingCtx *ctx, int dominate);
-struct _RsvgNodeChars {
- GString *contents;
-};
+G_GNUC_INTERNAL
+void rsvg_node_chars_get_string (RsvgNode *node, const char **out_str, gsize *out_len);
typedef void (*RsvgPropertyBagEnumFunc) (const char *key, const char *value, gpointer user_data);
diff --git a/rsvg-text.c b/rsvg-text.c
index 3c20e39..a114b8c 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -186,10 +186,19 @@ draw_text_child (RsvgNode *node, gpointer data)
closure = data;
if (type == RSVG_NODE_TYPE_CHARS) {
- RsvgNodeChars *chars = rsvg_rust_cnode_get_impl (node);
- GString *str = _rsvg_text_chomp (rsvg_current_state (closure->ctx), chars->contents,
closure->lastwasspace);
- rsvg_text_render_text (closure->ctx, str->str, closure->x, closure->y);
- g_string_free (str, TRUE);
+ const char *chars_str;
+ gsize chars_len;
+ GString *string;
+ GString *chomped;
+
+ rsvg_node_chars_get_string (node, &chars_str, &chars_len);
+ string = g_string_new_len (chars_str, chars_len);
+
+ chomped = _rsvg_text_chomp (rsvg_current_state (closure->ctx), string, closure->lastwasspace);
+ g_string_free (string, TRUE);
+
+ rsvg_text_render_text (closure->ctx, chomped->str, closure->x, closure->y);
+ g_string_free (chomped, TRUE);
} else {
if (closure->usetextonly) {
_rsvg_node_text_type_children (node,
@@ -288,10 +297,19 @@ compute_child_length (RsvgNode *node, gpointer data)
rsvg_state_reinherit_top (closure->ctx, rsvg_node_get_state (node), 0);
if (type == RSVG_NODE_TYPE_CHARS) {
- RsvgNodeChars *chars = rsvg_rust_cnode_get_impl (node);
- GString *str = _rsvg_text_chomp (rsvg_current_state (closure->ctx), chars->contents,
closure->lastwasspace);
- *closure->length += rsvg_text_length_text_as_string (closure->ctx, str->str);
- g_string_free (str, TRUE);
+ const char *chars_str;
+ gsize chars_len;
+ GString *string;
+ GString *chomped;
+
+ rsvg_node_chars_get_string (node, &chars_str, &chars_len);
+ string = g_string_new_len (chars_str, chars_len);
+
+ chomped = _rsvg_text_chomp (rsvg_current_state (closure->ctx), string, closure->lastwasspace);
+ g_string_free (string, TRUE);
+
+ *closure->length += rsvg_text_length_text_as_string (closure->ctx, chomped->str);
+ g_string_free (chomped, TRUE);
} else {
if (closure->usetextonly) {
done = _rsvg_node_text_length_children (node,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]