Esempio n. 1
0
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;
}
Esempio n. 2
0
Path::Path(const Path& other)
    : m_path(new CairoPath())
{
    cairo_t* cr = platformPath()->context();
    OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(other.platformPath()->context()));
    cairo_append_path(cr, pathCopy.get());
}
Esempio n. 3
0
void Context::copyPath( cinder::Shape2d *resultPath )
{
	resultPath->clear();	
	cairo_path_t *path = cairo_copy_path( mCairo );
	convertCairoToCinderPath( path, resultPath );
	cairo_path_destroy( path );
}
Esempio n. 4
0
// cairo_public cairo_path_t *
// cairo_copy_path (cairo_t *cr);
static int l_cairo_copy_path(lua_State* L)
{
    cairo_t *cr = get_cairo_t (L, 1);
    cairo_path_t *v = cairo_copy_path (cr);
    lua_pushlightuserdata(L, v);
    return 1;
}
Esempio n. 5
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;
}
void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const
{
    cairo_t* cr = context->platformContext();
    if (m_clipData.clipData().size() < 1)
        return;

    cairo_reset_clip(cr);
    context->beginPath();

    for (unsigned int x = 0; x < m_clipData.clipData().size(); x++) {
        ClipData data = m_clipData.clipData()[x];

        Path path = data.path;
        if (path.isEmpty())
            continue;
        path.closeSubpath();

        if (data.bboxUnits) {
            // Make use of the clipping units
            AffineTransform transform;
            transform.translate(boundingBox.x(), boundingBox.y());
            transform.scale(boundingBox.width(), boundingBox.height());
            path.transform(transform);
        }
        cairo_path_t* clipPath = cairo_copy_path(path.platformPath()->m_cr);
        cairo_append_path(cr, clipPath);

        cairo_set_fill_rule(cr, data.windRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
    }

    cairo_clip(cr);
}
Esempio n. 7
0
VALUE
shoes_canvas_shape(int argc, VALUE *argv, VALUE self)
{
  int x;
  double x1, y1, x2, y2;
  cairo_t *shape = NULL;
  cairo_path_t *line = NULL;
  SETUP_SHAPE();

  shape = canvas->shape;
  VALUE attr = shoes_shape_attr(argc, argv, 2, s_left, s_top);
  canvas->shape = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
  cairo_move_to(canvas->shape, 0, 0);
  if (rb_block_given_p()) rb_funcall(rb_block_proc(), s_call, 0);

#if CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR <= 4
  cairo_fill_extents(canvas->shape, &x1, &y1, &x2, &y2);
#else
  cairo_path_extents(canvas->shape, &x1, &y1, &x2, &y2);
#endif
  x = x2 - x1;
  ATTRSET(attr, width, INT2NUM(x));
  x = y2 - y1;
  ATTRSET(attr, height, INT2NUM(x));
  line = cairo_copy_path(canvas->shape);
  canvas->shape = shape;
  return shoes_add_shape(self, s_shape, attr, line);
}
Esempio n. 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);
}
Esempio n. 9
0
static PyObject *
pycairo_copy_path (PycairoContext *o) {
  cairo_path_t *cp;
  Py_BEGIN_ALLOW_THREADS;
  cp = cairo_copy_path (o->ctx);
  Py_END_ALLOW_THREADS;
  return PycairoPath_FromPath (cp);
}
Esempio n. 10
0
/* Paths */
static VALUE
cr_copy_path (VALUE self)
{
  cairo_path_t *path;

  path = cairo_copy_path (_SELF);
  rb_cairo_check_status (path->status);
  return CRPATH2RVAL (path);
}
Esempio n. 11
0
static inline void drawPathShadow(GraphicsContext* context, PathDrawingStyle drawingStyle)
{
    ShadowBlur& shadow = context->platformContext()->shadowBlur();
    if (shadow.type() == ShadowBlur::NoShadow)
        return;

    // Calculate the extents of the rendered solid paths.
    cairo_t* cairoContext = context->platformContext()->cr();
    OwnPtr<cairo_path_t> path = adoptPtr(cairo_copy_path(cairoContext));

    FloatRect solidFigureExtents;
    double x0 = 0;
    double x1 = 0;
    double y0 = 0;
    double y1 = 0;
    if (drawingStyle & Stroke) {
        cairo_stroke_extents(cairoContext, &x0, &y0, &x1, &y1);
        solidFigureExtents = FloatRect(x0, y0, x1 - x0, y1 - y0);
    }
    if (drawingStyle & Fill) {
        cairo_fill_extents(cairoContext, &x0, &y0, &x1, &y1);
        FloatRect fillExtents(x0, y0, x1 - x0, y1 - y0);
        solidFigureExtents.unite(fillExtents);
    }

    GraphicsContext* shadowContext = shadow.beginShadowLayer(context, solidFigureExtents);
    if (!shadowContext)
        return;

    cairo_t* cairoShadowContext = shadowContext->platformContext()->cr();

    // It's important to copy the context properties to the new shadow
    // context to preserve things such as the fill rule and stroke width.
    copyContextProperties(cairoContext, cairoShadowContext);

    if (drawingStyle & Fill) {
        cairo_save(cairoShadowContext);
        cairo_append_path(cairoShadowContext, path.get());
        shadowContext->platformContext()->prepareForFilling(context->state(), PlatformContextCairo::NoAdjustment);
        cairo_fill(cairoShadowContext);
        cairo_restore(cairoShadowContext);
    }

    if (drawingStyle & Stroke) {
        cairo_append_path(cairoShadowContext, path.get());
        shadowContext->platformContext()->prepareForStroking(context->state(), PlatformContextCairo::DoNotPreserveAlpha);
        cairo_stroke(cairoShadowContext);
    }

    // The original path may still be hanging around on the context and endShadowLayer
    // will take care of properly creating a path to draw the result shadow. We remove the path
    // temporarily and then restore it.
    // See: https://bugs.webkit.org/show_bug.cgi?id=108897
    cairo_new_path(cairoContext);
    shadow.endShadowLayer(context);
    cairo_append_path(cairoContext, path.get());
}
Esempio n. 12
0
static inline void drawPathShadow(GraphicsContext* context, PathDrawingStyle drawingStyle)
{
    ShadowBlur& shadow = context->platformContext()->shadowBlur();
    if (shadow.type() == ShadowBlur::NoShadow)
        return;

    // Calculate the extents of the rendered solid paths.
    cairo_t* cairoContext = context->platformContext()->cr();
    OwnPtr<cairo_path_t> path = adoptPtr(cairo_copy_path(cairoContext));

    FloatRect solidFigureExtents;
    double x0 = 0;
    double x1 = 0;
    double y0 = 0;
    double y1 = 0;
    if (drawingStyle & Stroke) {
        cairo_stroke_extents(cairoContext, &x0, &y0, &x1, &y1);
        solidFigureExtents = FloatRect(x0, y0, x1 - x0, y1 - y0);
    }
    if (drawingStyle & Fill) {
        cairo_fill_extents(cairoContext, &x0, &y0, &x1, &y1);
        FloatRect fillExtents(x0, y0, x1 - x0, y1 - y0);
        solidFigureExtents.unite(fillExtents);
    }

    GraphicsContext* shadowContext = shadow.beginShadowLayer(context, solidFigureExtents);
    if (!shadowContext)
        return;

    cairo_t* cairoShadowContext = shadowContext->platformContext()->cr();

    // It's important to copy the context properties to the new shadow
    // context to preserve things such as the fill rule and stroke width.
    copyContextProperties(cairoContext, cairoShadowContext);

    if (drawingStyle & Fill) {
        cairo_save(cairoShadowContext);
        cairo_append_path(cairoShadowContext, path.get());
        shadowContext->platformContext()->prepareForFilling(context->state(), PlatformContextCairo::NoAdjustment);
        cairo_clip(cairoShadowContext);
        cairo_paint(cairoShadowContext);
        cairo_restore(cairoShadowContext);
    }

    if (drawingStyle & Stroke) {
        cairo_append_path(cairoShadowContext, path.get());
        shadowContext->platformContext()->prepareForStroking(context->state(), PlatformContextCairo::DoNotPreserveAlpha);
        cairo_stroke(cairoShadowContext);
    }

    shadow.endShadowLayer(context);

    // ShadowBlur::endShadowLayer destroys the current path on the Cairo context. We restore it here.
    cairo_new_path(cairoContext);
    cairo_append_path(cairoContext, path.get());
}
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);
}
Esempio n. 14
0
Path::Path(const Path& other)
    : m_path(0)
{
    if (other.isNull())
        return;

    cairo_t* cr = ensurePlatformPath()->context();
    OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(other.platformPath()->context()));
    cairo_append_path(cr, pathCopy.get());
}
Esempio n. 15
0
static int
cr_copy_path (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_path_t **path = lua_newuserdata(L, sizeof(cairo_path_t *));
    *path = 0;
    luaL_getmetatable(L, OOCAIRO_MT_NAME_PATH);
    lua_setmetatable(L, -2);
    *path = cairo_copy_path(*obj);
    return 1;
}
Esempio n. 16
0
Path& Path::operator=(const Path& other)
{
    if (&other == this)
        return *this;

    clear();
    cairo_t* cr = platformPath()->context();
    OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(other.platformPath()->context()));
    cairo_append_path(cr, pathCopy.get());
    return *this;
}
Esempio n. 17
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);
  }
}
Esempio n. 18
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
}
Esempio n. 19
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;
}
Esempio n. 20
0
void GraphicsContext::clip(const Path& path)
{
    if (paintingDisabled())
        return;

    cairo_t* cr = platformContext()->cr();
    OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(path.platformPath()->context()));
    cairo_append_path(cr, pathCopy.get());
    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);
}
Esempio n. 21
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);
}
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);
}
Esempio n. 23
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;
}
Esempio n. 24
0
static bool
copyPath_func(JSContext *context,
              unsigned   argc,
              JS::Value *vp)
{
    GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
    cairo_path_t *path;
    cairo_t *cr = priv ? priv->cr : NULL;

    if (!gjs_parse_call_args(context, "", argv, ""))
        return false;

    path = cairo_copy_path(cr);
    argv.rval().setObjectOrNull(gjs_cairo_path_from_path(context, path));
    return true;
}
Esempio n. 25
0
/**
 * @brief Adds the path of the given way to current path, if path is not set it creates it form the data
 * @param cr the cairo contetx to add the path to
 *
 */
void WayRenderer::addWayPath(cairo_t* cr)
{
	cairo_new_path(cr);
	if (path != NULL) {
		cairo_append_path(cr, path);
		return;
	}

	const std::vector<NodeId>& children = way->getNodeIDs();
	paintLine(cr, children);

	path = cairo_copy_path(cr);

	double x0, y0, x1, y1;
	cairo_path_extents(cr, &x0, &y0, &x1, &y1);
	bounds = FloatRect(x0, y0, x1, y1);
}
Esempio n. 26
0
// Clip within the bounding box of the current_path()
void clip_path_rect(cairo_t *cr)
{
	double x1;
	double y1;
	double x2;
	double y2;
	cairo_path_extents(cr,&x1,&y1,&x2,&y2);
	cairo_path_t *ol_path = cairo_copy_path(cr);
	cairo_new_path(cr);
	// Create the bounding box
	cairo_rectangle(cr, x1-1, y1-1, (x2-x1)+1, (y2-y1)+1);
//	cairo_set_source_rgba(canvas, 1, 0, 0);
//	cairo_stroke_preserve(canvas);
	cairo_clip(cr);
	// Restore the old path

	cairo_append_path(cr,ol_path);
}
Esempio n. 27
0
Path& Path::operator=(const Path& other)
{
    if (&other == this)
        return *this;

    if (other.isNull()) {
        if (m_path) {
            delete m_path;
            m_path = 0;
        }
    } else {
        clear();
        cairo_t* cr = ensurePlatformPath()->context();
        OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(other.platformPath()->context()));
        cairo_append_path(cr, pathCopy.get());
    }

    return *this;
}
Esempio n. 28
0
static JSBool
copyPath_func(JSContext *context,
              uintN      argc,
              jsval     *vp)
{
    jsval *argv = JS_ARGV(context, vp);
    JSObject *obj = JS_THIS_OBJECT(context, vp);
    cairo_path_t *path;
    cairo_t *cr;

    if (!gjs_parse_args(context, "", "", argc, argv))
        return JS_FALSE;

    cr = gjs_cairo_context_get_context(context, obj);
    path = cairo_copy_path(cr);
    JS_SET_RVAL(context, vp,
                OBJECT_TO_JSVAL(gjs_cairo_path_from_path(context, path)));
    return JS_TRUE;
}
Esempio n. 29
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);
}
Esempio n. 30
0
void GraphicsContext::clip(const Path& path, WindRule windRule)
{
    if (paintingDisabled())
        return;

    cairo_t* cr = platformContext()->cr();
    OwnPtr<cairo_path_t> pathCopy;
    if (!path.isNull()) {
        pathCopy = adoptPtr(cairo_copy_path(path.platformPath()->context()));
        cairo_append_path(cr, pathCopy.get());
    }
    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    if (windRule == RULE_NONZERO)
        cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    else
        cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    cairo_clip(cr);
    cairo_set_fill_rule(cr, savedFillRule);
    m_data->clip(path);
}