comparison src/shape_text.c @ 461:61a0bceb369d

Add alignment support for the text layout
author wycc@122-116-38-188.HINET-IP.hinet.net
date Wed, 28 Oct 2009 02:35:08 +0800
parents 16116d84bc5e
children d8181696b689
comparison
equal deleted inserted replaced
460:115e7a936c94 461:61a0bceb369d
12 #define ERR -1 12 #define ERR -1
13 13
14 typedef struct _sh_text { 14 typedef struct _sh_text {
15 shape_t shape; 15 shape_t shape;
16 char *data; 16 char *data;
17 co_aix x, y; 17 co_aix x, y,w,h;
18 co_aix d_x, d_y; /* device x and y */ 18 co_aix d_x, d_y; /* device x and y */
19 co_aix font_size; 19 co_aix font_size;
20 co_aix d_font_size; 20 co_aix d_font_size;
21 mbe_font_face_t *face; 21 mbe_font_face_t *face;
22 mbe_scaled_font_t *scaled_font; 22 mbe_scaled_font_t *scaled_font;
62 62
63 text->shape.free = sh_text_free; 63 text->shape.free = sh_text_free;
64 text->layout = NULL; 64 text->layout = NULL;
65 text->attrs = attrs; 65 text->attrs = attrs;
66 text->align = TEXTALIGN_START; 66 text->align = TEXTALIGN_START;
67 text->w = text->h = 0;
67 68
68 rdman_shape_man(rdman, (shape_t *)text); 69 rdman_shape_man(rdman, (shape_t *)text);
69 70
70 return (shape_t *)text; 71 return (shape_t *)text;
71 } 72 }
139 attr->start_index = 0; 140 attr->start_index = 0;
140 attr->end_index = -1; 141 attr->end_index = -1;
141 pango_attr_list_change(text->attrs, attr); 142 pango_attr_list_change(text->attrs, attr);
142 } 143 }
143 144
145 void sh_text_set_align(shape_t *shape,int align)
146 {
147 sh_text_t *text = (sh_text_t *)shape;
148 text->align = align;
149 }
150 void sh_text_set_width(shape_t *shape,int width)
151 {
152 sh_text_t *text = (sh_text_t *)shape;
153 text->w = width;
154 }
144 void sh_text_set_style(shape_t *shape,int begin,int end,mb_textstyle_t *format) 155 void sh_text_set_style(shape_t *shape,int begin,int end,mb_textstyle_t *format)
145 { 156 {
146 PangoAttribute *attr; 157 PangoAttribute *attr;
147 sh_text_t *text = (sh_text_t *)shape; 158 sh_text_t *text = (sh_text_t *)shape;
148 159
255 } 266 }
256 text->layout = pango_cairo_create_layout(cr); 267 text->layout = pango_cairo_create_layout(cr);
257 desc = pango_font_description_from_string("Sans Bold"); 268 desc = pango_font_description_from_string("Sans Bold");
258 //mbe_set_source_rgb (cr, 0, 0, 0); 269 //mbe_set_source_rgb (cr, 0, 0, 0);
259 pango_layout_set_font_description (text->layout, desc); 270 pango_layout_set_font_description (text->layout, desc);
271 if (text->w != 0)
272 pango_layout_set_width(text->layout, text->w);
260 pango_layout_set_text(text->layout,text->data,strlen(text->data)); 273 pango_layout_set_text(text->layout,text->data,strlen(text->data));
261 pango_layout_set_attributes(text->layout, text->attrs); 274 pango_layout_set_attributes(text->layout, text->attrs);
275 if (text->align == TEXTALIGN_START)
276 pango_layout_set_alignment(text->layout, PANGO_ALIGN_LEFT);
277 else if (text->align == TEXTALIGN_MIDDLE)
278 pango_layout_set_alignment(text->layout, PANGO_ALIGN_CENTER);
279 else if (text->align == TEXTALIGN_END)
280 pango_layout_set_alignment(text->layout, PANGO_ALIGN_RIGHT);
262 pango_cairo_update_layout(cr,text->layout); 281 pango_cairo_update_layout(cr,text->layout);
263 printf("text=%s\n",text->data); 282 //printf("text=%s\n",text->data);
264 } 283 }
265 static void draw_text(sh_text_t *text, mbe_t *cr) { 284 static void draw_text(sh_text_t *text, mbe_t *cr) {
266 mbe_move_to(cr, text->d_x, text->d_y); 285 mbe_move_to(cr, text->d_x, text->d_y);
267 pango_cairo_layout_path(cr,text->layout); 286 pango_cairo_layout_path(cr,text->layout);
268 } 287 }