void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height, ExceptionCode& ec) { ec = 0; if (!(width >= 0 && height >= 0)) { ec = INDEX_SIZE_ERR; return; } GraphicsContext* c = drawingContext(); if (!c) return; // FIXME: Do this through platform-independent GraphicsContext API. #if PLATFORM(CG) CGRect rect = CGRectMake(x, y, width, height); willDraw(rect); if (state().m_fillStyle->gradient()) { // Shading works on the entire clip region, so convert the rect to a clip. c->save(); CGContextClipToRect(c->platformContext(), rect); CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading()); c->restore(); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); CGContextFillRect(c->platformContext(), rect); } #elif PLATFORM(QT) QRectF rect(x, y, width, height); willDraw(rect); QPainter* p = static_cast<QPainter*>(c->platformContext()); if (state().m_fillStyle->gradient()) { p->fillRect(rect, QBrush(*(state().m_fillStyle->gradient()->platformShading()))); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); p->fillRect(rect, p->brush()); } #elif PLATFORM(CAIRO) FloatRect rect(x, y, width, height); willDraw(rect); cairo_t* cr = c->platformContext(); cairo_save(cr); if (state().m_fillStyle->gradient()) { cairo_set_source(cr, state().m_fillStyle->gradient()->platformShading()); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); } cairo_rectangle(cr, x, y, width, height); cairo_fill(cr); cairo_restore(cr); #endif }
void CanvasRenderingContext2D::fill() { 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()) willDraw(CGContextGetPathBoundingBox(c->platformContext())); if (state().m_fillStyle->gradient()) { // Shading works on the entire clip region, so convert the current path to a clip. c->save(); CGContextClip(c->platformContext()); CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading()); c->restore(); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); CGContextFillPath(c->platformContext()); } #elif PLATFORM(QT) QPainterPath* path = state().m_path.platformPath(); QPainter* p = static_cast<QPainter*>(c->platformContext()); willDraw(path->controlPointRect()); if (state().m_fillStyle->gradient()) { p->fillPath(*path, QBrush(*(state().m_fillStyle->gradient()->platformShading()))); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); p->fillPath(*path, p->brush()); } #elif PLATFORM(CAIRO) cairo_t* pathCr = state().m_path.platformPath()->m_cr; cairo_t* cr = c->platformContext(); cairo_save(cr); willDraw(state().m_path.boundingRect()); if (state().m_fillStyle->gradient()) { cairo_set_source(cr, state().m_fillStyle->gradient()->platformShading()); c->addPath(state().m_path); cairo_fill(cr); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); c->addPath(state().m_path); cairo_fill(cr); } cairo_restore(cr); #endif clearPathForDashboardBackwardCompatibilityMode(); }
void CanvasRenderingContext2D::fill() { GraphicsContext* c = drawingContext(); if (!c) return; c->beginPath(); c->addPath(m_path); if (!m_path.isEmpty()) willDraw(m_path.boundingRect()); #if PLATFORM(CG) if (state().m_fillStyle->canvasGradient()) { // Shading works on the entire clip region, so convert the current path to a clip. c->save(); CGContextClip(c->platformContext()); CGContextDrawShading(c->platformContext(), state().m_fillStyle->canvasGradient()->gradient().platformGradient()); c->restore(); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); CGContextFillPath(c->platformContext()); } #elif PLATFORM(QT) QPainterPath* path = m_path.platformPath(); QPainter* p = static_cast<QPainter*>(c->platformContext()); if (state().m_fillStyle->canvasGradient()) { p->fillPath(*path, QBrush(*(state().m_fillStyle->canvasGradient()->gradient().platformGradient()))); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); p->fillPath(*path, p->brush()); } #elif PLATFORM(CAIRO) && !PLATFORM(BAL) cairo_t* cr = c->platformContext(); cairo_save(cr); if (state().m_fillStyle->canvasGradient()) { cairo_set_source(cr, state().m_fillStyle->canvasGradient()->gradient().platformGradient()); cairo_fill(cr); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); cairo_fill(cr); } cairo_restore(cr); #elif PLATFORM(BAL) //FIXME notImplemented(); #endif #if ENABLE(DASHBOARD_SUPPORT) clearPathForDashboardBackwardCompatibilityMode(); #endif }
void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height) { if (!validateRectForCanvas(x, y, width, height)) return; GraphicsContext* c = drawingContext(); if (!c) return; FloatRect rect(x, y, width, height); willDraw(rect); // FIXME: Do this through platform-independent GraphicsContext API. #if PLATFORM(CG) if (state().m_fillStyle->canvasGradient()) { // Shading works on the entire clip region, so convert the rect to a clip. c->save(); CGContextClipToRect(c->platformContext(), rect); CGContextDrawShading(c->platformContext(), state().m_fillStyle->canvasGradient()->gradient().platformGradient()); c->restore(); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); CGContextFillRect(c->platformContext(), rect); } #elif PLATFORM(QT) QPainter* p = static_cast<QPainter*>(c->platformContext()); if (state().m_fillStyle->canvasGradient()) { p->fillRect(rect, QBrush(*(state().m_fillStyle->canvasGradient()->gradient().platformGradient()))); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); p->fillRect(rect, p->brush()); } #elif PLATFORM(CAIRO) && !PLATFORM(BAL) cairo_t* cr = c->platformContext(); cairo_save(cr); if (state().m_fillStyle->canvasGradient()) { cairo_set_source(cr, state().m_fillStyle->canvasGradient()->gradient().platformGradient()); } else { if (state().m_fillStyle->pattern()) applyFillPattern(); } cairo_rectangle(cr, x, y, width, height); cairo_fill(cr); cairo_restore(cr); #elif PLATFORM(BAL) //FIXME notImplemented(); #endif }
void GraphicsContext::fillRect(const FloatRect& rect) { if (paintingDisabled()) return; CGContextRef context = platformContext(); if (m_state.fillGradient) { CGContextSaveGState(context); CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform()); if (hasShadow()) { CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0); CGContextRef layerContext = CGLayerGetContext(layer); m_state.fillGradient->paint(layerContext); CGContextDrawLayerAtPoint(context, CGPointMake(rect.left(), rect.top()), layer); CGLayerRelease(layer); } else { CGContextClipToRect(context, rect); m_state.fillGradient->paint(this); } CGContextRestoreGState(context); return; } if (m_state.fillPattern) applyFillPattern(); CGContextFillRect(context, rect); }
void GraphicsContext::fillPath(const Path& path) { if (paintingDisabled()) return; CGContextRef context = platformContext(); CGContextBeginPath(context); CGContextAddPath(context, path.platformPath()); if (m_state.fillGradient) { CGContextSaveGState(context); if (fillRule() == RULE_EVENODD) CGContextEOClip(context); else CGContextClip(context); CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform()); m_state.fillGradient->paint(this); CGContextRestoreGState(context); return; } if (m_state.fillPattern) applyFillPattern(); fillPathWithFillRule(context, fillRule()); }
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 EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter) { QPainterPath path; // first we invert the painter since we have our coordinate system inverted. // inversion is required to draw the elliptic curves at correct angles. painter->scale(1.0, -1.0); painter->translate(0, ((-boundingRect().top()) - boundingRect().bottom())); applyLinePattern(painter); applyFillPattern(painter); qreal startAngle = StringHandler::getNormalizedAngle(mStartAngle); qreal endAngle = StringHandler::getNormalizedAngle(mEndAngle); if ((startAngle - endAngle) == 0) { path.addEllipse(getBoundingRect()); painter->drawPath(path); } else { painter->drawPie(getBoundingRect(), mStartAngle*16, mEndAngle*16 - mStartAngle*16); } }
void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter) { applyLinePattern(painter); applyFillPattern(painter); painter->drawRoundedRect(getBoundingRect(), mRadius, mRadius); }