Merge branch 'matthiasc/for-master' into 'master'

textlayout: Remove some unnecessary code

See merge request GNOME/gtk!3400
This commit is contained in:
Matthias Clasen 2021-04-05 13:19:29 +00:00
commit 0ca573142a
10 changed files with 180 additions and 395 deletions

View File

@ -726,7 +726,7 @@ gsk_ngl_render_job_transform_bounds (GskNglRenderJob *job,
/* Our most common transform is 2d-affine, so inline it.
* Both identity and 2d-translate are virtually unseen here.
*/
if G_LIKELY (category == GSK_TRANSFORM_CATEGORY_2D_AFFINE)
if G_LIKELY (category >= GSK_TRANSFORM_CATEGORY_2D_AFFINE)
{
float dx, dy, scale_x, scale_y;

View File

@ -250,22 +250,19 @@ gtk_text_attributes_unref (GtkTextAttributes *values)
void
_gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
GtkTextTag** tags,
guint n_tags)
GPtrArray *tags)
{
guint n = 0;
guint left_margin_accumulative = 0;
guint right_margin_accumulative = 0;
while (n < n_tags)
for (guint n = 0; n < tags->len; n++)
{
GtkTextTag *tag = tags[n];
GtkTextTag *tag = g_ptr_array_index (tags, n);
GtkTextAttributes *vals = tag->priv->values;
g_assert (tag->priv->table != NULL);
if (n > 0)
g_assert (tags[n]->priv->priority > tags[n-1]->priv->priority);
g_assert (((GtkTextTag*)g_ptr_array_index (tags, n))->priv->priority > ((GtkTextTag *)g_ptr_array_index (tags, n - 1))->priv->priority);
if (tag->priv->bg_color_set)
{
@ -438,8 +435,6 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
if (tag->priv->insert_hyphens_set)
dest->no_hyphens = vals->no_hyphens;
++n;
}
dest->left_margin += left_margin_accumulative;

View File

@ -66,6 +66,7 @@ typedef struct _GtkTextAppearance GtkTextAppearance;
* @fg_color: Foreground #GdkColor.
* @rise: Super/subscript rise, can be negative.
* @underline: #PangoUnderline
* @overline: #PangoOverline
* @strikethrough: Strikethrough style
* @draw_bg: Whether to use background-related values; this is
* irrelevant for the values struct when in a tag, but is used for

View File

@ -80,15 +80,8 @@
*/
typedef struct TagInfo {
int numTags; /* Number of tags for which there
* is currently information in
* tags and counts. */
int arraySize; /* Number of entries allocated for
* tags and counts. */
GtkTextTag **tags; /* Array of tags seen so far.
* Malloc-ed. */
int *counts; /* Toggle count (so far) for each
* entry in tags. Malloc-ed. */
GPtrArray *tags;
GArray *counts;
} TagInfo;
@ -276,13 +269,6 @@ static void gtk_text_line_set_parent (GtkTextLine *line,
static void gtk_text_btree_node_remove_data (GtkTextBTreeNode *node,
gpointer view_id);
static NodeData *node_data_new (gpointer view_id);
static void node_data_destroy (NodeData *nd);
static void node_data_list_destroy (NodeData *nd);
static NodeData *node_data_find (NodeData *nd,
gpointer view_id);
static GtkTextBTreeNode *gtk_text_btree_node_new (void);
#if 0
static void gtk_text_btree_node_invalidate_downward (GtkTextBTreeNode *node);
@ -1481,30 +1467,28 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree,
{
int y = 0;
BTreeView *view;
GSList *nodes;
GSList *iter;
GtkTextBTreeNode *node;
GtkTextBTreeNode *nodes[64];
int tos = 0;
view = gtk_text_btree_get_view (tree, view_id);
g_return_val_if_fail (view != NULL, 0);
nodes = NULL;
node = target_line->parent;
while (node != NULL)
{
nodes = g_slist_prepend (nodes, node);
nodes[tos++] = node;
node = node->parent;
}
iter = nodes;
while (iter != NULL)
tos--;
while (tos >= 0)
{
node = iter->data;
node = nodes[tos];
if (node->level == 0)
{
g_slist_free (nodes);
return find_line_top_in_line_list (tree, view,
node->children.line,
target_line, y);
@ -1514,8 +1498,8 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree,
GtkTextBTreeNode *child;
GtkTextBTreeNode *target_node;
g_assert (iter->next != NULL); /* not at level 0 */
target_node = iter->next->data;
g_assert (tos > 0); /* not at level 0 */
target_node = nodes[tos - 1];
child = node->children.node;
@ -1538,7 +1522,7 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree,
ran out of nodes */
}
iter = iter->next;
tos--;
}
g_assert_not_reached (); /* we return when we find the target line */
@ -2209,9 +2193,8 @@ _gtk_text_btree_get_line_at_char (GtkTextBTree *tree,
/* It returns an array sorted by tags priority, ready to pass to
* _gtk_text_attributes_fill_from_tags() */
GtkTextTag**
_gtk_text_btree_get_tags (const GtkTextIter *iter,
int *num_tags)
GPtrArray *
_gtk_text_btree_get_tags (const GtkTextIter *iter)
{
GtkTextBTreeNode *node;
GtkTextLine *siblingline;
@ -2226,10 +2209,8 @@ _gtk_text_btree_get_tags (const GtkTextIter *iter,
line = _gtk_text_iter_get_text_line (iter);
byte_index = gtk_text_iter_get_line_index (iter);
tagInfo.numTags = 0;
tagInfo.arraySize = NUM_TAG_INFOS;
tagInfo.tags = g_new (GtkTextTag*, NUM_TAG_INFOS);
tagInfo.counts = g_new (int, NUM_TAG_INFOS);
tagInfo.tags = g_ptr_array_sized_new (NUM_TAG_INFOS);
tagInfo.counts = g_array_new (FALSE, FALSE, sizeof (int));
/*
* Record tag toggles within the line of indexPtr but preceding
@ -2300,26 +2281,26 @@ _gtk_text_btree_get_tags (const GtkTextIter *iter,
* of interest, but not at the desired character itself).
*/
for (src = 0, dst = 0; src < tagInfo.numTags; src++)
for (src = 0, dst = 0; src < tagInfo.tags->len; src++)
{
if (tagInfo.counts[src] & 1)
if (g_array_index (tagInfo.counts, int, src) & 1)
{
g_assert (GTK_IS_TEXT_TAG (tagInfo.tags[src]));
tagInfo.tags[dst] = tagInfo.tags[src];
g_assert (GTK_IS_TEXT_TAG (g_ptr_array_index (tagInfo.tags, src)));
g_ptr_array_index (tagInfo.tags, dst) = g_ptr_array_index (tagInfo.tags, src);
dst++;
}
}
*num_tags = dst;
g_free (tagInfo.counts);
g_ptr_array_set_size (tagInfo.tags, dst);
g_array_unref (tagInfo.counts);
if (dst == 0)
{
g_free (tagInfo.tags);
g_ptr_array_unref (tagInfo.tags);
return NULL;
}
/* Sort tags in ascending order of priority */
_gtk_text_tag_array_sort (tagInfo.tags, dst);
_gtk_text_tag_array_sort (tagInfo.tags);
return tagInfo.tags;
}
@ -2469,16 +2450,12 @@ _gtk_text_btree_char_count (GtkTextBTree *tree)
return tree->root_node->num_chars - 2;
}
#define LOTSA_TAGS 1000
gboolean
_gtk_text_btree_char_is_invisible (const GtkTextIter *iter)
{
gboolean invisible = FALSE; /* if nobody says otherwise, it's visible */
int deftagCnts[LOTSA_TAGS] = { 0, };
int *tagCnts = deftagCnts;
GtkTextTag *deftags[LOTSA_TAGS];
GtkTextTag **tags = deftags;
int *tagCnts;
GtkTextTag **tags;
int numTags;
GtkTextBTreeNode *node;
GtkTextLine *siblingline;
@ -2489,7 +2466,6 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter)
GtkTextBTree *tree;
int byte_index;
line = _gtk_text_iter_get_text_line (iter);
tree = _gtk_text_iter_get_btree (iter);
/* Short-circuit if we've never seen a visibility tag within the
@ -2498,16 +2474,14 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter)
if G_LIKELY (!_gtk_text_tag_table_affects_visibility (tree->table))
return FALSE;
line = _gtk_text_iter_get_text_line (iter);
byte_index = gtk_text_iter_get_line_index (iter);
numTags = gtk_text_tag_table_get_size (tree->table);
/* almost always avoid malloc, so stay out of system calls */
if (LOTSA_TAGS < numTags)
{
tagCnts = g_new0 (int, numTags);
tags = g_new (GtkTextTag*, numTags);
}
tagCnts = g_alloca (sizeof (int) * numTags);
tags = g_alloca (sizeof (GtkTextTag *) * numTags);
/*
* Record tag toggles within the line of indexPtr but preceding
@ -2610,12 +2584,6 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter)
}
}
if (LOTSA_TAGS < numTags)
{
g_free (tagCnts);
g_free (tags);
}
return invisible;
}
@ -3760,65 +3728,58 @@ _gtk_text_line_byte_count (GtkTextLine *line)
int
_gtk_text_line_char_index (GtkTextLine *target_line)
{
GSList *node_stack = NULL;
GtkTextBTreeNode *node_stack[64];
GtkTextBTreeNode *iter;
GtkTextLine *line;
int num_chars;
int tos = 0;
/* Push all our parent nodes onto a stack */
iter = target_line->parent;
g_assert (iter != NULL);
while (iter != NULL)
while (iter != NULL && tos < 64)
{
node_stack = g_slist_prepend (node_stack, iter);
node_stack[tos++] = iter;
iter = iter->parent;
}
tos--;
/* Check that we have the root node on top of the stack. */
g_assert (node_stack != NULL &&
node_stack->data != NULL &&
((GtkTextBTreeNode*)node_stack->data)->parent == NULL);
node_stack[tos] != NULL &&
node_stack[tos]->parent == NULL);
/* Add up chars in all nodes before the nodes in our stack.
*/
num_chars = 0;
iter = node_stack->data;
while (iter != NULL)
while (tos >= 0)
{
GtkTextBTreeNode *child_iter;
GtkTextBTreeNode *next_node;
next_node = node_stack->next ?
node_stack->next->data : NULL;
node_stack = g_slist_remove (node_stack, node_stack->data);
iter = node_stack[tos];
if (iter->level == 0)
{
/* stack should be empty when we're on the last node */
g_assert (node_stack == NULL);
g_assert (tos == 0);
break; /* Our children are now lines */
}
g_assert (next_node != NULL);
g_assert (iter != NULL);
g_assert (next_node->parent == iter);
tos--;
/* Add up chars before us in the tree */
child_iter = iter->children.node;
while (child_iter != next_node)
while (child_iter != node_stack[tos])
{
g_assert (child_iter != NULL);
num_chars += child_iter->num_chars;
child_iter = child_iter->next;
}
iter = next_node;
}
g_assert (iter != NULL);
@ -3833,7 +3794,6 @@ _gtk_text_line_char_index (GtkTextLine *target_line)
g_assert (line != NULL);
num_chars += _gtk_text_line_char_count (line);
line = line->next;
}
@ -4840,15 +4800,16 @@ cleanup_line (GtkTextLine *line)
* Nodes
*/
static NodeData*
node_data_new (gpointer view_id)
static inline NodeData*
node_data_new (gpointer view_id,
NodeData *next)
{
NodeData *nd;
nd = g_slice_new (NodeData);
nd->view_id = view_id;
nd->next = NULL;
nd->next = next;
nd->width = 0;
nd->height = 0;
nd->valid = FALSE;
@ -4856,19 +4817,19 @@ node_data_new (gpointer view_id)
return nd;
}
static void
static inline void
node_data_destroy (NodeData *nd)
{
g_slice_free (NodeData, nd);
}
static void
static inline void
node_data_list_destroy (NodeData *nd)
{
g_slice_free_chain (NodeData, nd, next);
}
static NodeData*
static inline NodeData*
node_data_find (NodeData *nd,
gpointer view_id)
{
@ -5557,24 +5518,10 @@ gtk_text_btree_node_ensure_data (GtkTextBTreeNode *node, gpointer view_id)
{
NodeData *nd;
nd = node->node_data;
while (nd != NULL)
{
if (nd->view_id == view_id)
break;
nd = nd->next;
}
nd = node_data_find (node->node_data, view_id);
if (nd == NULL)
{
nd = node_data_new (view_id);
if (node->node_data)
nd->next = node->node_data;
node->node_data = nd;
}
nd = node->node_data = node_data_new (view_id, node->node_data);
return nd;
}
@ -6496,15 +6443,12 @@ _gtk_change_node_toggle_count (GtkTextBTreeNode *node,
static void
inc_count (GtkTextTag *tag, int inc, TagInfo *tagInfoPtr)
{
GtkTextTag **tag_p;
int count;
for (tag_p = tagInfoPtr->tags, count = tagInfoPtr->numTags;
count > 0; tag_p++, count--)
for (int i = 0; i < tagInfoPtr->tags->len; i++)
{
if (*tag_p == tag)
GtkTextTag *t = g_ptr_array_index (tagInfoPtr->tags, i);
if (t == tag)
{
tagInfoPtr->counts[tagInfoPtr->numTags-count] += inc;
g_array_index (tagInfoPtr->counts, int, i) += inc;
return;
}
}
@ -6515,29 +6459,8 @@ inc_count (GtkTextTag *tag, int inc, TagInfo *tagInfoPtr)
* arrays first.
*/
if (tagInfoPtr->numTags == tagInfoPtr->arraySize)
{
GtkTextTag **newTags;
int *newCounts, newSize;
newSize = 2*tagInfoPtr->arraySize;
newTags = (GtkTextTag **) g_malloc ((unsigned)
(newSize*sizeof (GtkTextTag *)));
memcpy ((void *) newTags, (void *) tagInfoPtr->tags,
tagInfoPtr->arraySize *sizeof (GtkTextTag *));
g_free ((char *) tagInfoPtr->tags);
tagInfoPtr->tags = newTags;
newCounts = (int *) g_malloc ((unsigned) (newSize*sizeof (int)));
memcpy ((void *) newCounts, (void *) tagInfoPtr->counts,
tagInfoPtr->arraySize *sizeof (int));
g_free ((char *) tagInfoPtr->counts);
tagInfoPtr->counts = newCounts;
tagInfoPtr->arraySize = newSize;
}
tagInfoPtr->tags[tagInfoPtr->numTags] = tag;
tagInfoPtr->counts[tagInfoPtr->numTags] = inc;
tagInfoPtr->numTags++;
g_ptr_array_add (tagInfoPtr->tags, tag);
g_array_append_val (tagInfoPtr->counts, inc);
}
static void

View File

@ -128,8 +128,7 @@ GtkTextLine * _gtk_text_btree_get_line_at_char (GtkTextBTree *tree,
int char_index,
int *line_start_index,
int *real_char_index);
GtkTextTag** _gtk_text_btree_get_tags (const GtkTextIter *iter,
int *num_tags);
GPtrArray * _gtk_text_btree_get_tags (const GtkTextIter *iter);
char *_gtk_text_btree_get_text (const GtkTextIter *start,
const GtkTextIter *end,
gboolean include_hidden,

View File

@ -1386,36 +1386,30 @@ gtk_text_iter_has_tag (const GtkTextIter *iter,
GSList*
gtk_text_iter_get_tags (const GtkTextIter *iter)
{
GtkTextTag** tags;
int tag_count = 0;
int i;
GPtrArray *tags;
GSList *retval;
g_return_val_if_fail (iter != NULL, NULL);
/* Get the tags at this spot */
tags = _gtk_text_btree_get_tags (iter, &tag_count);
tags = _gtk_text_btree_get_tags (iter);
/* No tags, use default style */
if (tags == NULL || tag_count == 0)
if (tags == NULL || tags->len == 0)
{
g_free (tags);
if (tags)
g_ptr_array_unref (tags);
return NULL;
}
retval = NULL;
i = 0;
while (i < tag_count)
{
retval = g_slist_prepend (retval, tags[i]);
++i;
}
g_free (tags);
/* Return tags in ascending order of priority */
return g_slist_reverse (retval);
for (int i = tags->len - 1; i >= 0; i--)
retval = g_slist_prepend (retval, g_ptr_array_index (tags, i));
g_ptr_array_unref (tags);
return retval;
}
/**
@ -1506,25 +1500,22 @@ gboolean
gtk_text_iter_get_attributes (const GtkTextIter *iter,
GtkTextAttributes *values)
{
GtkTextTag** tags;
int tag_count = 0;
GPtrArray *tags;
/* Get the tags at this spot */
tags = _gtk_text_btree_get_tags (iter, &tag_count);
tags = _gtk_text_btree_get_tags (iter);
/* No tags, use default style */
if (tags == NULL || tag_count == 0)
if (tags == NULL || tags->len == 0)
{
g_free (tags);
if (tags)
g_ptr_array_unref (tags);
return FALSE;
}
_gtk_text_attributes_fill_from_tags (values,
tags,
tag_count);
_gtk_text_attributes_fill_from_tags (values, tags);
g_free (tags);
g_ptr_array_unref (tags);
return TRUE;
}

View File

@ -671,67 +671,6 @@ gtk_text_layout_cursors_changed (GtkTextLayout *layout,
gtk_text_layout_emit_changed (layout, y, old_height, new_height);
}
/*
* gtk_text_layout_get_lines:
*
* Returns: (element-type GtkTextLine) (transfer container):
*/
GSList*
gtk_text_layout_get_lines (GtkTextLayout *layout,
/* [top_y, bottom_y) */
int top_y,
int bottom_y,
int *first_line_y)
{
GtkTextLine *first_btree_line;
GtkTextLine *last_btree_line;
GtkTextLine *line;
GSList *retval;
g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), NULL);
if (top_y >= bottom_y)
return NULL;
retval = NULL;
first_btree_line =
_gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
layout, top_y, first_line_y);
if (first_btree_line == NULL)
{
/* off the bottom */
return NULL;
}
/* -1 since bottom_y is one past */
last_btree_line =
_gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
layout, bottom_y - 1, NULL);
if (!last_btree_line)
last_btree_line =
_gtk_text_btree_get_end_iter_line (_gtk_text_buffer_get_btree (layout->buffer));
g_assert (last_btree_line != NULL);
line = first_btree_line;
while (TRUE)
{
retval = g_slist_prepend (retval, line);
if (line == last_btree_line)
break;
line = _gtk_text_line_next_excluding_last (line);
}
retval = g_slist_reverse (retval);
return retval;
}
static void
invalidate_cached_style (GtkTextLayout *layout)
{
@ -1080,12 +1019,14 @@ void
gtk_text_layout_validate (GtkTextLayout *layout,
int max_pixels)
{
GtkTextBTree *btree;
int y, old_height, new_height;
g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
btree = _gtk_text_buffer_get_btree (layout->buffer);
while (max_pixels > 0 &&
_gtk_text_btree_validate (_gtk_text_buffer_get_btree (layout->buffer),
_gtk_text_btree_validate (btree,
layout, max_pixels,
&y, &old_height, &new_height))
{
@ -1167,9 +1108,7 @@ get_style (GtkTextLayout *layout,
gtk_text_attributes_copy_values (layout->default_style,
style);
_gtk_text_attributes_fill_from_tags (style,
(GtkTextTag**) tags->pdata,
tags->len);
_gtk_text_attributes_fill_from_tags (style, tags);
g_assert (style->refcount == 1);
@ -1883,12 +1822,13 @@ add_cursor (GtkTextLayout *layout,
int start)
{
CursorPosition cursor;
GtkTextBTree *btree;
btree = _gtk_text_buffer_get_btree (layout->buffer);
cursor.pos = start;
cursor.is_insert = _gtk_text_btree_mark_is_insert (_gtk_text_buffer_get_btree (layout->buffer),
seg->body.mark.obj);
cursor.is_selection_bound = _gtk_text_btree_mark_is_selection_bound (_gtk_text_buffer_get_btree (layout->buffer),
seg->body.mark.obj);
cursor.is_insert = _gtk_text_btree_mark_is_insert (btree, seg->body.mark.obj);
cursor.is_selection_bound = _gtk_text_btree_mark_is_selection_bound (btree, seg->body.mark.obj);
/* Hide insertion cursor when we have a selection or the layout
* user has hidden the cursor.
@ -1902,8 +1842,7 @@ add_cursor (GtkTextLayout *layout,
GtkTextIter iter;
gboolean cursor_at_line_end;
_gtk_text_btree_get_iter_at_mark (_gtk_text_buffer_get_btree (layout->buffer),
&iter, seg->body.mark.obj);
_gtk_text_btree_get_iter_at_mark (btree, &iter, seg->body.mark.obj);
if (get_block_cursor (layout, display, &iter, start,
&display->block_cursor,
@ -2263,28 +2202,6 @@ gtk_text_layout_update_display_cursors (GtkTextLayout *layout,
g_slist_free (cursor_segs);
}
/* Same as _gtk_text_btree_get_tags(), except it returns GPtrArray,
* to be used in gtk_text_layout_get_line_display(). */
static GPtrArray *
get_tags_array_at_iter (GtkTextIter *iter)
{
GtkTextTag **tags;
GPtrArray *array = NULL;
int n_tags;
tags = _gtk_text_btree_get_tags (iter, &n_tags);
if (n_tags > 0)
{
array = g_ptr_array_sized_new (n_tags);
g_ptr_array_set_size (array, n_tags);
memcpy (array->pdata, tags, n_tags * sizeof (GtkTextTag*));
}
g_free (tags);
return array;
}
/* Add the tag to the array if it's not there already, and remove
* it otherwise. It keeps the array sorted by tags priority. */
static GPtrArray *
@ -2343,6 +2260,7 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
PangoAttribute *last_font_attr = NULL;
PangoAttribute *last_scale_attr = NULL;
PangoAttribute *last_fallback_attr = NULL;
GtkTextBTree *btree;
g_return_val_if_fail (line != NULL, NULL);
@ -2375,6 +2293,8 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
}
btree = _gtk_text_buffer_get_btree (layout->buffer);
/* Allocate space for flat text for buffer
*/
text_allocated = _gtk_text_line_byte_count (line);
@ -2386,7 +2306,7 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
layout_byte_offset = 0; /* current length of 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);
tags = get_tags_array_at_iter (&iter);
tags = _gtk_text_btree_get_tags (&iter);
initial_toggle_segments = TRUE;
while (seg != NULL)
{
@ -2445,16 +2365,14 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
*/
if (layout->preedit_len > 0 &&
_gtk_text_btree_mark_is_insert (_gtk_text_buffer_get_btree (layout->buffer),
seg->body.mark.obj))
_gtk_text_btree_mark_is_insert (btree, seg->body.mark.obj))
break;
if (seg->body.mark.visible)
{
cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, GINT_TO_POINTER (layout_byte_offset));
cursor_segs = g_slist_prepend (cursor_segs, seg);
if (_gtk_text_btree_mark_is_insert (_gtk_text_buffer_get_btree (layout->buffer),
seg->body.mark.obj))
if (_gtk_text_btree_mark_is_insert (btree, seg->body.mark.obj))
display->insert_index = layout_byte_offset;
}
}
@ -2542,8 +2460,7 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
/* 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))
if (_gtk_text_btree_mark_is_insert (btree, seg->body.mark.obj))
{
display->insert_index = layout_byte_offset;
@ -2632,7 +2549,6 @@ gtk_text_layout_create_display (GtkTextLayout *layout,
pango_layout_get_extents (display->layout, NULL, &extents);
text_pixel_width = PIXEL_BOUND (extents.width);
display->width = text_pixel_width + display->left_margin + display->right_margin;
h_margin = display->left_margin + display->right_margin;
h_padding = layout->left_padding + layout->right_padding;
@ -2781,21 +2697,20 @@ get_line_at_y (GtkTextLayout *layout,
GtkTextLine **line,
int *line_top)
{
GtkTextBTree *btree = _gtk_text_buffer_get_btree (layout->buffer);
if (y < 0)
y = 0;
if (y > layout->height)
y = layout->height;
*line = _gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
layout, y, line_top);
*line = _gtk_text_btree_find_line_by_y (btree, layout, y, line_top);
if (*line == NULL)
{
*line = _gtk_text_btree_get_end_iter_line (_gtk_text_buffer_get_btree (layout->buffer));
*line = _gtk_text_btree_get_end_iter_line (btree);
if (line_top)
*line_top =
_gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
*line, layout);
*line_top = _gtk_text_btree_find_line_top (btree, *line, layout);
}
}
@ -3110,21 +3025,20 @@ find_display_line_below (GtkTextLayout *layout,
GtkTextIter *iter,
int y)
{
GtkTextBTree *btree;
GtkTextLine *line, *next;
GtkTextLine *found_line = NULL;
int line_top;
int found_byte = 0;
line = _gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
layout, y, &line_top);
btree = _gtk_text_buffer_get_btree (layout->buffer);
line = _gtk_text_btree_find_line_by_y (btree, layout, y, &line_top);
if (!line)
{
line =
_gtk_text_btree_get_end_iter_line (_gtk_text_buffer_get_btree (layout->buffer));
line = _gtk_text_btree_get_end_iter_line (btree);
line_top =
_gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
line, layout);
line_top = _gtk_text_btree_find_line_top (btree, line, layout);
}
while (line && !found_line)
@ -3178,17 +3092,19 @@ find_display_line_above (GtkTextLayout *layout,
GtkTextIter *iter,
int y)
{
GtkTextBTree *btree;
GtkTextLine *line;
GtkTextLine *found_line = NULL;
int line_top;
int found_byte = 0;
line = _gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer), layout, y, &line_top);
btree = _gtk_text_buffer_get_btree (layout->buffer);
line = _gtk_text_btree_find_line_by_y (btree, layout, y, &line_top);
if (!line)
{
line = _gtk_text_btree_get_end_iter_line (_gtk_text_buffer_get_btree (layout->buffer));
line = _gtk_text_btree_get_end_iter_line (btree);
line_top = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer), line, layout);
line_top = _gtk_text_btree_find_line_top (btree, line, layout);
}
while (line && !found_line)
@ -3909,32 +3825,18 @@ render_para (GskPangoRenderer *crenderer,
GtkTextLineDisplay *line_display,
int selection_start_index,
int selection_end_index,
const GdkRGBA *selection,
float cursor_alpha)
{
GtkStyleContext *context;
PangoLayout *layout = line_display->layout;
int byte_offset = 0;
PangoLayoutIter *iter;
int screen_width;
const GdkRGBA *selection = NULL;
gboolean first = TRUE;
g_return_if_fail (GTK_IS_TEXT_VIEW (crenderer->widget));
iter = pango_layout_get_iter (layout);
screen_width = line_display->total_width;
context = _gtk_widget_get_style_context (crenderer->widget);
if (selection_start_index != -1 || selection_end_index != -1)
{
GtkCssNode *selection_node = gtk_text_view_get_selection_node ((GtkTextView*)crenderer->widget);
gtk_style_context_save_to_node (context, selection_node);
selection = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
gtk_style_context_restore (context);
}
do
{
PangoLayoutLine *line = pango_layout_iter_get_line_readonly (iter);
@ -3964,14 +3866,13 @@ render_para (GskPangoRenderer *crenderer,
{
selection_y -= line_display->top_margin;
selection_height += line_display->top_margin;
first = FALSE;
}
at_last_line = pango_layout_iter_at_last_line (iter);
if (at_last_line)
selection_height += line_display->bottom_margin;
first = FALSE;
if (selection_start_index < byte_offset &&
selection_end_index > line->length + byte_offset) /* All selected */
{
@ -4068,10 +3969,12 @@ render_para (GskPangoRenderer *crenderer,
}
else if (line_display->has_block_cursor &&
gtk_widget_has_focus (crenderer->widget) &&
cursor_alpha > 0 &&
byte_offset <= line_display->insert_index &&
(line_display->insert_index < byte_offset + line->length ||
(at_last_line && line_display->insert_index == byte_offset + line->length)))
{
GtkStyleContext *context;
GdkRGBA cursor_color;
graphene_rect_t bounds = {
.origin.x = line_display->x_offset + line_display->block_cursor.x,
@ -4080,8 +3983,10 @@ render_para (GskPangoRenderer *crenderer,
.size.height = line_display->block_cursor.height,
};
/* we draw text using base color on filled cursor rectangle of cursor color
* (normally white on black) */
/* we draw text using base color on filled cursor rectangle
* of cursor color (normally white on black)
*/
context = _gtk_widget_get_style_context (crenderer->widget);
_gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
gtk_snapshot_push_opacity (crenderer->snapshot, cursor_alpha);
@ -4139,11 +4044,12 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
int selection_start_line;
int selection_end_line;
gboolean have_selection;
GSList *line_list;
GSList *tmp_list;
const GdkRGBA *selection;
GdkRGBA color;
GtkSnapshot *cursor_snapshot;
GskRenderNode *cursors;
GtkTextBTree *btree;
GtkTextLine *first_line;
GtkTextLine *last_line;
g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
g_return_if_fail (layout->default_style != NULL);
@ -4152,18 +4058,26 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
if (clip->height <= 0)
return;
btree = _gtk_text_buffer_get_btree (layout->buffer);
first_line = _gtk_text_btree_find_line_by_y (btree, layout, clip->y, &offset_y);
if (first_line == NULL)
return;
last_line = _gtk_text_btree_find_line_by_y (btree, layout, clip->y + clip->height - 1, NULL);
if (last_line == NULL)
last_line = _gtk_text_btree_get_end_iter_line (btree);
context = gtk_widget_get_style_context (widget);
gtk_style_context_get_color (context, &color);
line_list = gtk_text_layout_get_lines (layout, clip->y, clip->y + clip->height, &offset_y);
if (line_list == NULL)
return; /* nothing on the screen */
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, offset_y));
offset_y = 0;
cursor_snapshot = gtk_snapshot_new ();
cursor_snapshot = NULL;
crenderer = gsk_pango_renderer_acquire ();
@ -4173,26 +4087,36 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
crenderer->snapshot = snapshot;
crenderer->fg_color = &color;
gtk_text_layout_wrap_loop_start (layout);
have_selection = gtk_text_buffer_get_selection_bounds (layout->buffer,
&selection_start,
&selection_end);
if (have_selection)
{
GtkCssNode *selection_node;
selection_start_line = gtk_text_iter_get_line (&selection_start);
selection_end_line = gtk_text_iter_get_line (&selection_end);
selection_node = gtk_text_view_get_selection_node ((GtkTextView*)widget);
gtk_style_context_save_to_node (context, selection_node);
selection = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
gtk_style_context_restore (context);
}
else
{
selection_start_line = -1;
selection_end_line = -1;
selection = NULL;
}
tmp_list = line_list;
while (tmp_list != NULL)
gtk_text_layout_wrap_loop_start (layout);
for (GtkTextLine *line = first_line;
line != last_line;
line = _gtk_text_line_next_excluding_last (line))
{
GtkTextLine *line = tmp_list->data;
GtkTextLineDisplay *line_display;
int selection_start_index = -1;
int selection_end_index = -1;
@ -4241,18 +4165,19 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
if (line_display->node != NULL)
{
if (line_display->has_block_cursor &&
gtk_widget_has_focus (widget))
if (line_display->has_block_cursor && gtk_widget_has_focus (widget))
g_clear_pointer (&line_display->node, gsk_render_node_unref);
}
if (line_display->node == NULL)
if (line_display->node == NULL &&
(pango_layout_get_character_count (line_display->layout) > 0 ||
selection_start_index != -1 || selection_end_index != -1))
{
gtk_snapshot_push_collect (snapshot);
render_para (crenderer, line_display,
selection_start_index, selection_end_index,
selection,
cursor_alpha);
line_display->node = gtk_snapshot_pop_collect (snapshot);
}
@ -4270,9 +4195,10 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
*/
if (line_display->cursors != NULL)
{
int i;
if (cursor_snapshot == NULL)
cursor_snapshot = gtk_snapshot_new ();
for (i = 0; i < line_display->cursors->len; i++)
for (int i = 0; i < line_display->cursors->len; i++)
{
PangoDirection dir;
CursorPosition cursor;
@ -4296,24 +4222,25 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
offset_y += line_display->height;
gtk_text_line_display_unref (line_display);
tmp_list = tmp_list->next;
}
gtk_text_layout_wrap_loop_end (layout);
cursors = gtk_snapshot_free_to_node (cursor_snapshot);
if (cursors)
if (cursor_snapshot)
{
gtk_snapshot_append_node (crenderer->snapshot, cursors);
gsk_render_node_unref (cursors);
GskRenderNode *cursors;
cursors = gtk_snapshot_free_to_node (cursor_snapshot);
if (cursors)
{
gtk_snapshot_append_node (crenderer->snapshot, cursors);
gsk_render_node_unref (cursors);
}
}
/* Only update eviction source once per snapshot */
gtk_text_line_display_cache_delay_eviction (priv->cache);
g_slist_free (line_list);
gsk_pango_renderer_release (crenderer);
}

View File

@ -254,10 +254,6 @@ gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout *layout);
void gtk_text_layout_get_size (GtkTextLayout *layout,
int *width,
int *height);
GSList* gtk_text_layout_get_lines (GtkTextLayout *layout,
int top_y,
int bottom_y,
int *first_line_y);
void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout);
void gtk_text_layout_wrap_loop_end (GtkTextLayout *layout);

View File

@ -2410,52 +2410,7 @@ tag_sort_func (gconstpointer first, gconstpointer second)
}
void
_gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
guint len)
_gtk_text_tag_array_sort (GPtrArray *tags)
{
int i, j, prio;
GtkTextTag **tag;
GtkTextTag **maxPtrPtr, *tmp;
g_return_if_fail (tag_array_p != NULL);
g_return_if_fail (len > 0);
if (len < 2) {
return;
}
if (len < 20) {
GtkTextTag **iter = tag_array_p;
for (i = len-1; i > 0; i--, iter++) {
maxPtrPtr = tag = iter;
prio = tag[0]->priv->priority;
for (j = i, tag++; j > 0; j--, tag++) {
if (tag[0]->priv->priority < prio) {
prio = tag[0]->priv->priority;
maxPtrPtr = tag;
}
}
tmp = *maxPtrPtr;
*maxPtrPtr = *iter;
*iter = tmp;
}
} else {
qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
tag_sort_func);
}
#if 0
{
printf ("Sorted tag array: \n");
i = 0;
while (i < len)
{
GtkTextTag *t = tag_array_p[i];
printf (" %s priority %d\n", t->name, t->priority);
++i;
}
}
#endif
g_ptr_array_sort (tags, tag_sort_func);
}

View File

@ -97,10 +97,8 @@ struct _GtkTextTagPrivate
* ascending order of priority
*/
void _gtk_text_attributes_fill_from_tags (GtkTextAttributes *values,
GtkTextTag **tags,
guint n_tags);
void _gtk_text_tag_array_sort (GtkTextTag **tag_array_p,
guint len);
GPtrArray *tags);
void _gtk_text_tag_array_sort (GPtrArray *tags);
gboolean _gtk_text_tag_affects_size (GtkTextTag *tag);
gboolean _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag);