Qt 4.8
Public Functions | Properties | List of all members
QDashedStrokeProcessor Class Reference

#include <qtriangulatingstroker_p.h>

Public Functions

void addElement (QPainterPath::ElementType type, qreal x, qreal y)
 
int elementCount () const
 
QPainterPath::ElementTypeelementTypes () const
 
qrealpoints () const
 
void process (const QVectorPath &path, const QPen &pen, const QRectF &clip)
 
 QDashedStrokeProcessor ()
 
void setInvScale (qreal invScale)
 

Properties

QDashStroker m_dash_stroker
 
qreal m_inv_scale
 
QDataBuffer< qrealm_points
 
QDataBuffer< QPainterPath::ElementTypem_types
 

Detailed Description

Definition at line 95 of file qtriangulatingstroker_p.h.

Constructors and Destructors

◆ QDashedStrokeProcessor()

QDashedStrokeProcessor::QDashedStrokeProcessor ( )

Definition at line 483 of file qtriangulatingstroker.cpp.

484  : m_points(0), m_types(0),
486 {
490 }
static void qdashprocessor_cubicTo(qreal, qreal, qreal, qreal, qreal, qreal, void *)
static void qdashprocessor_moveTo(qreal x, qreal y, void *data)
void setCubicToHook(qStrokerCubicToHook cubicToHook)
Definition: qstroker_p.h:150
QDataBuffer< QPainterPath::ElementType > m_types
QDataBuffer< qreal > m_points
static void qdashprocessor_lineTo(qreal x, qreal y, void *data)
void setLineToHook(qStrokerLineToHook lineToHook)
Definition: qstroker_p.h:149
void setMoveToHook(qStrokerMoveToHook moveToHook)
Definition: qstroker_p.h:148

Functions

◆ addElement()

void QDashedStrokeProcessor::addElement ( QPainterPath::ElementType  type,
qreal  x,
qreal  y 
)
inline

Definition at line 102 of file qtriangulatingstroker_p.h.

102  {
103  m_points.add(x);
104  m_points.add(y);
105  m_types.add(type);
106  }
int type
Definition: qmetatype.cpp:239
QDataBuffer< QPainterPath::ElementType > m_types
QDataBuffer< qreal > m_points
void add(const Type &t)
Definition: qdatabuffer_p.h:93

◆ elementCount()

int QDashedStrokeProcessor::elementCount ( ) const
inline

Definition at line 108 of file qtriangulatingstroker_p.h.

108 { return m_types.size(); }
QDataBuffer< QPainterPath::ElementType > m_types
int size() const
Definition: qdatabuffer_p.h:83

◆ elementTypes()

QPainterPath::ElementType* QDashedStrokeProcessor::elementTypes ( ) const
inline

Definition at line 110 of file qtriangulatingstroker_p.h.

110 { return m_types.data(); }
Type * data() const
Definition: qdatabuffer_p.h:84
QDataBuffer< QPainterPath::ElementType > m_types

◆ points()

qreal* QDashedStrokeProcessor::points ( ) const
inline

Definition at line 109 of file qtriangulatingstroker_p.h.

109 { return m_points.data(); }
Type * data() const
Definition: qdatabuffer_p.h:84
QDataBuffer< qreal > m_points

◆ process()

void QDashedStrokeProcessor::process ( const QVectorPath path,
const QPen pen,
const QRectF clip 
)

Definition at line 492 of file qtriangulatingstroker.cpp.

493 {
494 
495  const qreal *pts = path.points();
496  const QPainterPath::ElementType *types = path.elements();
497  int count = path.elementCount();
498 
499  bool cosmetic = pen.isCosmetic();
500 
501  m_points.reset();
502  m_types.reset();
503  m_points.reserve(path.elementCount());
504  m_types.reserve(path.elementCount());
505 
506  qreal width = qpen_widthf(pen);
507  if (width == 0)
508  width = 1;
509 
511  m_dash_stroker.setStrokeWidth(cosmetic ? width * m_inv_scale : width);
515 
516  float curvynessAdd, curvynessMul;
517 
518  // simplfy pens that are thin in device size (2px wide or less)
519  if (width < 2.5 && (cosmetic || m_inv_scale == 1)) {
520  curvynessAdd = 0.5;
521  curvynessMul = CURVE_FLATNESS / m_inv_scale;
522  } else if (cosmetic) {
523  curvynessAdd= width / 2;
524  curvynessMul= CURVE_FLATNESS;
525  } else {
526  curvynessAdd = width * m_inv_scale;
527  curvynessMul = CURVE_FLATNESS / m_inv_scale;
528  }
529 
530  if (count < 2)
531  return;
532 
533  const qreal *endPts = pts + (count<<1);
534 
535  m_dash_stroker.begin(this);
536 
537  if (!types) {
538  m_dash_stroker.moveTo(pts[0], pts[1]);
539  pts += 2;
540  while (pts < endPts) {
541  m_dash_stroker.lineTo(pts[0], pts[1]);
542  pts += 2;
543  }
544  } else {
545  while (pts < endPts) {
546  switch (*types) {
548  m_dash_stroker.moveTo(pts[0], pts[1]);
549  pts += 2;
550  ++types;
551  break;
553  m_dash_stroker.lineTo(pts[0], pts[1]);
554  pts += 2;
555  ++types;
556  break;
558  QBezier b = QBezier::fromPoints(*(((const QPointF *) pts) - 1),
559  *(((const QPointF *) pts)),
560  *(((const QPointF *) pts) + 1),
561  *(((const QPointF *) pts) + 2));
562  QRectF bounds = b.bounds();
563  float rad = qMax(bounds.width(), bounds.height());
564  int threshold = qMin<float>(64, (rad + curvynessAdd) * curvynessMul);
565  if (threshold < 4)
566  threshold = 4;
567 
568  qreal threshold_minus_1 = threshold - 1;
569  for (int i=0; i<threshold; ++i) {
570  QPointF pt = b.pointAt(i / threshold_minus_1);
571  m_dash_stroker.lineTo(pt.x(), pt.y());
572  }
573  pts += 6;
574  types += 3;
575  break; }
576  default: break;
577  }
578  }
579  }
580 
582 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
void setClipRect(const QRectF &clip)
Definition: qstroker_p.h:165
double qreal
Definition: qglobal.h:1193
int elementCount() const
void lineTo(qfixed x, qfixed y)
Definition: qstroker_p.h:317
void setDashOffset(qreal offset)
Definition: qstroker_p.h:265
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define CURVE_FLATNESS
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
void setDashPattern(const QVector< qfixed > &dashPattern)
Definition: qstroker_p.h:262
const QPainterPath::ElementType * elements() const
QVector< qreal > dashPattern() const
Returns the dash pattern of this pen.
Definition: qpen.cpp:466
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void setMiterLimit(qreal limit)
Definition: qstroker_p.h:272
virtual void end()
Finishes the stroke.
Definition: qstroker_p.h:385
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
void reserve(int size)
QDataBuffer< QPainterPath::ElementType > m_types
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isCosmetic() const
Returns true if the pen is cosmetic; otherwise returns false.
Definition: qpen.cpp:840
virtual void begin(void *data)
Prepares the stroker.
Definition: qstroker_p.h:378
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal qpen_widthf(const QPen &p)
Definition: qpainter_p.h:88
QDataBuffer< qreal > m_points
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF bounds() const
Definition: qbezier.cpp:223
static const struct @32 types[]
qreal miterLimit() const
Returns the miter limit of the pen.
Definition: qpen.cpp:589
const qreal * points() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal dashOffset() const
Returns the dash offset for the pen.
Definition: qpen.cpp:547
void moveTo(qfixed x, qfixed y)
Definition: qstroker_p.h:308
void setStrokeWidth(qreal width)
Definition: qstroker_p.h:271
void reset()
Definition: qdatabuffer_p.h:79

◆ setInvScale()

void QDashedStrokeProcessor::setInvScale ( qreal  invScale)
inline

Definition at line 112 of file qtriangulatingstroker_p.h.

Referenced by QGL2PaintEngineExPrivate::updateMatrix().

112 { m_inv_scale = invScale; }

Properties

◆ m_dash_stroker

QDashStroker QDashedStrokeProcessor::m_dash_stroker
private

Definition at line 117 of file qtriangulatingstroker_p.h.

Referenced by process(), and QDashedStrokeProcessor().

◆ m_inv_scale

qreal QDashedStrokeProcessor::m_inv_scale
private

Definition at line 118 of file qtriangulatingstroker_p.h.

Referenced by process().

◆ m_points

QDataBuffer<qreal> QDashedStrokeProcessor::m_points
private

Definition at line 115 of file qtriangulatingstroker_p.h.

Referenced by process().

◆ m_types

QDataBuffer<QPainterPath::ElementType> QDashedStrokeProcessor::m_types
private

Definition at line 116 of file qtriangulatingstroker_p.h.

Referenced by process().


The documentation for this class was generated from the following files: