1/*
2
3DrawShape
4
5Copyright (c) 2002 OpenBeOS.
6
7Author:
8	Michael Pfeiffer
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to
13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14of the Software, and to permit persons to whom the Software is furnished to do
15so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27
28*/
29
30#ifndef DRAW_SHAPE_H
31#define DRAW_SHAPE_H
32
33#include "PDFWriter.h"
34
35class DrawShape : public BShapeIterator
36{
37	PDFWriter *fWriter;
38	bool       fStroke;
39	bool       fDrawn;
40	BPoint     fCurrentPoint;
41	SubPath    fSubPath;
42
43	inline FILE *Log()			{ return fWriter->fLog; }
44	inline PDF *Pdf()			{ return fWriter->fPdf; }
45	inline float tx(float x)	{ return fWriter->tx(x); }
46	inline float ty(float y)	{ return fWriter->ty(y); }
47	inline float scale(float f) { return fWriter->scale(f); }
48
49	inline bool IsDrawing() const  { return fWriter->IsDrawing(); }
50	inline bool IsClipping() const { return fWriter->IsClipping(); }
51
52	inline bool IsStroking() const { return fStroke; }
53	inline bool IsFilling() const  { return !fStroke; }
54
55	inline float PenSize() const { return fWriter->PenSize(); }
56	inline bool TransformPath() const { return IsStroking() && IsClipping(); }
57
58	enum {
59		kMinBezierPoints = 2, // must be greater or equal to 2
60		kMaxBezierPoints = 30
61	};
62
63	float BezierLength(BPoint *p, int n);
64	int   BezierPoints(BPoint *p, int n);
65	void  CreateBezierPath(BPoint *p);
66	void  EndSubPath();
67
68public:
69	DrawShape(PDFWriter *writer, bool stroke);
70	~DrawShape();
71	status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPoints);
72	status_t IterateClose(void);
73	status_t IterateLineTo(int32 lineCount, BPoint *linePoints);
74	status_t IterateMoveTo(BPoint *point);
75
76	void Draw();
77};
78
79#endif
80