Ejemplo n.º 1
0
void gfxContext::Ellipse(gfxPoint center, gfxSize dimensions)
{
    // circle?
    if (dimensions.width == dimensions.height) {
        double radius = dimensions.width / 2.0;

        cairo_arc(mCairo, center.x, center.y, radius, 0, 2.0 * M_PI);
    } else {
        double x = center.x;
        double y = center.y;
        double w = dimensions.width;
        double h = dimensions.height;

        cairo_new_path(mCairo);
        cairo_move_to(mCairo, x + w/2.0, y);

        cairo_rel_curve_to(mCairo,
                           0, 0,
                           w / 2.0, 0,
                           w / 2.0, h / 2.0);
        cairo_rel_curve_to(mCairo,
                           0, 0,
                           0, h / 2.0,
                           - w / 2.0, h / 2.0);
        cairo_rel_curve_to(mCairo,
                           0, 0,
                           - w / 2.0, 0,
                           - w / 2.0, - h / 2.0);
        cairo_rel_curve_to(mCairo,
                           0, 0,
                           0, - h / 2.0,
                           w / 2.0, - h / 2.0);
    }
}
Ejemplo n.º 2
0
Archivo: ruby.c Proyecto: Shoes3/shoes3
void shoes_cairo_rect(cairo_t *cr, double x, double y, double w, double h, double r) {
    double rc = r * BEZIER;
    cairo_move_to(cr, x + r, y);
    cairo_rel_line_to(cr, w - 2 * r, 0.0);
    if (r != 0.) cairo_rel_curve_to(cr, rc, 0.0, r, rc, r, r);
    cairo_rel_line_to(cr, 0, h - 2 * r);
    if (r != 0.) cairo_rel_curve_to(cr, 0.0, rc, rc - r, r, -r, r);
    cairo_rel_line_to(cr, -w + 2 * r, 0);
    if (r != 0.) cairo_rel_curve_to(cr, -rc, 0, -r, -rc, -r, -r);
    cairo_rel_line_to(cr, 0, -h + 2 * r);
    if (r != 0.) cairo_rel_curve_to(cr, 0.0, -rc, r - rc, -r, r, -r);
    cairo_close_path(cr);
}
Ejemplo n.º 3
0
ETERM * rel_curve_to(ETERM* arg, int c_node) {
    ETERM *c1x, *c1y, *c2x, *c2y, *x, *y;
    cairo_context *ctx = get_cairo_context(arg);
    if (ctx) {
        c1x = erl_element(2, arg);  
        c1y = erl_element(3, arg); 
        c2x = erl_element(4, arg);  
        c2y = erl_element(5, arg);
        x = erl_element(6, arg);  
        y = erl_element(7, arg);
        cairo_rel_curve_to(ctx->cr, val(c1x), 
            val(c1y),
            val(c2x),
            val(c2y),
            val(x),
            val(y));
        erl_free_term(c1x);
        erl_free_term(c1y);
        erl_free_term(c2x);
        erl_free_term(c2y);
        erl_free_term(x);
        erl_free_term(y);
        return erl_format("{c_node, ~i, ok}", c_node);
    } else { 
        return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
    }
}
Ejemplo n.º 4
0
static int
cr_rel_curve_to (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_rel_curve_to(*obj, luaL_checknumber(L, 2), luaL_checknumber(L, 3),
                       luaL_checknumber(L, 4), luaL_checknumber(L, 5),
                       luaL_checknumber(L, 6), luaL_checknumber(L, 7));
    return 0;
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRelCurveTo 
   (JNIEnv *env, jobject obj, jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2, jdouble dx3, jdouble dy3)
{
  struct graphics2d *gr = NULL;
  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
  g_assert (gr != NULL);
  if (gr->debug) printf ("cairo_rel_curve_to (%f, %f), (%f, %f), (%f, %f)\n", dx1, dy1, dx2, dy2, dx3, dy3);
  cairo_rel_curve_to (gr->cr, dx1, dy1, dx2, dy2, dx3, dy3);
}
Ejemplo n.º 6
0
void draw_rect(cairo_t *c, double x, double y, double w, double h, double r)
{
	if (r > 0.0) {
		double c1 = 0.55228475 * r;

		cairo_move_to(c, x+r, y);
		cairo_rel_line_to(c, w-2*r, 0);
		cairo_rel_curve_to(c, c1, 0.0, r, c1, r, r);
		cairo_rel_line_to(c, 0, h-2*r);
		cairo_rel_curve_to(c, 0.0, c1, c1-r, r, -r, r);
		cairo_rel_line_to (c, -w +2*r, 0);
		cairo_rel_curve_to (c, -c1, 0, -r, -c1, -r, -r);
		cairo_rel_line_to (c, 0, -h + 2 * r);
		cairo_rel_curve_to (c, 0, -c1, r - c1, -r, r, -r);
	}
	else
		cairo_rectangle(c, x, y, w, h);
}
Ejemplo n.º 7
0
static VALUE
cr_rel_curve_to (VALUE self, VALUE dx1, VALUE dy1,
                 VALUE dx2, VALUE dy2, VALUE dx3, VALUE dy3)
{
  cairo_rel_curve_to (_SELF, NUM2DBL (dx1), NUM2DBL (dy1),
                      NUM2DBL (dx2), NUM2DBL (dy2),
                      NUM2DBL (dx3), NUM2DBL (dy3));
  cr_check_status (_SELF);
  return self;
}
Ejemplo n.º 8
0
static void
make_path (cairo_t *cr)
{
    cairo_move_to (cr, 0, 0);
    cairo_rel_curve_to (cr,
			-SIZE/4, SIZE/3,
			-SIZE/4, SIZE/3,
			0, SIZE);
    cairo_rel_curve_to (cr,
			SIZE/3, -SIZE/4,
			SIZE/3, -SIZE/4,
			SIZE, 0);
    cairo_close_path (cr);

    cairo_move_to (cr, 5 * LINE_WIDTH, 3 * LINE_WIDTH);
    cairo_rel_curve_to (cr,
			0, -3 * LINE_WIDTH,
			0, -3 * LINE_WIDTH,
			-3 * LINE_WIDTH, -3 * LINE_WIDTH);
}
Ejemplo n.º 9
0
// cairo_public void
// cairo_rel_curve_to (cairo_t *cr,
//             double dx1, double dy1,
//             double dx2, double dy2,
//             double dx3, double dy3);
static int l_cairo_rel_curve_to(lua_State* L)
{
    cairo_t *cr = get_cairo_t (L, 1);
    double dx1 = luaL_checknumber(L, 2);
    double dy1 = luaL_checknumber(L, 3);
    double dx2 = luaL_checknumber(L, 4);
    double dy2 = luaL_checknumber(L, 5);
    double dx3 = luaL_checknumber(L, 6);
    double dy3 = luaL_checknumber(L, 7);
    cairo_rel_curve_to(cr, dx1, dy1, dx2, dy2, dx3, dy3);
    return 0;
}
Ejemplo n.º 10
0
static PyObject *
pycairo_rel_curve_to (PycairoContext *o, PyObject *args) {
  double dx1, dy1, dx2, dy2, dx3, dy3;

  if (!PyArg_ParseTuple (args, "dddddd:Context.rel_curve_to",
			 &dx1, &dy1, &dx2, &dy2, &dx3, &dy3))
    return NULL;

  cairo_rel_curve_to (o->ctx, dx1, dy1, dx2, dy2, dx3, dy3);
  RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
  Py_RETURN_NONE;
}
static PyObject *
pycairo_rel_curve_to (PycairoContext *o, PyObject *args)
{
    double dx1, dy1, dx2, dy2, dx3, dy3;

    if (!PyArg_ParseTuple (args, "dddddd:Context.rel_curve_to",
			   &dx1, &dy1, &dx2, &dy2, &dx3, &dy3))
	return NULL;

    cairo_rel_curve_to (o->ctx, dx1, dy1, dx2, dy2, dx3, dy3);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Ejemplo n.º 12
0
static int cairo_rel_curve_to_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  cairo_rel_curve_to( lc->cairo,
                      luaL_checknumber( L, 2 ),   /* dx1 */
                      luaL_checknumber( L, 3 ),   /* dy1 */
                      luaL_checknumber( L, 4 ),   /* dx2 */
                      luaL_checknumber( L, 5 ),   /* dy2 */
                      luaL_checknumber( L, 6 ),   /* dx3 */
                      luaL_checknumber( L, 7 ) ); /* dy3 */

  return( 0 );
}
Ejemplo n.º 13
0
static void
make_path (cairo_t *cr)
{
    cairo_move_to (cr, 0, SIZE/2 + LINE_WIDTH);
    cairo_rel_line_to (cr, SIZE, 0);
    cairo_rel_line_to (cr, -SIZE, 0);
    cairo_close_path (cr);

    cairo_move_to (cr, 3*SIZE/4, 0);
    cairo_rel_line_to (cr, -SIZE/2, SIZE);
    cairo_rel_line_to (cr, SIZE/2, -SIZE);
    cairo_close_path (cr);

    cairo_move_to (cr, 0, SIZE/2-LINE_WIDTH);
    cairo_rel_curve_to (cr,
			SIZE/2, -2*LINE_WIDTH,
			SIZE/2, 2*LINE_WIDTH,
			SIZE, 0);
    cairo_rel_curve_to (cr,
			-SIZE/2, 2*LINE_WIDTH,
			-SIZE/2, -2*LINE_WIDTH,
			-SIZE, 0);
    cairo_close_path (cr);
}
Ejemplo n.º 14
0
	void lime_cairo_rel_curve_to (double handle, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) {
		
		cairo_rel_curve_to ((cairo_t*)(intptr_t)handle, dx1, dy1, dx2, dy2, dx3, dy3);
		
	}
Ejemplo n.º 15
0
void Context::relCurveTo( double dx1, double dy1, double dx2, double dy2, double dx3, double dy3 )
{
	cairo_rel_curve_to( mCairo, dx1, dy1, dx2, dy2, dx3, dy3 );
}
Ejemplo n.º 16
0
static gboolean
draw_flower (ClutterCanvas *canvas,
             cairo_t       *cr,
             gint           width,
             gint           height,
             gpointer       user_data)
{
    /* No science here, just a hack from toying */
    gint i, j;

    double colors[] = {
        0.71, 0.81, 0.83,
        1.0,  0.78, 0.57,
        0.64, 0.30, 0.35,
        0.73, 0.40, 0.39,
        0.91, 0.56, 0.64,
        0.70, 0.47, 0.45,
        0.92, 0.75, 0.60,
        0.82, 0.86, 0.85,
        0.51, 0.56, 0.67,
        1.0, 0.79, 0.58,

    };

    gint size;
    gint petal_size;
    gint n_groups;    /* Num groups of petals 1-3 */
    gint n_petals;    /* num of petals 4 - 8  */
    gint pm1, pm2;

    gint idx, last_idx = -1;

    petal_size = GPOINTER_TO_INT (user_data);
    size = petal_size * 8;

    n_groups = rand() % 3 + 1;

    cairo_set_tolerance (cr, 0.1);

    /* Clear */
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint(cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

    cairo_translate(cr, size/2, size/2);

    for (i=0; i<n_groups; i++)
    {
        n_petals = rand() % 5 + 4;
        cairo_save (cr);

        cairo_rotate (cr, rand() % 6);

        do {
            idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
        } while (idx == last_idx);

        cairo_set_source_rgba (cr, colors[idx], colors[idx+1],
                               colors[idx+2], 0.5);

        last_idx = idx;

        /* some bezier randomness */
        pm1 = rand() % 20;
        pm2 = rand() % 4;

        for (j=1; j<n_petals+1; j++)
        {
            cairo_save (cr);
            cairo_rotate (cr, ((2*M_PI)/n_petals)*j);

            /* Petals are made up beziers */
            cairo_new_path (cr);
            cairo_move_to (cr, 0, 0);
            cairo_rel_curve_to (cr,
                                petal_size, petal_size,
                                (pm2+2)*petal_size, petal_size,
                                (2*petal_size) + pm1, 0);
            cairo_rel_curve_to (cr,
                                0 + (pm2*petal_size), -petal_size,
                                -petal_size, -petal_size,
                                -((2*petal_size) + pm1), 0);
            cairo_close_path (cr);
            cairo_fill (cr);
            cairo_restore (cr);
        }

        petal_size -= rand() % (size/8);

        cairo_restore (cr);
    }

    /* Finally draw flower center */
    do {
        idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
    } while (idx == last_idx);

    if (petal_size < 0)
        petal_size = rand() % 10;

    cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5);

    cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2);
    cairo_fill(cr);

    return TRUE;
}
static void render (cairo_t *pCairoContext, CairoDesklet *pDesklet)
{
	CDPanelParameters *pPanel = (CDPanelParameters *) pDesklet->pRendererData;
	//g_print ("%s(%x)\n", __func__, pPanel);
	if (pPanel == NULL)
		return ;
	
	double fRadius = pPanel->iRadius;
	double fLineWidth = pPanel->iLineWidth;
	double fOffsetX = fRadius + fLineWidth/2;
	double fOffsetY = fLineWidth/2;
	double fFrameWidth = pDesklet->container.iWidth - 2 * fRadius - fLineWidth;
	double fFrameHeight = pDesklet->container.iHeight - fLineWidth;
	// le cadre.
	cairo_set_line_width (pCairoContext, pPanel->iLineWidth);
	
	cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
	
	cairo_rel_curve_to (pCairoContext,
		fFrameWidth/2, 0,
		fFrameWidth/2, pPanel->iMainIconSize,
		fFrameWidth, pPanel->iMainIconSize);
	
	//\_________________ Coin haut droit.
	cairo_rel_curve_to (pCairoContext,
		0, 0,
		fRadius, 0,
		fRadius, fRadius);
	cairo_rel_line_to (pCairoContext, 0, fFrameHeight - fRadius * 2 - pPanel->iMainIconSize);
	//\_________________ Coin bas droit.
	cairo_rel_curve_to (pCairoContext,
		0, 0,
		0, fRadius,
		-fRadius, fRadius);

	cairo_rel_line_to (pCairoContext, - fFrameWidth, 0);
	//\_________________ Coin bas gauche.
	cairo_rel_curve_to (pCairoContext,
		0, 0,
		-fRadius, 0,
		-fRadius, - fRadius);
	cairo_rel_line_to (pCairoContext, 0, - (fFrameHeight - fRadius * 2));
	//\_________________ Coin haut gauche.
	cairo_rel_curve_to (pCairoContext,
		0, 0,
		0, -fRadius,
		fRadius, -fRadius);
	
	cairo_set_source_rgba (pCairoContext, pPanel->fBgColor[0], pPanel->fBgColor[1], pPanel->fBgColor[2], 1.);
	cairo_stroke_preserve (pCairoContext);
	
	cairo_set_source_rgba (pCairoContext, pPanel->fBgColor[0], pPanel->fBgColor[1], pPanel->fBgColor[2], pPanel->fBgColor[3]);
	cairo_fill (pCairoContext);
	
	// les icones.
	Icon *pIcon;
	GList *ic;
	
	pIcon = pDesklet->pIcon;
	if (pIcon && pIcon->image.pSurface != NULL)
	{
		cairo_save (pCairoContext);
		
		cairo_translate (pCairoContext, pIcon->fDrawX, pIcon->fDrawY);
		
		cairo_dock_apply_image_buffer_surface_with_offset (&pIcon->image, pCairoContext, 0, 0, pIcon->fAlpha);
		
		cairo_dock_draw_icon_overlays_cairo (pIcon, pDesklet->container.fRatio, pCairoContext);
		
		cairo_restore (pCairoContext);
	}
	
	GList *pFirstDrawnElement = cairo_dock_get_first_drawn_element_linear (pDesklet->icons);
	if (pFirstDrawnElement == NULL)
		return;
	ic = pFirstDrawnElement;
	do
	{
		pIcon = ic->data;
		if (pIcon->image.pSurface != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
		{
			cairo_save (pCairoContext);
			
			cairo_translate (pCairoContext, pIcon->fDrawX, pIcon->fDrawY);
			
			cairo_dock_apply_image_buffer_surface_with_offset (&pIcon->image, pCairoContext, 0, 0, pIcon->fAlpha);
			
			if (pIcon->label.pSurface != NULL)
			{
				cairo_save (pCairoContext);
				
				double fOffsetX = 0., fAlpha;
				if (pIcon->bPointed)
				{
					fAlpha = 1.;
					/**if (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->label.iWidth/2 > pDesklet->container.iWidth)
						fOffsetX = pDesklet->container.iWidth - (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->label.iWidth/2);
					if (pIcon->fDrawX + pIcon->fWidth/2 - pIcon->label.iWidth/2 < 0)
						fOffsetX = pIcon->label.iWidth/2 - (pIcon->fDrawX + pIcon->fWidth/2);
					cairo_set_source_surface (pCairoContext,
						pIcon->label.pSurface,
						fOffsetX + pIcon->fWidth/2 - pIcon->label.iWidth/2,
						-myIconsParam.iLabelSize);*/
					cairo_set_source_surface (pCairoContext,
						pIcon->label.pSurface,
						0.,
						-myIconsParam.iLabelSize);
					cairo_paint_with_alpha (pCairoContext, fAlpha);
				}
				else
				{
					fAlpha = .6;
					if (pIcon->label.iWidth > 2*pIcon->fWidth + 0 * myIconsParam.iLabelSize)
					{
						///fOffsetX = - myIconsParam.iLabelSize;
						cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (fOffsetX,
							0.,
							fOffsetX + 2*pIcon->fWidth + 0*myIconsParam.iLabelSize,
							0.);
						cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE);
						cairo_pattern_add_color_stop_rgba (pGradationPattern,
							0.,
							0.,
							0.,
							0.,
							fAlpha);
						cairo_pattern_add_color_stop_rgba (pGradationPattern,
							0.75,
							0.,
							0.,
							0.,
							fAlpha);
						cairo_pattern_add_color_stop_rgba (pGradationPattern,
							1.,
							0.,
							0.,
							0.,
							0.);
						cairo_set_source_surface (pCairoContext,
							pIcon->label.pSurface,
							fOffsetX,
							-myIconsParam.iLabelSize);
						cairo_mask (pCairoContext, pGradationPattern);
						cairo_pattern_destroy (pGradationPattern);
					}
					else
					{
						///fOffsetX = pIcon->fWidth/2 - pIcon->label.iWidth/2;
						cairo_set_source_surface (pCairoContext,
							pIcon->label.pSurface,
							fOffsetX,
							-myIconsParam.iLabelSize);
						cairo_paint_with_alpha (pCairoContext, fAlpha);
					}
				}
				
				cairo_restore (pCairoContext);
			}
			
			cairo_translate (pCairoContext,
				pIcon->fWidth,
				- pIcon->fHeight/2);  // not ideal, it should be vertically centered.
			cairo_dock_draw_icon_overlays_cairo (pIcon, pDesklet->container.fRatio, pCairoContext);
			
			cairo_restore (pCairoContext);
		}
		ic = cairo_dock_get_next_element (ic, pDesklet->icons);
	}
	while (ic != pFirstDrawnElement);
}
Ejemplo n.º 18
0
void dash_box_cairo_rounded_rectangle (cairo_t* c, gdouble x, gdouble y, gdouble width, gdouble height, gdouble radius) {
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble w;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gdouble h;
	gdouble _tmp4_;
	gdouble kappa;
	cairo_t* _tmp5_;
	gdouble _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	cairo_t* _tmp9_;
	cairo_t* _tmp10_;
	gdouble _tmp11_;
	gdouble _tmp12_;
	gdouble _tmp13_;
	gdouble _tmp14_;
	cairo_t* _tmp15_;
	cairo_t* _tmp16_;
	gdouble _tmp17_;
	gdouble _tmp18_;
	gdouble _tmp19_;
	gdouble _tmp20_;
	cairo_t* _tmp21_;
	cairo_t* _tmp22_;
	gdouble _tmp23_;
	gdouble _tmp24_;
	gdouble _tmp25_;
	gdouble _tmp26_;
	cairo_t* _tmp27_;
	cairo_t* _tmp28_;
	gdouble _tmp29_;
	gdouble _tmp30_;
	gdouble _tmp31_;
	gdouble _tmp32_;
	g_return_if_fail (c != NULL);
	_tmp0_ = width;
	_tmp1_ = radius;
	w = _tmp0_ - (_tmp1_ * 2);
	_tmp2_ = height;
	_tmp3_ = radius;
	h = _tmp2_ - (_tmp3_ * 2);
	_tmp4_ = radius;
	kappa = 0.5522847498 * _tmp4_;
	_tmp5_ = c;
	_tmp6_ = x;
	_tmp7_ = radius;
	_tmp8_ = y;
	cairo_move_to (_tmp5_, _tmp6_ + _tmp7_, _tmp8_);
	_tmp9_ = c;
	cairo_rel_line_to (_tmp9_, w, (gdouble) 0);
	_tmp10_ = c;
	_tmp11_ = radius;
	_tmp12_ = radius;
	_tmp13_ = radius;
	_tmp14_ = radius;
	cairo_rel_curve_to (_tmp10_, kappa, (gdouble) 0, _tmp11_, _tmp12_ - kappa, _tmp13_, _tmp14_);
	_tmp15_ = c;
	cairo_rel_line_to (_tmp15_, (gdouble) 0, h);
	_tmp16_ = c;
	_tmp17_ = radius;
	_tmp18_ = radius;
	_tmp19_ = radius;
	_tmp20_ = radius;
	cairo_rel_curve_to (_tmp16_, (gdouble) 0, kappa, kappa - _tmp17_, _tmp18_, -_tmp19_, _tmp20_);
	_tmp21_ = c;
	cairo_rel_line_to (_tmp21_, -w, (gdouble) 0);
	_tmp22_ = c;
	_tmp23_ = radius;
	_tmp24_ = radius;
	_tmp25_ = radius;
	_tmp26_ = radius;
	cairo_rel_curve_to (_tmp22_, -kappa, (gdouble) 0, -_tmp23_, kappa - _tmp24_, -_tmp25_, -_tmp26_);
	_tmp27_ = c;
	cairo_rel_line_to (_tmp27_, (gdouble) 0, -h);
	_tmp28_ = c;
	_tmp29_ = radius;
	_tmp30_ = radius;
	_tmp31_ = radius;
	_tmp32_ = radius;
	cairo_rel_curve_to (_tmp28_, (gdouble) 0, -kappa, _tmp29_ - kappa, -_tmp30_, _tmp31_, -_tmp32_);
}
Ejemplo n.º 19
0
static void
schgui_cairo_path_draw(SchGUICairoDrawItem *item, cairo_t *cairo)
{
    if (cairo != NULL)
    {
        SchGUICairoPathPrivate *privat = SCHGUI_CAIRO_PATH_GET_PRIVATE(item);

        if (privat != NULL)
        {
            GSList *node;
            SchPathCommand *command;

            cairo_set_source_rgba(cairo, privat->red, privat->green, privat->blue, privat->alpha);

            cairo_set_line_width(cairo, privat->line_width);

            node = privat->commands;

            while (node != NULL)
            {
                command = SCH_PATH_COMMAND(node->data);

                switch (command->type)
                {
                    case SCH_PATH_COMMAND_INVALID:
                        g_debug("SchGUICairoPath: invalid path command");
                        break;

                    case SCH_PATH_COMMAND_CLOSEPATH:
                        cairo_close_path(cairo);
                        break;

                    case SCH_PATH_COMMAND_CURVETO_ABS:
                        cairo_curve_to(
                            cairo,
                            command->curveto.x[0], command->curveto.y[0],
                            command->curveto.x[1], command->curveto.y[1],
                            command->curveto.x[2], command->curveto.y[2]
                            );
                        break;

                    case SCH_PATH_COMMAND_CURVETO_REL:
                        cairo_rel_curve_to(
                            cairo,
                            command->curveto.x[0], command->curveto.y[0],
                            command->curveto.x[1], command->curveto.y[1],
                            command->curveto.x[2], command->curveto.y[2]
                            );
                        break;

                    case SCH_PATH_COMMAND_LINETO_ABS:
                        cairo_line_to(cairo, command->lineto.x, command->lineto.y);
                        break;

                    case SCH_PATH_COMMAND_LINETO_REL:
                        cairo_rel_line_to(cairo, command->lineto.x, command->lineto.y);
                        break;

                    case SCH_PATH_COMMAND_MOVETO_ABS:
                        cairo_move_to(cairo, command->moveto.x, command->moveto.y);
                        break;

                    case SCH_PATH_COMMAND_MOVETO_REL:
                        cairo_rel_move_to(cairo, command->moveto.x, command->moveto.y);
                        break;

                    default:
                        g_debug("SchGUICairoPath: unknown path command");
                }

                node = g_slist_next(node);
            }

            if (privat->solid)
            {
                cairo_fill_preserve(cairo);
            }

            cairo_stroke(cairo);
        }
    }
}
Ejemplo n.º 20
0
static void draw_frame(ANativeWindow_Buffer *buffer) {
    int pixel_size = 0;
    cairo_surface_t *surface = NULL;

    /* Setup our cairo surface to render directly to the native window buffer */
    if (buffer->format == WINDOW_FORMAT_RGB_565) {
        pixel_size = 2;
        surface = cairo_image_surface_create_for_data(buffer->bits, CAIRO_FORMAT_RGB16_565, buffer->width, buffer->height, buffer->stride*pixel_size);
    } else if (buffer->format == WINDOW_FORMAT_RGBA_8888 || buffer->format == WINDOW_FORMAT_RGBX_8888) {
        pixel_size = 4;
        surface = cairo_image_surface_create_for_data(buffer->bits, CAIRO_FORMAT_RGB24, buffer->width, buffer->height, buffer->stride*pixel_size);
    } else {
        LOGE("Unsupported buffer format: %d", buffer->format);
        return;
    }

    cairo_t         *cr      = cairo_create(surface);

    /* clear the screen */
    memset(buffer->bits, 0, buffer->stride*pixel_size*buffer->height);

    /* Normalize our canvas size to make our lives easier */
    cairo_scale(cr, buffer->width, buffer->height);


    /* Draw the big X */
    double position = (tick%30)*(1.0/30);
    cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.7);
    cairo_move_to (cr, 0.1, position);
    cairo_line_to (cr, 0.9, 1.0-position);
    cairo_move_to (cr, 0.9, position);
    cairo_line_to (cr, 0.1, 1.0-position);
    cairo_set_line_width (cr, 0.1);
    cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
    cairo_stroke (cr);

    /* Draw three color squares */
    cairo_rectangle (cr, 0, 0,0.5, 0.5);
    cairo_set_source_rgba (cr, 1, 0, 0, 0.50);
    cairo_fill (cr);

    cairo_rectangle (cr, 0, 0.5, 0.5, 0.5);
    cairo_set_source_rgba (cr, 0, 1, 0, 0.50);
    cairo_fill (cr);

    cairo_rectangle (cr, 0.5, 0, 0.5, 0.5);
    cairo_set_source_rgba (cr, 0, 0, 1, 0.50);
    cairo_fill (cr);

    /* Draw a more complicated path */
    cairo_set_line_width (cr, 0.04);
    cairo_scale(cr, 0.5, 0.5);
    cairo_translate(cr, 0.5, 1.0);
    cairo_set_source_rgba (cr, 1.0, 0.2, 0.0, 0.5);
    cairo_move_to (cr, 0.25, 0.25);
    cairo_line_to (cr, 0.5, 0.375);
    cairo_rel_line_to (cr, 0.25, -0.125);
    cairo_arc (cr, 0.5, 0.5, 0.25 * sqrt(2), -0.25 * M_PI, 0.25 * M_PI);
    cairo_rel_curve_to (cr, -0.25, -0.125, -0.25, 0.125, -0.5, 0);
    cairo_close_path (cr);
    cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
    cairo_stroke (cr);

    /* Clean up. */
    cairo_destroy(cr);
    cairo_surface_destroy(surface);
}
Ejemplo n.º 21
0
ClutterActor*
make_flower_actor (void)
{
  /* No science here, just a hack from toying */
  gint i, j;

  double colors[] = {
    0.71, 0.81, 0.83,
    1.0,  0.78, 0.57,
    0.64, 0.30, 0.35,
    0.73, 0.40, 0.39,
    0.91, 0.56, 0.64,
    0.70, 0.47, 0.45,
    0.92, 0.75, 0.60,
    0.82, 0.86, 0.85,
    0.51, 0.56, 0.67,
    1.0, 0.79, 0.58,

  };

  gint size;
  gint petal_size;
  gint n_groups;    /* Num groups of petals 1-3 */
  gint n_petals;    /* num of petals 4 - 8  */
  gint pm1, pm2;

  gint idx, last_idx = -1;

  ClutterActor *ctex;
  cairo_t      *cr;

  petal_size = PETAL_MIN + rand() % PETAL_VAR;
  size = petal_size * 8;

  n_groups = rand() % 3 + 1;

  ctex = clutter_cairo_texture_new (size, size);

  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (ctex));

  cairo_set_tolerance (cr, 0.1);

  /* Clear */
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

  cairo_translate(cr, size/2, size/2);

  for (i=0; i<n_groups; i++)
    {
      n_petals = rand() % 5 + 4;
      cairo_save (cr);

      cairo_rotate (cr, rand() % 6);

      do {
	idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
      } while (idx == last_idx);

      cairo_set_source_rgba (cr, colors[idx], colors[idx+1],
			     colors[idx+2], 0.5);

      last_idx = idx;

      /* some bezier randomness */
      pm1 = rand() % 20;
      pm2 = rand() % 4;

      for (j=1; j<n_petals+1; j++)
	{
	  cairo_save (cr);
	  cairo_rotate (cr, ((2*M_PI)/n_petals)*j);

	  /* Petals are made up beziers */
	  cairo_new_path (cr);
	  cairo_move_to (cr, 0, 0);
	  cairo_rel_curve_to (cr,
			      petal_size, petal_size,
			      (pm2+2)*petal_size, petal_size,
			      (2*petal_size) + pm1, 0);
	  cairo_rel_curve_to (cr,
			      0 + (pm2*petal_size), -petal_size,
			      -petal_size, -petal_size,
			      -((2*petal_size) + pm1), 0);
	  cairo_close_path (cr);
	  cairo_fill (cr);
	  cairo_restore (cr);
	}

      petal_size -= rand() % (size/8);

      cairo_restore (cr);
    }

  /* Finally draw flower center */
  do {
      idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
  } while (idx == last_idx);

  if (petal_size < 0)
    petal_size = rand() % 10;

  cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5);

  cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2);
  cairo_fill(cr);

  cairo_destroy(cr);

  return ctex;
}
static void cd_render (cairo_t *pCairoContext, CairoDock *pDock)
{
	//\____________________ On trace le cadre.
	double fLineWidth = myDocksParam.iDockLineWidth;
	double fMargin = myDocksParam.iFrameMargin;
	double fRadius = (pDock->iDecorationsHeight + fLineWidth - 2 * myDocksParam.iDockRadius > 0 ? myDocksParam.iDockRadius : (pDock->iDecorationsHeight + fLineWidth) / 2 - 1);
	double fExtraWidth = 2 * fRadius + fLineWidth;
	double fDockWidth;
	int sens;
	double fDockOffsetX, fDockOffsetY;  // Offset du coin haut gauche du cadre.
	if (cairo_dock_is_extended_dock (pDock))  // mode panel etendu.
	{
		fDockWidth = pDock->container.iWidth - fExtraWidth;
		fDockOffsetX = fExtraWidth / 2;
	}
	else
	{
		fDockWidth = cairo_dock_get_current_dock_width_linear (pDock);
		Icon *pFirstIcon = cairo_dock_get_first_icon (pDock->icons);
		fDockOffsetX = (pFirstIcon != NULL ? pFirstIcon->fX - fMargin : fExtraWidth / 2);
		if (fDockOffsetX < fExtraWidth / 2)
			fDockOffsetX = fExtraWidth / 2;
		if (fDockOffsetX + fDockWidth + fExtraWidth / 2 > pDock->container.iWidth)
			fDockWidth = pDock->container.iWidth - fDockOffsetX - fExtraWidth / 2;
	}
	if (pDock->container.bDirectionUp)
	{
		sens = 1;
		fDockOffsetY = pDock->container.iHeight - pDock->iDecorationsHeight - 1.5 * fLineWidth;
	}
	else
	{
		sens = -1;
		fDockOffsetY = pDock->iDecorationsHeight + 1.5 * fLineWidth;
	}

	cairo_save (pCairoContext);
	double fDeltaXTrapeze = cairo_dock_draw_frame (pCairoContext, fRadius, fLineWidth, fDockWidth, pDock->iDecorationsHeight, fDockOffsetX, fDockOffsetY, sens, 0., pDock->container.bIsHorizontal, FALSE);  // FALSE <=> ignore 'myDocksParam.bRoundedBottomCorner', as bottom rounded corners looks bad for a panel.

	//\____________________ On dessine les decorations dedans.
	fDockOffsetY = (pDock->container.bDirectionUp ? pDock->container.iHeight - pDock->iDecorationsHeight - fLineWidth : fLineWidth);
	cairo_dock_render_decorations_in_frame (pCairoContext, pDock, fDockOffsetY, fDockOffsetX - fDeltaXTrapeze, fDockWidth + 2*fDeltaXTrapeze);

	//\____________________ On dessine le cadre.
	if (fLineWidth > 0)
	{
		cairo_set_line_width (pCairoContext, fLineWidth);
		if (myDocksParam.bUseDefaultColors)
			gldi_style_colors_set_line_color (pCairoContext);
		else
			gldi_color_set_cairo (pCairoContext, &myDocksParam.fLineColor);
		cairo_stroke (pCairoContext);
	}
	else
		cairo_new_path (pCairoContext);
	cairo_restore (pCairoContext);
	
	//\____________________ On dessine les separateurs physiques.
	GList *ic;
	Icon *pIcon;
	if (my_bPanelPhysicalSeparator)
	{
		cairo_save (pCairoContext);
		if (pDock->container.bIsHorizontal)
		{
			if (! pDock->container.bDirectionUp)
			{
				cairo_translate (pCairoContext, 0., pDock->container.iHeight);
				cairo_scale (pCairoContext, 1., -1.);
			}
		}
		else
		{
			cairo_translate (pCairoContext, pDock->container.iHeight/2., pDock->container.iWidth/2.);
			cairo_rotate (pCairoContext, G_PI/2);
			if (pDock->container.bDirectionUp)
				cairo_scale (pCairoContext, 1., -1.);
			cairo_translate (pCairoContext, -pDock->container.iWidth/2., -pDock->container.iHeight/2.);
		}
		
		double x1, x2, dx, delta, h = pDock->iDecorationsHeight + 2*fLineWidth, h_ = h - fLineWidth;
		for (ic = pDock->icons; ic != NULL; ic = ic->next)
		{
			pIcon = ic->data;
			if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
			{
				x1 = pIcon->fDrawX = pIcon->fX;
				
				pIcon = NULL;
				for (ic = ic->next; ic != NULL; ic = ic->next)
				{
					pIcon = ic->data;
					if (!CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
						break;
				}
				if (ic != NULL)
				{
					pIcon = ic->data;
					x2 = pIcon->fDrawX;
				}
				else
					break;
				
				dx = MIN (my_fPanelRadius, (x2 - x1) / 2);
				delta = dx + h*tan(my_fPanelInclination)/2;
				if (delta > (x2 - x1) / 2)
					delta = (x2 - x1) / 2;
				
				cairo_move_to (pCairoContext, x1, pDock->iMaxDockHeight - h);
				cairo_rel_curve_to (pCairoContext,
					dx, 0.,
					delta - dx, h,
					delta, h);
				cairo_rel_line_to (pCairoContext,
					x2 - x1 - 2*delta, 0.);
				cairo_rel_curve_to (pCairoContext,
					dx, 0.,
					delta - dx, -h,
					delta, -h);
				cairo_close_path (pCairoContext);
				
				cairo_set_operator (pCairoContext, CAIRO_OPERATOR_DEST_OUT);
				cairo_set_source_rgba (pCairoContext, 0.0, 0.0, 0.0, 1.0);
				cairo_fill (pCairoContext);
				
				if (fLineWidth > 0)
				{
					cairo_move_to (pCairoContext, x1, pDock->iMaxDockHeight - h_ - fLineWidth/2);
					cairo_rel_curve_to (pCairoContext,
						dx, 0.,
						delta - dx, h_,
						delta, h_);
					cairo_rel_line_to (pCairoContext,
						x2 - x1 - 2*delta, 0.);
					cairo_rel_curve_to (pCairoContext,
						dx, 0.,
						delta - dx, -h_,
						delta, -h_);
					
					cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
					cairo_set_line_width (pCairoContext, fLineWidth);
					if (myDocksParam.bUseDefaultColors)
						gldi_style_colors_set_line_color (pCairoContext);
					else
						gldi_color_set_cairo (pCairoContext, &myDocksParam.fLineColor);
					cairo_stroke (pCairoContext);
				}
			}
		}
		cairo_restore (pCairoContext);
	}
	
	//\____________________ On dessine la ficelle qui les joint.
	if (myIconsParam.iStringLineWidth > 0)
		cairo_dock_draw_string (pCairoContext, pDock, myIconsParam.iStringLineWidth, FALSE, FALSE);

	//\____________________ On dessine les icones et les etiquettes, en tenant compte de l'ordre pour dessiner celles en arriere-plan avant celles en avant-plan.
	GList *pFirstDrawnElement = cairo_dock_get_first_drawn_element_linear (pDock->icons);
	if (pFirstDrawnElement == NULL)
		return;
	
	double fDockMagnitude = cairo_dock_calculate_magnitude (pDock->iMagnitudeIndex);  // * pDock->fMagnitudeMax
	ic = pFirstDrawnElement;
	do
	{
		pIcon = ic->data;
		
		if (! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
		{
			cairo_save (pCairoContext);
			cairo_dock_render_one_icon (pIcon, pDock, pCairoContext, fDockMagnitude, pIcon->bPointed);
			cairo_restore (pCairoContext);
		}
		ic = cairo_dock_get_next_element (ic, pDock->icons);
	} while (ic != pFirstDrawnElement);
}
Ejemplo n.º 23
0
	void lime_cairo_rel_curve_to (value handle, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) {
		
		cairo_rel_curve_to ((cairo_t*)val_data (handle), dx1, dy1, dx2, dy2, dx3, dy3);
		
	}
Ejemplo n.º 24
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    cairo_surface_t *surface;
    cairo_t         *cr2;
    const char      *phase;
    const char	     string[] = "The quick brown fox jumps over the lazy dog.";
    cairo_text_extents_t extents, scaled_font_extents;
    cairo_status_t   status;
    int              errors = 0;

    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
                                            CAIRO_CONTENT_COLOR, 100, 100);
    /* don't use cr accidentally */
    cr = NULL;
    cr2 = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_set_line_width (cr2, 10);
    cairo_set_line_join (cr2, CAIRO_LINE_JOIN_MITER);
    cairo_set_miter_limit (cr2, 100);

    phase = "No path";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 0, 0, 0);

    cairo_save (cr2);

    cairo_new_path (cr2);
    cairo_move_to (cr2, 200, 400);
    cairo_rel_line_to (cr2, 0., 0.);
    phase = "Degenerate line";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_move_to (cr2, 200, 400);
    cairo_rel_curve_to (cr2, 0., 0., 0., 0., 0., 0.);
    phase = "Degenerate curve";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_arc (cr2, 200, 400, 0., 0, 2 * M_PI);
    phase = "Degenerate arc (R=0)";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_arc (cr2, 200, 400, 10., 0, 0);
    phase = "Degenerate arc (Θ=0)";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_restore (cr2);

    /* Test that with CAIRO_LINE_CAP_ROUND, we get "dots" from
     * cairo_move_to; cairo_rel_line_to(0,0) */
    cairo_save (cr2);

    cairo_set_line_cap (cr2, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_width (cr2, 20);

    cairo_move_to (cr2, 200, 400);
    cairo_rel_line_to (cr2, 0, 0);
    phase = "Single 'dot'";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 190, 390, 20, 20);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    /* Add another dot without starting a new path */
    cairo_move_to (cr2, 100, 500);
    cairo_rel_line_to (cr2, 0, 0);
    phase = "Multiple 'dots'";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 90, 390, 120, 120);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 100, 400, 100, 100);

    cairo_new_path (cr2);

    cairo_restore (cr2);

    /* http://bugs.freedesktop.org/show_bug.cgi?id=7965 */
    phase = "A vertical, open path";
    cairo_save (cr2);
    cairo_set_line_cap (cr2, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_join (cr2, CAIRO_LINE_JOIN_ROUND);
    cairo_move_to (cr2, 0, 180);
    cairo_line_to (cr2, 750, 180);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, -5, 175, 760, 10);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 180, 755, 0);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Simple rect";
    cairo_save (cr2);
    cairo_rectangle (cr2, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Two rects";
    cairo_save (cr2);
    cairo_rectangle (cr2, 10, 10, 10, 10);
    cairo_rectangle (cr2, 20, 20, 10, 10);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 20, 20);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 30, 30);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 20, 20);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Triangle";
    cairo_save (cr2);
    cairo_move_to (cr2, 10, 10);
    cairo_line_to (cr2, 90, 90);
    cairo_line_to (cr2, 90, 10);
    cairo_close_path (cr2);
    /* miter joins protrude 5*(1+sqrt(2)) above the top-left corner and to
       the right of the bottom-right corner */
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, 0, 5, 95, 95);
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    cairo_save (cr2);

    cairo_set_line_width (cr2, 4);

    cairo_rectangle (cr2, 10, 10, 30, 30);
    cairo_rectangle (cr2, 25, 10, 15, 30);

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
    phase = "EVEN_ODD overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Test other fill rule with the same path. */

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
    phase = "WINDING overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 30, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Now, change the direction of the second rectangle and test both
     * fill rules again. */
    cairo_new_path (cr2);
    cairo_rectangle (cr2, 10, 10, 30, 30);
    cairo_rectangle (cr2, 25, 40, 15, -30);

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
    phase = "EVEN_ODD overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Test other fill rule with the same path. */

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
    phase = "WINDING overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    cairo_new_path (cr2);

    cairo_restore (cr2);

    /* http://bugs.freedesktop.org/show_bug.cgi?id=7245 */
    phase = "Arc";
    cairo_save (cr2);
    cairo_arc (cr2, 250.0, 250.0, 157.0, 5.147, 3.432);
    cairo_set_line_width (cr2, 154.0);
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS, 16, 38, 468, 446);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Text";
    cairo_save (cr2);
    cairo_select_font_face (cr2, "Bitstream Vera Sans",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr2, 12);
    cairo_text_extents (cr2, string, &extents);
    /* double check that the two methods of measuring the text agree... */
    cairo_scaled_font_text_extents (cairo_get_scaled_font (cr2),
				    string,
				    &scaled_font_extents);
    if (memcmp (&extents, &scaled_font_extents, sizeof (extents))) {
	cairo_test_log (ctx, "Error: cairo_text_extents() does not match cairo_scaled_font_text_extents() - font extents (%f, %f) x (%f, %f) should be (%f, %f) x (%f, %f)\n",
		        scaled_font_extents.x_bearing,
			scaled_font_extents.y_bearing,
			scaled_font_extents.width,
			scaled_font_extents.height,
			extents.x_bearing,
			extents.y_bearing,
			extents.width,
			extents.height);
	errors++;
    }

    cairo_move_to (cr2, -extents.x_bearing, -extents.y_bearing);
    cairo_text_path (cr2, string);
    cairo_set_line_width (cr2, 2.0);
    /* XXX: We'd like to be able to use EQUALS here, but currently
     * when hinting is enabled freetype returns integer extents. See
     * http://cairographics.org/todo */
    errors += !check_extents (ctx, phase, cr2, FILL, APPROX_EQUALS,
			      0, 0, extents.width, extents.height);
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS,
			      -1, -1, extents.width+2, extents.height+2);
    errors += !check_extents (ctx, phase, cr2, PATH, APPROX_EQUALS,
			      0, 0, extents.width, extents.height);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, simple scale, getting extents with same transform";
    cairo_save (cr2);
    cairo_scale (cr2, 2, 2);
    cairo_rectangle (cr2, 5, 5, 40, 40);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 5, 5, 40, 40);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 50, 50);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 5, 5, 40, 40);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, simple scale, getting extents with no transform";
    cairo_save (cr2);
    cairo_save (cr2);
    cairo_scale (cr2, 2, 2);
    cairo_rectangle (cr2, 5, 5, 40, 40);
    cairo_restore (cr2);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, rotation, getting extents with transform";
    cairo_save (cr2);
    cairo_rectangle (cr2, -50, -50, 50, 50);
    cairo_rotate (cr2, -M_PI/4);
    /* the path in user space is now (nearly) the square rotated by
       45 degrees about the origin. Thus its x1 and x2 are both nearly 0.
       This should show any bugs where we just transform device-space
       x1,y1 and x2,y2 to get the extents. */
    /* The largest axis-aligned square inside the rotated path has
       side lengths 50*sqrt(2), so a bit over 35 on either side of
       the axes. With the stroke width added to the rotated path,
       the largest axis-aligned square is a bit over 38 on either side of
       the axes. */
    errors += !check_extents (ctx, phase, cr2, FILL, CONTAINS, -35, -35, 35, 35);
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, -38, -38, 38, 38);
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, -35, -35, 35, 35);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    status = cairo_status (cr2);
    cairo_destroy (cr2);

    if (status)
	return cairo_test_status_from_status (ctx, status);

    return errors == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_FAILURE;
}