403void QPaintEngine::drawPoints(
const QPointF *points,
int pointCount)
405 QPainter *p = painter();
409 qreal penWidth = p->pen().widthF();
413 bool ellipses = p->pen().capStyle() == Qt::RoundCap;
417 QTransform transform;
418 if (p->pen().isCosmetic()) {
419 transform = p->transform();
420 p->setTransform(QTransform());
423 p->setBrush(p->pen().brush());
424 p->setPen(Qt::NoPen);
426 for (
int i=0; i<pointCount; ++i) {
427 QPointF pos = transform.map(points[i]);
428 QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth);
431 p->drawEllipse(rect);
472void QPaintEngine::drawEllipse(
const QRectF &rect)
475 path.addEllipse(rect);
476 if (hasFeature(PainterPaths)) {
479 QPolygonF polygon = path.toFillPolygon();
480 drawPolygon(polygon.data(), polygon.size(), ConvexMode);
507 p.drawPixmap(0, 0, pixmap);
508 int x = pixmap.width();
509 while (x < tile->width()) {
510 p.drawPixmap(x, 0, *tile, 0, 0, x, pixmap.height());
513 int y = pixmap.height();
514 while (y < tile->height()) {
515 p.drawPixmap(0, y, *tile, 0, 0, tile->width(), y);
521 const QPixmap &pixmap, qreal xOffset, qreal yOffset)
523 qreal yPos, xPos, drawH, drawW, yOff, xOff;
526 while(yPos < y + h) {
527 drawH = pixmap.height() - yOff;
528 if (yPos + drawH > y + h)
529 drawH = y + h - yPos;
532 while(xPos < x + w) {
533 drawW = pixmap.width() - xOff;
534 if (xPos + drawW > x + w)
535 drawW = x + w - xPos;
536 if (drawW > 0 && drawH > 0)
537 gc->drawPixmap(QRectF(xPos, yPos, drawW, drawH), pixmap, QRectF(xOff, yOff, drawW, drawH));
552void QPaintEngine::drawTiledPixmap(
const QRectF &rect,
const QPixmap &pixmap,
const QPointF &p)
554 int sw = pixmap.width();
555 int sh = pixmap.height();
557 if (sw*sh < 8192 && sw*sh < 16*rect.width()*rect.height()) {
558 int tw = sw, th = sh;
559 while (tw*th < 32678 && tw < rect.width()/2)
561 while (tw*th < 32678 && th < rect.height()/2)
564 if (pixmap.depth() == 1) {
565 tile = QBitmap(tw, th);
567 tile = QPixmap(tw, th);
568 if (pixmap.hasAlphaChannel())
569 tile.fill(Qt::transparent);
571 qt_fill_tile(&tile, pixmap);
572 qt_draw_tile(
this, rect.x(), rect.y(), rect.width(), rect.height(), tile, p.x(), p.y());
574 qt_draw_tile(
this, rect.x(), rect.y(), rect.width(), rect.height(), pixmap, p.x(), p.y());
587void QPaintEngine::drawImage(
const QRectF &r,
const QImage &image,
const QRectF &sr,
588 Qt::ImageConversionFlags flags)
590 QRectF baseSize(0, 0, image.width(), image.height());
593 im = im.copy(qFloor(sr.x()), qFloor(sr.y()),
594 qCeil(sr.width()), qCeil(sr.height()));
595 QPixmap pm = QPixmap::fromImage(im, flags);
596 drawPixmap(r, pm, QRectF(QPointF(0, 0), pm.size()));
721void QPaintEngine::drawTextItem(
const QPointF &p,
const QTextItem &textItem)
723 const QTextItemInt &ti =
static_cast<
const QTextItemInt &>(textItem);
724 if (ti.glyphs.numGlyphs == 0)
727 if (ti.fontEngine->glyphFormat == QFontEngine::Format_ARGB) {
728 QVarLengthArray<QFixedPoint> positions;
729 QVarLengthArray<glyph_t> glyphs;
730 QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - ti.fontEngine->ascent().toReal());
731 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
733 painter()->setRenderHint(QPainter::SmoothPixmapTransform,
734 bool((painter()->renderHints() & QPainter::TextAntialiasing)
735 && !(painter()->font().styleStrategy() & QFont::NoAntialias)));
736 for (
int i = 0; i < ti.glyphs.numGlyphs; ++i) {
737 QImage glyph = ti.fontEngine->bitmapForGlyph(glyphs[i], QFixedPoint(), QTransform());
738 painter()->drawImage(positions[i].x.toReal(), positions[i].y.toReal(), glyph);
740 painter()->restore();
745 path.setFillRule(Qt::WindingFill);
746 ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags);
747 if (!path.isEmpty()) {
749 painter()->setRenderHint(QPainter::Antialiasing,
750 bool((painter()->renderHints() & QPainter::TextAntialiasing)
751 && !(painter()->font().styleStrategy() & QFont::NoAntialias)));
752 painter()->translate(p.x(), p.y());
753 painter()->fillPath(path, painter()->pen().brush());
754 painter()->restore();
763void QPaintEngine::drawLines(
const QLineF *lines,
int lineCount)
765 for (
int i=0; i<lineCount; ++i) {
766 QPointF pts[2] = { lines[i].p1(), lines[i].p2() };
768 if (pts[0] == pts[1]) {
769 if (state->pen().capStyle() != Qt::FlatCap)
774 drawPolygon(pts, 2, PolylineMode);
785void QPaintEngine::drawLines(
const QLine *lines,
int lineCount)
795 Q_ASSERT(
sizeof(PointF) ==
sizeof(QPointF));
796 Q_ASSERT(
sizeof(LineF) ==
sizeof(QLineF));
800 while (i < lineCount && i < 256) {
801 fl[i].p1.x = lines[i].x1();
802 fl[i].p1.y = lines[i].y1();
803 fl[i].p2.x = lines[i].x2();
804 fl[i].p2.y = lines[i].y2();
807 drawLines((QLineF *)(
void *)fl, i);
851void QPaintEngine::drawRects(
const QRectF *rects,
int rectCount)
853 if (hasFeature(PainterPaths) &&
854 !state->penNeedsResolving() &&
855 !state->brushNeedsResolving()) {
856 for (
int i=0; i<rectCount; ++i) {
858 path.addRect(rects[i]);
864 for (
int i=0; i<rectCount; ++i) {
865 QRectF rf = rects[i];
866 QPointF pts[4] = { QPointF(rf.x(), rf.y()),
867 QPointF(rf.x() + rf.width(), rf.y()),
868 QPointF(rf.x() + rf.width(), rf.y() + rf.height()),
869 QPointF(rf.x(), rf.y() + rf.height()) };
870 drawPolygon(pts, 4, ConvexMode);
973QPixmap QPaintEngine::createPixmap(QSize size)
975 if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) {
976 qWarning(
"QPaintEngine::createPixmap: QPixmap cannot be created without a QGuiApplication");
980 std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
981 data->resize(size.width(), size.height());
982 return QPixmap(data.release());
990QPixmap QPaintEngine::createPixmapFromImage(QImage image, Qt::ImageConversionFlags flags)
992 if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) {
993 qWarning(
"QPaintEngine::createPixmapFromImage: QPixmap cannot be created without a QGuiApplication");
997 std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
998 if (image.isDetached())
999 data->fromImageInPlace(image, flags);
1001 data->fromImage(image, flags);
1002 return QPixmap(data.release());
1009void QPaintEnginePrivate::drawBoxTextItem(
const QPointF &p,
const QTextItemInt &ti)
1011 if (!ti.glyphs.numGlyphs)
1015 const int size = qRound(ti.fontEngine->ascent());
1016 QVarLengthArray<QFixedPoint> positions;
1017 QVarLengthArray<glyph_t> glyphs;
1018 QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size);
1019 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
1020 if (glyphs.size() == 0)
1023 QSize s(size - 3, size - 3);
1025 QPainter *painter = q_func()->state->painter();
1027 painter->setBrush(Qt::NoBrush);
1028 QPen pen = painter->pen();
1029 pen.setWidthF(ti.fontEngine->lineThickness().toReal());
1030 painter->setPen(pen);
1031 for (
int k = 0; k < positions.size(); k++)
1032 painter->drawRect(QRectF(positions[k].toPointF(), s));
Q_GUI_EXPORT void qt_draw_tile(QPaintEngine *gc, qreal x, qreal y, qreal w, qreal h, const QPixmap &pixmap, qreal xOffset, qreal yOffset)