xref: /haiku/src/kits/print/PictureIterator.cpp (revision 268f99dd7dc4bd7474a8bd2742d3f1ec1de6752a)
112fd6cc2SKarsten Heimrich /*
212fd6cc2SKarsten Heimrich 
312fd6cc2SKarsten Heimrich PictureIterator
412fd6cc2SKarsten Heimrich 
5*2ca13760SColdfirex Copyright (c) 2001, 2002 Haiku.
612fd6cc2SKarsten Heimrich 
712fd6cc2SKarsten Heimrich Authors:
812fd6cc2SKarsten Heimrich 	Philippe Houdoin
912fd6cc2SKarsten Heimrich 	Simon Gauvin
1012fd6cc2SKarsten Heimrich 	Michael Pfeiffer
1112fd6cc2SKarsten Heimrich 
1212fd6cc2SKarsten Heimrich Permission is hereby granted, free of charge, to any person obtaining a copy of
1312fd6cc2SKarsten Heimrich this software and associated documentation files (the "Software"), to deal in
1412fd6cc2SKarsten Heimrich the Software without restriction, including without limitation the rights to
1512fd6cc2SKarsten Heimrich use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1612fd6cc2SKarsten Heimrich of the Software, and to permit persons to whom the Software is furnished to do
1712fd6cc2SKarsten Heimrich so, subject to the following conditions:
1812fd6cc2SKarsten Heimrich 
1912fd6cc2SKarsten Heimrich The above copyright notice and this permission notice shall be included in all
2012fd6cc2SKarsten Heimrich copies or substantial portions of the Software.
2112fd6cc2SKarsten Heimrich 
2212fd6cc2SKarsten Heimrich THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2312fd6cc2SKarsten Heimrich IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2412fd6cc2SKarsten Heimrich FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2512fd6cc2SKarsten Heimrich AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2612fd6cc2SKarsten Heimrich LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2712fd6cc2SKarsten Heimrich OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2812fd6cc2SKarsten Heimrich THE SOFTWARE.
2912fd6cc2SKarsten Heimrich 
3012fd6cc2SKarsten Heimrich */
3112fd6cc2SKarsten Heimrich 
3212fd6cc2SKarsten Heimrich #include "PictureIterator.h"
3312fd6cc2SKarsten Heimrich 
3412fd6cc2SKarsten Heimrich // BPicture playback handlers class instance redirectors
_MovePenBy(void * p,BPoint delta)3512fd6cc2SKarsten Heimrich static void	_MovePenBy(void *p, BPoint delta) 														{ return ((PictureIterator *) p)->MovePenBy(delta); }
_StrokeLine(void * p,BPoint start,BPoint end)3612fd6cc2SKarsten Heimrich static void	_StrokeLine(void *p, BPoint start, BPoint end) 											{ return ((PictureIterator *) p)->StrokeLine(start, end); }
_StrokeRect(void * p,BRect rect)3712fd6cc2SKarsten Heimrich static void	_StrokeRect(void *p, BRect rect) 														{ return ((PictureIterator *) p)->StrokeRect(rect); }
_FillRect(void * p,BRect rect)3812fd6cc2SKarsten Heimrich static void	_FillRect(void *p, BRect rect) 															{ return ((PictureIterator *) p)->FillRect(rect); }
_StrokeRoundRect(void * p,BRect rect,BPoint radii)3912fd6cc2SKarsten Heimrich static void	_StrokeRoundRect(void *p, BRect rect, BPoint radii) 									{ return ((PictureIterator *) p)->StrokeRoundRect(rect, radii); }
_FillRoundRect(void * p,BRect rect,BPoint radii)4012fd6cc2SKarsten Heimrich static void	_FillRoundRect(void *p, BRect rect, BPoint radii)  										{ return ((PictureIterator *) p)->FillRoundRect(rect, radii); }
_StrokeBezier(void * p,BPoint * control)4112fd6cc2SKarsten Heimrich static void	_StrokeBezier(void *p, BPoint *control)  												{ return ((PictureIterator *) p)->StrokeBezier(control); }
_FillBezier(void * p,BPoint * control)4212fd6cc2SKarsten Heimrich static void	_FillBezier(void *p, BPoint *control)  													{ return ((PictureIterator *) p)->FillBezier(control); }
_StrokeArc(void * p,BPoint center,BPoint radii,float startTheta,float arcTheta)4312fd6cc2SKarsten Heimrich static void	_StrokeArc(void *p, BPoint center, BPoint radii, float startTheta, float arcTheta)		{ return ((PictureIterator *) p)->StrokeArc(center, radii, startTheta, arcTheta); }
_FillArc(void * p,BPoint center,BPoint radii,float startTheta,float arcTheta)4412fd6cc2SKarsten Heimrich static void	_FillArc(void *p, BPoint center, BPoint radii, float startTheta, float arcTheta)		{ return ((PictureIterator *) p)->FillArc(center, radii, startTheta, arcTheta); }
_StrokeEllipse(void * p,BPoint center,BPoint radii)4512fd6cc2SKarsten Heimrich static void	_StrokeEllipse(void *p, BPoint center, BPoint radii)									{ return ((PictureIterator *) p)->StrokeEllipse(center, radii); }
_FillEllipse(void * p,BPoint center,BPoint radii)4612fd6cc2SKarsten Heimrich static void	_FillEllipse(void *p, BPoint center, BPoint radii)										{ return ((PictureIterator *) p)->FillEllipse(center, radii); }
_StrokePolygon(void * p,int32 numPoints,BPoint * points,bool isClosed)4712fd6cc2SKarsten Heimrich static void	_StrokePolygon(void *p, int32 numPoints, BPoint *points, bool isClosed) 				{ return ((PictureIterator *) p)->StrokePolygon(numPoints, points, isClosed); }
_FillPolygon(void * p,int32 numPoints,BPoint * points,bool isClosed)4812fd6cc2SKarsten Heimrich static void	_FillPolygon(void *p, int32 numPoints, BPoint *points, bool isClosed)					{ return ((PictureIterator *) p)->FillPolygon(numPoints, points, isClosed); }
_StrokeShape(void * p,BShape * shape)4912fd6cc2SKarsten Heimrich static void	_StrokeShape(void * p, BShape *shape)													{ return ((PictureIterator *) p)->StrokeShape(shape); }
_FillShape(void * p,BShape * shape)5012fd6cc2SKarsten Heimrich static void	_FillShape(void * p, BShape *shape)														{ return ((PictureIterator *) p)->FillShape(shape); }
_DrawString(void * p,char * string,float deltax,float deltay)5112fd6cc2SKarsten Heimrich static void	_DrawString(void *p, char *string, float deltax, float deltay)							{ return ((PictureIterator *) p)->DrawString(string, deltax, deltay); }
_DrawPixels(void * p,BRect src,BRect dest,int32 width,int32 height,int32 bytesPerRow,int32 pixelFormat,int32 flags,void * data)5212fd6cc2SKarsten Heimrich static void	_DrawPixels(void *p, BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data)
5312fd6cc2SKarsten Heimrich 						{ return ((PictureIterator *) p)->DrawPixels(src, dest, width, height, bytesPerRow, pixelFormat, flags, data); }
_SetClippingRects(void * p,BRect * rects,uint32 numRects)5412fd6cc2SKarsten Heimrich static void	_SetClippingRects(void *p, BRect *rects, uint32 numRects)								{ return ((PictureIterator *) p)->SetClippingRects(rects, numRects); }
_ClipToPicture(void * p,BPicture * picture,BPoint point,bool clip_to_inverse_picture)5512fd6cc2SKarsten Heimrich static void	_ClipToPicture(void * p, BPicture *picture, BPoint point, bool clip_to_inverse_picture)	{ return ((PictureIterator *) p)->ClipToPicture(picture, point, clip_to_inverse_picture); }
_PushState(void * p)5612fd6cc2SKarsten Heimrich static void	_PushState(void *p)  																	{ return ((PictureIterator *) p)->PushState(); }
_PopState(void * p)5712fd6cc2SKarsten Heimrich static void	_PopState(void *p)  																	{ return ((PictureIterator *) p)->PopState(); }
_EnterStateChange(void * p)5812fd6cc2SKarsten Heimrich static void	_EnterStateChange(void *p) 																{ return ((PictureIterator *) p)->EnterStateChange(); }
_ExitStateChange(void * p)5912fd6cc2SKarsten Heimrich static void	_ExitStateChange(void *p) 																{ return ((PictureIterator *) p)->ExitStateChange(); }
_EnterFontState(void * p)6012fd6cc2SKarsten Heimrich static void	_EnterFontState(void *p) 																{ return ((PictureIterator *) p)->EnterFontState(); }
_ExitFontState(void * p)6112fd6cc2SKarsten Heimrich static void	_ExitFontState(void *p) 																{ return ((PictureIterator *) p)->ExitFontState(); }
_SetOrigin(void * p,BPoint pt)6212fd6cc2SKarsten Heimrich static void	_SetOrigin(void *p, BPoint pt)															{ return ((PictureIterator *) p)->SetOrigin(pt); }
_SetPenLocation(void * p,BPoint pt)6312fd6cc2SKarsten Heimrich static void	_SetPenLocation(void *p, BPoint pt)														{ return ((PictureIterator *) p)->SetPenLocation(pt); }
_SetDrawingMode(void * p,drawing_mode mode)6412fd6cc2SKarsten Heimrich static void	_SetDrawingMode(void *p, drawing_mode mode)												{ return ((PictureIterator *) p)->SetDrawingMode(mode); }
_SetLineMode(void * p,cap_mode capMode,join_mode joinMode,float miterLimit)6512fd6cc2SKarsten Heimrich static void	_SetLineMode(void *p, cap_mode capMode, join_mode joinMode, float miterLimit)			{ return ((PictureIterator *) p)->SetLineMode(capMode, joinMode, miterLimit); }
_SetPenSize(void * p,float size)6612fd6cc2SKarsten Heimrich static void	_SetPenSize(void *p, float size)														{ return ((PictureIterator *) p)->SetPenSize(size); }
_SetForeColor(void * p,rgb_color color)6712fd6cc2SKarsten Heimrich static void	_SetForeColor(void *p, rgb_color color)													{ return ((PictureIterator *) p)->SetForeColor(color); }
_SetBackColor(void * p,rgb_color color)6812fd6cc2SKarsten Heimrich static void	_SetBackColor(void *p, rgb_color color)													{ return ((PictureIterator *) p)->SetBackColor(color); }
_SetStipplePattern(void * p,pattern pat)6912fd6cc2SKarsten Heimrich static void	_SetStipplePattern(void *p, pattern pat)												{ return ((PictureIterator *) p)->SetStipplePattern(pat); }
_SetScale(void * p,float scale)7012fd6cc2SKarsten Heimrich static void	_SetScale(void *p, float scale)															{ return ((PictureIterator *) p)->SetScale(scale); }
_SetFontFamily(void * p,char * family)7112fd6cc2SKarsten Heimrich static void	_SetFontFamily(void *p, char *family)													{ return ((PictureIterator *) p)->SetFontFamily(family); }
_SetFontStyle(void * p,char * style)7212fd6cc2SKarsten Heimrich static void	_SetFontStyle(void *p, char *style)														{ return ((PictureIterator *) p)->SetFontStyle(style); }
_SetFontSpacing(void * p,int32 spacing)7312fd6cc2SKarsten Heimrich static void	_SetFontSpacing(void *p, int32 spacing)													{ return ((PictureIterator *) p)->SetFontSpacing(spacing); }
_SetFontSize(void * p,float size)7412fd6cc2SKarsten Heimrich static void	_SetFontSize(void *p, float size)														{ return ((PictureIterator *) p)->SetFontSize(size); }
_SetFontRotate(void * p,float rotation)7512fd6cc2SKarsten Heimrich static void	_SetFontRotate(void *p, float rotation)													{ return ((PictureIterator *) p)->SetFontRotate(rotation); }
_SetFontEncoding(void * p,int32 encoding)7612fd6cc2SKarsten Heimrich static void	_SetFontEncoding(void *p, int32 encoding)												{ return ((PictureIterator *) p)->SetFontEncoding(encoding); }
_SetFontFlags(void * p,int32 flags)7712fd6cc2SKarsten Heimrich static void	_SetFontFlags(void *p, int32 flags)														{ return ((PictureIterator *) p)->SetFontFlags(flags); }
_SetFontShear(void * p,float shear)7812fd6cc2SKarsten Heimrich static void	_SetFontShear(void *p, float shear)														{ return ((PictureIterator *) p)->SetFontShear(shear); }
_SetFontFace(void * p,int32 flags)7912fd6cc2SKarsten Heimrich static void	_SetFontFace(void * p, int32 flags)														{ return ((PictureIterator *) p)->SetFontFace(flags); }
8012fd6cc2SKarsten Heimrich 
8112fd6cc2SKarsten Heimrich // undefined or undocumented operation handlers...
_op0(void * p)8212fd6cc2SKarsten Heimrich static void	_op0(void * p)	{ return ((PictureIterator *) p)->Op(0); }
_op19(void * p)8312fd6cc2SKarsten Heimrich static void	_op19(void * p)	{ return ((PictureIterator *) p)->Op(19); }
_op45(void * p)8412fd6cc2SKarsten Heimrich static void	_op45(void * p)	{ return ((PictureIterator *) p)->Op(45); }
_op47(void * p)8512fd6cc2SKarsten Heimrich static void	_op47(void * p)	{ return ((PictureIterator *) p)->Op(47); }
_op48(void * p)8612fd6cc2SKarsten Heimrich static void	_op48(void * p)	{ return ((PictureIterator *) p)->Op(48); }
_op49(void * p)8712fd6cc2SKarsten Heimrich static void	_op49(void * p)	{ return ((PictureIterator *) p)->Op(49); }
8812fd6cc2SKarsten Heimrich 
8912fd6cc2SKarsten Heimrich // Private Variables
9012fd6cc2SKarsten Heimrich // -----------------
9112fd6cc2SKarsten Heimrich 
9212fd6cc2SKarsten Heimrich static void *
9312fd6cc2SKarsten Heimrich playbackHandlers[] = {
9412fd6cc2SKarsten Heimrich 		(void *)_op0,					// 0	no operation
9512fd6cc2SKarsten Heimrich 		(void *)_MovePenBy,				// 1	MovePenBy(void *user, BPoint delta)
9612fd6cc2SKarsten Heimrich 		(void *)_StrokeLine,			// 2	StrokeLine(void *user, BPoint start, BPoint end)
9712fd6cc2SKarsten Heimrich 		(void *)_StrokeRect,			// 3	StrokeRect(void *user, BRect rect)
9812fd6cc2SKarsten Heimrich 		(void *)_FillRect,				// 4	FillRect(void *user, BRect rect)
9912fd6cc2SKarsten Heimrich 		(void *)_StrokeRoundRect,		// 5	StrokeRoundRect(void *user, BRect rect, BPoint radii)
10012fd6cc2SKarsten Heimrich 		(void *)_FillRoundRect,			// 6	FillRoundRect(void *user, BRect rect, BPoint radii)
10112fd6cc2SKarsten Heimrich 		(void *)_StrokeBezier,			// 7	StrokeBezier(void *user, BPoint *control)
10212fd6cc2SKarsten Heimrich 		(void *)_FillBezier,			// 8	FillBezier(void *user, BPoint *control)
10312fd6cc2SKarsten Heimrich 		(void *)_StrokeArc,				// 9	StrokeArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta)
10412fd6cc2SKarsten Heimrich 		(void *)_FillArc,				// 10	FillArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta)
10512fd6cc2SKarsten Heimrich 		(void *)_StrokeEllipse,			// 11	StrokeEllipse(void *user, BPoint center, BPoint radii)
10612fd6cc2SKarsten Heimrich 		(void *)_FillEllipse,			// 12	FillEllipse(void *user, BPoint center, BPoint radii)
10712fd6cc2SKarsten Heimrich 		(void *)_StrokePolygon,			// 13	StrokePolygon(void *user, int32 numPoints, BPoint *points, bool isClosed)
10812fd6cc2SKarsten Heimrich 		(void *)_FillPolygon,			// 14	FillPolygon(void *user, int32 numPoints, BPoint *points, bool isClosed)
10912fd6cc2SKarsten Heimrich 		(void *)_StrokeShape,			// 15	StrokeShape(void *user, BShape *shape)
11012fd6cc2SKarsten Heimrich 		(void *)_FillShape,				// 16	FillShape(void *user, BShape *shape)
11112fd6cc2SKarsten Heimrich 		(void *)_DrawString,			// 17	DrawString(void *user, char *string, float deltax, float deltay)
11212fd6cc2SKarsten Heimrich 		(void *)_DrawPixels,			// 18	DrawPixels(void *user, BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data)
11312fd6cc2SKarsten Heimrich 		(void *)_op19,					// 19	*reserved*
11412fd6cc2SKarsten Heimrich 		(void *)_SetClippingRects,		// 20	SetClippingRects(void *user, BRect *rects, uint32 numRects)
11512fd6cc2SKarsten Heimrich 		(void *)_ClipToPicture,			// 21	ClipToPicture(void *user, BPicture *picture, BPoint pt, bool clip_to_inverse_picture)
11612fd6cc2SKarsten Heimrich 		(void *)_PushState,				// 22	PushState(void *user)
11712fd6cc2SKarsten Heimrich 		(void *)_PopState,				// 23	PopState(void *user)
11812fd6cc2SKarsten Heimrich 		(void *)_EnterStateChange,		// 24	EnterStateChange(void *user)
11912fd6cc2SKarsten Heimrich 		(void *)_ExitStateChange,		// 25	ExitStateChange(void *user)
12012fd6cc2SKarsten Heimrich 		(void *)_EnterFontState,		// 26	EnterFontState(void *user)
12112fd6cc2SKarsten Heimrich 		(void *)_ExitFontState,			// 27	ExitFontState(void *user)
12212fd6cc2SKarsten Heimrich 		(void *)_SetOrigin,				// 28	SetOrigin(void *user, BPoint pt)
12312fd6cc2SKarsten Heimrich 		(void *)_SetPenLocation,		// 29	SetPenLocation(void *user, BPoint pt)
12412fd6cc2SKarsten Heimrich 		(void *)_SetDrawingMode,		// 30	SetDrawingMode(void *user, drawing_mode mode)
12512fd6cc2SKarsten Heimrich 		(void *)_SetLineMode,			// 31	SetLineMode(void *user, cap_mode capMode, join_mode joinMode, float miterLimit)
12612fd6cc2SKarsten Heimrich 		(void *)_SetPenSize,			// 32	SetPenSize(void *user, float size)
12712fd6cc2SKarsten Heimrich 		(void *)_SetForeColor,			// 33	SetForeColor(void *user, rgb_color color)
12812fd6cc2SKarsten Heimrich 		(void *)_SetBackColor,			// 34	SetBackColor(void *user, rgb_color color)
12912fd6cc2SKarsten Heimrich 		(void *)_SetStipplePattern,		// 35	SetStipplePattern(void *user, pattern p)
13012fd6cc2SKarsten Heimrich 		(void *)_SetScale,				// 36	SetScale(void *user, float scale)
13112fd6cc2SKarsten Heimrich 		(void *)_SetFontFamily,			// 37	SetFontFamily(void *user, char *family)
13212fd6cc2SKarsten Heimrich 		(void *)_SetFontStyle,			// 38	SetFontStyle(void *user, char *style)
13312fd6cc2SKarsten Heimrich 		(void *)_SetFontSpacing,		// 39	SetFontSpacing(void *user, int32 spacing)
13412fd6cc2SKarsten Heimrich 		(void *)_SetFontSize,			// 40	SetFontSize(void *user, float size)
13512fd6cc2SKarsten Heimrich 		(void *)_SetFontRotate,			// 41	SetFontRotate(void *user, float rotation)
13612fd6cc2SKarsten Heimrich 		(void *)_SetFontEncoding,		// 42	SetFontEncoding(void *user, int32 encoding)
13712fd6cc2SKarsten Heimrich 		(void *)_SetFontFlags,			// 43	SetFontFlags(void *user, int32 flags)
13812fd6cc2SKarsten Heimrich 		(void *)_SetFontShear,			// 44	SetFontShear(void *user, float shear)
13912fd6cc2SKarsten Heimrich 		(void *)_op45,					// 45	*reserved*
14012fd6cc2SKarsten Heimrich 		(void *)_SetFontFace,			// 46	SetFontFace(void *user, int32 flags)
14112fd6cc2SKarsten Heimrich 		(void *)_op47,
14212fd6cc2SKarsten Heimrich 		(void *)_op48,
14312fd6cc2SKarsten Heimrich 		(void *)_op49,
14412fd6cc2SKarsten Heimrich 
14512fd6cc2SKarsten Heimrich 		NULL
14612fd6cc2SKarsten Heimrich 	};
14712fd6cc2SKarsten Heimrich 
14812fd6cc2SKarsten Heimrich void
Iterate(BPicture * picture)14912fd6cc2SKarsten Heimrich PictureIterator::Iterate(BPicture* picture) {
15012fd6cc2SKarsten Heimrich 	picture->Play(playbackHandlers, 50, this);
15112fd6cc2SKarsten Heimrich }
152