summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-01 23:19:42 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-12-01 23:33:41 -0500
commitf2f9e410f295a326a81db8f2ae12889f4e4244b9 (patch)
tree59946f8b0675ec5f83cb52c9ecc33ea4ed7cf904 /pango/pango-layout.c
parent0a1c31901fbf0db9e98b02ad3ba02681f1c31774 (diff)
downloadpango-f2f9e410f295a326a81db8f2ae12889f4e4244b9.tar.gz
layout: Some restructuring of tab handling
Introduce a LastTab struct, and use it.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c97
1 files changed, 43 insertions, 54 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 473d1785..fc8cc212 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -92,6 +92,7 @@
typedef struct _ItemProperties ItemProperties;
typedef struct _ParaBreakState ParaBreakState;
+typedef struct _LastTabState LastTabState;
/* Note that letter_spacing and shape are constant across items,
* since we pass them into itemization.
@@ -3264,7 +3265,7 @@ pango_layout_line_leaked (PangoLayoutLine *line)
*****************/
static void shape_tab (PangoLayoutLine *line,
- ParaBreakState *state,
+ LastTabState *tab_state,
PangoItem *item,
PangoGlyphString *glyphs);
@@ -3490,13 +3491,6 @@ showing_space (const PangoAnalysis *analysis)
return FALSE;
}
-static void break_state_set_last_tab (ParaBreakState *state,
- PangoGlyphString *glyphs,
- int width,
- int tab_pos,
- PangoTabAlign tab_align,
- gunichar tab_decimal);
-
static void
ensure_decimal (PangoLayout *layout)
{
@@ -3504,9 +3498,18 @@ ensure_decimal (PangoLayout *layout)
layout->decimal = g_utf8_get_char (localeconv ()->decimal_point);
}
+struct _LastTabState {
+ PangoGlyphString *glyphs;
+ int index;
+ int width;
+ int pos;
+ PangoTabAlign align;
+ gunichar decimal;
+};
+
static void
shape_tab (PangoLayoutLine *line,
- ParaBreakState *state,
+ LastTabState *tab_state,
PangoItem *item,
PangoGlyphString *glyphs)
{
@@ -3560,7 +3563,12 @@ shape_tab (PangoLayoutLine *line,
tab_decimal = line->layout->decimal;
}
- break_state_set_last_tab (state, glyphs, current_width, tab_pos, tab_align, tab_decimal);
+ tab_state->glyphs = glyphs;
+ tab_state->index = i;
+ tab_state->width = current_width;
+ tab_state->pos = tab_pos;
+ tab_state->align = tab_align;
+ tab_state->decimal = tab_decimal;
}
static inline gboolean
@@ -3645,29 +3653,9 @@ struct _ParaBreakState
GList *baseline_shifts;
- PangoGlyphString *last_tab;
- int last_tab_width;
- int last_tab_pos;
- PangoTabAlign last_tab_align;
- gunichar last_tab_decimal;
+ LastTabState last_tab;
};
-static void
-break_state_set_last_tab (ParaBreakState *state,
- PangoGlyphString *glyphs,
- int width,
- int tab_pos,
- PangoTabAlign tab_align,
- gunichar tab_decimal)
-{
-
- state->last_tab = glyphs;
- state->last_tab_width = width;
- state->last_tab_pos = tab_pos;
- state->last_tab_align = tab_align;
- state->last_tab_decimal = tab_decimal;
-}
-
static gboolean
should_ellipsize_current_line (PangoLayout *layout,
ParaBreakState *state);
@@ -3716,7 +3704,7 @@ shape_run (PangoLayoutLine *line,
PangoGlyphString *glyphs = pango_glyph_string_new ();
if (layout->text[item->offset] == '\t')
- shape_tab (line, state, item, glyphs);
+ shape_tab (line, &state->last_tab, item, glyphs);
else
{
PangoShapeFlags shape_flags = PANGO_SHAPE_NONE;
@@ -3755,31 +3743,31 @@ shape_run (PangoLayoutLine *line,
glyphs->glyphs[glyphs->num_glyphs - 1].geometry.width += space_right;
}
- if (state->last_tab != NULL)
+ if (state->last_tab.glyphs != NULL)
{
int w;
- g_assert (state->last_tab->num_glyphs == 1);
+ g_assert (state->last_tab.glyphs->num_glyphs == 1);
/* Update the width of the current tab to position this run properly */
- w = state->last_tab_pos - state->last_tab_width;
+ w = state->last_tab.pos - state->last_tab.width;
- if (state->last_tab_align == PANGO_TAB_RIGHT)
+ if (state->last_tab.align == PANGO_TAB_RIGHT)
w -= pango_glyph_string_get_width (glyphs);
- else if (state->last_tab_align == PANGO_TAB_CENTER)
+ else if (state->last_tab.align == PANGO_TAB_CENTER)
w -= pango_glyph_string_get_width (glyphs) / 2;
- else if (state->last_tab_align == PANGO_TAB_DECIMAL)
+ else if (state->last_tab.align == PANGO_TAB_DECIMAL)
{
int width;
gboolean found;
- get_decimal_prefix_width (item, glyphs, layout->text, state->last_tab_decimal, &width, &found);
+ get_decimal_prefix_width (item, glyphs, layout->text, state->last_tab.decimal, &width, &found);
w -= width;
}
- state->last_tab->glyphs[0].geometry.width = MAX (w, 0);
+ state->last_tab.glyphs->glyphs[0].geometry.width = MAX (w, 0);
}
}
@@ -3817,27 +3805,27 @@ insert_run (PangoLayoutLine *line,
line->runs = g_slist_prepend (line->runs, run);
line->length += run_item->length;
- if (state->last_tab && run->glyphs != state->last_tab)
+ if (state->last_tab.glyphs && run->glyphs != state->last_tab.glyphs)
{
/* Adjust the tab position so placing further runs will continue to
* maintain the tab placement. In the case of decimal tabs, we are
* done once we've placed the run with the decimal point.
*/
- if (state->last_tab_align == PANGO_TAB_RIGHT)
- state->last_tab_width += pango_glyph_string_get_width (run->glyphs);
- else if (state->last_tab_align == PANGO_TAB_CENTER)
- state->last_tab_width += pango_glyph_string_get_width (run->glyphs) / 2;
- else if (state->last_tab_align == PANGO_TAB_DECIMAL)
+ if (state->last_tab.align == PANGO_TAB_RIGHT)
+ state->last_tab.width += pango_glyph_string_get_width (run->glyphs);
+ else if (state->last_tab.align == PANGO_TAB_CENTER)
+ state->last_tab.width += pango_glyph_string_get_width (run->glyphs) / 2;
+ else if (state->last_tab.align == PANGO_TAB_DECIMAL)
{
int width;
gboolean found;
- get_decimal_prefix_width (run->item, run->glyphs, line->layout->text, state->last_tab_decimal, &width, &found);
+ get_decimal_prefix_width (run->item, run->glyphs, line->layout->text, state->last_tab.decimal, &width, &found);
- state->last_tab_width += width;
+ state->last_tab.width += width;
if (found)
- state->last_tab = NULL;
+ state->last_tab.glyphs = NULL;
}
}
}
@@ -3955,8 +3943,8 @@ compute_log_widths (PangoLayout *layout,
static int
tab_width_change (ParaBreakState *state)
{
- if (state->last_tab)
- return state->last_tab->glyphs[0].geometry.width - (state->last_tab_pos - state->last_tab_width);
+ if (state->last_tab.glyphs)
+ return state->last_tab.glyphs->glyphs[0].geometry.width - (state->last_tab.pos - state->last_tab.width);
return 0;
}
@@ -4116,7 +4104,7 @@ process_item (PangoLayout *layout,
extra_width = 0;
if ((width + extra_width <= state->remaining_width || (item->num_chars == 1 && !line->runs) ||
- (state->last_tab && state->last_tab_align != PANGO_TAB_LEFT)) &&
+ (state->last_tab.glyphs && state->last_tab.align != PANGO_TAB_LEFT)) &&
!no_break_at_end)
{
PangoGlyphString *glyphs;
@@ -4487,8 +4475,9 @@ process_line (PangoLayout *layout,
else
state->remaining_width = state->line_width;
- state->last_tab = NULL;
- state->last_tab_align = PANGO_TAB_LEFT;
+ state->last_tab.glyphs = NULL;
+ state->last_tab.index = 0;
+ state->last_tab.align = PANGO_TAB_LEFT;
DEBUG ("starting to fill line", line, state);