402void QPaintEngine::drawPoints(
const QPointF *points,
int pointCount)
404 QPainter *p = painter();
408 qreal penWidth = p->pen().widthF();
412 bool ellipses = p->pen().capStyle() == Qt::RoundCap;
416 QTransform transform;
417 if (p->pen().isCosmetic()) {
418 transform = p->transform();
419 p->setTransform(QTransform());
422 p->setBrush(p->pen().brush());
423 p->setPen(Qt::NoPen);
425 for (
int i=0; i<pointCount; ++i) {
426 QPointF pos = transform.map(points[i]);
427 QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth);
430 p->drawEllipse(rect);
471void QPaintEngine::drawEllipse(
const QRectF &rect)
474 path.addEllipse(rect);
475 if (hasFeature(PainterPaths)) {
478 QPolygonF polygon = path.toFillPolygon();
479 drawPolygon(polygon.data(), polygon.size(), ConvexMode);
506 p.drawPixmap(0, 0, pixmap);
507 int x = pixmap.width();
508 while (x < tile->width()) {
509 p.drawPixmap(x, 0, *tile, 0, 0, x, pixmap.height());
512 int y = pixmap.height();
513 while (y < tile->height()) {
514 p.drawPixmap(0, y, *tile, 0, 0, tile->width(), y);
520 const QPixmap &pixmap, qreal xOffset, qreal yOffset)
522 qreal yPos, xPos, drawH, drawW, yOff, xOff;
525 while(yPos < y + h) {
526 drawH = pixmap.height() - yOff;
527 if (yPos + drawH > y + h)
528 drawH = y + h - yPos;
531 while(xPos < x + w) {
532 drawW = pixmap.width() - xOff;
533 if (xPos + drawW > x + w)
534 drawW = x + w - xPos;
535 if (drawW > 0 && drawH > 0)
536 gc->drawPixmap(QRectF(xPos, yPos, drawW, drawH), pixmap, QRectF(xOff, yOff, drawW, drawH));
551void QPaintEngine::drawTiledPixmap(
const QRectF &rect,
const QPixmap &pixmap,
const QPointF &p)
553 int sw = pixmap.width();
554 int sh = pixmap.height();
556 if (sw*sh < 8192 && sw*sh < 16*rect.width()*rect.height()) {
557 int tw = sw, th = sh;
558 while (tw*th < 32678 && tw < rect.width()/2)
560 while (tw*th < 32678 && th < rect.height()/2)
563 if (pixmap.depth() == 1) {
564 tile = QBitmap(tw, th);
566 tile = QPixmap(tw, th);
567 if (pixmap.hasAlphaChannel())
568 tile.fill(Qt::transparent);
570 qt_fill_tile(&tile, pixmap);
571 qt_draw_tile(
this, rect.x(), rect.y(), rect.width(), rect.height(), tile, p.x(), p.y());
573 qt_draw_tile(
this, rect.x(), rect.y(), rect.width(), rect.height(), pixmap, p.x(), p.y());
586void QPaintEngine::drawImage(
const QRectF &r,
const QImage &image,
const QRectF &sr,
587 Qt::ImageConversionFlags flags)
589 QRectF baseSize(0, 0, image.width(), image.height());
592 im = im.copy(qFloor(sr.x()), qFloor(sr.y()),
593 qCeil(sr.width()), qCeil(sr.height()));
594 QPixmap pm = QPixmap::fromImage(im, flags);
595 drawPixmap(r, pm, QRectF(QPointF(0, 0), pm.size()));
720void QPaintEngine::drawTextItem(
const QPointF &p,
const QTextItem &textItem)
722 const QTextItemInt &ti =
static_cast<
const QTextItemInt &>(textItem);
723 if (ti.glyphs.numGlyphs == 0)
726 if (ti.fontEngine->glyphFormat == QFontEngine::Format_ARGB) {
727 QVarLengthArray<QFixedPoint> positions;
728 QVarLengthArray<glyph_t> glyphs;
729 QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - ti.fontEngine->ascent().toReal());
730 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
732 painter()->setRenderHint(QPainter::SmoothPixmapTransform,
733 bool((painter()->renderHints() & QPainter::TextAntialiasing)
734 && !(painter()->font().styleStrategy() & QFont::NoAntialias)));
735 for (
int i = 0; i < ti.glyphs.numGlyphs; ++i) {
736 QImage glyph = ti.fontEngine->bitmapForGlyph(glyphs[i], QFixedPoint(), QTransform());
737 painter()->drawImage(positions[i].x.toReal(), positions[i].y.toReal(), glyph);
739 painter()->restore();
744 path.setFillRule(Qt::WindingFill);
745 ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags);
746 if (!path.isEmpty()) {
748 painter()->setRenderHint(QPainter::Antialiasing,
749 bool((painter()->renderHints() & QPainter::TextAntialiasing)
750 && !(painter()->font().styleStrategy() & QFont::NoAntialias)));
751 painter()->translate(p.x(), p.y());
752 painter()->fillPath(path, painter()->pen().brush());
753 painter()->restore();
762void QPaintEngine::drawLines(
const QLineF *lines,
int lineCount)
764 for (
int i=0; i<lineCount; ++i) {
765 QPointF pts[2] = { lines[i].p1(), lines[i].p2() };
767 if (pts[0] == pts[1]) {
768 if (state->pen().capStyle() != Qt::FlatCap)
773 drawPolygon(pts, 2, PolylineMode);
784void QPaintEngine::drawLines(
const QLine *lines,
int lineCount)
794 Q_ASSERT(
sizeof(PointF) ==
sizeof(QPointF));
795 Q_ASSERT(
sizeof(LineF) ==
sizeof(QLineF));
799 while (i < lineCount && i < 256) {
800 fl[i].p1.x = lines[i].x1();
801 fl[i].p1.y = lines[i].y1();
802 fl[i].p2.x = lines[i].x2();
803 fl[i].p2.y = lines[i].y2();
806 drawLines((QLineF *)(
void *)fl, i);
850void QPaintEngine::drawRects(
const QRectF *rects,
int rectCount)
852 if (hasFeature(PainterPaths) &&
853 !state->penNeedsResolving() &&
854 !state->brushNeedsResolving()) {
855 for (
int i=0; i<rectCount; ++i) {
857 path.addRect(rects[i]);
863 for (
int i=0; i<rectCount; ++i) {
864 QRectF rf = rects[i];
865 QPointF pts[4] = { QPointF(rf.x(), rf.y()),
866 QPointF(rf.x() + rf.width(), rf.y()),
867 QPointF(rf.x() + rf.width(), rf.y() + rf.height()),
868 QPointF(rf.x(), rf.y() + rf.height()) };
869 drawPolygon(pts, 4, ConvexMode);
972QPixmap QPaintEngine::createPixmap(QSize size)
974 if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) {
975 qWarning(
"QPaintEngine::createPixmap: QPixmap cannot be created without a QGuiApplication");
979 std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
980 data->resize(size.width(), size.height());
981 return QPixmap(data.release());
989QPixmap QPaintEngine::createPixmapFromImage(QImage image, Qt::ImageConversionFlags flags)
991 if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) {
992 qWarning(
"QPaintEngine::createPixmapFromImage: QPixmap cannot be created without a QGuiApplication");
996 std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
997 if (image.isDetached())
998 data->fromImageInPlace(image, flags);
1000 data->fromImage(image, flags);
1001 return QPixmap(data.release());
1008void QPaintEnginePrivate::drawBoxTextItem(
const QPointF &p,
const QTextItemInt &ti)
1010 if (!ti.glyphs.numGlyphs)
1014 const int size = qRound(ti.fontEngine->ascent());
1015 QVarLengthArray<QFixedPoint> positions;
1016 QVarLengthArray<glyph_t> glyphs;
1017 QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size);
1018 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
1019 if (glyphs.size() == 0)
1022 QSize s(size - 3, size - 3);
1024 QPainter *painter = q_func()->state->painter();
1026 painter->setBrush(Qt::NoBrush);
1027 QPen pen = painter->pen();
1028 pen.setWidthF(ti.fontEngine->lineThickness().toReal());
1029 painter->setPen(pen);
1030 for (
int k = 0; k < positions.size(); k++)
1031 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)