Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Protected Variables | List of all members
QDashStroker Class Reference

#include <qstroker_p.h>

Inheritance diagram for QDashStroker:
QStrokerOps

Public Functions

virtual void begin (void *data)
 Prepares the stroker. More...
 
qreal dashOffset () const
 
QVector< qfixeddashPattern () const
 
virtual void end ()
 Finishes the stroke. More...
 
 QDashStroker (QStroker *stroker)
 
void setDashOffset (qreal offset)
 
void setDashPattern (const QVector< qfixed > &dashPattern)
 
void setMiterLimit (qreal limit)
 
void setStrokeWidth (qreal width)
 
QStrokerstroker () const
 
- Public Functions inherited from QStrokerOps
QRectF clipRect () const
 
void cubicTo (qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey)
 
qfixed curveThreshold () const
 
void lineTo (qfixed x, qfixed y)
 
void moveTo (qfixed x, qfixed y)
 
 QStrokerOps ()
 
void setClipRect (const QRectF &clip)
 
void setCubicToHook (qStrokerCubicToHook cubicToHook)
 
void setCurveThreshold (qfixed threshold)
 
void setCurveThresholdFromTransform (const QTransform &transform)
 
void setLineToHook (qStrokerLineToHook lineToHook)
 
void setMoveToHook (qStrokerMoveToHook moveToHook)
 
void strokeEllipse (const QRectF &ellipse, void *data, const QTransform &matrix)
 Convenience function for stroking an ellipse with bounding rect rect. More...
 
void strokePath (const QPainterPath &path, void *data, const QTransform &matrix)
 Convenience function that decomposes path into begin(), moveTo(), lineTo(), curevTo() and end() calls. More...
 
void strokePolygon (const QPointF *points, int pointCount, bool implicit_close, void *data, const QTransform &matrix)
 Convenience function for stroking a polygon of the pointCount first points in points. More...
 
virtual ~QStrokerOps ()
 

Static Public Functions

static QVector< qfixedpatternForStyle (Qt::PenStyle style)
 

Protected Functions

virtual void processCurrentSubpath ()
 
- Protected Functions inherited from QStrokerOps
void emitCubicTo (qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
 
void emitLineTo (qfixed x, qfixed y)
 
void emitMoveTo (qfixed x, qfixed y)
 

Protected Variables

qreal m_dashOffset
 
QVector< qfixedm_dashPattern
 
qreal m_miter_limit
 
qreal m_stroke_width
 
QStrokerm_stroker
 
- Protected Variables inherited from QStrokerOps
QRectF m_clip_rect
 
qStrokerCubicToHook m_cubicTo
 
qfixed m_curveThreshold
 
void * m_customData
 
qfixed m_dashThreshold
 
QDataBuffer< Elementm_elements
 
qStrokerLineToHook m_lineTo
 
qStrokerMoveToHook m_moveTo
 

Detailed Description

Definition at line 253 of file qstroker_p.h.

Constructors and Destructors

◆ QDashStroker()

QDashStroker::QDashStroker ( QStroker stroker)

Definition at line 1024 of file qstroker.cpp.

1025  : m_stroker(stroker), m_dashOffset(0), m_stroke_width(1), m_miter_limit(1)
1026 {
1027  if (m_stroker) {
1031  }
1032 }
void setCubicToHook(qStrokerCubicToHook cubicToHook)
Definition: qstroker_p.h:150
static void qdashstroker_moveTo(qfixed x, qfixed y, void *data)
Definition: qstroker.cpp:1007
qreal m_dashOffset
Definition: qstroker_p.h:279
static void qdashstroker_lineTo(qfixed x, qfixed y, void *data)
Definition: qstroker.cpp:1011
static void qdashstroker_cubicTo(qfixed, qfixed, qfixed, qfixed, qfixed, qfixed, void *)
Definition: qstroker.cpp:1015
QStroker * m_stroker
Definition: qstroker_p.h:277
qreal m_stroke_width
Definition: qstroker_p.h:281
void setLineToHook(qStrokerLineToHook lineToHook)
Definition: qstroker_p.h:149
qreal m_miter_limit
Definition: qstroker_p.h:282
void setMoveToHook(qStrokerMoveToHook moveToHook)
Definition: qstroker_p.h:148

Functions

◆ begin()

void QDashStroker::begin ( void *  customData)
inlinevirtual

Prepares the stroker.

Call this function once before starting a stroke by calling moveTo, lineTo or cubicTo.

The customData is passed back through that callback functions and can be used by the user to for instance maintain state information.

Reimplemented from QStrokerOps.

Definition at line 378 of file qstroker_p.h.

Referenced by QDashedStrokeProcessor::process().

379 {
380  if (m_stroker)
381  m_stroker->begin(data);
383 }
static const char * data(const QByteArray &arr)
virtual void begin(void *customData)
Prepares the stroker.
Definition: qstroker.cpp:213
QStroker * m_stroker
Definition: qstroker_p.h:277

◆ dashOffset()

qreal QDashStroker::dashOffset ( ) const
inline

Definition at line 266 of file qstroker_p.h.

266 { return m_dashOffset; }
qreal m_dashOffset
Definition: qstroker_p.h:279

◆ dashPattern()

QVector<qfixed> QDashStroker::dashPattern ( ) const
inline

Definition at line 263 of file qstroker_p.h.

263 { return m_dashPattern; }
QVector< qfixed > m_dashPattern
Definition: qstroker_p.h:278

◆ end()

void QDashStroker::end ( )
inlinevirtual

Finishes the stroke.

Call this function once when an entire primitive has been stroked.

Reimplemented from QStrokerOps.

Definition at line 385 of file qstroker_p.h.

Referenced by QDashedStrokeProcessor::process().

386 {
388  if (m_stroker)
389  m_stroker->end();
390 }
virtual void end()
Finishes the stroke.
Definition: qstroker.cpp:224
QStroker * m_stroker
Definition: qstroker_p.h:277

◆ patternForStyle()

QVector< qfixed > QDashStroker::patternForStyle ( Qt::PenStyle  style)
static

Definition at line 1034 of file qstroker.cpp.

Referenced by QPainterPathStroker::setDashPattern().

1035 {
1036  const qfixed space = 2;
1037  const qfixed dot = 1;
1038  const qfixed dash = 4;
1039 
1040  QVector<qfixed> pattern;
1041 
1042  switch (style) {
1043  case Qt::DashLine:
1044  pattern << dash << space;
1045  break;
1046  case Qt::DotLine:
1047  pattern << dot << space;
1048  break;
1049  case Qt::DashDotLine:
1050  pattern << dash << space << dot << space;
1051  break;
1052  case Qt::DashDotDotLine:
1053  pattern << dash << space << dot << space << dot << space;
1054  break;
1055  default:
1056  break;
1057  }
1058 
1059  return pattern;
1060 }
static qreal dot(const QPointF &a, const QPointF &b)
qreal qfixed
Definition: qstroker_p.h:100

◆ processCurrentSubpath()

void QDashStroker::processCurrentSubpath ( )
protectedvirtual

Implements QStrokerOps.

Definition at line 1104 of file qstroker.cpp.

1105 {
1106  int dashCount = qMin(m_dashPattern.size(), 32);
1107  qfixed dashes[32];
1108 
1109  if (m_stroker) {
1113  }
1114 
1115  qreal longestLength = 0;
1116  qreal sumLength = 0;
1117  for (int i=0; i<dashCount; ++i) {
1118  dashes[i] = qMax(m_dashPattern.at(i), qreal(0)) * m_stroke_width;
1119  sumLength += dashes[i];
1120  if (dashes[i] > longestLength)
1121  longestLength = dashes[i];
1122  }
1123 
1124  if (qFuzzyIsNull(sumLength))
1125  return;
1126 
1127  qreal invSumLength = qreal(1) / sumLength;
1128 
1129  Q_ASSERT(dashCount > 0);
1130 
1131  dashCount = dashCount & -2; // Round down to even number
1132 
1133  int idash = 0; // Index to current dash
1134  qreal pos = 0; // The position on the curve, 0 <= pos <= path.length
1135  qreal elen = 0; // element length
1136  qreal doffset = m_dashOffset * m_stroke_width;
1137 
1138  // make sure doffset is in range [0..sumLength)
1139  doffset -= qFloor(doffset * invSumLength) * sumLength;
1140 
1141  while (doffset >= dashes[idash]) {
1142  doffset -= dashes[idash];
1143  if (++idash >= dashCount)
1144  idash = 0;
1145  }
1146 
1147  qreal estart = 0; // The elements starting position
1148  qreal estop = 0; // The element stop position
1149 
1150  QLineF cline;
1151 
1152  QPainterPath dashPath;
1153 
1155  qfixed2d prev = it.next();
1156 
1157  bool clipping = !m_clip_rect.isEmpty();
1158  qfixed2d move_to_pos = prev;
1159  qfixed2d line_to_pos;
1160 
1161  // Pad to avoid clipping the borders of thick pens.
1162  qfixed padding = qt_real_to_fixed(qMax(m_stroke_width, m_miter_limit) * longestLength);
1163  qfixed2d clip_tl = { qt_real_to_fixed(m_clip_rect.left()) - padding,
1164  qt_real_to_fixed(m_clip_rect.top()) - padding };
1165  qfixed2d clip_br = { qt_real_to_fixed(m_clip_rect.right()) + padding ,
1166  qt_real_to_fixed(m_clip_rect.bottom()) + padding };
1167 
1168  bool hasMoveTo = false;
1169  while (it.hasNext()) {
1170  QStrokerOps::Element e = it.next();
1171 
1172  Q_ASSERT(e.isLineTo());
1173  cline = QLineF(qt_fixed_to_real(prev.x),
1174  qt_fixed_to_real(prev.y),
1175  qt_fixed_to_real(e.x),
1176  qt_fixed_to_real(e.y));
1177  elen = cline.length();
1178 
1179  estop = estart + elen;
1180 
1181  bool done = pos >= estop;
1182 
1183  if (clipping) {
1184  // Check if the entire line can be clipped away.
1185  if (!lineIntersectsRect(prev, e, clip_tl, clip_br)) {
1186  // Cut away full dash sequences.
1187  elen -= qFloor(elen * invSumLength) * sumLength;
1188  // Update dash offset.
1189  while (!done) {
1190  qreal dpos = pos + dashes[idash] - doffset - estart;
1191 
1192  Q_ASSERT(dpos >= 0);
1193 
1194  if (dpos > elen) { // dash extends this line
1195  doffset = dashes[idash] - (dpos - elen); // subtract the part already used
1196  pos = estop; // move pos to next path element
1197  done = true;
1198  } else { // Dash is on this line
1199  pos = dpos + estart;
1200  done = pos >= estop;
1201  if (++idash >= dashCount)
1202  idash = 0;
1203  doffset = 0; // full segment so no offset on next.
1204  }
1205  }
1206  hasMoveTo = false;
1207  move_to_pos = e;
1208  }
1209  }
1210 
1211  // Dash away...
1212  while (!done) {
1213  QPointF p2;
1214 
1215  bool has_offset = doffset > 0;
1216  bool evenDash = (idash & 1) == 0;
1217  qreal dpos = pos + dashes[idash] - doffset - estart;
1218 
1219  Q_ASSERT(dpos >= 0);
1220 
1221  if (dpos > elen) { // dash extends this line
1222  doffset = dashes[idash] - (dpos - elen); // subtract the part already used
1223  pos = estop; // move pos to next path element
1224  done = true;
1225  p2 = cline.p2();
1226  } else { // Dash is on this line
1227  p2 = cline.pointAt(dpos/elen);
1228  pos = dpos + estart;
1229  done = pos >= estop;
1230  if (++idash >= dashCount)
1231  idash = 0;
1232  doffset = 0; // full segment so no offset on next.
1233  }
1234 
1235  if (evenDash) {
1236  line_to_pos.x = qt_real_to_fixed(p2.x());
1237  line_to_pos.y = qt_real_to_fixed(p2.y());
1238 
1239  if (!clipping
1240  || lineRectIntersectsRect(move_to_pos, line_to_pos, clip_tl, clip_br))
1241  {
1242  // If we have an offset, we're continuing a dash
1243  // from a previous element and should only
1244  // continue the current dash, without starting a
1245  // new subpath.
1246  if (!has_offset || !hasMoveTo) {
1247  emitMoveTo(move_to_pos.x, move_to_pos.y);
1248  hasMoveTo = true;
1249  }
1250 
1251  emitLineTo(line_to_pos.x, line_to_pos.y);
1252  } else {
1253  hasMoveTo = false;
1254  }
1255  move_to_pos = line_to_pos;
1256  } else {
1257  move_to_pos.x = qt_real_to_fixed(p2.x());
1258  move_to_pos.y = qt_real_to_fixed(p2.y());
1259  }
1260  }
1261 
1262  // Shuffle to the next cycle...
1263  estart = estop;
1264  prev = e;
1265  }
1266 
1267 }
qfixed strokeWidth() const
Definition: qstroker_p.h:213
QDataBuffer< Element > m_elements
Definition: qstroker_p.h:183
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
#define qt_real_to_fixed(real)
Definition: qstroker_p.h:101
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define it(className, varName)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void emitLineTo(qfixed x, qfixed y)
Definition: qstroker_p.h:296
int qFloor(qreal v)
Definition: qmath.h:73
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
QRectF m_clip_rect
Definition: qstroker_p.h:185
static bool lineIntersectsRect(qfixed2d p1, qfixed2d p2, const qfixed2d &tl, const qfixed2d &br)
Definition: qstroker.cpp:1069
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
bool isLineTo() const
Definition: qstroker_p.h:139
void emitMoveTo(qfixed x, qfixed y)
Definition: qstroker_p.h:290
qreal m_dashOffset
Definition: qstroker_p.h:279
qfixed x
Definition: qstroker_p.h:105
void * m_customData
Definition: qstroker_p.h:189
QVector< qfixed > m_dashPattern
Definition: qstroker_p.h:278
qfixed y
Definition: qstroker_p.h:106
qfixed miterLimit() const
Definition: qstroker_p.h:224
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static bool lineRectIntersectsRect(qfixed2d p1, qfixed2d p2, const qfixed2d &tl, const qfixed2d &br)
Definition: qstroker.cpp:1062
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102
QStroker * m_stroker
Definition: qstroker_p.h:277
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal m_stroke_width
Definition: qstroker_p.h:281
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qfixed m_dashThreshold
Definition: qstroker_p.h:187
qreal m_miter_limit
Definition: qstroker_p.h:282
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
qreal qfixed
Definition: qstroker_p.h:100

◆ setDashOffset()

void QDashStroker::setDashOffset ( qreal  offset)
inline

◆ setDashPattern()

void QDashStroker::setDashPattern ( const QVector< qfixed > &  dashPattern)
inline

Definition at line 262 of file qstroker_p.h.

Referenced by QPainterPathStroker::createStroke(), QDashedStrokeProcessor::process(), and QPdf::Stroker::setPen().

QVector< qfixed > m_dashPattern
Definition: qstroker_p.h:278
QVector< qfixed > dashPattern() const
Definition: qstroker_p.h:263

◆ setMiterLimit()

void QDashStroker::setMiterLimit ( qreal  limit)
inline

Definition at line 272 of file qstroker_p.h.

Referenced by QDashedStrokeProcessor::process().

272 { m_miter_limit = limit; }
qreal m_miter_limit
Definition: qstroker_p.h:282

◆ setStrokeWidth()

void QDashStroker::setStrokeWidth ( qreal  width)
inline

Definition at line 271 of file qstroker_p.h.

Referenced by QDashedStrokeProcessor::process().

271 { m_stroke_width = width; }
qreal m_stroke_width
Definition: qstroker_p.h:281

◆ stroker()

QStroker* QDashStroker::stroker ( ) const
inline

Definition at line 258 of file qstroker_p.h.

258 { return m_stroker; }
QStroker * m_stroker
Definition: qstroker_p.h:277

Properties

◆ m_dashOffset

qreal QDashStroker::m_dashOffset
protected

Definition at line 279 of file qstroker_p.h.

Referenced by processCurrentSubpath().

◆ m_dashPattern

QVector<qfixed> QDashStroker::m_dashPattern
protected

Definition at line 278 of file qstroker_p.h.

Referenced by processCurrentSubpath().

◆ m_miter_limit

qreal QDashStroker::m_miter_limit
protected

Definition at line 282 of file qstroker_p.h.

Referenced by processCurrentSubpath().

◆ m_stroke_width

qreal QDashStroker::m_stroke_width
protected

Definition at line 281 of file qstroker_p.h.

Referenced by processCurrentSubpath().

◆ m_stroker

QStroker* QDashStroker::m_stroker
protected

Definition at line 277 of file qstroker_p.h.

Referenced by processCurrentSubpath(), and QDashStroker().


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