1 /************************************************************************/
2 /*									*/
3 /*  Shapes.. Administration.						*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBufConfig.h"
8 
9 #   include	<stdlib.h>
10 #   include	<math.h>
11 
12 #   include	<geoAffineTransform.h>
13 
14 #   include	"docShape.h"
15 
16 #   include	<appDebugon.h>
17 
18 /************************************************************************/
19 /*									*/
20 /*  Return the rectangle and its normalized version for a shape .	*/
21 /*									*/
22 /************************************************************************/
23 
docShapeGetRects(DocumentRectangle * drHere,DocumentRectangle * drNorm,const DocumentRectangle * drTwips,const DrawingShape * ds)24 void docShapeGetRects(	DocumentRectangle *		drHere,
25 			DocumentRectangle *		drNorm,
26 			const DocumentRectangle *	drTwips,
27 			const DrawingShape *		ds )
28     {
29     *drHere= *drTwips;
30 
31     if  ( DSflipHORIZONTAL( ds ) )
32 	{ int sw= drHere->drX0; drHere->drX0= drHere->drX1; drHere->drX1= sw; }
33 
34     if  ( DSflipVERTICAL( ds ) )
35 	{ int sw= drHere->drY0; drHere->drY0= drHere->drY1; drHere->drY1= sw; }
36 
37     geoNormalizeRectangle( drNorm, drHere );
38 
39     return;
40     }
41 
42 /************************************************************************/
43 /*									*/
44 /*  Calculate the rectangle for a child shape.				*/
45 /*									*/
46 /************************************************************************/
47 
docShapeGetChildRect(DocumentRectangle * drChild,const DrawingShape * dsChild,const DocumentRectangle * dr,const DrawingShape * ds)48 void docShapeGetChildRect(	DocumentRectangle *		drChild,
49 				const DrawingShape *		dsChild,
50 				const DocumentRectangle *	dr,
51 				const DrawingShape *		ds )
52     {
53     const ShapeDrawing *	sd= &(ds->dsDrawing);
54     const ShapeDrawing *	sdChild= &(dsChild->dsDrawing);
55 
56     double			xscale;
57     double			yscale;
58 
59     xscale= ( 1.0* ( dr->drX1- dr->drX0 ) )/
60 				( sd->sdGroupRect.drX1- sd->sdGroupRect.drX0 );
61     yscale= ( 1.0* ( dr->drY1- dr->drY0 ) )/
62 				( sd->sdGroupRect.drY1- sd->sdGroupRect.drY0 );
63 
64     drChild->drX0= dr->drX0+ xscale*
65 			    ( sdChild->sdRelRect.drX0- sd->sdGroupRect.drX0 );
66     drChild->drY0= dr->drY0+ yscale*
67 			    ( sdChild->sdRelRect.drY0- sd->sdGroupRect.drY0 );
68     drChild->drX1= dr->drX0+ xscale*
69 			    ( sdChild->sdRelRect.drX1- sd->sdGroupRect.drX0 );
70     drChild->drY1= dr->drY0+ yscale*
71 			    ( sdChild->sdRelRect.drY1- sd->sdGroupRect.drY0 );
72 
73     return;
74     }
75 
76 /************************************************************************/
77 /*									*/
78 /*  Get the transform to draw this shape.				*/
79 /*									*/
80 /************************************************************************/
81 
docShapeStartShapeTransform(AffineTransform2D * at,const DrawingShape * ds,const DocumentRectangle * dr,int xSize,int ySize)82 void docShapeStartShapeTransform(
83 				AffineTransform2D *		at,
84 				const DrawingShape *		ds,
85 				const DocumentRectangle *	dr,
86 				int				xSize,
87 				int				ySize )
88     {
89     double			xs= 1.0;
90     double			ys= 1.0;
91 
92     AffineTransform2D		att;
93 
94     if  ( dr->drX1 != dr->drX0 )
95 	{ xs= ( dr->drX1- dr->drX0 )/ ( 1.0* xSize );	}
96     if  ( dr->drY1 != dr->drY0 )
97 	{ ys= ( dr->drY1- dr->drY0 )/ ( 1.0* ySize );	}
98 
99     geoScaleAffineTransform2D( at, xs, ys );
100 
101     geoTranslationAffineTransform2D( &att,
102 				( dr->drX1+ dr->drX0 )/ 2.0,
103 				( dr->drY1+ dr->drY0 )/ 2.0 );
104     geoAffineTransform2DProduct( at, &att, at );
105 
106     docShapeInternalTransform( &att, ds );
107     geoAffineTransform2DProduct( at, at, &att );
108 
109     return;
110     }
111 
112 
113 /************************************************************************/
114 /*									*/
115 /*  Return the transform for a shape.					*/
116 /*									*/
117 /************************************************************************/
118 
docShapeInternalTransform(AffineTransform2D * at,const DrawingShape * ds)119 void docShapeInternalTransform(	AffineTransform2D *	at,
120 				const DrawingShape *	ds )
121     {
122     const ShapeDrawing *	sd= &(ds->dsDrawing);
123 
124     if  ( sd->sdRotation != 0 )
125 	{
126 	geoRotationAffineTransform2D( at, ( M_PI* sd->sdRotation )/
127 							( 180.0 * 65536.0 ) );
128 	}
129     else{
130 	geoIdentityAffineTransform2D( at );
131 	}
132 
133     if  ( DSflipHORIZONTAL( ds ) )
134 	{
135 	AffineTransform2D	att;
136 
137 	geoScaleAffineTransform2D( &att, -1.0, 1.0 );
138 	geoAffineTransform2DProduct( at, at, &att );
139 	}
140 
141     if  ( DSflipVERTICAL( ds ) )
142 	{
143 	AffineTransform2D	att;
144 
145 	geoScaleAffineTransform2D( &att, 1.0, -1.0 );
146 	geoAffineTransform2DProduct( at, at, &att );
147 	}
148 
149     return;
150     }
151 
152 /************************************************************************/
153 /*									*/
154 /*  Get the fill color of a shape.					*/
155 /*									*/
156 /************************************************************************/
157 
docShapeGetFill(int * pFill,RGB8Color * rgb8,const DrawingShape * ds)158 int docShapeGetFill(	int *			pFill,
159 			RGB8Color *		rgb8,
160 			const DrawingShape *	ds )
161     {
162     const ShapeDrawing *	sd= &(ds->dsDrawing);
163     int				fill= 1;
164 
165     if  ( ! sd->sd_fFilled )
166 	{ *pFill= 0; return 0; }
167     if  ( sd->sdFillOpacity == 0 )
168 	{ *pFill= 0; return 0; }
169 
170     switch( sd->sdFillType )
171 	{
172 	case DSfillSOLID:
173 	    *rgb8= sd->sdFillColor;
174 	    fill= 1;
175 	    break;
176 
177 	case DSfillSHADE_START_TO_END:
178 	case DSfillSHADE_BOUNDS_TO_END:
179 	case DSfillSHADE_OUTLINE_TO_END:
180 	case DSfillSHADE_ANGLE:
181 	    /*LDEB(sd->sdFillType);*/
182 	    *rgb8= sd->sdFillColor;
183 	    fill= 1;
184 	    break;
185 
186 	default:
187 	    LDEB(sd->sdFillType);
188 	    return -1;
189 	}
190 
191     *pFill= fill;
192     return 0;
193     }
194 
195 /************************************************************************/
196 /*									*/
197 /*  Get the line/stroke color of a shape.				*/
198 /*									*/
199 /************************************************************************/
200 
docShapeGetLine(int * pLine,RGB8Color * rgb8,const DrawingShape * ds)201 int docShapeGetLine(	int *			pLine,
202 			RGB8Color *		rgb8,
203 			const DrawingShape *	ds )
204     {
205     const ShapeDrawing *	sd= &(ds->dsDrawing);
206     int				line= 1;
207 
208     if  ( ! sd->sd_fLine )
209 	{ *pLine= 0; return 0; }
210 
211     switch( sd->sdLineType )
212 	{
213 	case DSlineSOLID:
214 	    *rgb8= sd->sdLineColor;
215 	    line= 1;
216 	    break;
217 
218 	default:
219 	    LDEB(sd->sdLineType);
220 	    return -1;
221 	}
222 
223     *pLine= line;
224     return 0;
225     }
226 
227 /************************************************************************/
228 /*									*/
229 /*  Initialize/Clean a shape.						*/
230 /*									*/
231 /************************************************************************/
232 
docCleanDrawingShape(DrawingShape * ds)233 void docCleanDrawingShape(	DrawingShape *		ds )
234     {
235     utilCleanMemoryBuffer( &(ds->dsPictureData) );
236 
237     /* NO! The children will be cleaned via the paged list callbacks
238     for ( i= 0; i < ds->dsChildCount; i++ )
239 	{
240 	if  ( ds->dsChildren[i] )
241 	    { docCleanDrawingShape( ds->dsChildren[i] );	}
242 	}
243     */
244 
245     if  ( ds->dsChildren )
246 	{ free( ds->dsChildren ); }
247 
248     docCleanShapeDrawing( &(ds->dsDrawing) );
249 
250     if  ( ds->dsDocumentTree.dtRoot )
251 	{ LPDEB(ds->dsShapeNumber,ds->dsDocumentTree.dtRoot);	}
252 
253     bmCleanRasterImage( &(ds->dsRasterImage) );
254 
255     return;
256     }
257 
docInitShapeAllocated(DrawingShape * ds)258 void docInitShapeAllocated(	DrawingShape *	ds )
259     {
260     docInitShapeDrawingAllocated( &(ds->dsDrawing) );
261 
262     utilInitMemoryBuffer( &(ds->dsPictureData) );
263 
264     ds->dsChildCount= 0;
265     ds->dsChildren= (DrawingShape **)0;
266 
267     docInitSelectionScope( &(ds->dsSelectionScope) );
268     docInitDocumentTree( &(ds->dsDocumentTree) );
269 
270     ds->dsDrawingSurface= (struct DrawingSurface *)0;
271     bmInitRasterImage( &(ds->dsRasterImage) );
272 
273     return;
274     }
275 
docInitDrawingShape(DrawingShape * ds)276 void docInitDrawingShape(	DrawingShape *	ds )
277     {
278 			/************************************************/
279 			/*  Backbone.					*/
280 			/************************************************/
281     docInitShapeAllocated( ds );
282     ds->dsShapeNumber= -1;
283 
284 			/************************************************/
285 			/*  Properties.					*/
286 			/************************************************/
287 
288     docInitShapeProperties( &(ds->dsShapeProperties) );
289 
290 			/************************************************/
291 			/*  Position.					*/
292 			/************************************************/
293     ds->dsIsChildShape= 0;
294 
295 			/************************************************/
296 			/*  Drawing.					*/
297 			/************************************************/
298     docInitShapeDrawing( &(ds->dsDrawing) );
299 
300     docInitPictureProperties( &(ds->dsPictureProperties) );
301 
302     return;
303     }
304