Esempio n. 1
0
/* Parensblock : */
static void
parensblock_get_boundingbox(Block *block, Point *relpos,
                            Boolequation *booleq, Rectangle *rect)
{
    real pheight,pwidth;
    Point temppos;
    g_assert(block);
    g_assert(block->type == BLOCK_PARENS);

    temppos = block->pos = *relpos;
    block->d.inside->ops->get_boundingbox(block->d.inside,&temppos,booleq,rect);
    pheight = 1.1 * (block->d.inside->bl.y - block->d.inside->ur.y);
    pwidth = dia_font_string_width("()",booleq->font,pheight) / 2;
    temppos.x += pwidth;
    block->d.inside->ops->get_boundingbox(block->d.inside,&temppos,booleq,rect);

    block->bl.x = block->pos.x;
    block->bl.y = block->pos.y + dia_font_descent("()",booleq->font,pheight);
    block->ur.x = block->d.inside->ur.x + pwidth;
    block->ur.y = block->bl.y - pheight;

    rect->left = block->bl.x;
    rect->top = block->ur.y;
    rect->bottom = block->bl.y;
    rect->right = block->ur.x;
}
Esempio n. 2
0
static void
draw_string(DiaRenderer *self,
	    const char *text,
	    Point *pos, Alignment alignment,
	    Color *color)
{
  DiaPsRenderer *renderer = DIA_PS_RENDERER(self);
  Point pos_adj;
  gchar *buffer;

  if (1 > strlen(text))
    return;

  lazy_setcolor(renderer,color);

  buffer = ps_convert_string(text, renderer->ctx);

  fprintf(renderer->file, "(%s) ", buffer);
  g_free(buffer);

  pos_adj.x = pos->x;
  pos_adj.y = pos->y - dia_font_descent("", self->font, self->font_height);
  put_text_alignment (renderer, alignment, &pos_adj);

  fprintf(renderer->file, " gs 1 -1 sc sh gr\n");
}
Esempio n. 3
0
static DiaObject *
basestation_create(Point *startpoint,
                   void *user_data,
                   Handle **handle1,
                   Handle **handle2)
{
    Basestation *basestation;
    Element *elem;
    DiaObject *obj;
    Point p;
    DiaFont *font;
    int i;

    basestation = g_new0(Basestation, 1);
    elem = &basestation->element;
    obj = &elem->object;

    obj->type = &basestation_type;
    obj->ops = &basestation_ops;
    elem->corner = *startpoint;
    elem->width = BASESTATION_WIDTH;
    elem->height = BASESTATION_HEIGHT;

    font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8);
    p = *startpoint;
    p.y += BASESTATION_HEIGHT -
           dia_font_descent(_("Base Station"), font, 0.8);

    basestation->text = new_text(_("Base Station"),
                                 font, 0.8, &p, &color_black, ALIGN_CENTER);
    dia_font_unref(font);
    basestation->line_colour = color_black;
    basestation->fill_colour = color_white;
    basestation->sectors = 3;

    element_init(elem, 8, NUM_CONNECTIONS);

    for (i=0; i<NUM_CONNECTIONS; i++) {
        obj->connections[i] = &basestation->connections[i];
        basestation->connections[i].object = obj;
        basestation->connections[i].connected = NULL;
        basestation->connections[i].flags = 0;
    }
    basestation->connections[8].flags = CP_FLAGS_MAIN;

    elem->extra_spacing.border_trans = BASESTATION_LINEWIDTH/2.0;
    basestation_update_data(basestation);

    for (i=0; i<8; i++) {
        obj->handles[i]->type = HANDLE_NON_MOVABLE;
    }

    *handle1 = NULL;
    *handle2 = NULL;
    return &basestation->element.object;
}
Esempio n. 4
0
static void
opblock_get_boundingbox(Block *block, Point *relpos,
                        Boolequation *booleq, Rectangle *rect)
{
    const gchar* ops;
    g_assert(block);
    g_assert(block->type == BLOCK_OPERATOR);

    ops = opstring(block->d.operator);

    block->pos = *relpos;
    block->bl.x = block->pos.x;
    block->bl.y = block->pos.y +
                  dia_font_descent(ops,booleq->font,booleq->fontheight);
    block->ur.y = block->bl.y - booleq->fontheight;
    block->ur.x = block->bl.x + dia_font_string_width(ops, booleq->font,
                  booleq->fontheight);
    rect->left = block->bl.x;
    rect->top = block->ur.y;
    rect->bottom = block->bl.y;
    rect->right = block->ur.x;
}
Esempio n. 5
0
/* 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;
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
static void
largepackage_draw(LargePackage *pkg, DiaRenderer *renderer)
{
  DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
  Element *elem;
  real x, y, w, h;
  Point p1, p2;
  
  assert(pkg != NULL);
  assert(renderer != NULL);

  elem = &pkg->element;

  x = elem->corner.x;
  y = elem->corner.y;
  w = elem->width;
  h = elem->height;
  
  renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
  renderer_ops->set_linewidth(renderer, pkg->line_width);
  renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);


  p1.x = x; p1.y = y;
  p2.x = x+w; p2.y = y+h;

  renderer_ops->fill_rect(renderer, 
			   &p1, &p2,
			   &pkg->fill_color);
  renderer_ops->draw_rect(renderer, 
			   &p1, &p2,
			   &pkg->line_color);

  p1.x= x; p1.y = y - pkg->topheight;
  p2.x = x + pkg->topwidth; p2.y = y;

  renderer_ops->fill_rect(renderer, 
			   &p1, &p2,
			   &pkg->fill_color);
  
  renderer_ops->draw_rect(renderer, 
			   &p1, &p2,
			   &pkg->line_color);


  renderer_ops->set_font(renderer, pkg->font, LARGEPACKAGE_FONTHEIGHT);

  p1.x = x + 0.1;
  p1.y = y - LARGEPACKAGE_FONTHEIGHT -
      dia_font_descent(pkg->st_stereotype,
                       pkg->font, LARGEPACKAGE_FONTHEIGHT) - 0.1;



  if (pkg->st_stereotype && pkg->st_stereotype[0] != '\0') {
    renderer_ops->draw_string(renderer, pkg->st_stereotype, &p1,
			       ALIGN_LEFT, &pkg->text_color);
  }
  p1.y += LARGEPACKAGE_FONTHEIGHT;

  if (pkg->name)
    renderer_ops->draw_string(renderer, pkg->name, &p1,
			       ALIGN_LEFT, &pkg->text_color);
}
Esempio n. 9
0
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);
}