Exemple #1
0
void wxSVGCanvasCairo::DrawPath(cairo_t* cr, wxSVGCanvasPathCairo& canvasPath, const wxSVGMatrix& matrix,
		const wxCSSStyleDeclaration& style, wxSVGSVGElement& svgElem) {
	SetMatrix(cr, matrix);
	
	// Filling
	if (canvasPath.GetFill() && style.GetFill().Ok() && style.GetFill().GetPaintType() != wxSVG_PAINTTYPE_NONE) {
		cairo_path_t* path = canvasPath.GetPath();
		cairo_append_path(cr, path);
		SetPaint(cr, style.GetFill(), style.GetOpacity()*style.GetFillOpacity(), canvasPath, svgElem, matrix);
		cairo_fill(cr);
		cairo_path_destroy(path);
	}
	
	// Stroking
	if (style.GetStroke().Ok() && style.GetStrokeWidth() > 0
			&& style.GetStroke().GetPaintType() != wxSVG_PAINTTYPE_NONE) {
		cairo_path_t* path = canvasPath.GetPath();
		cairo_append_path(cr, path);
		SetPaint(cr, style.GetStroke(), style.GetOpacity()*style.GetStrokeOpacity(), canvasPath, svgElem, matrix);
		wxSVGCanvasPathCairo::ApplyStrokeStyle(cr, style);
		cairo_stroke(cr);
		cairo_path_destroy(path);
	}
	
	// marker
	if (style.HasMarkerStart()) {
		DrawMarker(style.GetMarkerStart().GetStringValue(), wxSVGMark::START, canvasPath, matrix, style, svgElem);
	}
	if (style.HasMarkerMid()) {
		DrawMarker(style.GetMarkerMid().GetStringValue(), wxSVGMark::MID, canvasPath, matrix, style, svgElem);
	}
	if (style.HasMarkerEnd()) {
		DrawMarker(style.GetMarkerEnd().GetStringValue(), wxSVGMark::END, canvasPath, matrix, style, svgElem);
	}
}
Exemple #2
0
void Context::copyPathFlat( cinder::Shape2d *resultPath )
{
	resultPath->clear();	
	cairo_path_t *path = cairo_copy_path_flat( mCairo );
	convertCairoToCinderPath( path, resultPath );
	cairo_path_destroy( path );
}
cairo_bool_t cairocks_map_path_onto(cairo_t* cr, cairo_path_t* path) {
	cairo_path_t* cur_path = 0;

	parametrized_path_t param;

	if(cairo_status(cr) || !path) return FALSE;

	cur_path = cairo_copy_path(cr);

	param.path = path;
	param.parametrization = parametrize_path(path);

	cairo_new_path(cr);

	transform_path(
		cur_path,
		(transform_point_func_t)(point_on_path),
		&param
	);

	cairo_append_path(cr, cur_path);

	free(param.parametrization);

	cairo_path_destroy(cur_path);

	return TRUE;
}
Exemple #4
0
String Path::debugString() const
{
    String string = "";
    cairo_path_t* path = cairo_copy_path(platformPath()->m_cr);
    cairo_path_data_t* data;

    if (!path->num_data )
        string = "EMPTY";

    for (int i = 0; i < path->num_data; i += path->data[i].header.length) {
        data = &path->data[i];
        switch (data->header.type) {
        case CAIRO_PATH_MOVE_TO:
            string += String::format("M %.2f,%.2f",
                                      data[1].point.x, data[1].point.y);
            break;
        case CAIRO_PATH_LINE_TO:
            string += String::format("L %.2f,%.2f",
                                      data[1].point.x, data[1].point.y);
            break;
        case CAIRO_PATH_CURVE_TO:
            string += String::format("C %.2f,%.2f,%.2f,%.2f,%.2f,%.2f",
                                      data[1].point.x, data[1].point.y,
                                      data[2].point.x, data[2].point.y,
                                      data[3].point.x, data[3].point.y);
            break;
        case CAIRO_PATH_CLOSE_PATH:
            string += "X";
            break;
        }
    }
    cairo_path_destroy(path);
    return string;
}
Exemple #5
0
static int
path_gc (lua_State *L) {
    cairo_path_t **obj = luaL_checkudata(L, 1, MT_NAME_PATH);
    cairo_path_destroy(*obj);
    *obj = 0;
    return 0;
}
static void cleanup
( void )
{
	gint i;
	for (i=0;i<4;i++)
		{ cairo_path_destroy(arrow_paths[i]); }
}
Exemple #7
0
// cairo_public void
// cairo_path_destroy (cairo_path_t *path);
static int l_cairo_path_destroy(lua_State* L)
{
	cairo_path_t *path;
    remove_Context(L, 1); // if called via Context userdata
    path = get_cairo_path_t (L, 1);
    cairo_path_destroy (path);
    return 0;
}
Exemple #8
0
Path::Path(const Path& other)
    : m_path(new CairoPath())
{
    cairo_t* cr = platformPath()->m_cr;
    cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr);
    cairo_append_path(cr, p);
    cairo_path_destroy(p);
}
Exemple #9
0
/*!
 * \brief Destruction of the object
 * \memberof Outline
 */
static void
outline_destroy (Outline *outline)
{
  if (outline->path)
    cairo_path_destroy (outline->path);
  g_free (outline->name);
  object_destroy(&outline->object);
  /* but not the object itself? */
}
Exemple #10
0
    void cairo_to_clipper(cairo_t* cr,
                          Polygons &pg,
                          int scaling_factor,
                          Transform transform)
    {
      if (scaling_factor > 8 || scaling_factor < 0)
        throw clipperCairoException("cairo_to_clipper: invalid scaling factor");
      double scaling = std::pow((double)10, scaling_factor);

      pg.clear();
      cairo_path_t *path = cairo_copy_path_flat(cr);

      int poly_count = 0;
      for (int i = 0; i < path->num_data; i += path->data[i].header.length) {
        if( path->data[i].header.type == CAIRO_PATH_CLOSE_PATH) poly_count++;
      }

      pg.resize(poly_count);
      int i = 0, pc = 0;
      while (pc < poly_count)
      {
        int vert_count = 1;
        int j = i;
        while(j < path->num_data &&
          path->data[j].header.type != CAIRO_PATH_CLOSE_PATH)
        {
          if (path->data[j].header.type == CAIRO_PATH_LINE_TO)
            vert_count++;
          j += path->data[j].header.length;
        }
        pg[pc].resize(vert_count);
        if (path->data[i].header.type != CAIRO_PATH_MOVE_TO) {
          pg.resize(pc);
          break;
        }
        pg[pc][0].X = Round(path->data[i+1].point.x *scaling);
        pg[pc][0].Y = Round(path->data[i+1].point.y *scaling);
        if (transform != tNone)
          transform_point(cr, transform, &pg[pc][0].X, &pg[pc][0].Y);

        i += path->data[i].header.length;

        j = 1;
        while (j < vert_count && i < path->num_data &&
          path->data[i].header.type == CAIRO_PATH_LINE_TO) {
          pg[pc][j].X = Round(path->data[i+1].point.x *scaling);
          pg[pc][j].Y = Round(path->data[i+1].point.y *scaling);
          if (transform != tNone)
            transform_point(cr, transform, &pg[pc][j].X, &pg[pc][j].Y);
          j++;
          i += path->data[i].header.length;
        }
        pc++;
        i += path->data[i].header.length;
      }
      cairo_path_destroy(path);
    }
Exemple #11
0
/* PycairoPath_FromPath
 * Create a new PycairoPath from a cairo_path_t
 * path - a cairo_path_t to 'wrap' into a Python object.
 *        path is unreferenced if the PycairoPath creation fails, or if path
 *        is in an error status.
 * Return value: New reference or NULL on failure
 */
PyObject *
PycairoPath_FromPath (cairo_path_t *path) {
  PyObject *o;

  assert (path != NULL);

  if (Pycairo_Check_Status (path->status)) {
    cairo_path_destroy (path);
    return NULL;
  }

  o = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
  if (o)
    ((PycairoPath *)o)->path = path;
  else
    cairo_path_destroy (path);
  return o;
}
Exemple #12
0
static void
_rsvg_node_text_type_text_path (RsvgNodeTextPath * self, RsvgDrawingCtx * ctx,
                                gdouble * x, gdouble * y,
                                gboolean * lastwasspace, gboolean usetextonly)
{
    if (self->link && self->link->type == RSVG_NODE_TYPE_PATH) {
        guint i;

        // Resolve the xlink:href id and get its cairo path object
        cairo_path_t *path = ((RsvgNodePath *)self->link)->path;

        // Get the cairo_t context
        RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
        cairo_t *cr = render->cr;

        // Flatten path
        cairo_save(cr);
        cairo_new_path(cr);
        cairo_append_path(cr, path);
        path = cairo_copy_path_flat (cr);
        cairo_restore(cr);

        // TODO recursively draw children
        rsvg_push_discrete_layer (ctx);
        for (i = 0; i < self->super.children->len; i++) {
            RsvgNode *node = g_ptr_array_index (self->super.children, i);
            RsvgNodeType type = RSVG_NODE_TYPE (node);

            if (type == RSVG_NODE_TYPE_CHARS) {
                RsvgNodeChars *chars = (RsvgNodeChars *) node;
                GString *str = _rsvg_text_chomp (rsvg_current_state (ctx), chars->contents, lastwasspace);
                double offset = 0;

                // Factor in start offset
                // Handle percentages as percent of path length
                if (self->startOffset.factor == 'p') {
                    offset = self->startOffset.length *_rsvg_path_length(path);
                } else {
                    offset = _rsvg_css_normalize_length (&self->startOffset,
                                                       ctx, 'h');
                }

                if (PANGO_GRAVITY_IS_VERTICAL (rsvg_current_state(ctx)->text_gravity))
                    *y += offset;
                else
                    *x += offset;

                draw_twisted (ctx, cr, path, x, y, str->str);
                g_string_free (str, TRUE);
            }
        }
        rsvg_pop_discrete_layer (ctx);

        cairo_path_destroy (path);
    }
}
void GraphicsContext::addPath(const Path& path)
{
    if (paintingDisabled())
        return;

    cairo_t* cr = m_data->cr;
    cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr);
    cairo_append_path(cr, p);
    cairo_path_destroy(p);
}
Exemple #14
0
/* ============ cairo_path_t * support ============ */
static HB_GARBAGE_FUNC( hb_cairo_path_destructor )
{
   cairo_path_t ** ppPath = ( cairo_path_t ** ) Cargo;

   if( *ppPath )
   {
      cairo_path_destroy( *ppPath );
      *ppPath = NULL;
   }
}
Exemple #15
0
static void
draw_twisted (RsvgDrawingCtx * ctx, cairo_t *cr, cairo_path_t *path,
              double *x, double *y, const char *text)
{

    cairo_path_t *path_copy;

    cairo_save (cr);

    /* Decrease tolerance a bit, since it's going to be magnified */
    cairo_set_tolerance (cr, 0.01);

    /* Using cairo_copy_path() here shows our deficiency in handling
     * Bezier curves, specially around sharper curves.
     *
     * Using cairo_copy_path_flat() on the other hand, magnifies the
     * flattening error with large off-path values.  We decreased
     * tolerance for that reason.  Increase tolerance to see that
     * artifact.
     */

    // Load the previously drawn path in order to make a copy
    cairo_new_path(cr);
    cairo_append_path(cr, path);
    path_copy = cairo_copy_path_flat (cr);

    // Draw the text
    cairo_new_path (cr);

    draw_text (ctx, cr, x, y, text);
    map_path_onto (cr, path_copy);

    cairo_path_destroy (path_copy);

    // Render the text path using current text settings
    //cairo_fill_preserve (cr);
    path_copy = cairo_copy_path(cr);
    ctx->render->render_path(ctx, path_copy);
    cairo_path_destroy (path_copy);

    cairo_restore (cr);
}
Exemple #16
0
void
CairoPathContext::CopyPathTo(cairo_t* aToContext, Matrix& aTransform)
{
  if (aToContext != mContext) {
    CairoTempMatrix tempMatrix(mContext, aTransform);
    cairo_path_t* path = cairo_copy_path(mContext);
    cairo_new_path(aToContext);
    cairo_append_path(aToContext, path);
    cairo_path_destroy(path);
  }
}
Exemple #17
0
static void
gjs_cairo_path_finalize(JSContext *context,
                        JSObject  *obj)
{
    GjsCairoPath *priv;
    priv = JS_GetPrivate(context, obj);
    if (priv == NULL)
        return;
    cairo_path_destroy(priv->path);
    g_slice_free(GjsCairoPath, priv);
}
Exemple #18
0
static void
gjs_cairo_path_finalize(JSFreeOp *fop,
                        JSObject *obj)
{
    GjsCairoPath *priv;
    priv = (GjsCairoPath*) JS_GetPrivate(obj);
    if (priv == NULL)
        return;
    cairo_path_destroy(priv->path);
    g_slice_free(GjsCairoPath, priv);
}
Exemple #19
0
static void
cr_rectangle_set_property(GObject *object, guint property_id,
                const GValue *value, GParamSpec *pspec)
{
        CrRectangle *rectangle = (CrRectangle*) object;
        double val;

        switch (property_id) {
                case PROP_WIDTH:
                        val = g_value_get_double (value);
                        if (!(rectangle->flags & CR_RECTANGLE_WIDTH) ||
                                        val != rectangle->width) {
                                rectangle->width = val;
                                rectangle->flags |= CR_RECTANGLE_WIDTH;

                                if (CR_PATH(rectangle)->path) 
                                        cairo_path_destroy(CR_PATH(rectangle)->
                                                        path);
                                CR_PATH(rectangle)->path = NULL;
                                cr_item_request_update(CR_ITEM(rectangle));
                        }
                        break;
                case PROP_HEIGHT:
                        val = g_value_get_double (value);
                        if (!(rectangle->flags & CR_RECTANGLE_HEIGHT) ||
                                        val != rectangle->height) {
                                rectangle->height = val;
                                rectangle->flags |= CR_RECTANGLE_HEIGHT;

                                if (CR_PATH(rectangle)->path) 
                                        cairo_path_destroy(CR_PATH(rectangle)->
                                                        path);
                                CR_PATH(rectangle)->path = NULL;
                                cr_item_request_update(CR_ITEM(rectangle));
                        }
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
                                property_id, pspec);
        }
}
Exemple #20
0
bool Path::isEmpty() const
{
    cairo_t* cr = platformPath()->m_cr;
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,10)
    return !cairo_has_current_point(cr);
#else
    cairo_path_t* p = cairo_copy_path(cr);
    bool hasData = p->num_data;
    cairo_path_destroy(p);
    return !hasData;
#endif
}
Exemple #21
0
Path& Path::operator=(const Path& other)
{
    if (&other == this)
        return *this;

    clear();
    cairo_t* cr = platformPath()->m_cr;
    cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr);
    cairo_append_path(cr, p);
    cairo_path_destroy(p);
    return *this;
}
/* Returns length of a Bezier curve. Seems like computing that analytically is not easy. The
 * code just flattens the curve using cairo and adds the length of segments. */
static double curve_length(
	double x0,
	double y0,
	double x1,
	double y1,
	double x2,
	double y2,
	double x3,
	double y3
) {
	cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 0, 0);
	cairo_t* cr = cairo_create(surface);
	double length = 0;
	cairo_path_t* path;
	cairo_path_data_t* data;
	cairo_path_data_t current_point;
	int i;

	current_point.point.x = 0.0;
	current_point.point.y = 0.0;

	cairo_surface_destroy(surface);
	cairo_move_to(cr, x0, y0);
	cairo_curve_to(cr, x1, y1, x2, y2, x3, y3);

	path = cairo_copy_path_flat(cr);

	for(i = 0; i < path->num_data; i += path->data[i].header.length) {
		data = &path->data[i];

		switch (data->header.type) {
		case CAIRO_PATH_MOVE_TO:
			current_point = data[1];

			break;

		case CAIRO_PATH_LINE_TO:
			length += two_points_distance(&current_point, &data[1]);
			current_point = data[1];

			break;

		default:
			break;
		}
	}

	cairo_path_destroy(path);
	cairo_destroy(cr);

	return length;
}
static void
path_dealloc(PycairoPath *p)
{
#ifdef DEBUG
    printf("path_dealloc start\n");
#endif
    if (p->path) {
	cairo_path_destroy(p->path);
	p->path = NULL;
    }
    p->ob_type->tp_free((PyObject *)p);
#ifdef DEBUG
    printf("path_dealloc end\n");
#endif
}
void GraphicsContext::clip(const Path& path)
{
    if (paintingDisabled())
        return;

    cairo_t* cr = m_data->cr;
    cairo_path_t* p = cairo_copy_path(path.platformPath()->m_cr);
    cairo_append_path(cr, p);
    cairo_path_destroy(p);
    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    cairo_clip(cr);
    cairo_set_fill_rule(cr, savedFillRule);
    m_data->clip(path);
}
Exemple #25
0
PathCairo::PathCairo(cairo_t *aContext)
  : mFillRule(FillRule::FILL_WINDING)
  , mContainingContext(nullptr)
{
  cairo_path_t *path = cairo_copy_path(aContext);

  // XXX - mCurrentPoint is not properly set here, the same is true for the
  // D2D Path code, we never require current point when hitting this codepath
  // but this should be fixed.
  for (int i = 0; i < path->num_data; i++) {
    mPathData.push_back(path->data[i]);
  }

  cairo_path_destroy(path);
}
Exemple #26
0
int freeSymbolCairo(symbolObj *s) {
    if(!s->renderer_cache)
        return MS_SUCCESS;
    switch(s->type) {
    case MS_SYMBOL_VECTOR:
        cairo_path_destroy(s->renderer_cache);
        break;
    case MS_SYMBOL_PIXMAP:
        cairo_surface_finish(s->renderer_cache);
        cairo_surface_destroy(s->renderer_cache);
        break;
    }
    s->renderer_cache=NULL;
    return MS_SUCCESS;
}
Exemple #27
0
static void
path_dealloc(PycairoPath *o) {
#ifdef DEBUG
  printf("path_dealloc start\n");
#endif
  if (o->path) {
    cairo_path_destroy(o->path);
    o->path = NULL;
  }
  //o->ob_type->tp_free((PyObject *)o);
  Py_TYPE(o)->tp_free(o);
#ifdef DEBUG
  printf("path_dealloc end\n");
#endif
}
Exemple #28
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_matrix_t m;
    int xoffset = 50;
    int yoffset = 50;

    cairo_surface_t *shadow;
    cairo_t *shadow_cr;
    cairo_path_t *path;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    cairo_translate (cr, 130, 130);
    cairo_rotate (cr, .5);//2*M_PI*angle/360);
    cairo_rectangle (cr, 0, 0, 50, 100);
    cairo_get_matrix (cr, &m);

    shadow = cairo_surface_create_similar (cairo_get_target (cr),
					   CAIRO_CONTENT_COLOR_ALPHA,
					   600 - xoffset,
					   600 - yoffset);
    cairo_surface_set_device_offset (shadow, xoffset, yoffset);
    shadow_cr = cairo_create (shadow);
    cairo_surface_destroy (shadow);

    cairo_set_source_rgb (shadow_cr, 0, 1, 0);
    cairo_set_matrix (shadow_cr, &m);

    path = cairo_copy_path (cr);
    cairo_new_path (shadow_cr);
    cairo_append_path (shadow_cr, path);
    cairo_fill (shadow_cr);
    cairo_path_destroy (path);

    cairo_identity_matrix (cr);
    cairo_translate (cr, 10, 50);
    cairo_set_source_surface (cr, cairo_get_target (shadow_cr), 0, 0);
    cairo_paint (cr);
    cairo_set_matrix (cr, &m);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_fill (cr);

    cairo_destroy (shadow_cr);

    return CAIRO_TEST_SUCCESS;
}
Exemple #29
0
/* Projects the current path of cr onto the provided path. */
static void
map_path_onto (cairo_t *cr, cairo_path_t *path)
{
    cairo_path_t *current_path;
    parametrized_path_t param;

    param.path = path;
    param.parametrization = parametrize_path (path);

    current_path = cairo_copy_path (cr);
    cairo_new_path (cr);

    transform_path (current_path,
                    (transform_point_func_t) point_on_path, &param);

    cairo_append_path (cr, current_path);

    cairo_path_destroy (current_path);
    g_free (param.parametrization);
}
void PlatformContextCairo::clipForPatternFilling(const GraphicsContextState& state)
{
    ASSERT(state.fillPattern);

    // Hold current cairo path in a variable for restoring it after configuring the pattern clip rectangle.
    auto currentPath = cairo_copy_path(m_cr.get());
    cairo_new_path(m_cr.get());

    // Initialize clipping extent from current cairo clip extents, then shrink if needed according to pattern.
    // Inspired by GraphicsContextQt::drawRepeatPattern.
    double x1, y1, x2, y2;
    cairo_clip_extents(m_cr.get(), &x1, &y1, &x2, &y2);
    FloatRect clipRect(x1, y1, x2 - x1, y2 - y1);

    Image* patternImage = state.fillPattern->tileImage();
    ASSERT(patternImage);
    const AffineTransform& patternTransform = state.fillPattern->getPatternSpaceTransform();
    FloatRect patternRect = patternTransform.mapRect(FloatRect(0, 0, patternImage->width(), patternImage->height()));

    bool repeatX = state.fillPattern->repeatX();
    bool repeatY = state.fillPattern->repeatY();

    if (!repeatX) {
        clipRect.setX(patternRect.x());
        clipRect.setWidth(patternRect.width());
    }
    if (!repeatY) {
        clipRect.setY(patternRect.y());
        clipRect.setHeight(patternRect.height());
    }
    if (!repeatX || !repeatY) {
        cairo_rectangle(m_cr.get(), clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height());
        cairo_clip(m_cr.get());
    }

    // Restoring cairo path.
    cairo_append_path(m_cr.get(), currentPath);
    cairo_path_destroy(currentPath);
}