1/*
2 * Copyright 2006-2018 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stefano Ceccherini, burton666@libero.it
7 *		Julian Harnath, <julian.harnath@rwth-achen.de>
8 *		Stephan A��mus <superstippi@gmx.de>
9 */
10#ifndef _PICTURE_DATA_WRITER_H
11#define _PICTURE_DATA_WRITER_H
12
13
14#include <AffineTransform.h>
15#include <InterfaceDefs.h>
16#include <Font.h>
17#include <OS.h>
18
19#include <stack>
20
21
22class Layer;
23class BGradient;
24class BPositionIO;
25class BRegion;
26
27class PictureDataWriter {
28public:
29								PictureDataWriter();
30								PictureDataWriter(BPositionIO* data);
31	virtual						~PictureDataWriter();
32
33			status_t			SetTo(BPositionIO* data);
34
35			status_t			WriteSetHighColor(const rgb_color& color);
36			status_t			WriteSetLowColor(const rgb_color& color);
37			status_t			WriteSetOrigin(const BPoint& point);
38			status_t			WriteSetDrawingMode(const drawing_mode& mode);
39			status_t			WriteSetPenLocation(const BPoint& point);
40			status_t			WriteSetPenSize(const float& penSize);
41			status_t			WriteSetLineMode(const cap_mode& cap,
42									const join_mode& join,
43									const float& miterLimit);
44			status_t			WriteSetFillRule(int32 fillRule);
45			status_t			WriteSetScale(const float& scale);
46			status_t			WriteSetTransform(BAffineTransform transform);
47			status_t			WriteTranslateBy(double x, double y);
48			status_t			WriteScaleBy(double x, double y);
49			status_t			WriteRotateBy(double angleRadians);
50			status_t			WriteSetPattern(const ::pattern& pattern);
51			status_t			WriteClipToPicture(int32 pictureToken,
52									const BPoint& origin, bool inverse);
53			status_t			WriteSetClipping(const BRegion& region);
54			status_t			WriteClearClipping();
55
56			status_t			WritePushState();
57			status_t			WritePopState();
58
59			status_t			WriteSetFontFamily(const font_family family);
60			status_t			WriteSetFontStyle(const font_style style);
61			status_t			WriteSetFontSpacing(const int32& spacing);
62			status_t			WriteSetFontSize(const float& size);
63			status_t			WriteSetFontRotation(const float& rotation);
64			status_t			WriteSetFontEncoding(const int32& encoding);
65			status_t			WriteSetFontFlags(const int32& flags);
66			status_t			WriteSetFontShear(const float& shear);
67			status_t			WriteSetFontFace(const int32& face);
68
69			status_t			WriteStrokeLine(const BPoint& start,
70									const BPoint& end);
71			status_t			WriteInvertRect(const BRect& rect);
72			status_t			WriteDrawRect(const BRect& rect,
73									const bool& fill);
74			status_t			WriteDrawRoundRect(const BRect& rect,
75									const BPoint& radius, const bool& fill);
76			status_t			WriteDrawEllipse(const BRect& rect,
77									const bool& fill);
78			status_t			WriteDrawArc(const BPoint& center,
79									const BPoint& radius,
80									const float& startTheta,
81									const float& arcTheta, const bool& fill);
82			status_t			WriteDrawPolygon(const int32& numPoints,
83									BPoint* points, const bool& isClosed,
84									const bool& fill);
85			status_t			WriteDrawBezier(const BPoint points[4],
86									const bool& fill);
87			status_t			WriteDrawString(const BPoint& where,
88									const char* string, const int32& length,
89									const escapement_delta& delta);
90			status_t			WriteDrawString(const char* string,
91									int32 length, const BPoint* locations,
92									int32 locationCount);
93			status_t			WriteDrawShape(const int32& opCount,
94									const void* opList, const int32& ptCount,
95									const void* ptList, const bool& fill);
96			status_t			WriteDrawRectGradient(const BRect& rect, const BGradient& gradient,
97									const bool& fill);
98			status_t			WriteDrawRoundRectGradient(const BRect& rect,
99									const BPoint& radius, const BGradient& gradient, const bool& fill);
100			status_t			WriteDrawBezierGradient(const BPoint points[4], const BGradient& gradient,
101									const bool& fill);
102			status_t			WriteDrawArcGradient(const BPoint& center,
103									const BPoint& radius,
104									const float& startTheta,
105									const float& arcTheta, const BGradient& gradient, const bool& fill);
106			status_t			WriteDrawEllipseGradient(const BRect& rect, const BGradient& gradient,
107									const bool& fill);
108			status_t			WriteDrawPolygonGradient(const int32& numPoints,
109									BPoint* points, const bool& isClosed, const BGradient& gradient,
110									const bool& fill);
111			status_t			WriteDrawShapeGradient(const int32& opCount,
112									const void* opList, const int32& ptCount,
113									const void* ptList, const BGradient& gradient, const bool& fill);
114			status_t			WriteDrawBitmap(const BRect& srcRect,
115									const BRect& dstRect, const int32& width,
116									const int32& height,
117									const int32& bytesPerRow,
118									const int32& colorSpace,
119									const int32& flags,
120									const void* data, const int32& length);
121
122			status_t			WriteDrawPicture(const BPoint& where,
123									const int32& token);
124
125			status_t			WriteBlendLayer(Layer* layer);
126			status_t			WriteClipToRect(const BRect& rect,
127									bool inverse);
128			status_t			WriteClipToShape(int32 opCount,
129									const void* opList, int32 ptCount,
130									const void* ptList, bool inverse);
131
132protected:
133	// throw a status_t on error
134			void				BeginOp(const int16& op);
135			void				EndOp();
136			void				WriteData(const void* data, size_t size);
137	template <typename T> void	Write(const T& data)
138									{ WriteData(&data, sizeof(data)); }
139
140private:
141			BPositionIO*		fData;
142			std::stack<off_t>	fStack;
143};
144
145
146#endif // _PICTURE_DATA_WRITER_H
147