static void chronoref_draw(Chronoref *chronoref, DiaRenderer *renderer) { DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer); Element *elem; Point lr_corner; real t; Point p1,p2,p3; assert(renderer != NULL); elem = &chronoref->element; renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID); renderer_ops->set_linejoin(renderer, LINEJOIN_MITER); lr_corner.x = elem->corner.x + elem->width; lr_corner.y = elem->corner.y + elem->height; p1.y = p2.y = elem->corner.y; renderer_ops->set_font(renderer, chronoref->font, chronoref->font_size); p3.y = p2.y + chronoref->majgrad_height + dia_font_ascent("1",chronoref->font, chronoref->font_size); renderer_ops->set_linewidth(renderer, chronoref->light_lwidth); if (chronoref->time_lstep > 0.0) { p2.y = p1.y + chronoref->mingrad_height; for (t = chronoref->firstmaj, p1.x = chronoref->firstmin_x; p1.x <= lr_corner.x; t += chronoref->time_lstep, p1.x += chronoref->mingrad) { p2.x = p1.x; renderer_ops->draw_line(renderer,&p1,&p2,&chronoref->color); } } renderer_ops->set_linewidth(renderer, chronoref->main_lwidth); if (chronoref->time_step > 0.0) { p2.y = p1.y + chronoref->majgrad_height; for (t = chronoref->firstmaj, p1.x = chronoref->firstmaj_x; p1.x <= lr_corner.x; t += chronoref->time_step, p1.x += chronoref->majgrad) { char time[10]; p3.x = p2.x = p1.x; renderer_ops->draw_line(renderer,&p1,&p2,&chronoref->color); g_snprintf(time,sizeof(time),"%.*f",chronoref->spec,t); renderer_ops->draw_string(renderer,time,&p3,ALIGN_CENTER, &chronoref->font_color); } } p1.x = elem->corner.x; p2.x = lr_corner.x; p1.y = p2.y = elem->corner.y; renderer_ops->draw_line(renderer,&p1,&p2,&chronoref->color); }
static void message_update_data(Message *message) { Connection *conn = &message->connection; DiaObject *obj = &conn->object; Rectangle rect; if (connpoint_is_autogap(conn->endpoint_handles[0].connected_to) || connpoint_is_autogap(conn->endpoint_handles[1].connected_to)) { connection_adjust_for_autogap(conn); } obj->position = conn->endpoints[0]; message->text_handle.pos = message->text_pos; connection_update_handles(conn); connection_update_boundingbox(conn); message->text_width = dia_font_string_width(message->text, message->font, message->font_height); /* Add boundingbox for text: */ rect.left = message->text_pos.x-message->text_width/2; rect.right = rect.left + message->text_width; rect.top = message->text_pos.y - dia_font_ascent(message->text, message->font, message->font_height); rect.bottom = rect.top + message->font_height; rectangle_union(&obj->bounding_box, &rect); }
static void mbr_update_data(Mbr *mbr) { Connection *conn = &mbr->connection; DiaObject *obj = &conn->object; Rectangle rect; Point p1,p2; Point p3,p4; gchar *text; /* Too complex to easily decide -- this is essentially a bezier curve */ /* if (connpoint_is_autogap(conn->endpoint_handles[0].connected_to) || connpoint_is_autogap(conn->endpoint_handles[1].connected_to)) { connection_adjust_for_autogap(conn); } */ obj->position = conn->endpoints[0]; mbr->pm_handle.pos = mbr->pm; connection_update_handles(conn); connection_update_boundingbox(conn); /* text width */ text=compute_text(mbr); mbr->text_width = dia_font_string_width(text, mbr_font, MBR_DECFONTHEIGHT); mbr->text_ascent = dia_font_ascent(text, mbr_font, MBR_DECFONTHEIGHT); /* endpoint */ p1 = conn->endpoints[0]; p2 = conn->endpoints[1]; /* bezier */ compute_line(&p1,&p2,&mbr->pm,mbr->line); /* Add boundingbox for mid decoration (slightly overestimated) : */ p3.x=mbr->pm.x-MBR_DEC_SIZE; p3.y=mbr->pm.y-MBR_DEC_SIZE; p4.x=p3.x+MBR_DEC_SIZE*2; p4.y=p3.y+MBR_DEC_SIZE*2; rect.left=p3.x; rect.right=p4.x; rect.top=p3.y; rect.bottom=p4.y; rectangle_union(&obj->bounding_box, &rect); /* Add boundingbox for text: */ rect.left = mbr->pm.x-mbr->text_width/2; rect.right = rect.left + mbr->text_width; rect.top = mbr->pm.y - mbr->text_ascent; rect.bottom = rect.top + MBR_DECFONTHEIGHT; rectangle_union(&obj->bounding_box, &rect); g_free(text); /* free auxilliary text */ }
static DiaObject * note_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Note *note; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; note = g_malloc0(sizeof(Note)); elem = ¬e->element; obj = &elem->object; obj->type = ¬e_type; obj->ops = ¬e_ops; elem->corner = *startpoint; note->line_width = attributes_get_default_linewidth(); note->line_color = attributes_get_foreground(); note->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8); p = *startpoint; p.x += note->line_width/2.0 + NOTE_MARGIN_X; p.y += note->line_width/2.0 + NOTE_CORNER + dia_font_ascent("A",font, 0.8); note->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = ¬e->connections[i]; note->connections[i].object = obj; note->connections[i].connected = NULL; } note->connections[NUM_CONNECTIONS-1].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = note->line_width/2.0; note_update_data(note); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return ¬e->element.object; }
static void constraint_update_data(Constraint *constraint) { Connection *conn = &constraint->connection; DiaObject *obj = &conn->object; Rectangle rect; LineBBExtras *extra; if ((constraint->text) && (constraint->text[0] == '{')) { /* we might have a string loaded from an older dia. Clean it up. */ g_free(constraint->brtext); constraint->brtext = constraint->text; constraint->text = bracketted_to_string(constraint->text,"{","}"); } else if (!constraint->brtext) { constraint->brtext = string_to_bracketted(constraint->text, "{", "}"); } if (connpoint_is_autogap(conn->endpoint_handles[0].connected_to) || connpoint_is_autogap(conn->endpoint_handles[1].connected_to)) { connection_adjust_for_autogap(conn); } obj->position = conn->endpoints[0]; constraint->text_width = dia_font_string_width(constraint->brtext, constraint->font, constraint->font_height); constraint->text_handle.pos = constraint->text_pos; connection_update_handles(conn); /* Boundingbox: */ extra = &conn->extra_spacing; extra->start_long = extra->start_trans = extra->end_long = constraint->line_width/2.0; extra->end_trans = MAX(constraint->line_width,CONSTRAINT_ARROWLEN)/2.0; connection_update_boundingbox(conn); /* Add boundingbox for text: */ rect.left = constraint->text_pos.x; rect.right = rect.left + constraint->text_width; rect.top = constraint->text_pos.y - dia_font_ascent(constraint->brtext, constraint->font, constraint->font_height); rect.bottom = rect.top + constraint->font_height; rectangle_union(&obj->bounding_box, &rect); }
/*! Not in the object interface but very important anyway. Used to recalculate the object data after a change */ static void measure_update_data (Measure *measure) { Connection *conn = &measure->connection; DiaObject *obj = &measure->connection.object; real value; Point *ends = measure->connection.endpoints; LineBBExtras *extra = &conn->extra_spacing; Rectangle bbox; Arrow arrow = MEASURE_ARROW(measure); real ascent, width; g_return_if_fail (obj->handles != NULL); connection_update_handles(conn); extra->start_trans = extra->end_trans = extra->start_long = extra->end_long = (measure->line_width / 2.0); g_free (measure->name); value = distance_point_point (&ends[0], &ends[1]); value *= measure->scale; value *= (28.346457 / units[measure->unit].factor); measure->name = g_strdup_printf ("%.*g %s", measure->precision, value, units[measure->unit].unit); ascent = dia_font_ascent (measure->name, measure->font, measure->font_height); width = dia_font_string_width (measure->name, measure->font, measure->font_height); measure->text_pos.x = (ends[0].x + ends[1].x) / 2; measure->text_pos.y = (ends[0].y + ends[1].y) / 2; /* for horizontal we could try to center over the line */ line_bbox (&ends[0], &ends[0], &conn->extra_spacing,&conn->object.bounding_box); arrow_bbox (&arrow, measure->line_width, &ends[0], &ends[1], &bbox); rectangle_union(&obj->bounding_box, &bbox); arrow_bbox (&arrow, measure->line_width, &ends[1], &ends[0], &bbox); rectangle_union(&obj->bounding_box, &bbox); bbox.left = measure->text_pos.x; bbox.top = measure->text_pos.y - ascent; bbox.bottom = bbox.top + measure->font_height; bbox.right = bbox.left + width; rectangle_union(&obj->bounding_box, &bbox); obj->position = conn->endpoints[0]; }
static void expand_bbox_for_text(Rectangle* bbox, Point* text_pos, gchar* text) { Rectangle text_box; real text_width; text_width = dia_font_string_width(text, transition_font, TRANSITION_FONTHEIGHT); text_box.left = text_pos->x - text_width/2; text_box.right = text_box.left + text_width; text_box.top = text_pos->y - dia_font_ascent(text, transition_font, TRANSITION_FONTHEIGHT); text_box.bottom = text_box.top + TRANSITION_FONTHEIGHT; rectangle_union(bbox, &text_box); }
/* Text block definition */ static void textblock_get_boundingbox(Block *block, Point *relpos, Boolequation *booleq, Rectangle *rect) { g_assert(block); g_assert(block->type == BLOCK_TEXT); block->pos = *relpos; block->bl.x = block->pos.x; block->bl.y = block->pos.y + dia_font_descent(block->d.text, booleq->font, booleq->fontheight); block->ur.y = block->pos.y - dia_font_ascent(block->d.text, booleq->font, booleq->fontheight); block->ur.x = block->bl.x + dia_font_string_width(block->d.text, booleq->font, booleq->fontheight); rect->left = block->bl.x; rect->top = block->ur.y; rect->bottom = block->bl.y; rect->right = block->ur.x; }
static void dependency_update_data(Dependency *dep) { OrthConn *orth = &dep->orth; DiaObject *obj = &orth->object; PolyBBExtras *extra = &orth->extra_spacing; int num_segm, i; Point *points; Rectangle rect; orthconn_update_data(orth); dep->stereotype = remove_stereotype_from_string(dep->stereotype); if (!dep->st_stereotype) { dep->st_stereotype = string_to_stereotype(dep->stereotype); } dep->text_width = 0.0; if (dep->name) dep->text_width = dia_font_string_width(dep->name, dep_font, DEPENDENCY_FONTHEIGHT); if (dep->stereotype) dep->text_width = MAX(dep->text_width, dia_font_string_width(dep->stereotype, dep_font, DEPENDENCY_FONTHEIGHT)); extra->start_trans = extra->start_long = extra->middle_trans = DEPENDENCY_WIDTH/2.0; extra->end_trans = extra->end_long = (dep->draw_arrow? (DEPENDENCY_WIDTH + DEPENDENCY_ARROWLEN)/2.0: DEPENDENCY_WIDTH/2.0); orthconn_update_boundingbox(orth); /* Calc text pos: */ num_segm = dep->orth.numpoints - 1; points = dep->orth.points; i = num_segm / 2; if ((num_segm % 2) == 0) { /* If no middle segment, use horizontal */ if (dep->orth.orientation[i]==VERTICAL) i--; } switch (dep->orth.orientation[i]) { case HORIZONTAL: dep->text_align = ALIGN_CENTER; dep->text_pos.x = 0.5*(points[i].x+points[i+1].x); dep->text_pos.y = points[i].y; if (dep->name) dep->text_pos.y -= dia_font_descent(dep->name, dep_font, DEPENDENCY_FONTHEIGHT); break; case VERTICAL: dep->text_align = ALIGN_LEFT; dep->text_pos.x = points[i].x + 0.1; dep->text_pos.y = 0.5*(points[i].y+points[i+1].y); if (dep->name) dep->text_pos.y -= dia_font_descent(dep->name, dep_font, DEPENDENCY_FONTHEIGHT); break; } /* Add the text recangle to the bounding box: */ rect.left = dep->text_pos.x; if (dep->text_align == ALIGN_CENTER) rect.left -= dep->text_width/2.0; rect.right = rect.left + dep->text_width; rect.top = dep->text_pos.y; if (dep->name) rect.top -= dia_font_ascent(dep->name, dep_font, DEPENDENCY_FONTHEIGHT); rect.bottom = rect.top + 2*DEPENDENCY_FONTHEIGHT; rectangle_union(&obj->bounding_box, &rect); }
static void realizes_update_data(Realizes *realize) { OrthConn *orth = &realize->orth; DiaObject *obj = &orth->object; int num_segm, i; Point *points; Rectangle rect; PolyBBExtras *extra; orthconn_update_data(orth); realize->text_width = 0.0; realize->stereotype = remove_stereotype_from_string(realize->stereotype); if (!realize->st_stereotype) { realize->st_stereotype = string_to_stereotype(realize->stereotype); } if (realize->name) realize->text_width = dia_font_string_width(realize->name, realize_font, REALIZES_FONTHEIGHT); if (realize->stereotype) realize->text_width = MAX(realize->text_width, dia_font_string_width(realize->stereotype, realize_font, REALIZES_FONTHEIGHT)); extra = &orth->extra_spacing; extra->start_trans = REALIZES_WIDTH/2.0 + REALIZES_TRIANGLESIZE; extra->start_long = extra->middle_trans = extra->end_trans = extra->end_long = REALIZES_WIDTH/2.0; orthconn_update_boundingbox(orth); /* Calc text pos: */ num_segm = realize->orth.numpoints - 1; points = realize->orth.points; i = num_segm / 2; if ((num_segm % 2) == 0) { /* If no middle segment, use horizontal */ if (realize->orth.orientation[i]==VERTICAL) i--; } switch (realize->orth.orientation[i]) { case HORIZONTAL: realize->text_align = ALIGN_CENTER; realize->text_pos.x = 0.5*(points[i].x+points[i+1].x); realize->text_pos.y = points[i].y; if (realize->name) realize->text_pos.y -= dia_font_descent(realize->name,realize_font, REALIZES_FONTHEIGHT); break; case VERTICAL: realize->text_align = ALIGN_LEFT; realize->text_pos.x = points[i].x + 0.1; realize->text_pos.y = 0.5*(points[i].y+points[i+1].y); if (realize->name) realize->text_pos.y -= dia_font_descent(realize->name, realize_font, REALIZES_FONTHEIGHT); break; } /* Add the text recangle to the bounding box: */ rect.left = realize->text_pos.x; if (realize->text_align == ALIGN_CENTER) rect.left -= realize->text_width/2.0; rect.right = rect.left + realize->text_width; rect.top = realize->text_pos.y; if (realize->name) rect.top -= dia_font_ascent(realize->name,realize_font, REALIZES_FONTHEIGHT); rect.bottom = rect.top + 2*REALIZES_FONTHEIGHT; rectangle_union(&obj->bounding_box, &rect); }
static void attribute_draw(Attribute *attribute, DiaRenderer *renderer) { DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer); Point center; Point start, end; Point p; Element *elem; real width; assert(attribute != NULL); assert(renderer != NULL); elem = &attribute->element; center.x = elem->corner.x + elem->width/2; center.y = elem->corner.y + elem->height/2; renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID); renderer_ops->fill_ellipse(renderer, ¢er, elem->width, elem->height, &attribute->inner_color); renderer_ops->set_linewidth(renderer, attribute->border_width); if (attribute->derived) { renderer_ops->set_linestyle(renderer, LINESTYLE_DASHED); renderer_ops->set_dashlength(renderer, 0.3); } else { renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID); } renderer_ops->draw_ellipse(renderer, ¢er, elem->width, elem->height, &attribute->border_color); if(attribute->multivalue) { renderer_ops->draw_ellipse(renderer, ¢er, elem->width - 2*MULTIVALUE_BORDER_WIDTH_X, elem->height - 2*MULTIVALUE_BORDER_WIDTH_Y, &attribute->border_color); } p.x = elem->corner.x + elem->width / 2.0; p.y = elem->corner.y + (elem->height - attribute->font_height)/2.0 + dia_font_ascent(attribute->name, attribute->font, attribute->font_height); renderer_ops->set_font(renderer, attribute->font, attribute->font_height); renderer_ops->draw_string(renderer, attribute->name, &p, ALIGN_CENTER, &color_black); if (attribute->key || attribute->weakkey) { if (attribute->weakkey) { renderer_ops->set_linestyle(renderer, LINESTYLE_DASHED); renderer_ops->set_dashlength(renderer, 0.3); } else { renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID); } width = dia_font_string_width(attribute->name, attribute->font, attribute->font_height); start.x = center.x - width / 2; start.y = center.y + 0.4; end.x = center.x + width / 2; end.y = center.y + 0.4; renderer_ops->draw_line(renderer, &start, &end, &color_black); } }
static void association_set_state(Association *assoc, AssociationState *state) { int i; AssociationEnd *end; g_free(assoc->name); assoc->name = state->name; assoc->text_width = 0.0; assoc->ascent = 0.0; assoc->descent = 0.0; if (assoc->name != NULL) { assoc->text_width = dia_font_string_width(assoc->name, assoc_font, ASSOCIATION_FONTHEIGHT); assoc->ascent = dia_font_ascent(assoc->name, assoc_font, ASSOCIATION_FONTHEIGHT); assoc->descent = dia_font_descent(assoc->name, assoc_font, ASSOCIATION_FONTHEIGHT); } assoc->direction = state->direction; for (i=0;i<2;i++) { end = &assoc->end[i]; g_free(end->role); g_free(end->multiplicity); end->role = state->end[i].role; end->multiplicity = state->end[i].multiplicity; end->arrow = state->end[i].arrow; end->aggregate = state->end[i].aggregate; end->visibility = state->end[i].visibility; end->text_width = 0.0; end->role_ascent = 0.0; end->role_descent = 0.0; end->multi_ascent = 0.0; end->multi_descent = 0.0; if (end->role != NULL && *end->role) { end->text_width = dia_font_string_width(end->role, assoc_font, ASSOCIATION_FONTHEIGHT); end->role_ascent = dia_font_ascent(end->role, assoc_font, ASSOCIATION_FONTHEIGHT); end->role_descent = dia_font_ascent(end->role, assoc_font, ASSOCIATION_FONTHEIGHT); } if (end->multiplicity != NULL) { end->text_width = MAX(end->text_width, dia_font_string_width(end->multiplicity, assoc_font, ASSOCIATION_FONTHEIGHT) ); end->role_ascent = dia_font_ascent(end->multiplicity, assoc_font,ASSOCIATION_FONTHEIGHT); end->role_descent = dia_font_descent(end->multiplicity, assoc_font,ASSOCIATION_FONTHEIGHT); } } g_free(state); association_update_data(assoc); }