void QPaintEngineEx::draw(const QVectorPath &path) { const QBrush &brush = state()->brush; if (qbrush_style(brush) != Qt::NoBrush) fill(path, brush); const QPen &pen = state()->pen; if (qpen_style(pen) != Qt::NoPen && qbrush_style(qpen_brush(pen)) != Qt::NoBrush) stroke(path, pen); }
void QBlitterPaintEnginePrivate::updateBrushState(QPainterState *s) { Qt::BrushStyle style = qbrush_style(s->brush); caps.updateState(STATE_BRUSH_PATTERN, style > Qt::SolidPattern); caps.updateState(STATE_BRUSH_ALPHA, qbrush_color(s->brush).alpha() < 255); }
void QBlitterPaintEngine::brushChanged() { Q_D(QBlitterPaintEngine); d->raster->brushChanged(); bool solid = qbrush_style(state()->brush) == Qt::SolidPattern; d->capabillities->updateState(STATE_BRUSH_PATTERN, !solid); d->capabillities->updateState(STATE_BRUSH_ALPHA, qbrush_color(state()->brush).alpha() < 255); }
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) { QPen bgPen = pen; bgPen.setBrush(s->bgBrush); bgPen.setStyle(Qt::SolidLine); real_engine->stroke(path, bgPen); } QBrush brush = pen.brush(); QPen copy = pen; Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { if (g->coordinateMode() == QGradient::StretchToDeviceMode) { QTransform mat = brush.transform(); mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); brush.setTransform(mat); copy.setBrush(brush); real_engine->stroke(path, copy); return; } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { QTransform mat = brush.transform(); QRectF r = path.controlPointRect(); mat.translate(r.x(), r.y()); mat.scale(r.width(), r.height()); brush.setTransform(mat); copy.setBrush(brush); real_engine->stroke(path, copy); return; } } } real_engine->stroke(path, pen); }
void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) { if (state()->bgMode == Qt::OpaqueMode) { const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); fillBGRect(rect); } QPainterState *s = state(); Qt::BrushStyle style = qbrush_style(s->pen.brush()); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { QPen savedPen = s->pen; QGradient g = *s->pen.brush().gradient(); if (g.coordinateMode() > QGradient::LogicalMode) { QTransform mat = s->pen.brush().transform(); if (g.coordinateMode() == QGradient::StretchToDeviceMode) { mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); } else if (g.coordinateMode() == QGradient::ObjectBoundingMode) { const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); QRectF r(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); mat.translate(r.x(), r.y()); mat.scale(r.width(), r.height()); } g.setCoordinateMode(QGradient::LogicalMode); QBrush brush(g); brush.setTransform(mat); s->pen.setBrush(brush); penChanged(); real_engine->drawTextItem(p, textItem); s->pen = savedPen; penChanged(); return; } } real_engine->drawTextItem(p, textItem); }
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode) { Qt::BrushStyle style = brush.style(); if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern) real_engine->fill(path, s->bgBrush); } Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { if (g->coordinateMode() == QGradient::StretchToDeviceMode) { QBrush copy = brush; QTransform mat = copy.transform(); mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); copy.setTransform(mat); real_engine->fill(path, copy); return; } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { QBrush copy = brush; QTransform mat = copy.transform(); QRectF r = path.controlPointRect(); mat.translate(r.x(), r.y()); mat.scale(r.width(), r.height()); copy.setTransform(mat); real_engine->fill(path, copy); return; } } } real_engine->fill(path, brush); }
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) { QPen bgPen = pen; bgPen.setBrush(s->bgBrush); bgPen.setStyle(Qt::SolidLine); real_engine->stroke(path, bgPen); } QBrush brush = pen.brush(); Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { QPaintEngineEx::stroke(path, pen); return; } } real_engine->stroke(path, pen); }
void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) { #ifdef QT_DEBUG_DRAW qDebug() << "QPaintEngineEx::stroke()" << pen; #endif Q_D(QPaintEngineEx); if (path.isEmpty()) return; if (!d->strokeHandler) { d->strokeHandler = new StrokeHandler(path.elementCount()+4); d->stroker.setMoveToHook(qpaintengineex_moveTo); d->stroker.setLineToHook(qpaintengineex_lineTo); d->stroker.setCubicToHook(qpaintengineex_cubicTo); } if (!qpen_fast_equals(pen, d->strokerPen)) { d->strokerPen = pen; d->stroker.setJoinStyle(pen.joinStyle()); d->stroker.setCapStyle(pen.capStyle()); d->stroker.setMiterLimit(pen.miterLimit()); qreal penWidth = pen.widthF(); if (penWidth == 0) d->stroker.setStrokeWidth(1); else d->stroker.setStrokeWidth(penWidth); Qt::PenStyle style = pen.style(); if (style == Qt::SolidLine) { d->activeStroker = &d->stroker; } else if (style == Qt::NoPen) { d->activeStroker = 0; } else { d->dasher.setDashPattern(pen.dashPattern()); d->dasher.setDashOffset(pen.dashOffset()); d->activeStroker = &d->dasher; } } if (!d->activeStroker) { return; } if (pen.style() > Qt::SolidLine) { if (pen.isCosmetic()) { d->activeStroker->setClipRect(d->exDeviceRect); } else { QRectF clipRect = state()->matrix.inverted().mapRect(QRectF(d->exDeviceRect)); d->activeStroker->setClipRect(clipRect); } } const QPainterPath::ElementType *types = path.elements(); const qreal *points = path.points(); int pointCount = path.elementCount(); const qreal *lastPoint = points + (pointCount<<1); d->strokeHandler->types.reset(); d->strokeHandler->pts.reset(); // Some engines might decide to optimize for the non-shape hint later on... uint flags = QVectorPath::WindingFill; if (path.elementCount() > 2) flags |= QVectorPath::NonConvexShapeMask; if (d->stroker.capStyle() == Qt::RoundCap || d->stroker.joinStyle() == Qt::RoundJoin) flags |= QVectorPath::CurvedShapeMask; // ### Perspective Xforms are currently not supported... if (!pen.isCosmetic()) { // We include cosmetic pens in this case to avoid having to // change the current transform. Normal transformed, // non-cosmetic pens will be transformed as part of fill // later, so they are also covered here.. d->activeStroker->setCurveThresholdFromTransform(state()->matrix); d->activeStroker->begin(d->strokeHandler); if (types) { while (points < lastPoint) { switch (*types) { case QPainterPath::MoveToElement: d->activeStroker->moveTo(points[0], points[1]); points += 2; ++types; break; case QPainterPath::LineToElement: d->activeStroker->lineTo(points[0], points[1]); points += 2; ++types; break; case QPainterPath::CurveToElement: d->activeStroker->cubicTo(points[0], points[1], points[2], points[3], points[4], points[5]); points += 6; types += 3; flags |= QVectorPath::CurvedShapeMask; break; default: break; } } if (path.hasImplicitClose()) d->activeStroker->lineTo(path.points()[0], path.points()[1]); } else { d->activeStroker->moveTo(points[0], points[1]); points += 2; while (points < lastPoint) { d->activeStroker->lineTo(points[0], points[1]); points += 2; } if (path.hasImplicitClose()) d->activeStroker->lineTo(path.points()[0], path.points()[1]); } d->activeStroker->end(); if (!d->strokeHandler->types.size()) // an empty path... return; QVectorPath strokePath(d->strokeHandler->pts.data(), d->strokeHandler->types.size(), d->strokeHandler->types.data(), flags); fill(strokePath, pen.brush()); } else { // For cosmetic pens we need a bit of trickery... We to process xform the input points if (state()->matrix.type() >= QTransform::TxProject) { QPainterPath painterPath = state()->matrix.map(path.convertToPainterPath()); d->activeStroker->strokePath(painterPath, d->strokeHandler, QTransform()); } else { d->activeStroker->setCurveThresholdFromTransform(QTransform()); d->activeStroker->begin(d->strokeHandler); if (types) { while (points < lastPoint) { switch (*types) { case QPainterPath::MoveToElement: { QPointF pt = (*(QPointF *) points) * state()->matrix; d->activeStroker->moveTo(pt.x(), pt.y()); points += 2; ++types; break; } case QPainterPath::LineToElement: { QPointF pt = (*(QPointF *) points) * state()->matrix; d->activeStroker->lineTo(pt.x(), pt.y()); points += 2; ++types; break; } case QPainterPath::CurveToElement: { QPointF c1 = ((QPointF *) points)[0] * state()->matrix; QPointF c2 = ((QPointF *) points)[1] * state()->matrix; QPointF e = ((QPointF *) points)[2] * state()->matrix; d->activeStroker->cubicTo(c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y()); points += 6; types += 3; flags |= QVectorPath::CurvedShapeMask; break; } default: break; } } if (path.hasImplicitClose()) { QPointF pt = * ((QPointF *) path.points()) * state()->matrix; d->activeStroker->lineTo(pt.x(), pt.y()); } } else { QPointF p = ((QPointF *)points)[0] * state()->matrix; d->activeStroker->moveTo(p.x(), p.y()); points += 2; while (points < lastPoint) { QPointF p = ((QPointF *)points)[0] * state()->matrix; d->activeStroker->lineTo(p.x(), p.y()); points += 2; } if (path.hasImplicitClose()) d->activeStroker->lineTo(p.x(), p.y()); } d->activeStroker->end(); } QVectorPath strokePath(d->strokeHandler->pts.data(), d->strokeHandler->types.size(), d->strokeHandler->types.data(), flags); QTransform xform = state()->matrix; state()->matrix = QTransform(); transformChanged(); QBrush brush = pen.brush(); if (qbrush_style(brush) != Qt::SolidPattern) brush.setTransform(brush.transform() * xform); fill(strokePath, brush); state()->matrix = xform; transformChanged(); } }
void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) { if (rect.size().isEmpty()) return; Q_D(QBlitterPaintEngine); if (qbrush_style(brush) == Qt::SolidPattern && d->caps.canBlitterAlphaFillRect()) { d->fillRect(rect, qbrush_color(brush), true); } else if (qbrush_style(brush) == Qt::SolidPattern && qbrush_color(brush).alpha() == 0xff && d->caps.canBlitterFillRect()) { d->fillRect(rect, qbrush_color(brush), false); } else if ((brush.style() == Qt::TexturePattern) && (brush.transform().type() <= QTransform::TxTranslate) && ((d->caps.canBlitterDrawPixmapOpacity(brush.texture())) || (d->caps.canBlitterDrawPixmap(rect, brush.texture(), rect)))) { bool rectIsFilled = false; QRectF transformedRect = state()->matrix.mapRect(rect); qreal x = transformedRect.x(); qreal y = transformedRect.y(); QPixmap pm = brush.texture(); d->unlock(); int srcX = int(rect.x() - state()->brushOrigin.x() - brush.transform().dx()) % pm.width(); if (srcX < 0) srcX = pm.width() + srcX; const int startX = srcX; int srcY = int(rect.y() - state()->brushOrigin.y() - brush.transform().dy()) % pm.height(); if (srcY < 0) srcY = pm.height() + srcY; while (!rectIsFilled) { qreal blitWidth = (pm.width() ) - srcX; qreal blitHeight = (pm.height() ) - srcY; if (x + blitWidth > transformedRect.right()) blitWidth = transformedRect.right() -x; if (y + blitHeight > transformedRect.bottom()) blitHeight = transformedRect.bottom() - y; const QClipData *clipData = d->clip(); if (clipData->hasRectClip) { QRect targetRect = QRect(x, y, blitWidth, blitHeight).intersected(clipData->clipRect); if (targetRect.isValid()) { int tmpSrcX = srcX + (targetRect.x() - x); int tmpSrcY = srcY + (targetRect.y() - y); QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height()); d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect); } } else if (clipData->hasRegionClip) { QVector<QRect> clipRects = clipData->clipRegion.rects(); QRect unclippedTargetRect(x, y, blitWidth, blitHeight); QRegion intersectedRects = clipData->clipRegion.intersected(unclippedTargetRect); for (int i = 0; i < intersectedRects.rects().size(); ++i) { QRect targetRect = intersectedRects.rects().at(i); if (!targetRect.isValid() || targetRect.isEmpty()) continue; int tmpSrcX = srcX + (targetRect.x() - x); int tmpSrcY = srcY + (targetRect.y() - y); QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height()); d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect); } } x+=blitWidth; if (qFuzzyCompare(x, transformedRect.right())) { x = transformedRect.x(); srcX = startX; srcY = 0; y += blitHeight; if (qFuzzyCompare(y, transformedRect.bottom())) rectIsFilled = true; } else srcX = 0; } } else { d->lock(); d->pmData->markRasterOverlay(rect); QRasterPaintEngine::fillRect(rect, brush); } }