changeset 292:7270e368ee98

Add more text API
author wycc
date Sun, 01 Feb 2009 02:14:45 +0800
parents 137a73822d48
children a171b94582ae
files include/mb_shapes.h src/shape_text.c
diffstat 2 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;