Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12859

QPaintEngine_raster does not take care of scaling if Pen has dashArray / dashOffset

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • 4.7.0
    • 4.6.3
    • GUI: Painting
    • None
    • c41dbbb5e6495e26cd3223d39c61decd951afeba, 119d7dddc8da189ccd1cbc55ed3292f311c30e0c, c46688b8a88da02028405604ab633b27d3fefa68

    Description

      This code gives a bad representation of the intended Curve:

      QPainter p(this);
      p.setRenderHint(QPainter::Antialiasing, true);
      
      QPen pe(Qt::red);
      pe.setWidth(5);
      QVector<qreal> v;
      v << 20;
      v << 20;
      			
      pe.setDashPattern(v);
      pe.setDashOffset(i/10.0f);
      
      p.setPen(pe);
      
      QPainterPath path;
      path.moveTo(0,20);
      path.cubicTo(0, 0, 20, 0, 30, 20);
      p.scale(width()/40, width()/40);
      
      p.drawPath(path);
      

      You can see that it draws Lines instead of a curve. This comes from QBezier::toPolygon not taking into account the current scaling of the matrix. It assumes that the control point coordinates map directly to pixels which is not the case.

      I fixed it in QBezier / QDashStroker / QPaintEngineEx by forwarding the scale factor and dividing "flatness/scale" in Qbezier.cpp:248:

      if (d < (flatness/_scaleMax)*l || b == beziers + 31) {

      This works but is not perfect, finding the right scaleMax is non obvious.

      Cheers,
      Marcus

      Attachments

        1. main.cpp
          0.8 kB
        2. native.png
          native.png
          7 kB
        3. raster.png
          raster.png
          7 kB
        4. opengl.png
          opengl.png
          3 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            janichol Andy Nichols
            marcusti Marcus T (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes