예제 #1
0
파일: pdf-import.cpp 프로젝트: mpuels/dia
/*!
 */
void
DiaOutputDev::_fill (GfxState *state, bool winding)
{
  GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
  DiaObject *obj = NULL;
  GfxPath *path = state->getPath();
  bool haveClose = true;

  if (doPath (points, state, path, haveClose) && points->len > 2) {
    if (path->getNumSubpaths() == 1 && haveClose)
      obj = create_standard_beziergon (points->len, &g_array_index (points, BezPoint, 0));
    else
      obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
    applyStyle (obj, true);
    if (this->pattern) {
      ObjectChange *change = dia_object_set_pattern (obj, this->pattern);
      if (change) {
	change->free (change);
	g_free (change);
      }
    }
  }
  g_array_free (points, TRUE);
  if (obj) {
    // Useful for debugging but high performance penalty 
    // dia_object_set_meta (obj, "fill-rule", winding ? "winding" : "even-odd");
    addObject (obj);
  }
}
예제 #2
0
파일: standard-path.c 프로젝트: UIKit0/dia
DiaObject *
create_standard_path_from_text (const Text *text)
{
  DiaObject *obj = NULL;
  GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));

  if (text_to_path (text, points))
    obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));

  g_array_free (points, TRUE);

  if (obj) {
    StdPath *path = (StdPath *)obj;
    Rectangle text_box;
    const Rectangle *pbb = &path->object.bounding_box;
    real sx, sy;
    Point pos;

    path->stroke_or_fill = PDO_FILL;
    path->fill_color = text->color;

    /* scale to fit the original size */
    text_calc_boundingbox ((Text *)text, &text_box);
    pos.x = text_box.left; pos.y = text_box.top;
    sx = (text_box.right - text_box.left) / (pbb->right - pbb->left);
    sy = (text_box.bottom - text_box.top) / (pbb->bottom - pbb->top);
    _stdpath_scale (path, sx, sy);

    /* also adjust top left corner - calling update, too */
    stdpath_move (path, &pos);
  }

  return obj;
}
예제 #3
0
파일: box.c 프로젝트: jbohren-forks/dia
static ObjectChange *
_box_convert_to_path_callback (DiaObject *obj, Point *clicked, gpointer data)
{
  const Box *box = (Box *)obj;
  const Element *elem = &box->element;
  DiaObject *path;
  int num_points;
  BezPoint *points;

  if (box->corner_radius > 0) {
    const real w = elem->width;
    const real h = elem->height;
    const real x = elem->corner.x;
    const real y = elem->corner.y;
    real r = box->corner_radius;
    num_points = 9;
    points = g_alloca (sizeof(BezPoint) * num_points);

    /* avoid r>w/w and r>h/2 */
    r = (w > h ) ? (r > h/2 ? h/2 : r) : (r > w/2 ? w/2 : r);

    points[0].type = BEZ_MOVE_TO;  points[0].p1.x = x + r; points[0].p1.y = y; /* top-left */
    points[1].type = BEZ_LINE_TO;  points[1].p1.x = x + w - r; points[1].p1.y = y; /* top-right */
    points[2].type = BEZ_CURVE_TO; points[2].p1.x = x + w - r; points[2].p1.y = y; /* around */
    points[2].p2.x = x + w; points[2].p2.y = y; points[2].p3.x = x + w; points[2].p3.y = y + r;
    points[3].type = BEZ_LINE_TO; points[3].p1.x =  x + w; points[3].p1.y = y + h - r; /* bottom-right */
    points[4].type = BEZ_CURVE_TO; points[4].p1.x = x + w; points[4].p1.y = y + h - r; /* around */
    points[4].p2.x = x + w; points[4].p2.y = y + h; points[4].p3.x = x + w - r; points[4].p3.y = y + h;
    points[5].type = BEZ_LINE_TO;  points[5].p1.x = x + r; points[5].p1.y = y + h; /* bottom-left */
    points[6].type = BEZ_CURVE_TO; points[6].p1.x = x + r; points[6].p1.y = y + h; /* around */
    points[6].p2.x = x; points[6].p2.y = y + h; points[6].p3.x = x; points[6].p3.y = y + h - r;
    points[7].type = BEZ_LINE_TO;  points[7].p1.x = x; points[7].p1.y = y + r; /* top-left */
    points[8].type = BEZ_CURVE_TO; points[8].p1.x = x; points[8].p1.y = y + r; /* around */
    points[8].p2.x = x; points[8].p2.y = y; points[8].p3.x = x + r; points[8].p3.y = y;
  } else {
    num_points = 5;
    points = g_alloca (sizeof(BezPoint) * num_points);

    points[0].type = BEZ_MOVE_TO;
    points[0].p1 = elem->corner;
    points[1].type = points[2].type = points[3].type = points[4].type = BEZ_LINE_TO;
    points[1].p1.x = elem->corner.x + elem->width;
    points[1].p1.y = elem->corner.y;
    points[2].p1.x = elem->corner.x + elem->width;
    points[2].p1.y = elem->corner.y + elem->height;
    points[3].p1.x = elem->corner.x;
    points[3].p1.y = elem->corner.y + elem->height;
    points[4].p1 = elem->corner;
  }
  path = create_standard_path (num_points, points);
  if (path)
    return object_substitute (obj, path);

  /* Empty change */
  return change_list_create ();
}
예제 #4
0
파일: beziergon.c 프로젝트: brunetton/dia
/*!
 * \brief Convert _Beziergon to _Path
 * \memberof _Beziergon
 */
static ObjectChange *
_beziergon_convert_to_path_callback (DiaObject *obj, Point *clicked, gpointer data)
{
  Beziergon *beziergon = (Beziergon *) obj;
  BezierShape *bez = &beziergon->bezier;
  DiaObject *path = NULL;

  if (bez->bezier.num_points > 1)
    path = create_standard_path (bez->bezier.num_points, bez->bezier.points);

  if (path)
    return object_substitute (obj, path);

  /* just an empty change */
  return change_list_create ();
}
예제 #5
0
/*!
 */
void
DiaOutputDev::_fill (GfxState *state, bool winding)
{
  GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
  DiaObject *obj = NULL;
  GfxPath *path = state->getPath();
  bool haveClose = true;

  if (doPath (points, state, path, haveClose)) {
    if (path->getNumSubpaths() == 1 && haveClose)
      obj = create_standard_beziergon (points->len, &g_array_index (points, BezPoint, 0));
    else
      obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
    applyStyle (obj, true);
  }
  g_array_free (points, TRUE);
  if (obj) {
    dia_object_set_meta (obj, "fill-rule", winding ? "winding" : "even-odd");
    addObject (obj);
  }
}
예제 #6
0
파일: pdf-import.cpp 프로젝트: mpuels/dia
/*!
 * \brief create a _Bezierline or _StdPath from the graphics state
 */
void
DiaOutputDev::stroke (GfxState *state)
{
  GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
  DiaObject *obj = NULL;
  GfxPath *path = state->getPath();
  bool haveClose = false;

  if (doPath (points, state, path, haveClose) && points->len > 1) {
    if (path->getNumSubpaths() == 1) {
      if (!haveClose)
        obj = create_standard_bezierline (points->len, &g_array_index (points, BezPoint, 0), NULL, NULL);
      else
        obj = create_standard_beziergon (points->len, &g_array_index (points, BezPoint, 0));
    } else {
      obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
    }
    applyStyle (obj, false);
  }
  g_array_free (points, TRUE);
  if (obj)
    addObject (obj);
}