+ GtkTextAppearance appearance = style->appearance;
+ PangoFontDescription *font_desc = pango_font_description_copy_static (style->font);
+ PangoAttribute *insert_attr;
+ GSList *extra_attrs = NULL;
+ GSList *tmp_list;
+ PangoLanguage *language;
+ gint start, end;
+
+ pango_attr_iterator_range (iter, &start, &end);
+
+ if (end == G_MAXINT)
+ end = layout->preedit_len;
+
+ if (end == start)
+ continue;
+
+ pango_attr_iterator_get_font (iter, font_desc, &language, &extra_attrs);
+
+ tmp_list = extra_attrs;
+ while (tmp_list)
+ {
+ PangoAttribute *attr = tmp_list->data;
+ GdkRGBA rgba;
+
+ switch (attr->klass->type)
+ {
+ case PANGO_ATTR_FOREGROUND:
+ convert_color (&rgba, (PangoAttrColor *)attr);
+ if (appearance.rgba[1])
+ gdk_rgba_free (appearance.rgba[1]);
+ appearance.rgba[1] = gdk_rgba_copy (&rgba);
+ break;
+ case PANGO_ATTR_BACKGROUND:
+ convert_color (&rgba, (PangoAttrColor *)attr);
+ if (appearance.rgba[0])
+ gdk_rgba_free (appearance.rgba[0]);
+ appearance.rgba[0] = gdk_rgba_copy (&rgba);
+ appearance.draw_bg = TRUE;
+ break;
+ case PANGO_ATTR_UNDERLINE:
+ appearance.underline = ((PangoAttrInt *)attr)->value;
+ break;
+ case PANGO_ATTR_STRIKETHROUGH:
+ appearance.strikethrough = ((PangoAttrInt *)attr)->value;
+ break;
+ case PANGO_ATTR_RISE:
+ appearance.rise = ((PangoAttrInt *)attr)->value;
+ break;
+ default:
+ break;
+ }
+
+ pango_attribute_destroy (attr);
+ tmp_list = tmp_list->next;
+ }
+
+ g_slist_free (extra_attrs);
+
+ insert_attr = pango_attr_font_desc_new (font_desc);
+ insert_attr->start_index = start + offset;
+ insert_attr->end_index = end + offset;
+
+ pango_attr_list_insert (attrs, insert_attr);
+
+ if (language)
+ {
+ insert_attr = pango_attr_language_new (language);
+ insert_attr->start_index = start + offset;
+ insert_attr->end_index = end + offset;
+
+ pango_attr_list_insert (attrs, insert_attr);
+ }
+
+ add_generic_attrs (layout, &appearance, end - start,
+ attrs, start + offset,
+ size_only, TRUE);
+
+ pango_font_description_free (font_desc);
+ }
+ while (pango_attr_iterator_next (iter));
+
+ pango_attr_iterator_destroy (iter);
+}
+
+/* Iterate over the line and fill in display->cursors.
+ * It's a stripped copy of gtk_text_layout_get_line_display() */
+static void
+update_text_display_cursors (GtkTextLayout *layout,
+ GtkTextLine *line,
+ GtkTextLineDisplay *display)
+{
+ GtkTextLineSegment *seg;
+ GtkTextIter iter;
+ gint layout_byte_offset, buffer_byte_offset;
+ GSList *cursor_byte_offsets = NULL;
+ GSList *cursor_segs = NULL;
+ GSList *tmp_list1, *tmp_list2;
+
+ if (!display->cursors_invalid)
+ return;
+
+ display->cursors_invalid = FALSE;
+
+ /* Special-case optimization for completely
+ * invisible lines; makes it faster to deal
+ * with sequences of invisible lines.
+ */
+ if (totally_invisible_line (layout, line, &iter))
+ return;
+
+ /* Iterate over segments */
+ layout_byte_offset = 0; /* position in the layout text (includes preedit, does not include invisible text) */
+ buffer_byte_offset = 0; /* position in the buffer line */
+ seg = _gtk_text_iter_get_any_segment (&iter);
+ while (seg != NULL)
+ {
+ /* Displayable segments */
+ if (seg->type == >k_text_char_type ||
+ seg->type == >k_text_pixbuf_type ||
+ seg->type == >k_text_child_type)
+ {
+ gtk_text_layout_get_iter_at_line (layout, &iter, line,
+ buffer_byte_offset);
+
+ if (!_gtk_text_btree_char_is_invisible (&iter))
+ layout_byte_offset += seg->byte_count;
+
+ buffer_byte_offset += seg->byte_count;
+ }
+
+ /* Marks */
+ else if (seg->type == >k_text_right_mark_type ||
+ seg->type == >k_text_left_mark_type)
+ {
+ gint cursor_offset = 0;
+
+ /* At the insertion point, add the preedit string, if any */
+
+ if (_gtk_text_btree_mark_is_insert (_gtk_text_buffer_get_btree (layout->buffer),
+ seg->body.mark.obj))
+ {
+ display->insert_index = layout_byte_offset;
+
+ if (layout->preedit_len > 0)
+ {
+ layout_byte_offset += layout->preedit_len;
+ /* DO NOT increment the buffer byte offset for preedit */
+ cursor_offset = layout->preedit_cursor - layout->preedit_len;
+ }
+ }
+
+ /* Display visible marks */
+
+ if (seg->body.mark.visible)
+ {
+ cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets,
+ GINT_TO_POINTER (layout_byte_offset + cursor_offset));
+ cursor_segs = g_slist_prepend (cursor_segs, seg);
+ }
+ }
+
+ /* Toggles */
+ else if (seg->type == >k_text_toggle_on_type ||
+ seg->type == >k_text_toggle_off_type)
+ {
+ }
+
+ else
+ g_error ("Unknown segment type: %s", seg->type->name);
+
+ seg = seg->next;
+ }
+
+ tmp_list1 = cursor_byte_offsets;
+ tmp_list2 = cursor_segs;
+ while (tmp_list1)
+ {
+ add_cursor (layout, display, tmp_list2->data,
+ GPOINTER_TO_INT (tmp_list1->data));
+ tmp_list1 = tmp_list1->next;
+ tmp_list2 = tmp_list2->next;
+ }
+ g_slist_free (cursor_byte_offsets);
+ g_slist_free (cursor_segs);
+}