Compare commits

...

1 Commits

Author SHA1 Message Date
Matthias Clasen
e91c1861ef wip: Add superscript and subscript to GtkTextTag
And update the markup demo to just use <sup>.
since it works now.

FIXME: this does not work since it does not accumulate.
2021-09-01 14:01:37 -04:00
8 changed files with 73 additions and 9 deletions

View File

@@ -287,10 +287,11 @@ insert_tags_for_attributes (GtkTextBuffer *buffer,
INT_ATTR (baseline_shift);
break;
/* Ignore font scale, since we treat baseline-shift as indicating
* both. And in practice, they will basically always occur together
* (from a <sup> or <sub>)
*/
case PANGO_ATTR_FONT_SCALE:
INT_ATTR (font_scale);
break;
case PANGO_ATTR_SHAPE:
case PANGO_ATTR_ABSOLUTE_SIZE:
case PANGO_ATTR_GRAVITY:

View File

@@ -11,7 +11,7 @@ Colorful <span underline="low" underline-color="blue"><span underline="double" u
Colorful <span strikethrough="true" strikethrough-color="magenta">strikethroughs</span> and <span overline="single" overline_color="green">overlines</span>
Superscripts and subscripts: 𝜀<span rise="-6000" size="x-small" font_desc="italic">0</span> = 𝜔<span rise="8000" size="smaller">𝜔<span rise="14000" size="smaller">𝜔<span rise="20000">.<span rise="23000">.<span rise="26000">.</span></span></span></span></span>
Superscripts and subscripts: <span font="italic">ε<sub><span size='smaller'>0</span></sub> = ω<sup>ω<sup>ω<sup>.<sup>.<sup>.</sup></sup></sup></sup></sup></span>
<span letter_spacing="3000">Letterspacing</span>

View File

@@ -447,6 +447,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
if (tag->priv->sentence_set)
dest->sentence = vals->sentence;
if (tag->priv->baseline_shift_set)
dest->baseline_shift = vals->baseline_shift;
}
dest->left_margin += left_margin_accumulative;
@@ -477,7 +480,8 @@ _gtk_text_tag_affects_size (GtkTextTag *tag)
priv->invisible_set ||
priv->font_features_set ||
priv->letter_spacing_set ||
priv->text_transform_set;
priv->text_transform_set ||
priv->baseline_shift_set;
}
gboolean

View File

@@ -108,7 +108,7 @@ struct _GtkTextAppearance
* @wrap_mode: `GtkWrapMode` for text.
* @language: `PangoLanguage` for text.
* @invisible: Hide the text.
* @bg_full_height: Background is fit to full line height rather than
* @bg_full_height: Background is fit to full line height rather than:
* baseline +/- ascent/descent (font height).
* @editable: Can edit this text.
* @no_fallback: Whether to disable font fallback.
@@ -162,6 +162,7 @@ struct _GtkTextAttributes
guint text_transform : 3; /* PangoTextTransform */
guint word : 1;
guint sentence : 1;
guint baseline_shift : 2; /* PangoFontScale / PangoBaselineShift */
};
GtkTextAttributes* gtk_text_attributes_new (void);

View File

@@ -4740,10 +4740,11 @@ insert_tags_for_attributes (GtkTextBuffer *buffer,
INT_ATTR (baseline_shift);
break;
/* Ignore font scale, since we treat baseline-shift as indicating
* both. And in practice, they will basically always occur together
* (from a <sup> or <sub>)
*/
case PANGO_ATTR_FONT_SCALE:
INT_ATTR (font_scale);
break;
case PANGO_ATTR_SHAPE:
case PANGO_ATTR_ABSOLUTE_SIZE:
case PANGO_ATTR_GRAVITY:

View File

@@ -1710,6 +1710,21 @@ add_text_attrs (GtkTextLayout *layout,
attr->start_index = start;
attr->end_index = start + byte_count;
pango_attr_list_insert (attrs, attr);
}
if (style->baseline_shift)
{
attr = pango_attr_baseline_shift_new (style->baseline_shift);
attr->start_index = start;
attr->end_index = start + byte_count;
pango_attr_list_insert (attrs, attr);
attr = pango_attr_font_scale_new (style->baseline_shift);
attr->start_index = start;
attr->end_index = start + byte_count;
pango_attr_list_insert (attrs, attr);
}
}

View File

@@ -137,6 +137,7 @@ enum {
PROP_TEXT_TRANSFORM,
PROP_WORD,
PROP_SENTENCE,
PROP_BASELINE_SHIFT,
/* Behavior args */
PROP_ACCUMULATIVE_MARGIN,
@@ -182,6 +183,7 @@ enum {
PROP_TEXT_TRANSFORM_SET,
PROP_WORD_SET,
PROP_SENTENCE_SET,
PROP_BASELINE_SHIFT_SET,
LAST_ARG
};
@@ -912,6 +914,23 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkTextTag:baseline-shift:
*
* Whether the tag contents should be shifted to superscript or subscript position,
* relative to the previous content. This also changes the font to a smaller size.
*
* Since: 4.6
*/
g_object_class_install_property (object_class,
PROP_BASELINE_SHIFT,
g_param_spec_enum ("baseline-shift",
P_("Baseline Shift"),
P_("Whether to shift the baseline."),
PANGO_TYPE_BASELINE_SHIFT,
PANGO_BASELINE_SHIFT_NONE,
GTK_PARAM_READWRITE));
/**
* GtkTextTag:accumulative-margin:
*
@@ -1102,6 +1121,10 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
ADD_SET_PROP ("sentence-set", PROP_WORD_SET,
P_("Sentence set"),
P_("Whether this tag represents a single sentence"));
ADD_SET_PROP ("baseline-shift-set", PROP_BASELINE_SHIFT_SET,
P_("Baseline Shift set"),
P_("Whether this tag represents a baseline shift"));
}
static void
@@ -1869,6 +1892,12 @@ gtk_text_tag_set_property (GObject *object,
g_object_notify (object, "sentence-set");
break;
case PROP_BASELINE_SHIFT:
priv->baseline_shift_set = TRUE;
priv->values->baseline_shift = g_value_get_enum (value);
g_object_notify (object, "baseline-shift-set");
break;
case PROP_ACCUMULATIVE_MARGIN:
priv->accumulative_margin = g_value_get_boolean (value);
g_object_notify (object, "accumulative-margin");
@@ -2045,6 +2074,10 @@ gtk_text_tag_set_property (GObject *object,
priv->sentence_set = g_value_get_boolean (value);
break;
case PROP_BASELINE_SHIFT_SET:
priv->baseline_shift_set = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -2269,6 +2302,10 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_boolean (value, priv->values->sentence);
break;
case PROP_BASELINE_SHIFT:
g_value_set_boolean (value, priv->values->baseline_shift);
break;
case PROP_ACCUMULATIVE_MARGIN:
g_value_set_boolean (value, priv->accumulative_margin);
break;
@@ -2423,6 +2460,10 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_boolean (value, priv->sentence_set);
break;
case PROP_BASELINE_SHIFT_SET:
g_value_set_boolean (value, priv->baseline_shift_set);
break;
case PROP_BACKGROUND:
case PROP_FOREGROUND:
case PROP_PARAGRAPH_BACKGROUND:

View File

@@ -90,6 +90,7 @@ struct _GtkTextTagPrivate
guint text_transform_set : 1;
guint word_set : 1;
guint sentence_set : 1;
guint baseline_shift_set : 1;
/* Whether these margins accumulate or override */
guint accumulative_margin : 1;