static void
skillgui_cairo_render_ellipse(GVJ_t *job, pointf *A, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_ellipse);
  ++__num_ellipse;
#endif
  //printf("Render ellipse\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  Cairo::Matrix old_matrix;
  cairo->get_matrix(old_matrix);

  skillgui_cairo_set_penstyle(cairo, job);

  cairo->translate(A[0].x, -A[0].y);

  double rx = A[1].x - A[0].x;
  double ry = A[1].y - A[0].y;
  cairo->scale(1, ry / rx);
  cairo->move_to(rx, 0);
  cairo->arc(0, 0, rx, 0, 2 * M_PI);
  cairo->close_path();

  cairo->set_matrix(old_matrix);

  if (filled) {
    skillgui_cairo_set_color(cairo, &(obj->fillcolor));
    cairo->fill_preserve();
  }
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->stroke();

#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_ellipse);
#endif
}
Beispiel #2
0
Matrix3d getMatrix(const Cairo::RefPtr<Cairo::Context> context)
{
  /* A #cairo_matrix_t holds an affine transformation, such as a scale,
   * rotation, shear, or a combination of those. The transformation of
   * a point (x, y) is given by:
   * <programlisting>
   *     x_new = xx * x + xy * y + x0;
   *     y_new = yx * x + yy * y + y0;
   * </programlisting>
   **/
  //   typedef struct _cairo_matrix {
  //     double xx; double yx;
  //     double xy; double yy;
  //     double x0; double y0;
  //   } cairo_matrix_t;
  // In a cairo.matrix(1,2,3,4,5,6), 1 is a11, 2 is a21, 3 is a12, 4 is a22, 5 is a13 and 6 is a23. a31 and a32 are 0, a33 is 1.
  Cairo::Matrix cm;
  context->get_matrix(cm);
  Matrix3d m;
  m[0][0] = cm.xx; m[0][1] = cm.xy; m[0][2] = cm.x0;
  m[1][0] = cm.yx; m[1][1] = cm.yy; m[1][2] = cm.y0;
  m[2][0] = 0;     m[2][1] = 0;     m[2][2] = 1;
  return m;
}
static void
skillgui_cairo_render_textpara(GVJ_t *job, pointf p, textpara_t *para)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_text);
  ++__num_text;
#endif
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  Cairo::FontWeight weight = Cairo::FONT_WEIGHT_NORMAL;
  Cairo::FontSlant slant   = Cairo::FONT_SLANT_NORMAL;
  char *fontweight = NULL;
  char *fontslant = NULL;
  if (obj->type == CLUSTER_OBJTYPE) {
    fontweight = agget(obj->u.sg, (char *)"fontweight");
    fontslant  = agget(obj->u.sg, (char *)"fontslant");
  } else if (obj->type == ROOTGRAPH_OBJTYPE) {
    fontweight = agget(obj->u.g, (char *)"fontweight");
    fontslant  = agget(obj->u.g, (char *)"fontslant");
  } else if (obj->type == NODE_OBJTYPE) {
    fontweight = agget(obj->u.n, (char *)"fontweight");
    fontslant  = agget(obj->u.n, (char *)"fontslant");
  } else if (obj->type == EDGE_OBJTYPE) {
    fontweight = agget(obj->u.e, (char *)"fontweight");
    fontslant  = agget(obj->u.e, (char *)"fontslant");
  }
  if (fontweight && (strcmp(fontweight, "bold") == 0)) {
    weight = Cairo::FONT_WEIGHT_BOLD;
    p.x -= 8;
  }
  if (fontslant && (strcmp(fontslant, "italic") == 0)) {
    slant = Cairo::FONT_SLANT_ITALIC;
  }

  double offsetx = 0.0;
  double offsety = 0.0;
  double rotate  = 0.0;

  if ( (obj->type == EDGE_OBJTYPE) && (strcmp(para->str, obj->headlabel) == 0) ) {
    char *labelrotate = agget(obj->u.e, (char *)"labelrotate");
    if (labelrotate && (strlen(labelrotate) > 0)) {
      rotate = fawkes::deg2rad(atof(labelrotate));
    }
    char *labeloffsetx = agget(obj->u.e, (char *)"labeloffsetx");
    if (labeloffsetx && (strlen(labeloffsetx) > 0)) {
      offsetx = atof(labeloffsetx);
    }
    char *labeloffsety = agget(obj->u.e, (char *)"labeloffsety");
    if (labeloffsety && (strlen(labeloffsety) > 0)) {
      offsety = atof(labeloffsety);
    }
  }
  //__tt.ping_start(__ttc_text_1);

  Cairo::Matrix old_matrix;
  cairo->get_matrix(old_matrix);

  if (__fontname) {
    cairo->select_font_face(__fontname, slant, weight);
  } else {
    cairo->select_font_face(para->fontname, slant, weight);
  }
  cairo->set_font_size(para->fontsize);
  //cairo->set_font_options ( Cairo::FontOptions() );
  //cairo->set_line_width(1.0);

  Cairo::TextExtents extents;
  cairo->get_text_extents(para->str, extents);

  if (para->just == 'r') {
    p.x -= extents.width;
  } else if (para->just != 'l') {
    p.x -= extents.width / 2.0;
  }

  cairo->move_to(p.x + offsetx, -p.y + offsety);
  cairo->rotate(rotate);
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->text_path( para->str );
  cairo->fill();

  cairo->set_matrix(old_matrix);

  //__tt.ping_end(__ttc_text_5);
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_text);
#endif
}