static void goo_canvas_polyline_compute_bounds (GooCanvasPolyline *polyline, cairo_t *cr, GooCanvasBounds *bounds) { GooCanvasItemSimple *simple = (GooCanvasItemSimple*) polyline; GooCanvasItemSimpleData *simple_data = simple->simple_data; GooCanvasPolylineData *polyline_data = polyline->polyline_data; GooCanvasBounds tmp_bounds; cairo_matrix_t transform; if (polyline_data->num_points == 0) { bounds->x1 = bounds->x2 = bounds->y1 = bounds->y2 = 0.0; return; } /* Use the identity matrix to get the bounds completely in user space. */ cairo_get_matrix (cr, &transform); cairo_identity_matrix (cr); goo_canvas_polyline_create_path (polyline, cr); goo_canvas_item_simple_get_path_bounds (simple, cr, bounds); /* Add on the arrows, if required. */ if ((polyline_data->start_arrow || polyline_data->end_arrow) && polyline_data->num_points >= 2) { /* We use the stroke pattern to match the style of the line. */ goo_canvas_style_set_stroke_options (simple_data->style, cr); if (polyline_data->start_arrow) { goo_canvas_polyline_create_start_arrow_path (polyline, cr); cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1, &tmp_bounds.x2, &tmp_bounds.y2); bounds->x1 = MIN (bounds->x1, tmp_bounds.x1); bounds->y1 = MIN (bounds->y1, tmp_bounds.y1); bounds->x2 = MAX (bounds->x2, tmp_bounds.x2); bounds->y2 = MAX (bounds->y2, tmp_bounds.y2); } if (polyline_data->end_arrow) { goo_canvas_polyline_create_end_arrow_path (polyline, cr); cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1, &tmp_bounds.x2, &tmp_bounds.y2); bounds->x1 = MIN (bounds->x1, tmp_bounds.x1); bounds->y1 = MIN (bounds->y1, tmp_bounds.y1); bounds->x2 = MAX (bounds->x2, tmp_bounds.x2); bounds->y2 = MAX (bounds->y2, tmp_bounds.y2); } } cairo_set_matrix (cr, &transform); }
gfxRect gfxContext::GetUserFillExtent() { double xmin, ymin, xmax, ymax; cairo_fill_extents(mCairo, &xmin, &ymin, &xmax, &ymax); return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin); }
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); }
static PyObject * pycairo_fill_extents (PycairoContext *o) { double x1, y1, x2, y2; cairo_fill_extents (o->ctx, &x1, &y1, &x2, &y2); RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx); return Py_BuildValue("(dddd)", x1, y1, x2, y2); }
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()); }
static PyObject * pycairo_fill_extents (PycairoContext *o) { double x1, y1, x2, y2; cairo_fill_extents (o->ctx, &x1, &y1, &x2, &y2); if (Pycairo_Check_Status (cairo_status (o->ctx))) return NULL; return Py_BuildValue("(dddd)", x1, y1, x2, y2); }
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()); }
static int cr_fill_extents (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); double x1, y1, x2, y2; cairo_fill_extents(*obj, &x1, &y1, &x2, &y2); lua_pushnumber(L, x1); lua_pushnumber(L, y1); lua_pushnumber(L, x2); lua_pushnumber(L, y2); return 4; }
static VALUE cr_fill_extents (VALUE self) { double extents[4]; if (rb_block_given_p ()) { cr_new_path (self); rb_yield (self); } cairo_fill_extents (_SELF, extents, extents + 1, extents + 2, extents + 3); return rb_cairo__float_array (extents, 4); }
static void goo_canvas_path_common_get_extent (GooCanvas *canvas, GooCanvasPathData *path_data, GooCanvasBounds *bounds) { cairo_t *cr; cr = goo_canvas_create_cairo_context (canvas); goo_canvas_create_path (path_data->path_commands, cr); cairo_fill_extents (cr, &bounds->x1, &bounds->y1, &bounds->x2, &bounds->y2); cairo_destroy (cr); }
wxSVGRect wxSVGCanvasPathCairo::GetBBox(const wxSVGMatrix& matrix) { if (&matrix) { cairo_matrix_t m; cairo_matrix_init(&m, matrix.GetA(), matrix.GetB(), matrix.GetC(), matrix.GetD(), matrix.GetE(), matrix.GetF()); cairo_set_matrix(m_cr, &m); } double x1, y1, x2, y2; cairo_fill_extents(m_cr, &x1, &y1, &x2, &y2); if (&matrix) { cairo_matrix_t mat; cairo_matrix_init(&mat, 1, 0, 0, 1, 0, 0); cairo_set_matrix(m_cr, &mat); } return wxSVGRect(x1, y1, x2 - x1, y2 - y1); }
static int cairo_fill_extents_l( lua_State* L ) { double x1 = 0.0; double y1 = 0.0; double x2 = 0.0; double y2 = 0.0; lua_cairo_t* lc = lua_cairo_check( L, 1 ); cairo_fill_extents( lc->cairo, &x1, &y1, &x2, &y2 ); lua_pushnumber( L, x1 ); lua_pushnumber( L, y1 ); lua_pushnumber( L, x2 ); lua_pushnumber( L, y2 ); return( 4 ); }
CAMLprim value ml_cairo_fill_extents (value v_cr) { double x1, y1, x2, y2; cairo_fill_extents (cairo_t_val (v_cr), &x1, &y1, &x2, &y2); check_cairo_status (v_cr); { CAMLparam0 (); CAMLlocal1 (t); t = caml_alloc_tuple (4); Store_field (t, 0, caml_copy_double (x1)); Store_field (t, 1, caml_copy_double (y1)); Store_field (t, 2, caml_copy_double (x2)); Store_field (t, 3, caml_copy_double (y2)); CAMLreturn (t); } }
/*! * \brief Make use of the pattern if any */ static void _dia_cairo_fill (DiaCairoRenderer *renderer) { if (!renderer->pattern) { cairo_fill (renderer->cr); } else { /* maybe we should cache the cairo-pattern */ cairo_pattern_t *pat; Rectangle fe; /* Using the extents to scale the pattern is probably not correct */ cairo_fill_extents (renderer->cr, &fe.left, &fe.top, &fe.right, &fe.bottom); pat = _pattern_build_for_cairo (renderer->pattern, &fe); cairo_set_source (renderer->cr, pat); cairo_fill (renderer->cr); cairo_pattern_destroy (pat); } }
wxSVGRect wxSVGCanvasPathCairo::GetResultBBox(const wxCSSStyleDeclaration& style, const wxSVGMatrix& matrix) { if (&matrix) { cairo_matrix_t m; cairo_matrix_init(&m, matrix.GetA(), matrix.GetB(), matrix.GetC(), matrix.GetD(), matrix.GetE(), matrix.GetF()); cairo_set_matrix(m_cr, &m); } ApplyStrokeStyle(m_cr, style); double x1, y1, x2, y2; if (style.GetStrokeWidth() > 0) cairo_stroke_extents(m_cr, &x1, &y1, &x2, &y2); else cairo_fill_extents(m_cr, &x1, &y1, &x2, &y2); if (&matrix) { cairo_matrix_t mat; cairo_matrix_init(&mat, 1, 0, 0, 1, 0, 0); cairo_set_matrix(m_cr, &mat); } return wxSVGRect(x1, y1, x2 - x1, y2 - y1); }
static void goc_component_update_bounds (GocItem *item) { cairo_surface_t *surface; cairo_t *cr; GocComponent *component = GOC_COMPONENT (item); double x0, y0 = component->y; GocCanvas *canvas = item->canvas; if (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL) { x0 = component->x + component->w; goc_group_adjust_coords (item->parent, &x0, &y0); x0 = canvas->width - (int) (x0 - canvas->scroll_x1) * canvas->pixels_per_unit; } else { x0 = component->x; goc_group_adjust_coords (item->parent, &x0, &y0); x0 = (int) (x0 - canvas->scroll_x1) * canvas->pixels_per_unit; } surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cr = cairo_create (surface); _goc_item_transform (item, cr, FALSE); if (component->rotation == 0.) cairo_translate (cr, x0, (int) (y0 - canvas->scroll_y1)); else { cairo_translate (cr, x0 + component->w / 2, (int) (y0 - canvas->scroll_y1 + component->h / 2)); cairo_rotate (cr, -component->rotation); cairo_translate (cr, -component->w / 2, -component->h / 2); } cairo_rectangle (cr, 0., 0., component->w, component->h); cairo_fill_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1); cairo_destroy (cr); cairo_surface_destroy (surface); }
void mume_resobj_brush_fill_preserve( cairo_t *cr, mume_resobj_brush_t *br) { if (br->p) { double x1, y1, x2, y2; int x, y, width, height; cairo_fill_extents(cr, &x1, &y1, &x2, &y2); x = x1; y = y1; width = x2 - x1; height = y2 - y1; mume_draw_resobj_image(cr, br->p, x, y, width, height); } else { cairo_save(cr); cairo_set_source_rgb( cr, mume_color_rval(&br->color), mume_color_gval(&br->color), mume_color_bval(&br->color)); cairo_fill_preserve(cr); cairo_restore(cr); } }
svg_status_t _svg_android_set_gradient (svg_android_t *svg_android, svg_gradient_t *gradient, svg_android_render_type_t type) { svg_gradient_stop_t *stop; int i; jobject matrix, gradient_matrix; jobject gradient_shader = NULL; matrix = ANDROID_IDENTITY_MATRIX(svg_android); switch (gradient->units) { case SVG_GRADIENT_UNITS_USER: break; case SVG_GRADIENT_UNITS_BBOX: { jfloatArray farr; jfloat *coords; farr = ANDROID_PATH_GET_BOUNDS(svg_android, svg_android->state->path); coords = (*(svg_android->env))->GetFloatArrayElements((svg_android->env), farr, 0); // Maybe we need to add the stroke width to be correct here? (if type == SVG_ANDROID_RENDER_TYPE_STROKE) ANDROID_MATRIX_TRANSLATE(svg_android, matrix, coords[0], coords[1]); ANDROID_MATRIX_SCALE(svg_android, matrix, coords[2] - coords[0], coords[3] - coords[1]); (*(svg_android->env))->ReleaseFloatArrayElements(svg_android->env, farr, coords, 0); #if 0 // note here how the cairo version checks for fill or stroke, the extents might be different.. but for android I use the bounds of the path, this doesn't account for stroke painting outside.. double x1, y1, x2, y2; if (type == SVG_ANDROID_RENDER_TYPE_FILL) cairo_fill_extents (svg_android->cr, &x1, &y1, &x2, &y2); else cairo_stroke_extents (svg_android->cr, &x1, &y1, &x2, &y2); cairo_matrix_translate (&matrix, x1, y1); cairo_matrix_scale (&matrix, x2 - x1, y2 - y1); #endif svg_android->state->bbox = 1; } break; } // create java float array for the stops offsets, and int array for the colors jfloat offsets[gradient->num_stops]; jint colors[gradient->num_stops]; for (i = 0; i < gradient->num_stops; i++) { stop = &gradient->stops[i]; offsets[i] = stop->offset; unsigned long r, g, b, o; r = svg_color_get_red (&stop->color); g = svg_color_get_green (&stop->color); b = svg_color_get_blue (&stop->color); o = (unsigned long)(stop->opacity * 255.0); colors[i] = (o & 0xff) << 24 | (r & 0xff) << 16 | (g & 0xff) << 8 | (b & 0xff); } jfloatArray offsets_a; jintArray colors_a; offsets_a = (*(svg_android->env))->NewFloatArray(svg_android->env, gradient->num_stops); colors_a = (*(svg_android->env))->NewIntArray(svg_android->env, gradient->num_stops); (*(svg_android->env))->SetFloatArrayRegion(svg_android->env, offsets_a, 0, gradient->num_stops, offsets); (*(svg_android->env))->SetIntArrayRegion(svg_android->env, colors_a, 0, gradient->num_stops, colors); int spreadType = 2; switch (gradient->spread) { case SVG_GRADIENT_SPREAD_REPEAT: spreadType = 0; break; case SVG_GRADIENT_SPREAD_REFLECT: spreadType = 1; break; default: spreadType = 2; break; } switch (gradient->type) { case SVG_GRADIENT_LINEAR: { double x1, y1, x2, y2; _svg_android_length_to_pixel (svg_android, &gradient->u.linear.x1, &x1); _svg_android_length_to_pixel (svg_android, &gradient->u.linear.y1, &y1); _svg_android_length_to_pixel (svg_android, &gradient->u.linear.x2, &x2); _svg_android_length_to_pixel (svg_android, &gradient->u.linear.y2, &y2); if((*(svg_android->env))->ExceptionOccurred(svg_android->env)) { (*(svg_android->env))->ExceptionDescribe(svg_android->env); } gradient_shader = ANDROID_CREATE_LINEAR_GRADIENT(svg_android, x1, y1, x2, y2, colors_a, offsets_a, spreadType); if((*(svg_android->env))->ExceptionOccurred(svg_android->env)) { (*(svg_android->env))->ExceptionDescribe(svg_android->env); } } break; case SVG_GRADIENT_RADIAL: { double cx, cy, r, fx, fy; _svg_android_length_to_pixel (svg_android, &gradient->u.radial.cx, &cx); _svg_android_length_to_pixel (svg_android, &gradient->u.radial.cy, &cy); _svg_android_length_to_pixel (svg_android, &gradient->u.radial.r, &r); _svg_android_length_to_pixel (svg_android, &gradient->u.radial.fx, &fx); _svg_android_length_to_pixel (svg_android, &gradient->u.radial.fy, &fy); gradient_shader = ANDROID_CREATE_RADIAL_GRADIENT(svg_android, fx, fy, r, colors_a, offsets_a, spreadType); #if 0 // note here that there is a start and an end circel, android doesn't support that. The end circle in Android always have the same coords as the start circle pattern = cairo_pattern_create_radial (fx, fy, 0.0, cx, cy, r); #endif } break; } gradient_matrix = ANDROID_MATRIX_CREATE(svg_android, gradient->transform[0], gradient->transform[1], gradient->transform[2], gradient->transform[3], gradient->transform[4], gradient->transform[5]); ANDROID_MATRIX_MULTIPLY(svg_android, matrix, gradient_matrix); ANDROID_MATRIX_MULTIPLY(svg_android, matrix, svg_android->state->matrix); if(svg_android->fit_to_area) ANDROID_MATRIX_MULTIPLY(svg_android, matrix, svg_android->fit_to_MATRIX); if(gradient_shader) { ANDROID_SHADER_SET_MATRIX(svg_android, gradient_shader, matrix); ANDROID_PAINT_SET_SHADER(svg_android, gradient_shader); } svg_android->state->bbox = 0; return SVG_STATUS_SUCCESS; }
void lime_cairo_fill_extents (value handle, double x1, double y1, double x2, double y2) { cairo_fill_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2); }
static void draw_check_if_object_is_in_selected_area (cairo_t *cairoTarget, gboolean isStroke, gerbv_selection_info_t *selectionInfo, gerbv_image_t *image, struct gerbv_net *net, enum draw_mode drawMode) { gerbv_selection_item_t sItem = {image, net}; gdouble corner1X, corner1Y, corner2X, corner2Y; gdouble x1, x2, y1, y2; gdouble minX, minY, maxX, maxY; corner1X = selectionInfo->lowerLeftX; corner1Y = selectionInfo->lowerLeftY; corner2X = selectionInfo->upperRightX; corner2Y = selectionInfo->upperRightY; /* calculate the coordinate of the user's click in the current transformation matrix */ cairo_device_to_user (cairoTarget, &corner1X, &corner1Y); cairo_device_to_user (cairoTarget, &corner2X, &corner2Y); switch (selectionInfo->type) { case GERBV_SELECTION_POINT_CLICK: /* use the cairo in_fill routine to see if the point is within the drawn area */ if ((isStroke && cairo_in_stroke (cairoTarget, corner1X, corner1Y)) || (!isStroke && cairo_in_fill (cairoTarget, corner1X, corner1Y))) { if (!draw_net_is_in_selection_buffer_remove (net, selectionInfo, (drawMode == FIND_SELECTIONS_TOGGLE))) { selection_add_item (selectionInfo, &sItem); } } break; case GERBV_SELECTION_DRAG_BOX: /* we can't assume the "lowerleft" corner is actually in the lower left, since the cairo transformation matrix may be mirrored,etc */ minX = MIN(corner1X,corner2X); maxX = MAX(corner1X,corner2X); minY = MIN(corner1Y,corner2Y); maxY = MAX(corner1Y,corner2Y); if (isStroke) cairo_stroke_extents (cairoTarget, &x1, &y1, &x2, &y2); else cairo_fill_extents (cairoTarget, &x1, &y1, &x2, &y2); if ((minX < x1) && (minY < y1) && (maxX > x2) && (maxY > y2)) { if (!draw_net_is_in_selection_buffer_remove (net, selectionInfo, (drawMode == FIND_SELECTIONS_TOGGLE))) { selection_add_item (selectionInfo, &sItem); } } break; default: break; } /* clear the path, since we didn't actually draw it and cairo doesn't reset it after the previous calls */ cairo_new_path (cairoTarget); }
void trap_render (int w, int h, int fill_gradient) { double *ctrlpts = animpts; int len = (NUMPTS * 2); double prevx = ctrlpts[len - 2]; double prevy = ctrlpts[len - 1]; double curx = ctrlpts[0]; double cury = ctrlpts[1]; double midx = (curx + prevx) / 2.0; double midy = (cury + prevy) / 2.0; int i; cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle (cr, 0, 0, w, h); cairo_fill (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0); cairo_set_line_width (cr, 1.0); cairo_save (cr); cairo_scale (cr, (double) w / 512.0, (double) h / 512.0); cairo_save (cr); cairo_translate (cr, 170.0, 330.0); cairo_rotate (cr, gear1_rotation); gear (30.0, 120.0, 20, 20.0); cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); cairo_stroke (cr); cairo_restore (cr); cairo_save (cr); cairo_translate (cr, 369.0, 330.0); cairo_rotate (cr, gear2_rotation); gear (15.0, 75.0, 12, 20.0); cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); cairo_stroke (cr); cairo_restore (cr); cairo_save (cr); cairo_translate (cr, 170.0, 116.0); cairo_rotate (cr, gear3_rotation); gear (20.0, 90.0, 14, 20.0); cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); cairo_stroke (cr); cairo_restore (cr); cairo_restore (cr); gear1_rotation += 0.01; gear2_rotation -= (0.01 * (20.0 / 12.0)); gear3_rotation -= (0.01 * (20.0 / 14.0)); stroke_and_fill_step (w, h); cairo_new_path (cr); cairo_move_to (cr, midx, midy); for (i = 2; i <= (NUMPTS * 2); i += 2) { double x2, x1 = (midx + curx) / 2.0; double y2, y1 = (midy + cury) / 2.0; prevx = curx; prevy = cury; if (i < (NUMPTS * 2)) { curx = ctrlpts[i + 0]; cury = ctrlpts[i + 1]; } else { curx = ctrlpts[0]; cury = ctrlpts[1]; } midx = (curx + prevx) / 2.0; midy = (cury + prevy) / 2.0; x2 = (prevx + midx) / 2.0; y2 = (prevy + midy) / 2.0; cairo_curve_to (cr, x1, y1, x2, y2, midx, midy); } cairo_close_path (cr); if (fill_gradient) { double x1, y1, x2, y2; cairo_pattern_t *pattern; cairo_fill_extents (cr, &x1, &y1, &x2, &y2); pattern = cairo_pattern_create_linear (x1, y1, x2, y2); cairo_pattern_add_color_stop_rgb (pattern, 0.0, 1.0, 0.0, 0.0); cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0.0, 0.0, 1.0); cairo_pattern_set_filter (pattern, CAIRO_FILTER_BILINEAR); cairo_move_to (cr, 0, 0); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); } else { cairo_set_source_rgba (cr, FILL_R, FILL_G, FILL_B, FILL_OPACITY); } cairo_fill_preserve (cr); cairo_set_source_rgba (cr, STROKE_R, STROKE_G, STROKE_B, STROKE_OPACITY); cairo_set_line_width (cr, LINEWIDTH); cairo_stroke (cr); }
void lime_cairo_fill_extents (double handle, double x1, double y1, double x2, double y2) { cairo_fill_extents ((cairo_t*)(intptr_t)handle, &x1, &y1, &x2, &y2); }
static void gnm_so_path_set_property (GObject *obj, guint param_id, GValue const *value, GParamSpec *pspec) { GnmSOPath *sop = GNM_SO_PATH (obj); switch (param_id) { case SOP_PROP_STYLE: { GOStyle *style = go_style_dup (g_value_get_object (value)); style->interesting_fields = GO_STYLE_OUTLINE | GO_STYLE_FILL; g_object_unref (sop->style); sop->style = style; break; } case SOP_PROP_PATH: { GOPath *path = g_value_get_boxed (value); if (sop->path) go_path_free (sop->path); else if (sop->paths) g_ptr_array_unref (sop->paths); sop->path = NULL; sop->paths = NULL; if (path) { cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cairo_t *cr = cairo_create (surface); sop->path = go_path_ref (path); /* evaluates the bounding rectangle */ go_path_to_cairo (path, GO_PATH_DIRECTION_FORWARD, cr); cairo_fill_extents (cr, &sop->x_offset, &sop->y_offset, &sop->width, &sop->height); sop->width -= sop->x_offset; sop->height -= sop->y_offset; cairo_destroy (cr); cairo_surface_destroy (surface); } break; } case SOP_PROP_PATHS: { GPtrArray *paths = g_value_get_boxed (value); unsigned i; for (i = 0; i < paths->len; i++) /* we can only check that the path is not NULL */ g_return_if_fail (g_ptr_array_index (paths, i) != NULL); if (sop->path) go_path_free (sop->path); else if (sop->paths) g_ptr_array_unref (sop->paths); sop->path = NULL; sop->paths = NULL; if (paths) { cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cairo_t *cr = cairo_create (surface); sop->paths = g_ptr_array_ref (paths); /* evaluates the bounding rectangle */ for (i = 0; i < paths->len; i++) go_path_to_cairo ((GOPath *) g_ptr_array_index (paths, i), GO_PATH_DIRECTION_FORWARD, cr); cairo_fill_extents (cr, &sop->x_offset, &sop->y_offset, &sop->width, &sop->height); sop->width -= sop->x_offset; sop->height -= sop->y_offset; cairo_destroy (cr); cairo_surface_destroy (surface); } break; } case SOP_PROP_TEXT: { char const *str = g_value_get_string (value); g_free (sop->text); sop->text = g_strdup (str == NULL ? "" : str); break; } case SOP_PROP_MARKUP: if (sop->markup != NULL) pango_attr_list_unref (sop->markup); sop->markup = g_value_peek_pointer (value); if (sop->markup != NULL) pango_attr_list_ref (sop->markup); break; case SOP_PROP_VIEWBOX: /* not settable */ default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec); return; } }
static cairo_bool_t check_extents (const cairo_test_context_t *ctx, const char *message, cairo_t *cr, enum ExtentsType type, enum Relation relation, double x, double y, double width, double height) { double ext_x1, ext_y1, ext_x2, ext_y2; const char *type_string; const char *relation_string; switch (type) { default: case FILL: type_string = "fill"; cairo_fill_extents (cr, &ext_x1, &ext_y1, &ext_x2, &ext_y2); break; case STROKE: type_string = "stroke"; cairo_stroke_extents (cr, &ext_x1, &ext_y1, &ext_x2, &ext_y2); break; case PATH: type_string = "path"; cairo_path_extents (cr, &ext_x1, &ext_y1, &ext_x2, &ext_y2); break; } /* ignore results after an error occurs */ if (cairo_status (cr)) return 1; /* let empty rects match */ if ((ext_x1 == ext_x2 || ext_y1 == ext_y2) && (width == 0 || height == 0)) return 1; switch (relation) { default: case EQUALS: relation_string = "equal"; if (ext_x1 == x && ext_y1 == y && ext_x2 == x + width && ext_y2 == y + height) return 1; break; case APPROX_EQUALS: relation_string = "approx. equal"; if (fabs (ext_x1 - x) < 1. && fabs (ext_y1 - y) < 1. && fabs (ext_x2 - (x + width)) < 1. && fabs (ext_y2 - (y + height)) < 1.) { return 1; } break; case CONTAINS: relation_string = "contain"; if (width == 0 || height == 0) { /* odd test that doesn't really test anything... */ return 1; } if (ext_x1 <= x && ext_y1 <= y && ext_x2 >= x + width && ext_y2 >= y + height) return 1; break; } cairo_test_log (ctx, "Error: %s; %s extents (%g, %g) x (%g, %g) should %s (%g, %g) x (%g, %g)\n", message, type_string, ext_x1, ext_y1, ext_x2 - ext_x1, ext_y2 - ext_y1, relation_string, x, y, width, height); return 0; }
void Context::fillExtents( double *x1, double *y1, double *x2, double *y2 ) { cairo_fill_extents( mCairo, x1, y1, x2, y2 ); }