static gboolean textobj_transform(Textobj *textobj, const DiaMatrix *m) { real a, sx, sy; g_return_val_if_fail(m != NULL, FALSE); if (!dia_matrix_get_angle_and_scales (m, &a, &sx, &sy)) { dia_log_message ("textobj_transform() can't convert given matrix"); return FALSE; } else { /* XXX: what to do if width!=height */ real height = text_get_height (textobj->text) * MIN(sx,sy); real angle = a*180/G_PI; Point p = textobj->object.position; /* rotation is invariant to the handle position */ transform_point (&p, m); text_set_height (textobj->text, height); textobj->text_angle = angle; textobj->object.position = p; } textobj_update_data(textobj); return TRUE; }
static ObjectChange* textobj_move(Textobj *textobj, Point *to) { textobj->object.position = *to; textobj_update_data(textobj); return NULL; }
static DiaObject * textobj_load(ObjectNode obj_node, int version, DiaContext *ctx) { Textobj *textobj; DiaObject *obj; AttributeNode attr; Point startpoint = {0.0, 0.0}; textobj = g_malloc0(sizeof(Textobj)); obj = &textobj->object; obj->type = &textobj_type; obj->ops = &textobj_ops; object_load(obj, obj_node, ctx); attr = object_find_attribute(obj_node, "text"); if (attr != NULL) { textobj->text = data_text(attribute_first_data(attr), ctx); } else { DiaFont* font = dia_font_new_from_style(DIA_FONT_MONOSPACE,1.0); textobj->text = new_text("", font, 1.0, &startpoint, &color_black, ALIGN_CENTER); dia_font_unref(font); } attr = object_find_attribute(obj_node, "valign"); if (attr != NULL) textobj->vert_align = data_enum(attribute_first_data(attr), ctx); else if (version == 0) { textobj->vert_align = VALIGN_FIRST_LINE; } /* default visibility must be off to keep compatibility */ textobj->fill_color = attributes_get_background(); attr = object_find_attribute(obj_node, "fill_color"); if (attr) data_color(attribute_first_data(attr), &textobj->fill_color, ctx); attr = object_find_attribute(obj_node, "show_background"); if (attr) textobj->show_background = data_boolean(attribute_first_data(attr), ctx); else textobj->show_background = FALSE; object_init(obj, 1, 0); obj->handles[0] = &textobj->text_handle; textobj->text_handle.id = HANDLE_TEXT; textobj->text_handle.type = HANDLE_MAJOR_CONTROL; textobj->text_handle.connect_type = HANDLE_CONNECTABLE; textobj->text_handle.connected_to = NULL; textobj_update_data(textobj); return &textobj->object; }
static DiaObject * textobj_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Textobj *textobj; DiaObject *obj; Color col; DiaFont *font = NULL; real font_height; textobj = g_malloc0(sizeof(Textobj)); obj = &textobj->object; obj->enclosing_box = g_new0 (Rectangle, 1); obj->type = &textobj_type; obj->ops = &textobj_ops; col = attributes_get_foreground(); attributes_get_default_font(&font, &font_height); textobj->text = new_text("", font, font_height, startpoint, &col, default_properties.alignment ); /* need to initialize to object.position as well, it is used update data */ obj->position = *startpoint; dia_font_unref(font); textobj->vert_align = default_properties.vert_align; /* default visibility must be off to keep compatibility */ textobj->fill_color = attributes_get_background(); textobj->show_background = FALSE; object_init(obj, 1, 0); obj->handles[0] = &textobj->text_handle; textobj->text_handle.id = HANDLE_TEXT; textobj->text_handle.type = HANDLE_MAJOR_CONTROL; textobj->text_handle.connect_type = HANDLE_CONNECTABLE; textobj->text_handle.connected_to = NULL; /* no margin till Dia 0.98 */ textobj->margin = 0.0; textobj_update_data(textobj); *handle1 = NULL; *handle2 = obj->handles[0]; return &textobj->object; }
static void textobj_set_props(Textobj *textobj, GPtrArray *props) { object_set_props_from_offsets(&textobj->object,textobj_offsets,props); textobj_update_data(textobj); }