[pango/pango2: 41/168] Shuffle utils around
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 41/168] Shuffle utils around
- Date: Mon, 20 Jun 2022 16:28:39 +0000 (UTC)
commit fd7e223aa79d238d6d05e4e9e9398c900ed6f58f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jun 7 21:07:53 2022 -0400
Shuffle utils around
pango/pango-markup.c | 1114 ++++++++++++++++++++++++------------------
pango/pango-utils-internal.h | 19 -
pango/pango-utils.c | 219 ---------
3 files changed, 640 insertions(+), 712 deletions(-)
---
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index e8bd9bf6..b9dee89e 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -10,7 +10,7 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
@@ -85,78 +85,244 @@ struct _OpenTag
};
typedef gboolean (*TagParseFunc) (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean b_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean big_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean span_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean i_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean markup_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean s_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean sub_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean sup_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean small_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean tt_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
static gboolean u_parse_func (MarkupData *md,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error);
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error);
+
+static gboolean
+_pango_scan_int (const char **pos, int *out)
+{
+ char *end;
+ long temp;
+
+ errno = 0;
+ temp = strtol (*pos, &end, 10);
+ if (errno == ERANGE)
+ {
+ errno = 0;
+ return FALSE;
+ }
+
+ *out = (int)temp;
+ if ((long)(*out) != temp)
+ {
+ return FALSE;
+ }
+
+ *pos = end;
+
+ return TRUE;
+}
+
+static gboolean
+parse_int (const char *word,
+ int *out)
+{
+ char *end;
+ long val;
+ int i;
+
+ if (word == NULL)
+ return FALSE;
+
+ val = strtol (word, &end, 10);
+ i = val;
+
+ if (end != word && *end == '\0' && val >= 0 && val == i)
+ {
+ if (out)
+ *out = i;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+_pango_parse_enum (GType type,
+ const char *str,
+ int *value,
+ gboolean warn,
+ char **possible_values)
+{
+ GEnumClass *class = NULL;
+ gboolean ret = TRUE;
+ GEnumValue *v = NULL;
+
+ class = g_type_class_ref (type);
+
+ if (G_LIKELY (str))
+ v = g_enum_get_value_by_nick (class, str);
+
+ if (v)
+ {
+ if (G_LIKELY (value))
+ *value = v->value;
+ }
+ else if (!parse_int (str, value))
+ {
+ ret = FALSE;
+ if (G_LIKELY (warn || possible_values))
+ {
+ int i;
+ GString *s = g_string_new (NULL);
+
+ for (i = 0, v = g_enum_get_value (class, i); v;
+ i++ , v = g_enum_get_value (class, i))
+ {
+ if (i)
+ g_string_append_c (s, '/');
+ g_string_append (s, v->value_nick);
+ }
+
+ if (warn)
+ g_warning ("%s must be one of %s",
+ G_ENUM_CLASS_TYPE_NAME(class),
+ s->str);
+
+ if (possible_values)
+ *possible_values = s->str;
+
+ g_string_free (s, possible_values ? FALSE : TRUE);
+ }
+ }
+
+ g_type_class_unref (class);
+
+ return ret;
+}
+
+static gboolean
+pango_parse_flags (GType type,
+ const char *str,
+ int *value,
+ char **possible_values)
+{
+ GFlagsClass *class = NULL;
+ gboolean ret = TRUE;
+ GFlagsValue *v = NULL;
+
+ class = g_type_class_ref (type);
+
+ v = g_flags_get_value_by_nick (class, str);
+
+ if (v)
+ {
+ *value = v->value;
+ }
+ else if (!parse_int (str, value))
+ {
+ char **strv = g_strsplit (str, "|", 0);
+ int i;
+
+ *value = 0;
+
+ for (i = 0; strv[i]; i++)
+ {
+ strv[i] = g_strstrip (strv[i]);
+ v = g_flags_get_value_by_nick (class, strv[i]);
+ if (!v)
+ {
+ ret = FALSE;
+ break;
+ }
+ *value |= v->value;
+ }
+ g_strfreev (strv);
+
+ if (!ret && possible_values)
+ {
+ int i;
+ GString *s = g_string_new (NULL);
+
+ for (i = 0; i < class->n_values; i++)
+ {
+ v = &class->values[i];
+ if (i)
+ g_string_append_c (s, '/');
+ g_string_append (s, v->value_nick);
+ }
+
+ *possible_values = s->str;
+
+ g_string_free (s, FALSE);
+ }
+ }
+
+ g_type_class_unref (class);
+
+ return ret;
+}
static double
scale_factor (int scale_level, double base)
@@ -170,21 +336,21 @@ scale_factor (int scale_level, double base)
{
i = 0;
while (i < scale_level)
- {
- factor *= 1.2;
+ {
+ factor *= 1.2;
- ++i;
- }
+ ++i;
+ }
}
else if (scale_level < 0)
{
i = scale_level;
while (i < 0)
- {
- factor /= 1.2;
+ {
+ factor /= 1.2;
- ++i;
- }
+ ++i;
+ }
}
return factor;
@@ -200,7 +366,7 @@ open_tag_free (OpenTag *ot)
static void
open_tag_set_absolute_font_size (OpenTag *ot,
- int font_size)
+ int font_size)
{
ot->base_font_size = font_size;
ot->has_base_font_size = TRUE;
@@ -210,7 +376,7 @@ open_tag_set_absolute_font_size (OpenTag *ot,
static void
open_tag_set_absolute_font_scale (OpenTag *ot,
- double scale)
+ double scale)
{
ot->base_scale_factor = scale;
ot->has_base_font_size = FALSE;
@@ -267,7 +433,7 @@ markup_data_close_tag (MarkupData *md)
/* pop the stack */
ot = md->tag_stack->data;
md->tag_stack = g_slist_delete_link (md->tag_stack,
- md->tag_stack);
+ md->tag_stack);
/* Adjust end indexes, and push each attr onto the front of the
* to_apply list. This means that outermost tags are on the front of
@@ -295,7 +461,7 @@ markup_data_close_tag (MarkupData *md)
PangoAttribute *a;
if (ot->has_base_font_size)
- {
+ {
/* Create a font using the absolute point size as the base size
* to be scaled from.
* We need to use a local variable to ensure that the compiler won't
@@ -306,15 +472,15 @@ markup_data_close_tag (MarkupData *md)
size = scale_factor (ot->scale_level, 1.0) * ot->base_font_size;
a = pango_attr_size_new (size);
- }
+ }
else
- {
- /* Create a font using the current scale factor
- * as the base size to be scaled from
- */
- a = pango_attr_scale_new (scale_factor (ot->scale_level,
- ot->base_scale_factor));
- }
+ {
+ /* Create a font using the current scale factor
+ * as the base size to be scaled from
+ */
+ a = pango_attr_scale_new (scale_factor (ot->scale_level,
+ ot->base_scale_factor));
+ }
a->start_index = ot->start_index;
a->end_index = md->index;
@@ -328,11 +494,11 @@ markup_data_close_tag (MarkupData *md)
static void
start_element_handler (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
{
TagParseFunc parse_func = NULL;
OpenTag *ot;
@@ -341,42 +507,42 @@ start_element_handler (GMarkupParseContext *context,
{
case 'b':
if (strcmp ("b", element_name) == 0)
- parse_func = b_parse_func;
+ parse_func = b_parse_func;
else if (strcmp ("big", element_name) == 0)
- parse_func = big_parse_func;
+ parse_func = big_parse_func;
break;
case 'i':
if (strcmp ("i", element_name) == 0)
- parse_func = i_parse_func;
+ parse_func = i_parse_func;
break;
case 'm':
if (strcmp ("markup", element_name) == 0)
- parse_func = markup_parse_func;
+ parse_func = markup_parse_func;
break;
case 's':
if (strcmp ("span", element_name) == 0)
- parse_func = span_parse_func;
+ parse_func = span_parse_func;
else if (strcmp ("s", element_name) == 0)
- parse_func = s_parse_func;
+ parse_func = s_parse_func;
else if (strcmp ("sub", element_name) == 0)
- parse_func = sub_parse_func;
+ parse_func = sub_parse_func;
else if (strcmp ("sup", element_name) == 0)
- parse_func = sup_parse_func;
+ parse_func = sup_parse_func;
else if (strcmp ("small", element_name) == 0)
- parse_func = small_parse_func;
+ parse_func = small_parse_func;
break;
case 't':
if (strcmp ("tt", element_name) == 0)
- parse_func = tt_parse_func;
+ parse_func = tt_parse_func;
break;
case 'u':
if (strcmp ("u", element_name) == 0)
- parse_func = u_parse_func;
+ parse_func = u_parse_func;
break;
default:
@@ -388,14 +554,14 @@ start_element_handler (GMarkupParseContext *context,
gint line_number, char_number;
g_markup_parse_context_get_position (context,
- &line_number, &char_number);
+ &line_number, &char_number);
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- _("Unknown tag '%s' on line %d char %d"),
- element_name,
- line_number, char_number);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ _("Unknown tag '%s' on line %d char %d"),
+ element_name,
+ line_number, char_number);
return;
}
@@ -405,8 +571,8 @@ start_element_handler (GMarkupParseContext *context,
/* note ot may be NULL if the user didn't want the attribute list */
if (!(*parse_func) (user_data, ot,
- attribute_names, attribute_values,
- context, error))
+ attribute_names, attribute_values,
+ context, error))
{
/* there's nothing to do; we return an error, and end up
* freeing ot off the tag stack later.
@@ -416,19 +582,19 @@ start_element_handler (GMarkupParseContext *context,
static void
end_element_handler (GMarkupParseContext *context G_GNUC_UNUSED,
- const gchar *element_name G_GNUC_UNUSED,
- gpointer user_data,
- GError **error G_GNUC_UNUSED)
+ const gchar *element_name G_GNUC_UNUSED,
+ gpointer user_data,
+ GError **error G_GNUC_UNUSED)
{
markup_data_close_tag (user_data);
}
static void
text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error G_GNUC_UNUSED)
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error G_GNUC_UNUSED)
{
MarkupData *md = user_data;
@@ -448,7 +614,7 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
const gchar *range_start;
const gchar *range_end;
gssize uline_index = -1;
- gsize uline_len = 0; /* Quiet GCC */
+ gsize uline_len = 0; /* Quiet GCC */
range_end = NULL;
range_start = text;
@@ -456,45 +622,45 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
end = text + text_len;
while (p != end)
- {
- gunichar c;
-
- c = g_utf8_get_char (p);
-
- if (range_end)
- {
- if (c == md->accel_marker)
- {
- /* escaped accel marker; move range_end
- * past the accel marker that came before,
- * append the whole thing
- */
- range_end = g_utf8_next_char (range_end);
- g_string_append_len (md->text,
- range_start,
- range_end - range_start);
- md->index += range_end - range_start;
-
- /* set next range_start, skipping accel marker */
- range_start = g_utf8_next_char (p);
- }
- else
- {
- /* Don't append the accel marker (leave range_end
- * alone); set the accel char to c; record location for
- * underline attribute
- */
- if (md->accel_char == 0)
- md->accel_char = c;
-
- g_string_append_len (md->text,
- range_start,
- range_end - range_start);
- md->index += range_end - range_start;
-
- /* The underline should go underneath the char
- * we're setting as the next range_start
- */
+ {
+ gunichar c;
+
+ c = g_utf8_get_char (p);
+
+ if (range_end)
+ {
+ if (c == md->accel_marker)
+ {
+ /* escaped accel marker; move range_end
+ * past the accel marker that came before,
+ * append the whole thing
+ */
+ range_end = g_utf8_next_char (range_end);
+ g_string_append_len (md->text,
+ range_start,
+ range_end - range_start);
+ md->index += range_end - range_start;
+
+ /* set next range_start, skipping accel marker */
+ range_start = g_utf8_next_char (p);
+ }
+ else
+ {
+ /* Don't append the accel marker (leave range_end
+ * alone); set the accel char to c; record location for
+ * underline attribute
+ */
+ if (md->accel_char == 0)
+ md->accel_char = c;
+
+ g_string_append_len (md->text,
+ range_start,
+ range_end - range_start);
+ md->index += range_end - range_start;
+
+ /* The underline should go underneath the char
+ * we're setting as the next range_start
+ */
if (md->attr_list != NULL)
{
/* Add the underline indicating the accelerator */
@@ -518,19 +684,19 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
pango_attr_list_change (md->attr_list, attr);
}
- /* set next range_start to include this char */
- range_start = p;
- }
+ /* set next range_start to include this char */
+ range_start = p;
+ }
- /* reset range_end */
- range_end = NULL;
- }
- else if (c == md->accel_marker)
- {
- range_end = p;
- }
+ /* reset range_end */
+ range_end = NULL;
+ }
+ else if (c == md->accel_marker)
+ {
+ range_end = p;
+ }
- p = g_utf8_next_char (p);
+ p = g_utf8_next_char (p);
}
g_string_append_len (md->text,
@@ -570,8 +736,8 @@ destroy_markup_data (MarkupData *md)
static GMarkupParseContext *
pango_markup_parser_new_internal (char accel_marker,
- GError **error,
- gboolean want_attr_list)
+ GError **error,
+ gboolean want_attr_list)
{
MarkupData *md;
GMarkupParseContext *context;
@@ -597,7 +763,7 @@ pango_markup_parser_new_internal (char accel_marker,
md->to_apply = NULL;
context = g_markup_parse_context_new (&pango_markup_parser,
- 0, md,
+ 0, md,
(GDestroyNotify)destroy_markup_data);
if (!g_markup_parse_context_parse (context, "<markup>", -1, error))
@@ -638,12 +804,12 @@ pango_markup_parser_new_internal (char accel_marker,
**/
gboolean
pango_parse_markup (const char *markup_text,
- int length,
- gunichar accel_marker,
- PangoAttrList **attr_list,
- char **text,
- gunichar *accel_char,
- GError **error)
+ int length,
+ gunichar accel_marker,
+ PangoAttrList **attr_list,
+ char **text,
+ gunichar *accel_char,
+ GError **error)
{
GMarkupParseContext *context = NULL;
gboolean ret = FALSE;
@@ -765,14 +931,14 @@ pango_markup_parser_finish (GMarkupParseContext *context,
*/
tmp_list = md->to_apply;
while (tmp_list != NULL)
- {
- PangoAttribute *attr = tmp_list->data;
+ {
+ PangoAttribute *attr = tmp_list->data;
- /* Innermost tags before outermost */
- pango_attr_list_insert (md->attr_list, attr);
+ /* Innermost tags before outermost */
+ pango_attr_list_insert (md->attr_list, attr);
- tmp_list = g_slist_next (tmp_list);
- }
+ tmp_list = g_slist_next (tmp_list);
+ }
g_slist_free (md->to_apply);
md->to_apply = NULL;
}
@@ -801,27 +967,27 @@ pango_markup_parser_finish (GMarkupParseContext *context,
static void
set_bad_attribute (GError **error,
- GMarkupParseContext *context,
- const char *element_name,
- const char *attribute_name)
+ GMarkupParseContext *context,
+ const char *element_name,
+ const char *attribute_name)
{
gint line_number, char_number;
g_markup_parse_context_get_position (context,
- &line_number, &char_number);
+ &line_number, &char_number);
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
- _("Tag '%s' does not support attribute '%s' on line %d char %d"),
- element_name,
- attribute_name,
- line_number, char_number);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ _("Tag '%s' does not support attribute '%s' on line %d char %d"),
+ element_name,
+ attribute_name,
+ line_number, char_number);
}
static void
add_attribute (OpenTag *ot,
- PangoAttribute *attr)
+ PangoAttribute *attr)
{
if (ot == NULL)
pango_attribute_destroy (attr);
@@ -830,18 +996,18 @@ add_attribute (OpenTag *ot,
}
#define CHECK_NO_ATTRS(elem) G_STMT_START { \
- if (*names != NULL) { \
- set_bad_attribute (error, context, (elem), *names); \
- return FALSE; \
- } }G_STMT_END
+ if (*names != NULL) { \
+ set_bad_attribute (error, context, (elem), *names); \
+ return FALSE; \
+ } }G_STMT_END
static gboolean
b_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("b");
add_attribute (tag, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
@@ -850,11 +1016,11 @@ b_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
big_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("big");
@@ -931,7 +1097,7 @@ done:
/* a string compare func that ignores '-' vs '_' differences */
static gint
attr_strcmp (gconstpointer pa,
- gconstpointer pb)
+ gconstpointer pb)
{
const char *a = pa;
const char *b = pb;
@@ -945,13 +1111,13 @@ attr_strcmp (gconstpointer pa,
cb = *b++;
if (ca == cb)
- continue;
+ continue;
ca = ca == '_' ? '-' : ca;
cb = cb == '_' ? '-' : cb;
if (ca != cb)
- return cb - ca;
+ return cb - ca;
}
ca = *a;
@@ -962,22 +1128,22 @@ attr_strcmp (gconstpointer pa,
static gboolean
span_parse_int (const char *attr_name,
- const char *attr_val,
- int *val,
- int line_number,
- GError **error)
+ const char *attr_val,
+ int *val,
+ int line_number,
+ GError **error)
{
const char *end = attr_val;
if (!_pango_scan_int (&end, val) || *end != '\0')
{
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "on line %d could not be parsed; "
- "should be an integer, not '%s'"),
- attr_name, line_number, attr_val);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of '%s' attribute on <span> tag "
+ "on line %d could not be parsed; "
+ "should be an integer, not '%s'"),
+ attr_name, line_number, attr_val);
return FALSE;
}
@@ -1009,10 +1175,10 @@ span_parse_float (const char *attr_name,
static gboolean
span_parse_boolean (const char *attr_name,
- const char *attr_val,
- gboolean *val,
- int line_number,
- GError **error)
+ const char *attr_val,
+ gboolean *val,
+ int line_number,
+ GError **error)
{
if (strcmp (attr_val, "true") == 0 ||
strcmp (attr_val, "yes") == 0 ||
@@ -1020,19 +1186,19 @@ span_parse_boolean (const char *attr_name,
strcmp (attr_val, "y") == 0)
*val = TRUE;
else if (strcmp (attr_val, "false") == 0 ||
- strcmp (attr_val, "no") == 0 ||
- strcmp (attr_val, "f") == 0 ||
- strcmp (attr_val, "n") == 0)
+ strcmp (attr_val, "no") == 0 ||
+ strcmp (attr_val, "f") == 0 ||
+ strcmp (attr_val, "n") == 0)
*val = FALSE;
else
{
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "line %d should have one of "
- "'true/yes/t/y' or 'false/no/f/n': '%s' is not valid"),
- attr_name, line_number, attr_val);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of '%s' attribute on <span> tag "
+ "line %d should have one of "
+ "'true/yes/t/y' or 'false/no/f/n': '%s' is not valid"),
+ attr_name, line_number, attr_val);
return FALSE;
}
@@ -1041,21 +1207,21 @@ span_parse_boolean (const char *attr_name,
static gboolean
span_parse_color (const char *attr_name,
- const char *attr_val,
- PangoColor *color,
+ const char *attr_val,
+ PangoColor *color,
guint16 *alpha,
- int line_number,
- GError **error)
+ int line_number,
+ GError **error)
{
if (!pango_color_parse_with_alpha (color, alpha, attr_val))
{
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "on line %d could not be parsed; "
- "should be a color specification, not '%s'"),
- attr_name, line_number, attr_val);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of '%s' attribute on <span> tag "
+ "on line %d could not be parsed; "
+ "should be a color specification, not '%s'"),
+ attr_name, line_number, attr_val);
return FALSE;
}
@@ -1100,12 +1266,12 @@ span_parse_alpha (const char *attr_name,
else
{
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "on line %d could not be parsed; "
- "should be an integer, not '%s'"),
- attr_name, line_number, attr_val);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of '%s' attribute on <span> tag "
+ "on line %d could not be parsed; "
+ "should be an integer, not '%s'"),
+ attr_name, line_number, attr_val);
return FALSE;
}
@@ -1114,23 +1280,23 @@ span_parse_alpha (const char *attr_name,
static gboolean
span_parse_enum (const char *attr_name,
- const char *attr_val,
- GType type,
- int *val,
- int line_number,
- GError **error)
+ const char *attr_val,
+ GType type,
+ int *val,
+ int line_number,
+ GError **error)
{
char *possible_values = NULL;
if (!_pango_parse_enum (type, attr_val, val, FALSE, &possible_values))
{
g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the '%s' "
- "attribute on <span> tag, line %d; valid "
- "values are %s"),
- attr_val, attr_name, line_number, possible_values);
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the '%s' "
+ "attribute on <span> tag, line %d; valid "
+ "values are %s"),
+ attr_val, attr_name, line_number, possible_values);
g_free (possible_values);
return FALSE;
}
@@ -1195,11 +1361,11 @@ parse_length (const char *attr_val,
static gboolean
span_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values,
+ GMarkupParseContext *context,
+ GError **error)
{
int line_number, char_number;
int i;
@@ -1239,24 +1405,24 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
const char *font_scale = NULL;
g_markup_parse_context_get_position (context,
- &line_number, &char_number);
+ &line_number, &char_number);
#define CHECK_DUPLICATE(var) G_STMT_START{ \
- if ((var) != NULL) { \
- g_set_error (error, G_MARKUP_ERROR, \
- G_MARKUP_ERROR_INVALID_CONTENT, \
- _("Attribute '%s' occurs twice on <span> tag " \
- "on line %d char %d, may only occur once"), \
- names[i], line_number, char_number); \
- return FALSE; \
- }}G_STMT_END
+ if ((var) != NULL) { \
+ g_set_error (error, G_MARKUP_ERROR, \
+ G_MARKUP_ERROR_INVALID_CONTENT, \
+ _("Attribute '%s' occurs twice on <span> tag " \
+ "on line %d char %d, may only occur once"), \
+ names[i], line_number, char_number); \
+ return FALSE; \
+ }}G_STMT_END
#define CHECK_ATTRIBUTE2(var, name) \
- if (attr_strcmp (names[i], (name)) == 0) { \
- CHECK_DUPLICATE (var); \
- (var) = values[i]; \
- found = TRUE; \
- break; \
- }
+ if (attr_strcmp (names[i], (name)) == 0) { \
+ CHECK_DUPLICATE (var); \
+ (var) = values[i]; \
+ found = TRUE; \
+ break; \
+ }
#define CHECK_ATTRIBUTE(var) CHECK_ATTRIBUTE2 (var, G_STRINGIFY (var))
i = 0;
@@ -1270,89 +1436,89 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
CHECK_ATTRIBUTE (alpha);
break;
case 'b':
- CHECK_ATTRIBUTE (background);
- CHECK_ATTRIBUTE2(background, "bgcolor");
+ CHECK_ATTRIBUTE (background);
+ CHECK_ATTRIBUTE2(background, "bgcolor");
CHECK_ATTRIBUTE (background_alpha);
CHECK_ATTRIBUTE2(background_alpha, "bgalpha");
CHECK_ATTRIBUTE(baseline_shift);
break;
case 'c':
- CHECK_ATTRIBUTE2(foreground, "color");
+ CHECK_ATTRIBUTE2(foreground, "color");
break;
case 'f':
- CHECK_ATTRIBUTE (fallback);
- CHECK_ATTRIBUTE2(desc, "font");
- CHECK_ATTRIBUTE2(desc, "font_desc");
- CHECK_ATTRIBUTE2(family, "face");
-
- CHECK_ATTRIBUTE2(family, "font_family");
- CHECK_ATTRIBUTE2(size, "font_size");
- CHECK_ATTRIBUTE2(stretch, "font_stretch");
- CHECK_ATTRIBUTE2(style, "font_style");
- CHECK_ATTRIBUTE2(variant, "font_variant");
- CHECK_ATTRIBUTE2(weight, "font_weight");
- CHECK_ATTRIBUTE(font_scale);
-
- CHECK_ATTRIBUTE (foreground);
- CHECK_ATTRIBUTE2(foreground, "fgcolor");
- CHECK_ATTRIBUTE2(alpha, "fgalpha");
-
- CHECK_ATTRIBUTE (font_features);
- break;
+ CHECK_ATTRIBUTE (fallback);
+ CHECK_ATTRIBUTE2(desc, "font");
+ CHECK_ATTRIBUTE2(desc, "font_desc");
+ CHECK_ATTRIBUTE2(family, "face");
+
+ CHECK_ATTRIBUTE2(family, "font_family");
+ CHECK_ATTRIBUTE2(size, "font_size");
+ CHECK_ATTRIBUTE2(stretch, "font_stretch");
+ CHECK_ATTRIBUTE2(style, "font_style");
+ CHECK_ATTRIBUTE2(variant, "font_variant");
+ CHECK_ATTRIBUTE2(weight, "font_weight");
+ CHECK_ATTRIBUTE(font_scale);
+
+ CHECK_ATTRIBUTE (foreground);
+ CHECK_ATTRIBUTE2(foreground, "fgcolor");
+ CHECK_ATTRIBUTE2(alpha, "fgalpha");
+
+ CHECK_ATTRIBUTE (font_features);
+ break;
case 's':
- CHECK_ATTRIBUTE (show);
- CHECK_ATTRIBUTE (size);
- CHECK_ATTRIBUTE (stretch);
- CHECK_ATTRIBUTE (strikethrough);
- CHECK_ATTRIBUTE (strikethrough_color);
- CHECK_ATTRIBUTE (style);
- CHECK_ATTRIBUTE (segment);
- break;
+ CHECK_ATTRIBUTE (show);
+ CHECK_ATTRIBUTE (size);
+ CHECK_ATTRIBUTE (stretch);
+ CHECK_ATTRIBUTE (strikethrough);
+ CHECK_ATTRIBUTE (strikethrough_color);
+ CHECK_ATTRIBUTE (style);
+ CHECK_ATTRIBUTE (segment);
+ break;
case 't':
CHECK_ATTRIBUTE (text_transform);
break;
case 'g':
- CHECK_ATTRIBUTE (gravity);
- CHECK_ATTRIBUTE (gravity_hint);
- break;
+ CHECK_ATTRIBUTE (gravity);
+ CHECK_ATTRIBUTE (gravity_hint);
+ break;
case 'i':
CHECK_ATTRIBUTE (insert_hyphens);
break;
case 'l':
- CHECK_ATTRIBUTE (lang);
- CHECK_ATTRIBUTE (letter_spacing);
+ CHECK_ATTRIBUTE (lang);
+ CHECK_ATTRIBUTE (letter_spacing);
CHECK_ATTRIBUTE (line_height);
- break;
+ break;
case 'o':
- CHECK_ATTRIBUTE (overline);
- CHECK_ATTRIBUTE (overline_color);
- break;
+ CHECK_ATTRIBUTE (overline);
+ CHECK_ATTRIBUTE (overline_color);
+ break;
case 'u':
- CHECK_ATTRIBUTE (underline);
- CHECK_ATTRIBUTE (underline_position);
- CHECK_ATTRIBUTE (underline_color);
- break;
+ CHECK_ATTRIBUTE (underline);
+ CHECK_ATTRIBUTE (underline_position);
+ CHECK_ATTRIBUTE (underline_color);
+ break;
case 'r':
- CHECK_ATTRIBUTE (rise);
+ CHECK_ATTRIBUTE (rise);
break;
case 'v':
- CHECK_ATTRIBUTE (variant);
+ CHECK_ATTRIBUTE (variant);
break;
case 'w':
- CHECK_ATTRIBUTE (weight);
- break;
+ CHECK_ATTRIBUTE (weight);
+ break;
default:;
}
if (!found)
- {
- g_set_error (error, G_MARKUP_ERROR,
- G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
- _("Attribute '%s' is not allowed on the <span> tag "
- "on line %d char %d"),
- names[i], line_number, char_number);
- return FALSE;
- }
+ {
+ g_set_error (error, G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ _("Attribute '%s' is not allowed on the <span> tag "
+ "on line %d char %d"),
+ names[i], line_number, char_number);
+ return FALSE;
+ }
++i;
}
@@ -1364,12 +1530,12 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
parsed = pango_font_description_from_string (desc);
if (parsed)
- {
- add_attribute (tag, pango_attr_font_desc_new (parsed));
- if (tag)
- open_tag_set_absolute_font_size (tag, pango_font_description_get_size (parsed));
- pango_font_description_free (parsed);
- }
+ {
+ add_attribute (tag, pango_attr_font_desc_new (parsed));
+ if (tag)
+ open_tag_set_absolute_font_size (tag, pango_font_description_get_size (parsed));
+ pango_font_description_free (parsed);
+ }
}
if (G_UNLIKELY (family))
@@ -1388,34 +1554,34 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
open_tag_set_absolute_font_size (tag, n);
}
else if (strcmp (size, "smaller") == 0)
- {
- if (tag)
- {
- tag->scale_level_delta -= 1;
- tag->scale_level -= 1;
- }
- }
+ {
+ if (tag)
+ {
+ tag->scale_level_delta -= 1;
+ tag->scale_level -= 1;
+ }
+ }
else if (strcmp (size, "larger") == 0)
- {
- if (tag)
- {
- tag->scale_level_delta += 1;
- tag->scale_level += 1;
- }
- }
+ {
+ if (tag)
+ {
+ tag->scale_level_delta += 1;
+ tag->scale_level += 1;
+ }
+ }
else if (parse_absolute_size (tag, size))
- ; /* nothing */
+ ; /* nothing */
else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of 'size' attribute on <span> tag on line %d "
- "could not be parsed; should be an integer, or a "
- "string such as 'small', not '%s'"),
- line_number, size);
- goto error;
- }
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of 'size' attribute on <span> tag on line %d "
+ "could not be parsed; should be an integer, or a "
+ "string such as 'small', not '%s'"),
+ line_number, size);
+ goto error;
+ }
}
if (G_UNLIKELY (style))
@@ -1423,18 +1589,18 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoStyle pango_style;
if (pango_parse_style (style, &pango_style, FALSE))
- add_attribute (tag, pango_attr_style_new (pango_style));
+ add_attribute (tag, pango_attr_style_new (pango_style));
else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the 'style' attribute "
- "on <span> tag, line %d; valid values are "
- "'normal', 'oblique', 'italic'"),
- style, line_number);
- goto error;
- }
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the 'style' attribute "
+ "on <span> tag, line %d; valid values are "
+ "'normal', 'oblique', 'italic'"),
+ style, line_number);
+ goto error;
+ }
}
if (G_UNLIKELY (weight))
@@ -1442,19 +1608,19 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoWeight pango_weight;
if (pango_parse_weight (weight, &pango_weight, FALSE))
- add_attribute (tag,
- pango_attr_weight_new (pango_weight));
+ add_attribute (tag,
+ pango_attr_weight_new (pango_weight));
else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the 'weight' "
- "attribute on <span> tag, line %d; valid "
- "values are for example 'light', 'ultrabold' or a number"),
- weight, line_number);
- goto error;
- }
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the 'weight' "
+ "attribute on <span> tag, line %d; valid "
+ "values are for example 'light', 'ultrabold' or a number"),
+ weight, line_number);
+ goto error;
+ }
}
if (G_UNLIKELY (variant))
@@ -1462,18 +1628,18 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoVariant pango_variant;
if (pango_parse_variant (variant, &pango_variant, FALSE))
- add_attribute (tag, pango_attr_variant_new (pango_variant));
+ add_attribute (tag, pango_attr_variant_new (pango_variant));
else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the 'variant' "
- "attribute on <span> tag, line %d; valid values are "
- "'normal', 'smallcaps'"),
- variant, line_number);
- goto error;
- }
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the 'variant' "
+ "attribute on <span> tag, line %d; valid values are "
+ "'normal', 'smallcaps'"),
+ variant, line_number);
+ goto error;
+ }
}
if (G_UNLIKELY (stretch))
@@ -1481,19 +1647,19 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoStretch pango_stretch;
if (pango_parse_stretch (stretch, &pango_stretch, FALSE))
- add_attribute (tag, pango_attr_stretch_new (pango_stretch));
+ add_attribute (tag, pango_attr_stretch_new (pango_stretch));
else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the 'stretch' "
- "attribute on <span> tag, line %d; valid "
- "values are for example 'condensed', "
- "'ultraexpanded', 'normal'"),
- stretch, line_number);
- goto error;
- }
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the 'stretch' "
+ "attribute on <span> tag, line %d; valid "
+ "values are for example 'condensed', "
+ "'ultraexpanded', 'normal'"),
+ stretch, line_number);
+ goto error;
+ }
}
if (G_UNLIKELY (foreground))
@@ -1502,7 +1668,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
guint16 alpha;
if (!span_parse_color ("foreground", foreground, &color, &alpha, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_foreground_new (&color));
if (alpha != 0xffff)
@@ -1515,7 +1681,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
guint16 alpha;
if (!span_parse_color ("background", background, &color, &alpha, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_background_new (&color));
if (alpha != 0xffff)
@@ -1547,7 +1713,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoLineStyle style = PANGO_LINE_STYLE_NONE;
if (!span_parse_enum ("underline", underline, PANGO_TYPE_LINE_STYLE, (int*)(void*)&style, line_number,
error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_underline_new (style));
}
@@ -1557,7 +1723,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoUnderlinePosition pos = PANGO_UNDERLINE_POSITION_NORMAL;
if (!span_parse_enum ("underline_position", underline_position, PANGO_TYPE_UNDERLINE_POSITION,
(int*)(void*)&pos, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_underline_position_new (pos));
}
@@ -1567,7 +1733,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoColor color;
if (!span_parse_color ("underline_color", underline_color, &color, NULL, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_underline_color_new (&color));
}
@@ -1577,7 +1743,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoOverline ol = PANGO_OVERLINE_NONE;
if (!span_parse_enum ("overline", overline, PANGO_TYPE_OVERLINE, (int*)(void*)&ol, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_overline_new (ol));
}
@@ -1587,7 +1753,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoColor color;
if (!span_parse_color ("overline_color", overline_color, &color, NULL, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_overline_color_new (&color));
}
@@ -1597,19 +1763,19 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoGravity gr = PANGO_GRAVITY_SOUTH;
if (!span_parse_enum ("gravity", gravity, PANGO_TYPE_GRAVITY, (int*)(void*)&gr, line_number, error))
- goto error;
+ goto error;
if (gr == PANGO_GRAVITY_AUTO)
{
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("'%s' is not a valid value for the 'gravity' "
- "attribute on <span> tag, line %d; valid "
- "values are for example 'south', 'east', "
- "'north', 'west'"),
- gravity, line_number);
- goto error;
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("'%s' is not a valid value for the 'gravity' "
+ "attribute on <span> tag, line %d; valid "
+ "values are for example 'south', 'east', "
+ "'north', 'west'"),
+ gravity, line_number);
+ goto error;
}
add_attribute (tag, pango_attr_gravity_new (gr));
@@ -1620,7 +1786,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoGravityHint hint = PANGO_GRAVITY_HINT_NATURAL;
if (!span_parse_enum ("gravity_hint", gravity_hint, PANGO_TYPE_GRAVITY_HINT, (int*)(void*)&hint,
line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_gravity_hint_new (hint));
}
@@ -1640,7 +1806,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoColor color;
if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, NULL, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_strikethrough_color_new (&color));
}
@@ -1650,7 +1816,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
gboolean b = FALSE;
if (!span_parse_boolean ("fallback", fallback, &b, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_fallback_new (b));
}
@@ -1660,7 +1826,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoShowFlags flags;
if (!span_parse_flags ("show", show, PANGO_TYPE_SHOW_FLAGS, (int*)(void*)&flags, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_show_new (flags));
}
@@ -1670,7 +1836,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoTextTransform tf;
if (!span_parse_enum ("text_transform", text_transform, PANGO_TYPE_TEXT_TRANSFORM, (int*)(void*)&tf,
line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_text_transform_new (tf));
}
@@ -1721,7 +1887,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
PangoFontScale scale;
if (!span_parse_enum ("font_scale", font_scale, PANGO_TYPE_FONT_SCALE, (int*)(void*)&scale,
line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_font_scale_new (scale));
}
@@ -1731,7 +1897,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
gint n = 0;
if (!span_parse_int ("letter_spacing", letter_spacing, &n, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_letter_spacing_new (n));
}
@@ -1752,7 +1918,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
if (G_UNLIKELY (lang))
{
add_attribute (tag,
- pango_attr_language_new (pango_language_from_string (lang)));
+ pango_attr_language_new (pango_language_from_string (lang)));
}
if (G_UNLIKELY (font_features))
@@ -1775,7 +1941,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
gboolean b = FALSE;
if (!span_parse_boolean ("insert_hyphens", insert_hyphens, &b, line_number, error))
- goto error;
+ goto error;
add_attribute (tag, pango_attr_insert_hyphens_new (b));
}
@@ -1810,11 +1976,11 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
i_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("i");
add_attribute (tag, pango_attr_style_new (PANGO_STYLE_ITALIC));
@@ -1824,11 +1990,11 @@ i_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
markup_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag G_GNUC_UNUSED,
- const gchar **names G_GNUC_UNUSED,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context G_GNUC_UNUSED,
- GError **error G_GNUC_UNUSED)
+ OpenTag *tag G_GNUC_UNUSED,
+ const gchar **names G_GNUC_UNUSED,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context G_GNUC_UNUSED,
+ GError **error G_GNUC_UNUSED)
{
/* We don't do anything with this tag at the moment. */
CHECK_NO_ATTRS("markup");
@@ -1838,11 +2004,11 @@ markup_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
s_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("s");
add_attribute (tag, pango_attr_strikethrough_new (TRUE));
@@ -1852,11 +2018,11 @@ s_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
sub_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("sub");
@@ -1868,11 +2034,11 @@ sub_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
sup_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("sup");
@@ -1884,11 +2050,11 @@ sup_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
small_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("small");
@@ -1904,11 +2070,11 @@ small_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
tt_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("tt");
@@ -1919,11 +2085,11 @@ tt_parse_func (MarkupData *md G_GNUC_UNUSED,
static gboolean
u_parse_func (MarkupData *md G_GNUC_UNUSED,
- OpenTag *tag,
- const gchar **names,
- const gchar **values G_GNUC_UNUSED,
- GMarkupParseContext *context,
- GError **error)
+ OpenTag *tag,
+ const gchar **names,
+ const gchar **values G_GNUC_UNUSED,
+ GMarkupParseContext *context,
+ GError **error)
{
CHECK_NO_ATTRS("u");
add_attribute (tag, pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
diff --git a/pango/pango-utils-internal.h b/pango/pango-utils-internal.h
index adb62544..086f6e4a 100644
--- a/pango/pango-utils-internal.h
+++ b/pango/pango-utils-internal.h
@@ -26,21 +26,6 @@
G_BEGIN_DECLS
-gboolean _pango_scan_int (const char **pos,
- int *out);
-
-gboolean _pango_parse_enum (GType type,
- const char *str,
- int *value,
- gboolean warn,
- char **possible_values);
-gboolean pango_parse_flags (GType type,
- const char *str,
- int *value,
- char **possible_values);
-
-char *_pango_trim_string (const char *str);
-
PangoDirection pango_find_base_dir (const char *text,
int length);
@@ -57,8 +42,4 @@ gboolean pango_parse_stretch (const char *str,
PangoStretch *stretch,
gboolean warn);
-void pango_quantize_line_geometry (int *thickness,
- int *position);
-
-
G_END_DECLS
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 874977bc..863414dc 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -131,189 +131,6 @@ pango_version_check (int required_major,
return NULL;
}
-char *
-_pango_trim_string (const char *str)
-{
- int len;
-
- g_return_val_if_fail (str != NULL, NULL);
-
- while (*str && g_ascii_isspace (*str))
- str++;
-
- len = strlen (str);
- while (len > 0 && g_ascii_isspace (str[len-1]))
- len--;
-
- return g_strndup (str, len);
-}
-
-gboolean
-_pango_scan_int (const char **pos, int *out)
-{
- char *end;
- long temp;
-
- errno = 0;
- temp = strtol (*pos, &end, 10);
- if (errno == ERANGE)
- {
- errno = 0;
- return FALSE;
- }
-
- *out = (int)temp;
- if ((long)(*out) != temp)
- {
- return FALSE;
- }
-
- *pos = end;
-
- return TRUE;
-}
-
-static gboolean
-parse_int (const char *word,
- int *out)
-{
- char *end;
- long val;
- int i;
-
- if (word == NULL)
- return FALSE;
-
- val = strtol (word, &end, 10);
- i = val;
-
- if (end != word && *end == '\0' && val >= 0 && val == i)
- {
- if (out)
- *out = i;
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-gboolean
-_pango_parse_enum (GType type,
- const char *str,
- int *value,
- gboolean warn,
- char **possible_values)
-{
- GEnumClass *class = NULL;
- gboolean ret = TRUE;
- GEnumValue *v = NULL;
-
- class = g_type_class_ref (type);
-
- if (G_LIKELY (str))
- v = g_enum_get_value_by_nick (class, str);
-
- if (v)
- {
- if (G_LIKELY (value))
- *value = v->value;
- }
- else if (!parse_int (str, value))
- {
- ret = FALSE;
- if (G_LIKELY (warn || possible_values))
- {
- int i;
- GString *s = g_string_new (NULL);
-
- for (i = 0, v = g_enum_get_value (class, i); v;
- i++ , v = g_enum_get_value (class, i))
- {
- if (i)
- g_string_append_c (s, '/');
- g_string_append (s, v->value_nick);
- }
-
- if (warn)
- g_warning ("%s must be one of %s",
- G_ENUM_CLASS_TYPE_NAME(class),
- s->str);
-
- if (possible_values)
- *possible_values = s->str;
-
- g_string_free (s, possible_values ? FALSE : TRUE);
- }
- }
-
- g_type_class_unref (class);
-
- return ret;
-}
-
-gboolean
-pango_parse_flags (GType type,
- const char *str,
- int *value,
- char **possible_values)
-{
- GFlagsClass *class = NULL;
- gboolean ret = TRUE;
- GFlagsValue *v = NULL;
-
- class = g_type_class_ref (type);
-
- v = g_flags_get_value_by_nick (class, str);
-
- if (v)
- {
- *value = v->value;
- }
- else if (!parse_int (str, value))
- {
- char **strv = g_strsplit (str, "|", 0);
- int i;
-
- *value = 0;
-
- for (i = 0; strv[i]; i++)
- {
- strv[i] = g_strstrip (strv[i]);
- v = g_flags_get_value_by_nick (class, strv[i]);
- if (!v)
- {
- ret = FALSE;
- break;
- }
- *value |= v->value;
- }
- g_strfreev (strv);
-
- if (!ret && possible_values)
- {
- int i;
- GString *s = g_string_new (NULL);
-
- for (i = 0; i < class->n_values; i++)
- {
- v = &class->values[i];
- if (i)
- g_string_append_c (s, '/');
- g_string_append (s, v->value_nick);
- }
-
- *possible_values = s->str;
-
- g_string_free (s, FALSE);
- }
- }
-
- g_type_class_unref (class);
-
- return ret;
-}
-
/**
* pango_is_zero_width:
* @ch: a Unicode character
@@ -372,42 +189,6 @@ pango_is_zero_width (gunichar ch)
|| ch == 0xFEFF);
}
-/**
- * pango_quantize_line_geometry:
- * @thickness: (inout): pointer to the thickness of a line, in Pango units
- * @position: (inout): corresponding position
- *
- * Quantizes the thickness and position of a line to whole device pixels.
- *
- * This is typically used for underline or strikethrough. The purpose of
- * this function is to avoid such lines looking blurry.
- *
- * Care is taken to make sure @thickness is at least one pixel when this
- * function returns, but returned @position may become zero as a result
- * of rounding.
- */
-void
-pango_quantize_line_geometry (int *thickness,
- int *position)
-{
- int thickness_pixels = (*thickness + PANGO_SCALE / 2) / PANGO_SCALE;
- if (thickness_pixels == 0)
- thickness_pixels = 1;
-
- if (thickness_pixels & 1)
- {
- int new_center = ((*position - *thickness / 2) & ~(PANGO_SCALE - 1)) + PANGO_SCALE / 2;
- *position = new_center + (PANGO_SCALE * thickness_pixels) / 2;
- }
- else
- {
- int new_center = ((*position - *thickness / 2 + PANGO_SCALE / 2) & ~(PANGO_SCALE - 1));
- *position = new_center + (PANGO_SCALE * thickness_pixels) / 2;
- }
-
- *thickness = thickness_pixels * PANGO_SCALE;
-}
-
/**
* pango_units_from_double:
* @d: double floating-point value
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]