summaryrefslogtreecommitdiff
path: root/pango/pango-tabs.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-29 00:09:50 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-11-29 08:12:11 -0500
commitae8297b785eacc61890b6042c0f89af6f65b3bb3 (patch)
tree2ea240fdb43f818145781910cb1116e4a1a03d17 /pango/pango-tabs.c
parenta6ed4ff80188bb0472891b08c421d3ca4c846315 (diff)
downloadpango-ae8297b785eacc61890b6042c0f89af6f65b3bb3.tar.gz
tabs: Add a decimal point
This is useful for PANGO_TAB_DECIMAL. Implement this in PangoLayout, in the serializer, and update tests.
Diffstat (limited to 'pango/pango-tabs.c')
-rw-r--r--pango/pango-tabs.c94
1 files changed, 82 insertions, 12 deletions
diff --git a/pango/pango-tabs.c b/pango/pango-tabs.c
index 47ac95c3..318f305b 100644
--- a/pango/pango-tabs.c
+++ b/pango/pango-tabs.c
@@ -28,12 +28,9 @@ typedef struct _PangoTab PangoTab;
struct _PangoTab
{
- gint location; /* Offset in pixels of this tab stop
- * from the left margin of the text.
- */
- PangoTabAlign alignment; /* Where the tab stop appears relative
- * to the text.
- */
+ int location;
+ PangoTabAlign alignment;
+ gunichar decimal_point;
};
/**
@@ -42,7 +39,8 @@ struct _PangoTab
* A `PangoTabArray` contains an array of tab stops.
*
* `PangoTabArray` can be used to set tab stops in a `PangoLayout`.
- * Each tab stop has an alignment and a position.
+ * Each tab stop has an alignment, a position, and optionally
+ * a character to use as decimal point.
*/
struct _PangoTabArray
{
@@ -59,6 +57,7 @@ init_tabs (PangoTabArray *array, gint start, gint end)
{
array->tabs[start].location = 0;
array->tabs[start].alignment = PANGO_TAB_LEFT;
+ array->tabs[start].decimal_point = 0;
++start;
}
}
@@ -141,6 +140,7 @@ pango_tab_array_new_with_positions (gint size,
array->tabs[0].alignment = first_alignment;
array->tabs[0].location = first_position;
+ array->tabs[0].decimal_point = 0;
if (size == 1)
return array;
@@ -155,6 +155,7 @@ pango_tab_array_new_with_positions (gint size,
array->tabs[i].alignment = align;
array->tabs[i].location = pos;
+ array->tabs[i].decimal_point = 0;
++i;
}
@@ -266,9 +267,6 @@ pango_tab_array_resize (PangoTabArray *tab_array,
* @location: tab location in Pango units
*
* Sets the alignment and location of a tab stop.
- *
- * @alignment must always be %PANGO_TAB_LEFT in the current
- * implementation.
*/
void
pango_tab_array_set_tab (PangoTabArray *tab_array,
@@ -409,6 +407,9 @@ pango_tab_array_to_string (PangoTabArray *tab_array)
g_string_append_printf (s, "%d", tab_array->tabs[i].location);
if (tab_array->positions_in_pixels)
g_string_append (s, "px");
+
+ if (tab_array->tabs[i].decimal_point != 0)
+ g_string_append_printf (s, ":%d", tab_array->tabs[i].decimal_point);
}
return g_string_free (s, FALSE);
@@ -483,10 +484,9 @@ pango_tab_array_from_string (const char *text)
pos = g_ascii_strtoll (p, &endp, 10);
if (pos < 0 ||
(pixels && *endp != 'p') ||
- (!pixels && !g_ascii_isspace (*endp) && *endp != '\0')) goto fail;
+ (!pixels && !g_ascii_isspace (*endp) && *endp != ':' && *endp != '\0')) goto fail;
pango_tab_array_set_tab (array, i, align, pos);
- i++;
p = (const char *)endp;
if (pixels)
@@ -494,7 +494,23 @@ pango_tab_array_from_string (const char *text)
if (p[0] != 'p' || p[1] != 'x') goto fail;
p += 2;
}
+
+ if (p[0] == ':')
+ {
+ gunichar ch;
+
+ p++;
+ ch = g_ascii_strtoll (p, &endp, 10);
+ if (!g_ascii_isspace (*endp) && *endp != '\0') goto fail;
+
+ pango_tab_array_set_decimal_point (array, i, ch);
+
+ p = (const char *)endp;
+ }
+
p = skip_whitespace (p);
+
+ i++;
}
goto success;
@@ -506,3 +522,57 @@ fail:
success:
return array;
}
+
+/**
+ * pango_tab_array_set_decimal_point:
+ * @tab_array: a `PangoTabArray`
+ * @tab_index: the index of a tab stop
+ * @decimal_point: the decimal point to use
+ *
+ * Sets the decimal point to use.
+ *
+ * This is only relevant for %PANGO_TAB_DECIMAL.
+ *
+ * By default, Pango uses the decimal point according
+ * to the current locale.
+ *
+ * Since: 1.50
+ */
+void
+pango_tab_array_set_decimal_point (PangoTabArray *tab_array,
+ int tab_index,
+ gunichar decimal_point)
+{
+ g_return_if_fail (tab_array != NULL);
+ g_return_if_fail (tab_index >= 0);
+
+ if (tab_index >= tab_array->size)
+ pango_tab_array_resize (tab_array, tab_index + 1);
+
+ tab_array->tabs[tab_index].decimal_point = decimal_point;
+}
+
+/**
+ * pango_tab_array_get_decimal_point:
+ * @tab_array: a `PangoTabArray`
+ * @tab_index: the index of a tab stop
+ *
+ * Gets the decimal point to use.
+ *
+ * This is only relevant for %PANGO_TAB_DECIMAL.
+ *
+ * The default value of 0 means that Pango will use the
+ * decimal point according to the current locale.
+ *
+ * Since: 1.50
+ */
+gunichar
+pango_tab_array_get_decimal_point (PangoTabArray *tab_array,
+ int tab_index)
+{
+ g_return_val_if_fail (tab_array != NULL, 0);
+ g_return_val_if_fail (tab_index < tab_array->size, 0);
+ g_return_val_if_fail (tab_index >= 0, 0);
+
+ return tab_array->tabs[tab_index].decimal_point;
+}