[pango/redo-attrs: 20/25] More work on line styles
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/redo-attrs: 20/25] More work on line styles
- Date: Sun, 13 Feb 2022 20:31:45 +0000 (UTC)
commit 086586622c11ebf3d3fd54d26a6779248e7cbc40
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Feb 7 02:36:19 2022 -0500
More work on line styles
pango/pango-attr-list.c | 4 +--
pango/pango-attributes.c | 6 ++---
pango/pango-attributes.h | 24 +++++------------
pango/pango-layout.c | 45 ++++++++++++++++++--------------
pango/pango-markup.c | 6 ++---
pango/pango-renderer.c | 68 +++++++++++++++++++++++++++++++-----------------
pango/pango-renderer.h | 2 ++
pango/serializer.c | 13 ++-------
tests/testattributes.c | 4 +--
9 files changed, 89 insertions(+), 83 deletions(-)
---
diff --git a/pango/pango-attr-list.c b/pango/pango-attr-list.c
index 505963f2..ca82fd60 100644
--- a/pango/pango-attr-list.c
+++ b/pango/pango-attr-list.c
@@ -767,7 +767,7 @@ get_attr_value_type (PangoAttrType type)
case PANGO_ATTR_GRAVITY_HINT: return PANGO_TYPE_GRAVITY_HINT;
case PANGO_ATTR_UNDERLINE: return PANGO_TYPE_LINE_STYLE;
case PANGO_ATTR_STRIKETHROUGH: return PANGO_TYPE_LINE_STYLE;
- case PANGO_ATTR_OVERLINE: return PANGO_TYPE_OVERLINE;
+ case PANGO_ATTR_OVERLINE: return PANGO_TYPE_LINE_STYLE;
case PANGO_ATTR_BASELINE_SHIFT: return PANGO_TYPE_BASELINE_SHIFT;
case PANGO_ATTR_FONT_SCALE: return PANGO_TYPE_FONT_SCALE;
case PANGO_ATTR_TEXT_TRANSFORM: return PANGO_TYPE_TEXT_TRANSFORM;
@@ -1217,7 +1217,7 @@ pango_attr_list_from_string (const char *text)
break;
case PANGO_ATTR_OVERLINE:
- ENUM_ATTR(overline, PangoOverline, PANGO_OVERLINE_NONE, PANGO_OVERLINE_SINGLE);
+ ENUM_ATTR(overline, PangoLineStyle, PANGO_LINE_STYLE_NONE, PANGO_LINE_STYLE_DOTTED);
break;
case PANGO_ATTR_OVERLINE_COLOR:
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 1e305229..2dd7ac25 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -734,7 +734,7 @@ pango_attr_sentence_new (void)
/**
* pango_attr_overline_new:
- * @overline: the overline style
+ * @style: the line style
*
* Create a new overline-style attribute.
*
@@ -745,9 +745,9 @@ pango_attr_sentence_new (void)
* Since: 1.46
*/
PangoAttribute *
-pango_attr_overline_new (PangoOverline overline)
+pango_attr_overline_new (PangoLineStyle style)
{
- return pango_attr_int_new (PANGO_ATTR_OVERLINE, (int)overline);
+ return pango_attr_int_new (PANGO_ATTR_OVERLINE, (int)style);
}
/**
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index b9b82632..10689e43 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -148,7 +148,9 @@ PangoAttribute * pango_attr_font_desc_new (const PangoFont
* @PANGO_LINE_STYLE_NONE: no line should be drawn
* @PANGO_LINE_STYLE_SINGLE: a single line should be drawn
* @PANGO_LINE_STYLE_DOUBLE: a double line should be drawn
+ * @PANGO_LINE_STYLE_DASHED: an dashed line should be drawn
* @PANGO_LINE_STYLE_DOTTED: an dotted line should be drawn
+ * @PANGO_LINE_STYLE_WAVY: an wavy line should be drawn
*
* The `PangoLineStyle` enumeration is used to specify how
* lines should be drawn.
@@ -157,7 +159,9 @@ typedef enum {
PANGO_LINE_STYLE_NONE,
PANGO_LINE_STYLE_SINGLE,
PANGO_LINE_STYLE_DOUBLE,
- PANGO_LINE_STYLE_DOTTED
+ PANGO_LINE_STYLE_DASHED,
+ PANGO_LINE_STYLE_DOTTED,
+ PANGO_LINE_STYLE_WAVY
} PangoLineStyle;
PANGO_AVAILABLE_IN_ALL
@@ -248,24 +252,8 @@ PangoAttribute * pango_attr_sentence_new (void);
PANGO_AVAILABLE_IN_1_44
PangoAttribute * pango_attr_insert_hyphens_new (gboolean
insert_hyphens);
-/**
- * PangoOverline:
- * @PANGO_OVERLINE_NONE: no overline should be drawn
- * @PANGO_OVERLINE_SINGLE: Draw a single line above the ink
- * extents of the text being underlined.
- *
- * The `PangoOverline` enumeration is used to specify whether text
- * should be overlined, and if so, the type of line.
- *
- * Since: 1.46
- */
-typedef enum {
- PANGO_OVERLINE_NONE,
- PANGO_OVERLINE_SINGLE
-} PangoOverline;
-
PANGO_AVAILABLE_IN_1_46
-PangoAttribute * pango_attr_overline_new (PangoOverline overline);
+PangoAttribute * pango_attr_overline_new (PangoLineStyle style);
PANGO_AVAILABLE_IN_1_46
PangoAttribute * pango_attr_overline_color_new (PangoColor *color);
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index cd9d2174..7d65b0ae 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -109,7 +109,7 @@ struct _ItemProperties
PangoLineStyle uline_style;
PangoUnderlinePosition uline_position;
PangoLineStyle strikethrough_style;
- guint oline_single : 1;
+ PangoLineStyle oline_style;
guint showing_space : 1;
gint letter_spacing;
double line_height;
@@ -5561,7 +5561,7 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
pango_layout_get_item_properties (run->item, &properties);
has_underline = properties.uline_style != PANGO_LINE_STYLE_NONE;
- has_overline = properties.oline_single;
+ has_overline = properties.oline_style != PANGO_LINE_STYLE_NONE;
has_strikethrough = properties.strikethrough_style != PANGO_LINE_STYLE_NONE;
if (!run_logical && (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE))
@@ -5613,13 +5613,23 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
}
}
- if (properties.oline_single)
+ if (properties.oline_style == PANGO_LINE_STYLE_SINGLE ||
+ properties.oline_style == PANGO_LINE_STYLE_DASHED ||
+ properties.oline_style == PANGO_LINE_STYLE_DOTTED)
{
run_ink->y -= underline_thickness;
run_ink->height += underline_thickness;
}
+ else if (properties.oline_style == PANGO_LINE_STYLE_DOUBLE ||
+ properties.oline_style == PANGO_LINE_STYLE_WAVY)
+ {
+ run_ink->y -= 3 * underline_thickness;
+ run_ink->height += 3 * underline_thickness;
+ }
- if (properties.uline_style == PANGO_LINE_STYLE_SINGLE)
+ if (properties.uline_style == PANGO_LINE_STYLE_SINGLE ||
+ properties.uline_style == PANGO_LINE_STYLE_DASHED ||
+ properties.uline_style == PANGO_LINE_STYLE_DOTTED)
{
if (properties.uline_position == PANGO_UNDERLINE_POSITION_UNDER)
run_ink->height += 2 * underline_thickness;
@@ -5627,12 +5637,15 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
run_ink->height = MAX (run_ink->height,
underline_thickness - underline_position - run_ink->y);
}
- else if (properties.uline_style == PANGO_LINE_STYLE_DOUBLE)
- run_ink->height = MAX (run_ink->height,
- 3 * underline_thickness - underline_position - run_ink->y);
- else if (properties.uline_style == PANGO_LINE_STYLE_DOTTED)
- run_ink->height = MAX (run_ink->height,
- 3 * underline_thickness - underline_position - run_ink->y);
+ else if (properties.uline_style == PANGO_LINE_STYLE_DOUBLE ||
+ properties.uline_style == PANGO_LINE_STYLE_WAVY)
+ {
+ if (properties.uline_position == PANGO_UNDERLINE_POSITION_UNDER)
+ run_ink->height += 4 * underline_thickness;
+ else
+ run_ink->height = MAX (run_ink->height,
+ 3 * underline_thickness - underline_position - run_ink->y);
+ }
}
if (height)
@@ -6731,7 +6744,7 @@ pango_layout_get_item_properties (PangoItem *item,
properties->uline_style = PANGO_LINE_STYLE_NONE;
properties->uline_position = PANGO_UNDERLINE_POSITION_NORMAL;
properties->strikethrough_style = PANGO_LINE_STYLE_NONE;
- properties->oline_single = FALSE;
+ properties->oline_style = PANGO_LINE_STYLE_NONE;
properties->showing_space = FALSE;
properties->letter_spacing = 0;
properties->line_height = 0.0;
@@ -6752,15 +6765,7 @@ pango_layout_get_item_properties (PangoItem *item,
break;
case PANGO_ATTR_OVERLINE:
- switch (attr->int_value)
- {
- case PANGO_OVERLINE_SINGLE:
- properties->oline_single = TRUE;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
+ properties->oline_style = attr->int_value;
break;
case PANGO_ATTR_STRIKETHROUGH:
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index b2da8e49..f8fa495a 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -1578,12 +1578,12 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
if (G_UNLIKELY (overline))
{
- PangoOverline ol = PANGO_OVERLINE_NONE;
+ PangoLineStyle style = PANGO_LINE_STYLE_NONE;
- if (!span_parse_enum ("overline", overline, PANGO_TYPE_OVERLINE, (int*)(void*)&ol, line_number, error))
+ if (!span_parse_enum ("overline", overline, PANGO_TYPE_LINE_STYLE, (int*)(void*)&style, line_number,
error))
goto error;
- add_attribute (tag, pango_attr_overline_new (ol));
+ add_attribute (tag, pango_attr_overline_new (style));
}
if (G_UNLIKELY (overline_color))
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 9fb10a42..6f6f2c73 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -49,7 +49,7 @@ struct _LineState
PangoRectangle strikethrough_rect;
int strikethrough_glyphs;
- PangoOverline overline;
+ PangoLineStyle overline;
PangoRectangle overline_rect;
int logical_rect_end;
@@ -63,7 +63,6 @@ struct _PangoRendererPrivate
PangoLayoutLine *line;
LineState *line_state;
- PangoOverline overline;
};
static void pango_renderer_finalize (GObject *gobject);
@@ -234,6 +233,8 @@ draw_underline (PangoRenderer *renderer,
rect->height);
G_GNUC_FALLTHROUGH;
case PANGO_LINE_STYLE_SINGLE:
+ case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_DASHED:
pango_renderer_draw_rectangle (renderer,
PANGO_RENDER_PART_UNDERLINE,
rect->x,
@@ -241,7 +242,7 @@ draw_underline (PangoRenderer *renderer,
rect->width,
rect->height);
break;
- case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_WAVY:
pango_renderer_draw_error_underline (renderer,
rect->x,
rect->y,
@@ -258,15 +259,26 @@ draw_overline (PangoRenderer *renderer,
LineState *state)
{
PangoRectangle *rect = &state->overline_rect;
- PangoOverline overline = state->overline;
+ PangoLineStyle overline = state->overline;
- state->overline = PANGO_OVERLINE_NONE;
+ state->overline = PANGO_LINE_STYLE_NONE;
switch (overline)
{
- case PANGO_OVERLINE_NONE:
+ case PANGO_LINE_STYLE_NONE:
break;
- case PANGO_OVERLINE_SINGLE:
+ case PANGO_LINE_STYLE_DOUBLE:
+ pango_renderer_draw_rectangle (renderer,
+ PANGO_RENDER_PART_OVERLINE,
+ rect->x,
+ rect->y - 2 * rect->height,
+ rect->width,
+ rect->height);
+ G_GNUC_FALLTHROUGH;
+ case PANGO_LINE_STYLE_SINGLE:
+ case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_DASHED:
+ case PANGO_LINE_STYLE_WAVY:
pango_renderer_draw_rectangle (renderer,
PANGO_RENDER_PART_OVERLINE,
rect->x,
@@ -305,6 +317,8 @@ draw_strikethrough (PangoRenderer *renderer,
G_GNUC_FALLTHROUGH;
case PANGO_LINE_STYLE_SINGLE:
case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_DASHED:
+ case PANGO_LINE_STYLE_WAVY:
pango_renderer_draw_rectangle (renderer,
PANGO_RENDER_PART_STRIKETHROUGH,
rect->x,
@@ -347,13 +361,13 @@ handle_line_state_change (PangoRenderer *renderer,
}
if (part == PANGO_RENDER_PART_OVERLINE &&
- state->overline != PANGO_OVERLINE_NONE)
+ state->overline != PANGO_LINE_STYLE_NONE)
{
PangoRectangle *rect = &state->overline_rect;
rect->width = state->logical_rect_end - rect->x;
draw_overline (renderer, state);
- state->overline = renderer->priv->overline;
+ state->overline = renderer->overline;
rect->x = state->logical_rect_end;
rect->width = 0;
}
@@ -395,6 +409,8 @@ add_underline (PangoRenderer *renderer,
g_assert_not_reached ();
break;
case PANGO_LINE_STYLE_SINGLE:
+ case PANGO_LINE_STYLE_DASHED:
+ case PANGO_LINE_STYLE_DOTTED:
if (renderer->underline_position == PANGO_UNDERLINE_POSITION_UNDER)
{
new_rect.y += ink_rect->y + ink_rect->height + underline_thickness;
@@ -402,7 +418,7 @@ add_underline (PangoRenderer *renderer,
}
G_GNUC_FALLTHROUGH;
case PANGO_LINE_STYLE_DOUBLE:
- case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_WAVY:
new_rect.y -= underline_position;
if (state->underline == renderer->underline)
{
@@ -452,14 +468,18 @@ add_overline (PangoRenderer *renderer,
new_rect.height = underline_thickness;
new_rect.y = base_y;
- switch (renderer->priv->overline)
+ switch (renderer->overline)
{
- case PANGO_OVERLINE_NONE:
+ case PANGO_LINE_STYLE_NONE:
g_assert_not_reached ();
break;
- case PANGO_OVERLINE_SINGLE:
+ case PANGO_LINE_STYLE_SINGLE:
+ case PANGO_LINE_STYLE_DOUBLE:
+ case PANGO_LINE_STYLE_DASHED:
+ case PANGO_LINE_STYLE_DOTTED:
+ case PANGO_LINE_STYLE_WAVY:
new_rect.y -= ascent;
- if (state->overline == renderer->priv->overline)
+ if (state->overline == renderer->overline)
{
new_rect.y = MIN (current_rect->y, new_rect.y);
new_rect.height = MAX (current_rect->height, new_rect.height);
@@ -471,7 +491,7 @@ add_overline (PangoRenderer *renderer,
break;
}
- if (renderer->priv->overline == state->overline &&
+ if (renderer->overline == state->overline &&
new_rect.y == current_rect->y &&
new_rect.height == current_rect->height)
{
@@ -482,7 +502,7 @@ add_overline (PangoRenderer *renderer,
draw_overline (renderer, state);
*current_rect = new_rect;
- state->overline = renderer->priv->overline;
+ state->overline = renderer->overline;
}
}
@@ -574,7 +594,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
state.underline = PANGO_LINE_STYLE_NONE;
state.underline_position = PANGO_UNDERLINE_POSITION_NORMAL;
- state.overline = PANGO_OVERLINE_NONE;
+ state.overline = PANGO_LINE_STYLE_NONE;
state.strikethrough = PANGO_LINE_STYLE_NONE;
text = G_LIKELY (line->layout) ? pango_layout_get_text (line->layout) : NULL;
@@ -593,7 +613,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
pango_renderer_prepare_run (renderer, run);
if (renderer->underline != PANGO_LINE_STYLE_NONE ||
- renderer->priv->overline != PANGO_OVERLINE_NONE ||
+ renderer->overline != PANGO_LINE_STYLE_NONE ||
renderer->strikethrough != PANGO_LINE_STYLE_NONE)
{
ink = &ink_rect;
@@ -646,7 +666,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
x + x_off, y - y_off);
if (renderer->underline != PANGO_LINE_STYLE_NONE ||
- renderer->priv->overline != PANGO_OVERLINE_NONE ||
+ renderer->overline != PANGO_LINE_STYLE_NONE ||
renderer->strikethrough != PANGO_LINE_STYLE_NONE)
{
metrics = pango_font_get_metrics (run->item->analysis.font,
@@ -657,7 +677,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
x + x_off, y - y_off,
ink, logical);
- if (renderer->priv->overline != PANGO_OVERLINE_NONE)
+ if (renderer->overline != PANGO_LINE_STYLE_NONE)
add_overline (renderer, &state,metrics,
x + x_off, y - y_off,
ink, logical);
@@ -674,8 +694,8 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
state.underline != PANGO_LINE_STYLE_NONE)
draw_underline (renderer, &state);
- if (renderer->priv->overline == PANGO_OVERLINE_NONE &&
- state.overline != PANGO_OVERLINE_NONE)
+ if (renderer->overline == PANGO_LINE_STYLE_NONE &&
+ state.overline != PANGO_LINE_STYLE_NONE)
draw_overline (renderer, &state);
if (renderer->strikethrough == PANGO_LINE_STYLE_NONE &&
@@ -1431,7 +1451,7 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
renderer->underline = PANGO_LINE_STYLE_NONE;
renderer->underline_position = PANGO_UNDERLINE_POSITION_NORMAL;
- renderer->priv->overline = PANGO_OVERLINE_NONE;
+ renderer->overline = PANGO_LINE_STYLE_NONE;
renderer->strikethrough = PANGO_LINE_STYLE_NONE;
for (l = run->item->analysis.extra_attrs; l; l = l->next)
@@ -1449,7 +1469,7 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
break;
case PANGO_ATTR_OVERLINE:
- renderer->priv->overline = attr->int_value;
+ renderer->overline = attr->int_value;
break;
case PANGO_ATTR_STRIKETHROUGH:
diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h
index 6848f749..2151a243 100644
--- a/pango/pango-renderer.h
+++ b/pango/pango-renderer.h
@@ -82,6 +82,8 @@ struct _PangoRenderer
PangoLineStyle underline;
PangoUnderlinePosition underline_position;
PangoLineStyle strikethrough;
+ PangoLineStyle overline;
+
int active_count;
/*< public >*/
diff --git a/pango/serializer.c b/pango/serializer.c
index 61650b22..4e88351d 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -86,12 +86,6 @@ static const char *underline_position_names[] = {
NULL
};
-static const char *overline_names[] = {
- "none",
- "single",
- NULL
-};
-
static const char *gravity_names[] = {
"south",
"east",
@@ -325,6 +319,7 @@ add_attribute (GtkJsonPrinter *printer,
case PANGO_ATTR_UNDERLINE:
case PANGO_ATTR_STRIKETHROUGH:
+ case PANGO_ATTR_OVERLINE:
gtk_json_printer_add_string (printer, "value", line_style_names[attr->int_value]);
break;
@@ -332,10 +327,6 @@ add_attribute (GtkJsonPrinter *printer,
gtk_json_printer_add_string (printer, "value", underline_position_names[attr->int_value]);
break;
- case PANGO_ATTR_OVERLINE:
- gtk_json_printer_add_string (printer, "value", overline_names[attr->int_value]);
- break;
-
case PANGO_ATTR_GRAVITY:
gtk_json_printer_add_string (printer, "value", gravity_names[attr->int_value]);
break;
@@ -1089,7 +1080,7 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_OVERLINE:
- attr = pango_attr_overline_new ((PangoOverline) parser_select_string (parser, overline_names));
+ attr = pango_attr_overline_new ((PangoLineStyle) parser_select_string (parser, line_style_names));
break;
case PANGO_ATTR_OVERLINE_COLOR:
diff --git a/tests/testattributes.c b/tests/testattributes.c
index c308d67c..71144821 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -53,7 +53,7 @@ test_attributes_basic (void)
test_copy (pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
test_copy (pango_attr_underline_new (PANGO_LINE_STYLE_DOTTED));
test_copy (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
- test_copy (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
+ test_copy (pango_attr_overline_new (PANGO_LINE_STYLE_SINGLE));
test_copy (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
test_copy (pango_attr_strikethrough_new (TRUE));
test_copy (pango_attr_strikethrough_color_new (&(PangoColor){100, 200, 300}));
@@ -233,7 +233,7 @@ test_binding_helpers (void)
test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_DOTTED));
test_binding (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
- test_binding (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
+ test_binding (pango_attr_overline_new (PANGO_LINE_STYLE_SINGLE));
test_binding (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
test_binding (pango_attr_strikethrough_new (TRUE));
test_binding (pango_attr_strikethrough_color_new (&(PangoColor){100, 200, 300}));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]