# HG changeset patch # User wycc # Date 1233425685 -28800 # Node ID 7270e368ee98a96ad92b0b64612a10d6a7167f4a # Parent 137a73822d48d75db8c2cce4eab8b83df92a1cbb Add more text API diff -r 137a73822d48 -r 7270e368ee98 include/mb_shapes.h --- a/include/mb_shapes.h Sun Feb 01 01:45:53 2009 +0800 +++ b/include/mb_shapes.h Sun Feb 01 02:14:45 2009 +0800 @@ -109,6 +109,11 @@ } mb_text_t; extern void sh_text_set_style(shape_t *shape,int begin,int end,mb_textstyle_t *format); +extern void sh_text_set_color(shape_t *shape, unsigned color); +extern void sh_text_set_bold(shape_t *shape, int bold); +extern void sh_text_set_italic(shape_t *shape, int italic); +extern void sh_text_set_underline(shape_t *shape, int underline); +extern void sh_text_set_font(shape_t *shape, char *family); static inline void mb_textstyle_init(mb_textstyle_t *style) { style->property = 0; diff -r 137a73822d48 -r 7270e368ee98 src/shape_text.c --- a/src/shape_text.c Sun Feb 01 01:45:53 2009 +0800 +++ b/src/shape_text.c Sun Feb 01 02:14:45 2009 +0800 @@ -81,6 +81,47 @@ text->data = buf; } +void sh_text_set_color(shape_t *shape, unsigned int color) +{ + PangoAttribute *attr = pango_attr_color_new(color); + sh_text_t *text = (sh_text_t *)shape; + attr->begin_index = 0; + attr->end_index = -1; + pango_attr_list_change(text->attrs, attr); +} +void sh_text_set_bold(shape_t *shape,int bold) +{ + PangoAttribute *attr = pango_attr_weight_new(bold? PANGO_WEIGHT_BOLD:PANGO_WEIGHT_NORMAL); + sh_text_t *text = (sh_text_t *)shape; + attr->begin_index = 0; + attr->end_index = -1; + pango_attr_list_change(text->attrs, attr); +} +void sh_text_set_italic(shape_t *shape,int italic) +{ + PangoAttribute *attr = pango_attr_style_new(italic? PANGO_STYLE_ITALIC:PANGO_STYLE_NORMAL); + sh_text_t *text = (sh_text_t *)shape; + attr->begin_index = 0; + attr->end_index = -1; + pango_attr_list_change(text->attrs, attr); +} +void sh_text_set_underline(shape_t *shape,int underline) +{ + PangoAttribute *attr = pango_attr_underline_new(underline? PANGO_UNDERLINE_SINGLE:PANGO_UNDERLINE_NONE); + sh_text_t *text = (sh_text_t *)shape; + attr->begin_index = 0; + attr->end_index = -1; + pango_attr_list_change(text->attrs, attr); +} +void sh_text_set_font(shape_t *shape,char *family) +{ + PangoAttribute *attr = pango_attr_family_new(family); + sh_text_t *text = (sh_text_t *)shape; + attr->begin_index = 0; + attr->end_index = -1; + pango_attr_list_change(text->attrs, attr); +} + void sh_text_set_style(shape_t *shape,int begin,int end,mb_textstyle_t *format) { PangoAttribute *attr;