/src/wt/src/Wt/WVmlImage.h
Line | Count | Source |
1 | | // This may look like C code, but it's really -*- C++ -*- |
2 | | /* |
3 | | * Copyright (C) 2008 Emweb bv, Herent, Belgium. |
4 | | * |
5 | | * See the LICENSE file for terms of use. |
6 | | */ |
7 | | #ifndef WVML_IMAGE_H_ |
8 | | #define WVML_IMAGE_H_ |
9 | | |
10 | | #include <Wt/WBrush.h> |
11 | | #include <Wt/WPen.h> |
12 | | #include <Wt/WRectF.h> |
13 | | #include <Wt/WShadow.h> |
14 | | #include <Wt/WTransform.h> |
15 | | #include <Wt/WVectorImage.h> |
16 | | #include <Wt/WResource.h> |
17 | | |
18 | | #include <sstream> |
19 | | |
20 | | namespace Wt { |
21 | | |
22 | | /*! \class WVmlImage Wt/WVmlImage.h Wt/WVmlImage.h |
23 | | * \brief A paint device for rendering using the VML pseudo-standard. |
24 | | * |
25 | | * The %WVmlImage is used by WPaintedWidget to render to the browser |
26 | | * using the Vector Markup Language (VML) (to support graphics on |
27 | | * Internet Explorer browsers). |
28 | | * |
29 | | * \note The current implementation has only limited support for |
30 | | * clipping: only rectangular areas aligned with the X/Y axes can be used |
31 | | * as clipping path. |
32 | | * |
33 | | * \note To paint an image (WPainter::drawImage()), this requires its |
34 | | * URI. |
35 | | * |
36 | | * \sa WAbstractDataInfo |
37 | | * |
38 | | * \ingroup painting |
39 | | */ |
40 | | class WT_API WVmlImage : public WVectorImage |
41 | | { |
42 | | public: |
43 | | /*! \brief Create a VML paint device. |
44 | | * |
45 | | * If \p paintUpdate is \c true, then only a VML fragment will be |
46 | | * rendered that can be used to update the DOM of an existing VML |
47 | | * image, instead of a full VML image. |
48 | | */ |
49 | | WVmlImage(const WLength& width, const WLength& height, bool paintUpdate); |
50 | | virtual ~WVmlImage(); |
51 | | |
52 | | virtual WFlags<PaintDeviceFeatureFlag> features() const override; |
53 | | virtual void setChanged(WFlags<PainterChangeFlag> flags) override; |
54 | | virtual void drawArc(const WRectF& rect, double startAngle, double spanAngle) override; |
55 | | WT_DEPRECATED("Use drawImage() with WAbstractDataInfo* instead of a string") |
56 | | virtual void drawImage(const WRectF& rect, const std::string& imgUri, |
57 | | int imgWidth, int imgHeight, const WRectF& sourceRect) override; |
58 | | virtual void drawImage(const WRectF& rect, const WAbstractDataInfo* info, |
59 | | int imgWidth, int imgHeight, const WRectF& sourceRect) override; |
60 | | virtual void drawLine(double x1, double y1, double x2, double y2) override; |
61 | | virtual void drawRect(const WRectF& rectangle) override; |
62 | | virtual void drawPath(const WPainterPath& path) override; |
63 | | virtual void drawText(const WRectF& rect, |
64 | | WFlags<AlignmentFlag> alignmentFlags, |
65 | | TextFlag textFlag, |
66 | | const WString& text, |
67 | | const WPointF *clipPoint) override; |
68 | | virtual WTextItem measureText(const WString& text, double maxWidth = -1, |
69 | | bool wordWrap = false) override; |
70 | | virtual WFontMetrics fontMetrics() override; |
71 | | virtual void init() override; |
72 | | virtual void done() override; |
73 | 0 | virtual bool paintActive() const override { return painter_ != nullptr; } |
74 | | |
75 | | virtual std::string rendered() override; |
76 | | |
77 | 0 | virtual WLength width() const override { return width_; } |
78 | 0 | virtual WLength height() const override { return height_; } |
79 | | |
80 | | protected: |
81 | 0 | virtual WPainter *painter() const override { return painter_; } |
82 | 0 | virtual void setPainter(WPainter *painter) override { painter_ = painter; } |
83 | | |
84 | | private: |
85 | | WLength width_, height_; |
86 | | WPainter *painter_; |
87 | | bool paintUpdate_; |
88 | | |
89 | | bool penBrushShadowChanged_; |
90 | | bool clippingChanged_; |
91 | | |
92 | | WBrush currentBrush_; |
93 | | WPen currentPen_; |
94 | | WShadow currentShadow_; |
95 | | |
96 | | struct ActivePath { |
97 | | std::string path; |
98 | | WRectF bbox; |
99 | | |
100 | | ActivePath() |
101 | 0 | : bbox(0, 0, 0, 0) |
102 | 0 | { } |
103 | | }; |
104 | | |
105 | | std::vector<ActivePath> activePaths_; |
106 | | |
107 | | std::stringstream rendered_; |
108 | | |
109 | | void finishPaths(); |
110 | | void processClipping(); |
111 | | std::string fillElement(const WBrush& brush) const; |
112 | | std::string strokeElement(const WPen& pen) const; |
113 | | std::string skewElement(const WTransform& transform) const; |
114 | | std::string shadowElement(const WShadow& shadow) const; |
115 | | std::string createShadowFilter() const; |
116 | | |
117 | | static std::string colorAttributes(const WColor& color); |
118 | | static std::string quote(double s); |
119 | | static std::string quote(const std::string& s); |
120 | | |
121 | | void startClip(const WRectF& rect); |
122 | | void stopClip(); |
123 | | |
124 | | void doDrawImage(const WRectF& rect, const WAbstractDataInfo* info, |
125 | | int imgWidth, int imgHeight, const WRectF& sourceRect); |
126 | | |
127 | | WRectF currentRect_; |
128 | | }; |
129 | | |
130 | | } |
131 | | |
132 | | #endif // WVML_IMAGE_H_ |