diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2007-01-16 09:52:02 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2007-01-16 09:52:02 +0000 |
commit | 56e7902a63f2036ea46a386c9d80827d6420f143 (patch) | |
tree | 6363106a16cc800436c945d09d88bbad951b5997 /examples | |
parent | 7a102793913cb7a1a0eefbbfc9d5c0d04c9eb868 (diff) | |
download | pango-56e7902a63f2036ea46a386c9d80827d6420f143.tar.gz |
New attribute types PANGO_ATTR_GRAVITY and PANGO_ATTR_GRAVITY_HINT. New
2007-01-16 Behdad Esfahbod <behdad@gnome.org>
* pango/pango-attributes.h:
* pango/pango-attributes.c:
New attribute types PANGO_ATTR_GRAVITY and PANGO_ATTR_GRAVITY_HINT.
New public functions:
pango_attr_gravity_new()
pango_attr_gravity_hint_new()
* pango/pango-context.c (update_attr_iterator),
(itemize_state_init), (itemize_state_add_character),
(get_shaper_and_font), (itemize_state_update_for_new_run):
Handle gravity and gravity_hint attributes.
* pango/pango-utils.h:
* pango/pango-utils.c:
New public function:
pango_parse_enum()
* pango/pango-markup.c (span_parse_func): Parse gravity and
gravity_hint attributes for <span>. Optimize a bit.
* pango/pango-markup.c (parse_absolute_size), (attr_strcmp),
(span_parse_int), (span_parse_boolean), (span_parse_color),
(span_parse_enum), (span_parse_func): Use pango_scan_int(),
pango_color_parse(), and pango_parse_enum(). Also, ignore '-' and
'_' differences when matching attribute names for <span>.
* examples/renderdemo.c (parse_enum), (parse_ellipsis),
(parse_gravity), (parse_gravity_hint), (parse_hinting),
(parse_wrap): Use a generic parse_enum() that uses pango_parse_enum().
* modules/basic/basic-fc.c (basic_engine_shape):
* pango/pangofc-fontmap.c (pango_fc_make_pattern):
Use PANGO_GRAVITY_IS_VERTICAL().
* pango/pango.def:
* docs/pango-sections.txt:
* docs/tmpl/text-attributes.sgml:
* docs/tmpl/utils.sgml:
Update.
svn path=/trunk/; revision=2145
Diffstat (limited to 'examples')
-rw-r--r-- | examples/renderdemo.c | 122 |
1 files changed, 40 insertions, 82 deletions
diff --git a/examples/renderdemo.c b/examples/renderdemo.c index 21773e4e..75a5ca4a 100644 --- a/examples/renderdemo.c +++ b/examples/renderdemo.c @@ -333,61 +333,57 @@ do_output (PangoContext *context, pango_matrix_free (orig_matrix); } - static gboolean -parse_ellipsis (const char *name, - const char *arg, - gpointer data, - GError **error) +parse_enum (GType *type, + int *value, + const char *name, + const char *arg, + gpointer data, + GError **error) { - static GEnumClass *class = NULL; - gboolean ret = TRUE; - GEnumValue *value; + char *possible_values = NULL; + gboolean ret; - if (!class) - class = g_type_class_ref (PANGO_TYPE_ELLIPSIZE_MODE); + ret = pango_parse_enum (type, + arg, + value, + FALSE, + &possible_values); - value = g_enum_get_value_by_nick (class, arg); - if (value) - opt_ellipsize = value->value; - else + if (!ret && error) { - g_set_error(error, - G_OPTION_ERROR, - G_OPTION_ERROR_BAD_VALUE, - "Argument for --ellipsize must be one of none/start/middle/end"); - ret = FALSE; + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for %s must be one of %s", + name, + possible_values); + ret = FALSE; } + g_free (possible_values); + return ret; } static gboolean +parse_ellipsis (const char *name, + const char *arg, + gpointer data, + GError **error) +{ + return parse_enum (PANGO_TYPE_ELLIPSIZE_MODE, &opt_ellipsize, + name, arg, data, error); +} + +static gboolean parse_gravity (const char *name, const char *arg, gpointer data, GError **error) { - static GEnumClass *class = NULL; - gboolean ret = TRUE; - GEnumValue *value; - - if (!class) - class = g_type_class_ref (PANGO_TYPE_GRAVITY); - - value = g_enum_get_value_by_nick (class, arg); - if (value) - opt_gravity = value->value; - else - { - g_set_error(error, - G_OPTION_ERROR, - G_OPTION_ERROR_BAD_VALUE, - "Argument for --gravity must be one of south/east/north/west/auto"); - ret = FALSE; - } - - return ret; + return parse_enum (PANGO_TYPE_GRAVITY, &opt_gravity, + name, arg, data, error); } static gboolean @@ -396,26 +392,8 @@ parse_gravity_hint (const char *name, gpointer data, GError **error) { - static GEnumClass *class = NULL; - gboolean ret = TRUE; - GEnumValue *value; - - if (!class) - class = g_type_class_ref (PANGO_TYPE_GRAVITY_HINT); - - value = g_enum_get_value_by_nick (class, arg); - if (value) - opt_gravity_hint = value->value; - else - { - g_set_error(error, - G_OPTION_ERROR, - G_OPTION_ERROR_BAD_VALUE, - "Argument for --gravity-hint must be one of natural/strong/line"); - ret = FALSE; - } - - return ret; + return parse_enum (PANGO_TYPE_GRAVITY_HINT, &opt_gravity_hint, + name, arg, data, error); } static gboolean @@ -424,12 +402,8 @@ parse_hinting (const char *name, gpointer data, GError **error) { - static GEnumClass *class = NULL; gboolean ret = TRUE; - if (!class) - class = g_type_class_ref (PANGO_TYPE_ELLIPSIZE_MODE); - if (strcmp (arg, "none") == 0) opt_hinting = HINT_NONE; else if (strcmp (arg, "auto") == 0) @@ -454,28 +428,12 @@ parse_wrap (const char *name, gpointer data, GError **error) { - static GEnumClass *class = NULL; - gboolean ret = TRUE; - GEnumValue *value; - - if (!class) - class = g_type_class_ref (PANGO_TYPE_WRAP_MODE); - - value = g_enum_get_value_by_nick (class, arg); - if (value) + gboolean ret; + if ((ret = parse_enum (PANGO_TYPE_WRAP_MODE, &opt_wrap, + name, arg, data, error))) { - opt_wrap = value->value; opt_wrap_set = TRUE; } - else - { - g_set_error(error, - G_OPTION_ERROR, - G_OPTION_ERROR_BAD_VALUE, - "Argument for --wrap must be one of word/char/word-char"); - ret = FALSE; - } - return ret; } |