summaryrefslogtreecommitdiff
path: root/gtk/gtktextchild.c
diff options
context:
space:
mode:
authorGeorg Vienna <georg.vienna@himbarsoft.com>2021-12-03 16:02:48 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-12-03 16:02:48 +0000
commitc517e945de399488b5c7577a25617a62bc2cb92a (patch)
treed6ef3d3db2e028476a36bd154c582efdf7221684 /gtk/gtktextchild.c
parente3a1a2e0c6b36f29173f44e4ed914b2cc9a13a98 (diff)
downloadgtk+-c517e945de399488b5c7577a25617a62bc2cb92a.tar.gz
textchildanchor: allow to specify replacement character
Diffstat (limited to 'gtk/gtktextchild.c')
-rw-r--r--gtk/gtktextchild.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/gtk/gtktextchild.c b/gtk/gtktextchild.c
index f1716efb75..2976550301 100644
--- a/gtk/gtktextchild.c
+++ b/gtk/gtktextchild.c
@@ -267,9 +267,6 @@ child_segment_check_func (GtkTextLineSegment *seg,
if (seg->next == NULL)
g_error ("child segment is the last segment in a line");
- if (seg->byte_count != GTK_TEXT_UNKNOWN_CHAR_UTF8_LEN)
- g_error ("child segment has byte count of %d", seg->byte_count);
-
if (seg->char_count != 1)
g_error ("child segment has char count of %d", seg->char_count);
}
@@ -301,11 +298,8 @@ _gtk_widget_segment_new (GtkTextChildAnchor *anchor)
seg->next = NULL;
- /* We convert to the 0xFFFC "unknown character",
- * a 3-byte sequence in UTF-8.
- */
- seg->byte_count = GTK_TEXT_UNKNOWN_CHAR_UTF8_LEN;
- seg->char_count = 1;
+ seg->byte_count = strlen (anchor->chars);
+ seg->char_count = g_utf8_strlen (anchor->chars, seg->byte_count);
seg->body.child.obj = anchor;
seg->body.child.obj->segment = seg;
@@ -410,7 +404,28 @@ gtk_text_child_anchor_class_init (GtkTextChildAnchorClass *klass)
GtkTextChildAnchor*
gtk_text_child_anchor_new (void)
{
- return g_object_new (GTK_TYPE_TEXT_CHILD_ANCHOR, NULL);
+ return gtk_text_child_anchor_new_with_replacement (_gtk_text_unknown_char_utf8);
+}
+
+/**
+ * gtk_text_child_anchor_new_with_replacement:
+ *
+ * Creates a new `GtkTextChildAnchor` with the given replacement character.
+ *
+ * Usually you would then insert it into a `GtkTextBuffer` with
+ * [method@Gtk.TextBuffer.insert_child_anchor].
+ *
+ * Returns: a new `GtkTextChildAnchor`
+ **/
+GtkTextChildAnchor *
+gtk_text_child_anchor_new_with_replacement (const char *replacement_character)
+{
+ /* only a single character can be set as replacement */
+ g_return_val_if_fail (g_utf8_strlen (replacement_character, -1) == 1, NULL);
+
+ GtkTextChildAnchor *anchor = g_object_new (GTK_TYPE_TEXT_CHILD_ANCHOR, NULL);
+ anchor->chars = g_strdup (replacement_character);
+ return anchor;
}
static void