static cairo_test_status_t draw (cairo_t *cr, int width, int height) { double x1, y1, x2, y2; cairo_move_to (cr, 0.0, 0.0); cairo_line_to (cr, 100.0, 100.0); cairo_set_line_width (cr, 0.0); cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); cairo_stroke_extents (cr, &x1, &y1, &x2, &y2); cairo_in_stroke (cr, 50, 50); cairo_stroke_preserve (cr); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); cairo_stroke_extents (cr, &x1, &y1, &x2, &y2); cairo_in_stroke (cr, 50, 50); cairo_stroke_preserve (cr); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); cairo_stroke_extents (cr, &x1, &y1, &x2, &y2); cairo_in_stroke (cr, 50, 50); cairo_stroke (cr); return CAIRO_TEST_SUCCESS; }
static PyObject * pycairo_stroke_extents (PycairoContext *o) { double x1, y1, x2, y2; cairo_stroke_extents (o->ctx, &x1, &y1, &x2, &y2); RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx); return Py_BuildValue("(dddd)", x1, y1, x2, y2); }
gfxRect gfxContext::GetUserStrokeExtent() { double xmin, ymin, xmax, ymax; cairo_stroke_extents(mCairo, &xmin, &ymin, &xmax, &ymax); return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin); }
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_stroke_extents (PycairoContext *o) { double x1, y1, x2, y2; cairo_stroke_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_stroke_extents (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); double x1, y1, x2, y2; cairo_stroke_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 { 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); }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { cairo_t* cr = platformPath()->context(); if (applier) { GraphicsContext gc(cr); applier->strokeStyle(&gc); } double x0, x1, y0, y1; cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
FloatRect RenderPath::strokeBBox() const { // TODO: this implementation is naive cairo_t* cr = path().platformPath()->m_cr; double x0, x1, y0, y1; cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); FloatRect bbox = FloatRect(x0, y0, x1 - x0, y1 - y0); return bbox; }
/* Rectangular extents */ static VALUE cr_stroke_extents (VALUE self) { double extents[4]; if (rb_block_given_p ()) { cr_new_path (self); rb_yield (self); } cairo_stroke_extents (_SELF, extents, extents + 1, extents + 2, extents + 3); return rb_cairo__float_array (extents, 4); }
Rect PathCairo::GetStrokedBounds(const StrokeOptions &aStrokeOptions, const Matrix &aTransform) const { EnsureContainingContext(); double x1, y1, x2, y2; SetCairoStrokeOptions(mContainingContext, aStrokeOptions); cairo_stroke_extents(mContainingContext, &x1, &y1, &x2, &y2); Rect bounds((Float)x1, (Float)y1, (Float)(x2 - x1), (Float)(y2 - y1)); return aTransform.TransformBounds(bounds); }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { // Should this be isEmpty() or can an empty path have a non-zero origin? if (isNull()) return FloatRect(); cairo_t* cr = platformPath()->context(); if (applier) { GraphicsContext gc(cr); applier->strokeStyle(&gc); } double x0, x1, y0, y1; cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
CAMLprim value ml_cairo_stroke_extents (value v_cr) { double x1, y1, x2, y2; cairo_stroke_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); } }
static int cairo_stroke_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_stroke_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 ); }
static void goc_polyline_update_bounds (GocItem *item) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); cr = cairo_create (surface); if (goc_polyline_prepare_draw (item, cr, 0)) { cairo_stroke_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1); } else { item->x0 = item->y0 = G_MAXDOUBLE; item->x1 = item->y1 = -G_MAXDOUBLE; } cairo_destroy (cr); cairo_surface_destroy (surface); }
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); }
void lime_cairo_stroke_extents (value handle, double x1, double y1, double x2, double y2) { cairo_stroke_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2); }
void lime_cairo_stroke_extents (double handle, double x1, double y1, double x2, double y2) { cairo_stroke_extents ((cairo_t*)(intptr_t)handle, &x1, &y1, &x2, &y2); }
void Context::strokeExtents( double *x1, double *y1, double *x2, double *y2 ) { cairo_stroke_extents( mCairo, 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); }
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; }
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; }