FloatRect Path::boundingRect() const { cairo_t* cr = platformPath()->context(); double x0, x1, y0, y1; cairo_path_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
static PyObject * pycairo_path_extents (PycairoContext *o) { double x1, y1, x2, y2; cairo_path_extents (o->ctx, &x1, &y1, &x2, &y2); RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx); return Py_BuildValue("(dddd)", x1, y1, x2, y2); }
Rect PathGeometry::ComputePathBounds () { if (!IsBuilt ()) Build (); Value *v = GetValueNoAutoCreate (FiguresProperty); PathFigureCollection *figures = v ? v->AsPathFigureCollection() : NULL; if (!figures && (!path || (path->cairo.num_data == 0))) return Rect (); cairo_t *cr = measuring_context_create (); cairo_append_path (cr, &path->cairo); double x1, y1, x2, y2; cairo_path_extents (cr, &x1, &y1, &x2, &y2); Rect bounds = Rect (MIN (x1, x2), MIN (y1, y2), fabs (x2 - x1), fabs (y2 - y1)); measuring_context_destroy (cr); return bounds; }
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); }
gfxRect gfxContext::GetUserPathExtent() { double xmin, ymin, xmax, ymax; cairo_path_extents(mCairo, &xmin, &ymin, &xmax, &ymax); return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin); }
void wxCairoSVGRadialGradient::Op(cairo_t* cairo_image, bool preserve, wxCairoSVGPaintServerOp op) { cairo_pattern_t *pat; bool saved = false; if (m_gradientUnits == _T("objectBoundingBox")) { cairo_save(cairo_image); saved = true; double minx; double miny; double maxx; double maxy; cairo_path_extents(cairo_image, &minx, &miny, &maxx, &maxy); cairo_matrix_t mat; cairo_matrix_init(&mat, maxx-minx, 0, 0, maxy-miny, minx, miny); cairo_transform(cairo_image, &mat); wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op transformed to objectBoundingBox minx %f miny %f maxx %f maxy %f"), minx, miny, maxx, maxy); } else if (m_gradientTransform.Contains(_T("matrix"))) { double m[6]; wxArrayString params = wxStringTokenize(m_gradientTransform.Mid(m_gradientTransform.Find(_T("matrix(")) + 7), _T(" ")); if (params.Count() == 6) { for (int i = 0; i < 6; i++) { params[i].Strip().ToDouble(&m[i]); } cairo_save(cairo_image); saved = true; cairo_matrix_t mat; cairo_matrix_init(&mat, m[0], m[1], m[2], m[3], m[4], m[5]); cairo_transform(cairo_image, &mat); wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op matrix transform %f %f %f %f %f %f"), m[0], m[1], m[2], m[3], m[4], m[5]); } } pat = cairo_pattern_create_radial(m_cx, m_cy, 0, m_cx, m_cy, m_r); wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op cairo_pattern_create_radial cx %f cy %f r %f"), m_cx, m_cy, m_r); for (wxCairoSVGGradientStopList::iterator i = m_stopList.begin(); i != m_stopList.end(); ++i) { wxCairoSVGGradientStop* stop = *i; if (stop->m_opacity == 1) { cairo_pattern_add_color_stop_rgb(pat, stop->m_offset, (double) stop->m_r / 255.0, (double) stop->m_g / 255.0, (double) stop->m_b / 255.0); } else { cairo_pattern_add_color_stop_rgba(pat, stop->m_offset, (double) stop->m_r / 255.0, (double) stop->m_g / 255.0, (double) stop->m_b / 255.0, stop->m_opacity); } } cairo_set_source(cairo_image, pat); wxCairoSVGPaintServer::Op(cairo_image, preserve, op); if (saved) cairo_restore(cairo_image); cairo_pattern_destroy(pat); wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op done")); }
static VALUE cr_path_extents (VALUE self) { double x1, y1, x2, y2; cairo_path_extents (_SELF, &x1, &y1, &x2, &y2); cr_check_status (_SELF); return rb_ary_new3 (4, rb_float_new(x1), rb_float_new(y1), rb_float_new(x2), rb_float_new(y2)); }
static int cr_path_extents (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); double x1, y1, x2, y2; cairo_path_extents(*obj, &x1, &y1, &x2, &y2); lua_pushnumber(L, x1); lua_pushnumber(L, y1); lua_pushnumber(L, x2); lua_pushnumber(L, y2); return 4; }
FloatRect Path::boundingRect() const { // Should this be isEmpty() or can an empty path have a non-zero origin? if (isNull()) return FloatRect(); cairo_t* cr = platformPath()->context(); double x0, x1, y0, y1; cairo_path_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
FloatRect Path::boundingRect() const { cairo_t* cr = platformPath()->m_cr; double x0, x1, y0, y1; #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0) cairo_path_extents(cr, &x0, &y0, &x1, &y1); #else cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); #endif return FloatRect(x0, y0, x1 - x0, y1 - y0); }
Rect PathCairo::GetBounds(const Matrix &aTransform) const { EnsureContainingContext(); double x1, y1, x2, y2; cairo_path_extents(mContainingContext, &x1, &y1, &x2, &y2); Rect bounds(Float(x1), Float(y1), Float(x2 - x1), Float(y2 - y1)); return aTransform.TransformBounds(bounds); }
Rect PathCairo::GetBounds(const Matrix &aTransform) const { CairoTempMatrix(*mPathContext, mTransform); double x1, y1, x2, y2; cairo_path_extents(*mPathContext, &x1, &y1, &x2, &y2); Rect bounds(Float(x1), Float(y1), Float(x2 - x1), Float(y2 - y1)); return aTransform.TransformBounds(bounds); }
// cairo_public void // cairo_path_extents (cairo_t *cr, // double *x1, double *y1, // double *x2, double *y2); static int l_cairo_path_extents(lua_State* L) { /// WARN:different usage cairo_t *cr = get_cairo_t (L, 1); double x1 = luaL_optnumber(L, 2, 0.0); double y1 = luaL_optnumber(L, 3, 0.0); double x2 = luaL_optnumber(L, 4, 0.0); double y2 = luaL_optnumber(L, 5, 0.0); cairo_path_extents (cr, &x1, &y1, &x2, &y2); lua_pushnumber(L, x1); lua_pushnumber(L, y1); lua_pushnumber(L, x2); lua_pushnumber(L, y2); return 4; }
/** * @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); }
static int cairo_path_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_path_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 ); }
// 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); }
void cairo_context::set_gradient(cairo_gradient const& pattern, const box2d<double> &bbox) { cairo_pattern_t * gradient = pattern.gradient(); double bx1=bbox.minx(); double by1=bbox.miny(); double bx2=bbox.maxx(); double by2=bbox.maxy(); if (pattern.units() != USER_SPACE_ON_USE) { if (pattern.units() == OBJECT_BOUNDING_BOX) { cairo_path_extents(cairo_.get(), &bx1, &by1, &bx2, &by2); } cairo_matrix_t cairo_matrix; cairo_pattern_get_matrix(gradient, &cairo_matrix); cairo_matrix_scale(&cairo_matrix,1.0/(bx2-bx1),1.0/(by2-by1)); cairo_matrix_translate(&cairo_matrix, -bx1,-by1); cairo_pattern_set_matrix(gradient, &cairo_matrix); } cairo_set_source(cairo_.get(), const_cast<cairo_pattern_t*>(gradient)); check_object_status_and_throw_exception(*this); }
Rect Geometry::ComputePathBounds() { if (!IsBuilt ()) Build (); if (!path || (path->cairo.num_data == 0)) return Rect (); cairo_t *cr = measuring_context_create (); cairo_append_path (cr, &path->cairo); double x1, y1, x2, y2; cairo_path_extents (cr, &x1, &y1, &x2, &y2); Rect bounds = Rect (MIN (x1, x2), MIN (y1, y2), fabs (x2 - x1), fabs (y2 - y1)); measuring_context_destroy (cr); return bounds; }
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; 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_yield(Qnil); cairo_path_extents(canvas->shape, &x1, &y1, &x2, &y2); 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 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; }