1 enum { 2 PAINTING_CLEAR, 3 4 PAINTING_MOVE = 4, 5 PAINTING_MOVE_REL, 6 PAINTING_LINE, 7 PAINTING_LINE_REL, 8 PAINTING_QUADRATIC, 9 PAINTING_QUADRATIC_REL, 10 PAINTING_QUADRATIC_S, 11 PAINTING_QUADRATIC_S_REL, 12 PAINTING_CUBIC, 13 PAINTING_CUBIC_REL, 14 PAINTING_CUBIC_S, 15 PAINTING_CUBIC_S_REL, 16 PAINTING_ARC, 17 PAINTING_ARC_REL, 18 PAINTING_SVGARC, 19 PAINTING_SVGARC_REL, 20 PAINTING_CLOSE, 21 PAINTING_DIV, 22 23 PAINTING_FILL_SOLID, 24 PAINTING_FILL_IMAGE, 25 PAINTING_FILL_GRADIENT, 26 PAINTING_FILL_RADIAL, 27 28 PAINTING_STROKE_SOLID, 29 PAINTING_STROKE_IMAGE, 30 PAINTING_STROKE_GRADIENT, 31 PAINTING_STROKE_RADIAL, 32 33 PAINTING_CLIP, 34 35 PAINTING_CHARACTER, 36 PAINTING_TEXT, 37 38 PAINTING_COLORSTOP, 39 PAINTING_CLEARSTOPS, 40 PAINTING_OPACITY, 41 PAINTING_LINECAP, 42 PAINTING_LINEJOIN, 43 PAINTING_MITERLIMIT, 44 PAINTING_EVENODD, 45 PAINTING_DASH, 46 47 PAINTING_TRANSFORM, 48 PAINTING_BEGIN, 49 PAINTING_END, 50 PAINTING_BEGINMASK, 51 PAINTING_BEGINONPATH, 52 53 PAINTING_INVERT, 54 55 PAINTING_FILL_GRADIENT_X, 56 PAINTING_STROKE_GRADIENT_X, 57 58 PAINTING_FILL_RADIAL_X, 59 PAINTING_STROKE_RADIAL_X, 60 }; 61 62 class PaintingPainter : public Painter { 63 StringStream cmd; 64 ValueArray data; 65 Sizef size; 66 Put(int c)67 void Put(int c) { cmd.Put(c); } Put32(int c)68 void Put32(int c) { cmd.Put32(c); } Put(const RGBA & c)69 void Put(const RGBA& c) { cmd.Put(&c, sizeof(RGBA)); } Putf(const double & d)70 void Putf(const double& d) { ASSERT(!IsNaN(d)); cmd.Put(&d, sizeof(double)); } Putf(const Pointf & p)71 void Putf(const Pointf& p) { ASSERT(!IsNaN(p.x) && !IsNaN(p.y)); cmd.Put(&p, sizeof(p)); } Putf(const Xform2D & m)72 void Putf(const Xform2D& m) { cmd.Put(&m, sizeof(m)); } Put(const Font & f)73 void Put(const Font& f) { cmd.Put(&f, sizeof(Font)); } 74 75 protected: 76 virtual void ClearOp(const RGBA& color); 77 78 virtual void MoveOp(const Pointf& p, bool rel); 79 virtual void LineOp(const Pointf& p, bool rel); 80 virtual void QuadraticOp(const Pointf& p1, const Pointf& p, bool rel); 81 virtual void QuadraticOp(const Pointf& p, bool rel); 82 virtual void CubicOp(const Pointf& p1, const Pointf& p2, const Pointf& p, bool rel); 83 virtual void CubicOp(const Pointf& p2, const Pointf& p, bool rel); 84 virtual void ArcOp(const Pointf& c, const Pointf& r, double angle, double sweep, bool rel); 85 virtual void SvgArcOp(const Pointf& r, double xangle, bool large, bool sweep, 86 const Pointf& p, bool rel); 87 virtual void CloseOp(); 88 virtual void DivOp(); 89 90 virtual void FillOp(const RGBA& color); 91 virtual void FillOp(const Image& image, const Xform2D& transsrc, dword flags); 92 virtual void FillOp(const Pointf& p1, const RGBA& color1, 93 const Pointf& p2, const RGBA& color2, 94 int style); 95 virtual void FillOp(const RGBA& color1, const RGBA& color2, const Xform2D& transsrc, 96 int style); 97 virtual void FillOp(const Pointf& f, const RGBA& color1, 98 const Pointf& c, double r, const RGBA& color2, 99 int style); 100 virtual void FillOp(const Pointf& f, const RGBA& color1, const RGBA& color2, 101 const Xform2D& transsrc, int style); 102 103 virtual void StrokeOp(double width, const RGBA& rgba); 104 virtual void StrokeOp(double width, const Image& image, const Xform2D& transsrc, 105 dword flags); 106 virtual void StrokeOp(double width, const Pointf& p1, const RGBA& color1, 107 const Pointf& p2, const RGBA& color2, 108 int style); 109 virtual void StrokeOp(double width, const RGBA& color1, const RGBA& color2, 110 const Xform2D& transsrc, int style); 111 virtual void StrokeOp(double width, const Pointf& f, const RGBA& color1, 112 const Pointf& c, double r, const RGBA& color2, 113 int style); 114 virtual void StrokeOp(double width, const Pointf& f, 115 const RGBA& color1, const RGBA& color2, 116 const Xform2D& transsrc, int style); 117 118 virtual void ClipOp(); 119 120 virtual void CharacterOp(const Pointf& p, int ch, Font fnt); 121 virtual void TextOp(const Pointf& p, const wchar *text, Font fnt, int n = -1, 122 const double *dx = NULL); 123 124 virtual void ColorStopOp(double pos, const RGBA& color); 125 virtual void ClearStopsOp(); 126 127 virtual void OpacityOp(double o); 128 virtual void LineCapOp(int linecap); 129 virtual void LineJoinOp(int linejoin); 130 virtual void MiterLimitOp(double l); 131 virtual void EvenOddOp(bool evenodd); 132 virtual void DashOp(const Vector<double>& dash, double start); 133 virtual void InvertOp(bool invert); 134 135 virtual void TransformOp(const Xform2D& m); 136 137 virtual void BeginOp(); 138 virtual void EndOp(); 139 140 virtual void BeginMaskOp(); 141 virtual void BeginOnPathOp(double q, bool abs); 142 143 public: 144 Painting GetResult(); Painting()145 operator Painting() { return GetResult(); } 146 147 void Create(double cx, double cy); 148 void Create(Sizef sz); 149 GetSize()150 Sizef GetSize() const { return size; } 151 PaintingPainter()152 PaintingPainter() {} PaintingPainter(double cx,double cy)153 PaintingPainter(double cx, double cy) { Create(cx, cy); } PaintingPainter(Sizef sz)154 PaintingPainter(Sizef sz) { Create(sz); } 155 }; 156