Mercurial > MadButterfly
comparison src/shape_text.c @ 285:248a40d51473
Check in test program for sh_text_set_text for debugging. It is not working yet.
author | wycc |
---|---|
date | Sat, 31 Jan 2009 16:52:28 +0800 |
parents | c8b6ca46950b |
children | 13ce87b6dbf5 |
comparison
equal
deleted
inserted
replaced
284:046a02a93fd9 | 285:248a40d51473 |
---|---|
108 r = get_extents(text, &extents); | 108 r = get_extents(text, &extents); |
109 | 109 |
110 //printf("x=%f y=%f text=%s ascent=%d,descent=%d,width=%d height=%d\n", x,y,text->data,PANGO_ASCENT(extents), PANGO_DESCENT(extents), extents.width, extents.height); | 110 //printf("x=%f y=%f text=%s ascent=%d,descent=%d,width=%d height=%d\n", x,y,text->data,PANGO_ASCENT(extents), PANGO_DESCENT(extents), extents.width, extents.height); |
111 ASSERT(r == OK); | 111 ASSERT(r == OK); |
112 | 112 |
113 text->d_x = x; | 113 text->d_x = x-5; |
114 text->d_y = y-text->font_size; | 114 text->d_y = y-PANGO_DESCENT(extents)+5; |
115 shw = shape->stroke_width / 2; | 115 shw = shape->stroke_width / 2; |
116 /* FIXME: It is unreasonable that a font exceed it's bbox. | 116 /* FIXME: It is unreasonable that a font exceed it's bbox. |
117 * We add 5 pixels in get right bbox. But, it is unreasonable. | 117 * We add 5 pixels in get right bbox. But, it is unreasonable. |
118 */ | 118 */ |
119 | 119 |
120 poses[0][0] = x + extents.x - 5 - shw; | 120 poses[0][0] = x + extents.x - shw; |
121 poses[0][1] = y + extents.y - 5 - shw; | 121 poses[0][1] = y + extents.y - shw; |
122 poses[1][0] = poses[0][0] + extents.width + 10 + shape->stroke_width; | 122 poses[1][0] = poses[0][0] + extents.width + shape->stroke_width; |
123 poses[1][1] = poses[0][1] + extents.height + 10 + shape->stroke_width; | 123 poses[1][1] = poses[0][1] + extents.height + shape->stroke_width; |
124 geo_from_positions(shape->geo, 2, poses); | 124 geo_from_positions(shape->geo, 2, poses); |
125 /*! \todo Support ratation for shape_text. */ | 125 /*! \todo Support ratation for shape_text. */ |
126 } | 126 } |
127 | 127 |
128 static void sh_text_P_generate_layout(sh_text_t *text,cairo_t *cr) | 128 static void sh_text_P_generate_layout(sh_text_t *text,cairo_t *cr) |
134 if (text->layout) { | 134 if (text->layout) { |
135 g_object_unref(text->layout); | 135 g_object_unref(text->layout); |
136 } | 136 } |
137 text->layout = pango_cairo_create_layout(cr); | 137 text->layout = pango_cairo_create_layout(cr); |
138 desc = pango_font_description_from_string("Sans Bold"); | 138 desc = pango_font_description_from_string("Sans Bold"); |
139 cairo_set_source_rgb (cr, 0, 0, 0); | |
139 pango_layout_set_font_description (text->layout, desc); | 140 pango_layout_set_font_description (text->layout, desc); |
140 pango_cairo_update_layout(cr,text->layout); | |
141 pango_layout_set_text(text->layout,text->data,strlen(text->data)); | 141 pango_layout_set_text(text->layout,text->data,strlen(text->data)); |
142 pango_layout_set_attributes(text->layout, text->attrs); | 142 pango_layout_set_attributes(text->layout, text->attrs); |
143 pango_cairo_update_layout(cr,text->layout); | |
143 } | 144 } |
144 static void draw_text(sh_text_t *text, cairo_t *cr) { | 145 static void draw_text(sh_text_t *text, cairo_t *cr) { |
145 sh_text_P_generate_layout(text, cr); | 146 sh_text_P_generate_layout(text, cr); |
146 cairo_move_to(cr, text->d_x, text->d_y); | 147 cairo_move_to(cr, text->d_x, text->d_y); |
147 pango_cairo_show_layout(cr,text->layout); | 148 pango_cairo_show_layout(cr,text->layout); |