void GraphicsContext::drawPath(const Path& path) { if (paintingDisabled()) return; CGContextRef context = platformContext(); const GraphicsContextState& state = m_state; if (state.fillGradient || state.strokeGradient) { // We don't have any optimized way to fill & stroke a path using gradients // FIXME: Be smarter about this. fillPath(path); strokePath(path); return; } CGContextBeginPath(context); CGContextAddPath(context, path.platformPath()); if (state.fillPattern) applyFillPattern(); if (state.strokePattern) applyStrokePattern(); CGPathDrawingMode drawingMode; if (calculateDrawingMode(state, drawingMode)) CGContextDrawPath(context, drawingMode); }
void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, float lineWidth, ExceptionCode& ec) { ec = 0; if (!(width >= 0 && height >= 0 && lineWidth >= 0)) { ec = INDEX_SIZE_ERR; return; } GraphicsContext* c = drawingContext(); if (!c) return; FloatRect rect(x, y, width, height); FloatRect boundingRect = rect; boundingRect.inflate(lineWidth / 2); willDraw(boundingRect); // FIXME: No support for gradients! if (state().m_strokeStyle->pattern()) applyStrokePattern(); c->strokeRect(rect, lineWidth); }
void CanvasRenderingContext2D::stroke() { GraphicsContext* c = drawingContext(); if (!c) return; // FIXME: Do this through platform-independent GraphicsContext API. #if PLATFORM(CG) CGContextBeginPath(c->platformContext()); CGContextAddPath(c->platformContext(), state().m_path.platformPath()); if (!state().m_path.isEmpty()) { float lineWidth = state().m_lineWidth; float inset = -lineWidth / 2; CGRect boundingRect = CGRectInset(CGContextGetPathBoundingBox(c->platformContext()), inset, inset); willDraw(boundingRect); } if (state().m_strokeStyle->gradient()) { // Shading works on the entire clip region, so convert the current path to a clip. c->save(); CGContextReplacePathWithStrokedPath(c->platformContext()); CGContextClip(c->platformContext()); CGContextDrawShading(c->platformContext(), state().m_strokeStyle->gradient()->platformShading()); c->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); CGContextStrokePath(c->platformContext()); } #elif PLATFORM(QT) QPainterPath* path = state().m_path.platformPath(); QPainter* p = static_cast<QPainter*>(c->platformContext()); willDraw(path->controlPointRect()); if (state().m_strokeStyle->gradient()) { p->save(); p->setBrush(*(state().m_strokeStyle->gradient()->platformShading())); p->strokePath(*path, p->pen()); p->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); p->strokePath(*path, p->pen()); } #endif clearPathForDashboardBackwardCompatibilityMode(); }
void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, float lineWidth, ExceptionCode& ec) { ec = 0; if (!(width >= 0 && height >= 0 && lineWidth >= 0)) { ec = INDEX_SIZE_ERR; return; } GraphicsContext* c = drawingContext(); if (!c) return; FloatRect rect(x, y, width, height); FloatRect boundingRect = rect; boundingRect.inflate(lineWidth / 2); willDraw(boundingRect); #if PLATFORM(QT) //This is done because underneath doesn't support gradients // once we have canvas gradients implemented in the general code // just remove this section if (state().m_strokeStyle->pattern()) applyStrokePattern(); QPainter* p = static_cast<QPainter*>(c->platformContext()); p->save(); { p->setBrush(Qt::NoBrush); QPen pen = p->pen(); pen.setWidthF(lineWidth); if (state().m_strokeStyle->gradient()) pen.setBrush(QBrush(*(state().m_strokeStyle->gradient()->platformShading()))); p->setPen(pen); p->drawRect(rect); } p->restore(); #else // FIXME: No support for gradients! if (state().m_strokeStyle->pattern()) applyStrokePattern(); c->strokeRect(rect, lineWidth); #endif }
void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth) { if (paintingDisabled()) return; CGContextRef context = platformContext(); if (m_state.strokeGradient) { CGContextSaveGState(context); setStrokeThickness(lineWidth); CGContextAddRect(context, r); CGContextReplacePathWithStrokedPath(context); CGContextClip(context); m_state.strokeGradient->paint(this); CGContextRestoreGState(context); return; } if (m_state.strokePattern) applyStrokePattern(); CGContextStrokeRectWithWidth(context, r, lineWidth); }
void GraphicsContext::strokePath(const Path& path) { if (paintingDisabled()) return; CGContextRef context = platformContext(); CGContextBeginPath(context); CGContextAddPath(context, path.platformPath()); if (m_state.strokeGradient) { CGContextSaveGState(context); CGContextReplacePathWithStrokedPath(context); CGContextClip(context); CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform()); m_state.strokeGradient->paint(this); CGContextRestoreGState(context); return; } if (m_state.strokePattern) applyStrokePattern(); CGContextStrokePath(context); }
void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, float lineWidth) { if (!validateRectForCanvas(x, y, width, height)) return; if (!(lineWidth >= 0)) return; GraphicsContext* c = drawingContext(); if (!c) return; FloatRect rect(x, y, width, height); FloatRect boundingRect = rect; boundingRect.inflate(lineWidth / 2); willDraw(boundingRect); // FIXME: No support for gradients! if (state().m_strokeStyle->pattern()) applyStrokePattern(); c->strokeRect(rect, lineWidth); }
void CanvasRenderingContext2D::stroke() { GraphicsContext* c = drawingContext(); if (!c) return; c->beginPath(); c->addPath(m_path); if (!m_path.isEmpty()) { // FIXME: This is insufficient, need to use CGContextReplacePathWithStrokedPath to expand to required bounds float lineWidth = state().m_lineWidth; float inset = lineWidth / 2; FloatRect boundingRect = m_path.boundingRect(); boundingRect.inflate(inset); willDraw(boundingRect); } // FIXME: Do this through platform-independent GraphicsContext API. #if PLATFORM(CG) if (state().m_strokeStyle->canvasGradient()) { // Shading works on the entire clip region, so convert the current path to a clip. c->save(); CGContextReplacePathWithStrokedPath(c->platformContext()); CGContextClip(c->platformContext()); CGContextDrawShading(c->platformContext(), state().m_strokeStyle->canvasGradient()->gradient().platformGradient()); c->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); CGContextStrokePath(c->platformContext()); } #elif PLATFORM(QT) QPainterPath* path = m_path.platformPath(); QPainter* p = static_cast<QPainter*>(c->platformContext()); if (state().m_strokeStyle->canvasGradient()) { p->save(); p->setBrush(*(state().m_strokeStyle->canvasGradient()->gradient().platformGradient())); p->strokePath(*path, p->pen()); p->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); p->strokePath(*path, p->pen()); } #elif PLATFORM(CAIRO) && !PLATFORM(BAL) cairo_t* cr = c->platformContext(); cairo_save(cr); if (state().m_strokeStyle->canvasGradient()) { cairo_set_source(cr, state().m_strokeStyle->canvasGradient()->gradient().platformGradient()); c->addPath(m_path); cairo_stroke(cr); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); c->addPath(m_path); cairo_stroke(cr); } cairo_restore(cr); #elif PLATFORM(BAL) //FIXME notImplemented(); #endif #if ENABLE(DASHBOARD_SUPPORT) clearPathForDashboardBackwardCompatibilityMode(); #endif }