1 /************************************************************************/
2 /*									*/
3 /*  Read/Write MS-Word 95 style drawing objects from/to rtf.		*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docRtfConfig.h"
8 
9 #   include	<stdlib.h>
10 #   include	<stdio.h>
11 #   include	<ctype.h>
12 #   include	<bitmap.h>
13 
14 #   include	<docDrawingObject.h>
15 #   include	<docShape.h>
16 #   include	<appDebugon.h>
17 
18 #   include	"docRtfReaderImpl.h"
19 
docRtfDrawingObjectAllocatePoints(DrawingShape * ds,int n)20 static int docRtfDrawingObjectAllocatePoints(	DrawingShape *	ds,
21 						int		n )
22     {
23     ShapeDrawing *	sd= &(ds->dsDrawing);
24     Point2DI *		fresh;
25 
26     fresh= (Point2DI *)realloc( sd->sdVertices, n* sizeof(Point2DI) );
27     if  ( ! fresh )
28 	{ LXDEB(n,fresh); return -1;	}
29 
30     sd->sdVertices= fresh;
31     fresh += sd->sdVertexCount;
32 
33     while( sd->sdVertexCount < n )
34 	{
35 	fresh->x= fresh->y= 0;
36 	fresh++; sd->sdVertexCount++;
37 	}
38 
39     return 0;
40     }
41 
docRtfDrawingObjectProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)42 int docRtfDrawingObjectProperty(	const RtfControlWord *	rcw,
43 					int			arg,
44 					RtfReader *		rrc )
45     {
46     DrawingShape *	ds= rrc->rrDrawingShape;
47     ShapeDrawing *	sd;
48     ShapeProperties *	sp;
49 
50     if  ( ! ds )
51 	{ SLLXDEB(rcw->rcwWord,arg,rrc->rrCurrentLine,ds); return 0;	}
52 
53     sd= &(ds->dsDrawing);
54     sp= &(ds->dsShapeProperties);
55 
56     switch( rcw->rcwID )
57 	{
58 	case DOpropANCHOR_LOCKED:
59 	    sp->spLockAnchor= arg != 0;
60 	    break;
61 
62 	case DOpropX_ATTACH:
63 	    sd->sdXReference= arg;
64 	    sp->spXReference= arg;
65 	    break;
66 
67 	case DOpropY_ATTACH:
68 	    sd->sdYReference= arg;
69 	    sp->spYReference= arg;
70 	    break;
71 
72 	case DOpropKIND:
73 	    sd->sdShapeType= arg;
74 	    sd->sd_fFilled= 0; /* Have a different default from shapes ? */
75 
76 	    if  ( sd->sdShapeType == SHPtyLINE )
77 		{
78 		rrc->rrcNextObjectVertex= sd->sdVertexCount;
79 		if  ( docRtfDrawingObjectAllocatePoints( ds, 2 ) )
80 		    { LDEB(arg); return -1;	}
81 		}
82 	    break;
83 
84 	case DOpropLINE_STYLE:
85 	    if  ( arg == DSdashHOLLOW )
86 		{
87 		sd->sdLineDashing= DSdashSOLID;
88 		sd->sd_fLine= 0;
89 		}
90 	    else{
91 		sd->sdLineDashing= arg;
92 		sd->sd_fLine= 1;
93 		}
94 	    break;
95 
96 	case DOpropFILL_PATTERN:
97 	    switch( arg )
98 		{
99 		static int op[]= { 100,5,10,20,30,40,50,60,70,75,80,90 };
100 
101 		case 0:
102 		    sd->sd_fFilled= 0;
103 		    sd->sdFillType= DSfillSOLID;
104 		    break;
105 		case  1: case  2: case  3: case  4: case  5: case  6: case  7:
106 		case  8: case  9: case 10: case 11: case 12: case 13:
107 		    sd->sd_fFilled= 1;
108 		    sd->sdFillType= DSfillSOLID;
109 		    sd->sdFillOpacity= ( op[arg-1]* 65536 )/ 100;
110 		    break;
111 
112 		default:
113 		    LDEB(arg); break;
114 		}
115 	    break;
116 
117 	case DOpropARC_FLIP_X:
118 	    sd->sd_fFlipH= arg != 0;
119 	    sd->sd_fRelFlipH= arg != 0;
120 	    break;
121 	case DOpropARC_FLIP_Y:
122 	    sd->sd_fFlipV= arg != 0;
123 	    sd->sd_fRelFlipV= arg != 0;
124 	    break;
125 
126 	case DOpropX:
127 	    sp->spRect.drX0= arg;
128 	    sd->sdGeoRect.drX0= arg;
129 	    break;
130 	case DOpropY:
131 	    sp->spRect.drY0= arg;
132 	    sd->sdGeoRect.drY0= arg;
133 	    break;
134 	case DOpropZ:
135 	    sp->spZ= arg;
136 	    break;
137 	case DOpropWIDE:
138 	    sp->spRect.drX1= sp->spRect.drX0+ arg;
139 	    sd->sdGeoRect.drX1= sd->sdGeoRect.drX0+ arg;
140 	    break;
141 	case DOpropHIGH:
142 	    sp->spRect.drY1= sp->spRect.drY0+ arg;
143 	    sd->sdGeoRect.drY1= sd->sdGeoRect.drY0+ arg;
144 	    break;
145 
146 	case DOpropTEXT_BOX_MARGIN:
147 	    sd->sd_dxTextLeft= TWIPStoEMU( arg );
148 	    sd->sd_dyTextTop= TWIPStoEMU( arg );
149 	    sd->sd_dxTextRight= TWIPStoEMU( arg );
150 	    sd->sd_dyTextBottom= TWIPStoEMU( arg );
151 	    break;
152 
153 	case DOpropLINE_WIDTH:
154 	    sd->sdLineWidthEmu= TWIPStoEMU( arg );
155 	    break;
156 
157 	case DOpropPOINT_COUNT:
158 	    rrc->rrcNextObjectVertex= sd->sdVertexCount;
159 	    if  ( docRtfDrawingObjectAllocatePoints( ds, arg ) )
160 		{ LDEB(arg); return -1;	}
161 	    break;
162 
163 	case DOpropSTART_ARROW_HEAD:
164 	    sd->sdLineHeadArrow.saArrowHead= arg;
165 	    break;
166 	case DOpropEND_ARROW_HEAD:
167 	    sd->sdLineTailArrow.saArrowHead= arg;
168 	    break;
169 	case DOpropSTART_ARROW_WIDTH:
170 	    sd->sdLineHeadArrow.saArrowWidth= arg;
171 	    break;
172 	case DOpropEND_ARROW_WIDTH:
173 	    sd->sdLineTailArrow.saArrowWidth= arg;
174 	    break;
175 	case DOpropSTART_ARROW_LENGTH:
176 	    sd->sdLineHeadArrow.saArrowLength= arg;
177 	    break;
178 	case DOpropEND_ARROW_LENGTH:
179 	    sd->sdLineTailArrow.saArrowLength= arg;
180 	    break;
181 
182 	case DOpropLINE_RED:
183 	    sd->sdLineColor.rgb8Red= arg;
184 	    break;
185 	case DOpropLINE_GREEN:
186 	    sd->sdLineColor.rgb8Green= arg;
187 	    break;
188 	case DOpropLINE_BLUE:
189 	    sd->sdLineColor.rgb8Blue= arg;
190 	    break;
191 	case DOpropLINE_GRAY:
192 	    sd->sdLineColor.rgb8Red= arg;
193 	    sd->sdLineColor.rgb8Green= arg;
194 	    sd->sdLineColor.rgb8Blue= arg;
195 	    break;
196 
197 			/*  Note swap of fore and back.		*/
198 	case DOpropFILL_FORE_RED:
199 	    sd->sdFillBackColor.rgb8Red= arg;
200 	    break;
201 	case DOpropFILL_FORE_GREEN:
202 	    sd->sdFillBackColor.rgb8Green= arg;
203 	    break;
204 	case DOpropFILL_FORE_BLUE:
205 	    sd->sdFillBackColor.rgb8Blue= arg;
206 	    break;
207 	case DOpropFILL_FORE_GRAY:
208 	    sd->sdFillBackColor.rgb8Red= arg;
209 	    sd->sdFillBackColor.rgb8Green= arg;
210 	    sd->sdFillBackColor.rgb8Blue= arg;
211 	    break;
212 
213 			/*  Note swap of fore and back.		*/
214 	case DOpropFILL_BACK_RED:
215 	    sd->sdFillColor.rgb8Red= arg;
216 	    break;
217 	case DOpropFILL_BACK_GREEN:
218 	    sd->sdFillColor.rgb8Green= arg;
219 	    break;
220 	case DOpropFILL_BACK_BLUE:
221 	    sd->sdFillColor.rgb8Blue= arg;
222 	    break;
223 	case DOpropFILL_BACK_GRAY:
224 	    sd->sdFillColor.rgb8Red= arg;
225 	    sd->sdFillColor.rgb8Green= arg;
226 	    sd->sdFillColor.rgb8Blue= arg;
227 	    break;
228 
229 	case DOpropTEXT_FLOW:
230 	    /* SLDEB(rcw->rcwWord,rcw->rcwID); */
231 	    break;
232 
233 	default:
234 	    SLDEB(rcw->rcwWord,rcw->rcwID);
235 	    break;
236 	}
237 
238     return 0;
239     }
240 
docRtfDrawingObjectCoordinate(const RtfControlWord * rcw,int arg,RtfReader * rrc)241 int docRtfDrawingObjectCoordinate(	const RtfControlWord *	rcw,
242 					int			arg,
243 					RtfReader *	rrc )
244     {
245     DrawingShape *	ds= rrc->rrDrawingShape;
246     ShapeDrawing *	sd;
247 
248     if  ( ! ds )
249 	{ SLLXDEB(rcw->rcwWord,arg,rrc->rrCurrentLine,ds); return 0;	}
250 
251     sd= &(ds->dsDrawing);
252 
253     if  ( rrc->rrcNextObjectVertex >= sd->sdVertexCount	||
254 	  rrc->rrcNextObjectVertex < 0			)
255 	{
256 	LLLDEB(sd->sdShapeType,rrc->rrcNextObjectVertex,sd->sdVertexCount);
257 	return 0;
258 	}
259 
260     switch( rcw->rcwID )
261 	{
262 	case DOpropX:
263 	    sd->sdVertices[rrc->rrcNextObjectVertex  ].x= arg;
264 	    break;
265 	case DOpropY:
266 	    sd->sdVertices[rrc->rrcNextObjectVertex++].y= arg;
267 	    break;
268 
269 	default:
270 	    SLDEB(rcw->rcwWord,rcw->rcwID);
271 	    break;
272 	}
273 
274     return 0;
275     }
276 
277