New algorithm for drawing thin lines
[profile/ivi/qtbase.git] / src / gui / painting / qcosmeticstroker_p.h
1 #ifndef QCOSMETICSTROKER_P_H
2 #define QCOSMETICSTROKER_P_H
3
4 #include <private/qdrawhelper_p.h>
5 #include <private/qvectorpath_p.h>
6 #include <private/qpaintengine_raster_p.h>
7 #include <qpen.h>
8
9 class QCosmeticStroker;
10
11
12 typedef void (*StrokeLine)(QCosmeticStroker *stroker, qreal x1, qreal y1, qreal x2, qreal y2, int caps);
13
14 class QCosmeticStroker
15 {
16 public:
17     struct Point {
18         int x;
19         int y;
20     };
21     struct PointF {
22         qreal x;
23         qreal y;
24     };
25
26     enum Caps {
27         NoCaps = 0,
28         CapBegin = 0x1,
29         CapEnd = 0x2,
30     };
31
32     // used to avoid drop outs or duplicated points
33     enum Direction {
34         TopToBottom,
35         BottomToTop,
36         LeftToRight,
37         RightToLeft
38     };
39
40     QCosmeticStroker(QRasterPaintEngineState *s, const QRect &dr)
41         : state(s),
42           clip(dr),
43           pattern(0),
44           reversePattern(0),
45           patternSize(0),
46           patternLength(0),
47           patternOffset(0),
48           current_span(0),
49           lastDir(LeftToRight),
50           lastAxisAligned(false)
51     { setup(); }
52     ~QCosmeticStroker() { free(pattern); free(reversePattern); }
53     void drawLine(const QPointF &p1, const QPointF &p2);
54     void drawPath(const QVectorPath &path);
55     void drawPoints(const QPoint *points, int num);
56     void drawPoints(const QPointF *points, int num);
57
58
59     QRasterPaintEngineState *state;
60     QRect clip;
61     // clip bounds in real
62     qreal xmin, xmax;
63     qreal ymin, ymax;
64
65     StrokeLine stroke;
66     bool drawCaps;
67
68     int *pattern;
69     int *reversePattern;
70     int patternSize;
71     int patternLength;
72     int patternOffset;
73
74     enum { NSPANS = 255 };
75     QT_FT_Span spans[NSPANS];
76     int current_span;
77     ProcessSpans blend;
78
79     int opacity;
80
81     uint color;
82     uint *pixels;
83     int ppl;
84
85     Direction lastDir;
86     Point lastPixel;
87     bool lastAxisAligned;
88
89 private:
90     void setup();
91
92     void renderCubic(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, int caps);
93     void renderCubicSubdivision(PointF *points, int level, int caps);
94     // used for closed subpaths
95     void calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal ry2);
96
97 public:
98     bool clipLine(qreal &x1, qreal &y1, qreal &x2, qreal &y2);
99 };
100
101 #endif // QCOSMETICLINE_H