Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <rtl/math.hxx>
21 : #include <osl/endian.h>
22 : #include <vcl/graph.hxx>
23 : #include <tools/poly.hxx>
24 : #include <vcl/graphicfilter.hxx>
25 : #include "sgffilt.hxx"
26 : #include "sgfbram.hxx"
27 : #include "sgvmain.hxx"
28 : #include "sgvspln.hxx"
29 : #include <unotools/ucbstreamhelper.hxx>
30 :
31 : #if defined OSL_BIGENDIAN
32 :
33 : #define SWAPPOINT(p) { \
34 : p.x=OSL_SWAPWORD(p.x); \
35 : p.y=OSL_SWAPWORD(p.y); }
36 :
37 : #define SWAPPAGE(p) { \
38 : p.Next =OSL_SWAPDWORD (p.Next ); \
39 : p.nList =OSL_SWAPDWORD (p.nList ); \
40 : p.ListEnd=OSL_SWAPDWORD (p.ListEnd); \
41 : p.Paper.Size.x=OSL_SWAPWORD(p.Paper.Size.x); \
42 : p.Paper.Size.y=OSL_SWAPWORD(p.Paper.Size.y); \
43 : p.Paper.RandL =OSL_SWAPWORD(p.Paper.RandL ); \
44 : p.Paper.RandR =OSL_SWAPWORD(p.Paper.RandR ); \
45 : p.Paper.RandO =OSL_SWAPWORD(p.Paper.RandO ); \
46 : p.Paper.RandU =OSL_SWAPWORD(p.Paper.RandU ); \
47 : SWAPPOINT(p.U); \
48 : sal_uInt16 iTemp; \
49 : for (iTemp=0;iTemp<20;iTemp++) { \
50 : rPage.HlpLnH[iTemp]=OSL_SWAPWORD(rPage.HlpLnH[iTemp]); \
51 : rPage.HlpLnV[iTemp]=OSL_SWAPWORD(rPage.HlpLnV[iTemp]); }}
52 :
53 : #define SWAPOBJK(o) { \
54 : o.Last =OSL_SWAPDWORD (o.Last ); \
55 : o.Next =OSL_SWAPDWORD (o.Next ); \
56 : o.MemSize =OSL_SWAPWORD(o.MemSize ); \
57 : SWAPPOINT(o.ObjMin); \
58 : SWAPPOINT(o.ObjMax); }
59 :
60 : #define SWAPLINE(l) { \
61 : l.LMSize=OSL_SWAPWORD(l.LMSize); \
62 : l.LDicke=OSL_SWAPWORD(l.LDicke); }
63 :
64 : #define SWAPAREA(a) { \
65 : a.FDummy2=OSL_SWAPWORD(a.FDummy2); \
66 : a.FMuster=OSL_SWAPWORD(a.FMuster); }
67 :
68 : #define SWAPTEXT(t) { \
69 : SWAPLINE(t.L); \
70 : SWAPAREA(t.F); \
71 : t.FontLo =OSL_SWAPWORD(t.FontLo ); \
72 : t.FontHi =OSL_SWAPWORD(t.FontHi ); \
73 : t.Grad =OSL_SWAPWORD(t.Grad ); \
74 : t.Breite =OSL_SWAPWORD(t.Breite ); \
75 : t.Schnitt=OSL_SWAPWORD(t.Schnitt); \
76 : t.LnFeed =OSL_SWAPWORD(t.LnFeed ); \
77 : t.Slant =OSL_SWAPWORD(t.Slant ); \
78 : SWAPLINE(t.ShdL); \
79 : SWAPAREA(t.ShdF); \
80 : SWAPPOINT(t.ShdVers); \
81 : SWAPAREA(t.BackF); }
82 :
83 : #endif
84 :
85 : // Restrictions:
86 :
87 : // - area patterns are matched to the available ones in Starview.
88 : // - line ends are always rounded in StarView and continue past the end of line.
89 : // - line patterns are matched to the available ones in Starview.
90 : // transparency/opacity is not taken into account
91 : // - no rotated ellipses
92 :
93 : // for font translation
94 : SgfFontLst* pSgfFonts = 0;
95 :
96 : // for circle kinds, text and rotated rectangles
97 0 : void RotatePoint(PointType& P, sal_Int16 cx, sal_Int16 cy, double sn, double cs)
98 : {
99 : sal_Int16 dx,dy;
100 : double x1,y1;
101 0 : dx=P.x-cx;
102 0 : dy=P.y-cy;
103 0 : x1=dx*cs-dy*sn;
104 0 : y1=dy*cs+dx*sn;
105 0 : P.x=cx+sal_Int16(x1);
106 0 : P.y=cy+sal_Int16(y1);
107 0 : }
108 :
109 0 : void RotatePoint(Point& P, sal_Int16 cx, sal_Int16 cy, double sn, double cs)
110 : {
111 : sal_Int16 dx,dy;
112 : double x1,y1;
113 0 : dx=(sal_Int16)(P.X()-cx);
114 0 : dy=(sal_Int16)(P.Y()-cy);
115 0 : x1=dx*cs-dy*sn;
116 0 : y1=dy*cs+dx*sn;
117 0 : P=Point(cx+sal_Int16(x1),cy+sal_Int16(y1));
118 0 : }
119 :
120 0 : sal_Int16 iMulDiv(sal_Int16 a, sal_Int16 Mul, sal_Int16 Div)
121 : {
122 : sal_Int32 Temp;
123 0 : Temp=sal_Int32(a)*sal_Int32(Mul)/sal_Int32(Div);
124 0 : return sal_Int16(Temp);
125 : }
126 :
127 0 : sal_uInt16 MulDiv(sal_uInt16 a, sal_uInt16 Mul, sal_uInt16 Div)
128 : {
129 : sal_uInt32 Temp;
130 0 : Temp=sal_uInt32(a)*sal_uInt32(Mul)/sal_uInt32(Div);
131 0 : return sal_uInt16(Temp);
132 : }
133 :
134 : // SgfFilterSDrw
135 :
136 0 : SvStream& ReadDtHdType(SvStream& rIStream, DtHdType& rDtHd)
137 : {
138 0 : rIStream.Read((char*)&rDtHd.Reserved[0],DtHdSize);
139 0 : return rIStream;
140 : }
141 :
142 4 : void DtHdOverSeek(SvStream& rInp)
143 : {
144 4 : sal_uLong FPos=rInp.Tell();
145 4 : FPos+=(sal_uLong)DtHdSize;
146 4 : rInp.Seek(FPos);
147 4 : }
148 :
149 4 : PageType::PageType()
150 : {
151 4 : memset( this, 0, sizeof( PageType ) );
152 4 : }
153 :
154 16 : SvStream& ReadPageType(SvStream& rIStream, PageType& rPage)
155 : {
156 16 : rIStream.Read((char*)&rPage.Next,PageSize);
157 : #if defined OSL_BIGENDIAN
158 : SWAPPAGE(rPage);
159 : #endif
160 16 : return rIStream;
161 : }
162 :
163 0 : void ObjkOverSeek(SvStream& rInp, ObjkType& rObjk)
164 : {
165 : sal_uLong Siz;
166 0 : Siz=(sal_uLong)rObjk.MemSize+rObjk.Last; // ObjSize+ObjAnhSize
167 0 : rInp.Seek(rInp.Tell()+Siz);
168 0 : }
169 :
170 16 : SvStream& ReadObjkType(SvStream& rInp, ObjkType& rObjk)
171 : {
172 : // fileposition in stream is not changed!
173 : sal_uLong nPos;
174 16 : nPos=rInp.Tell();
175 16 : rInp.Read((char*)&rObjk.Last,ObjkSize);
176 : #if defined OSL_BIGENDIAN
177 : SWAPOBJK(rObjk);
178 : #endif
179 16 : rInp.Seek(nPos);
180 16 : return rInp;
181 : }
182 0 : SvStream& ReadStrkType(SvStream& rInp, StrkType& rStrk)
183 : {
184 0 : rInp.Read((char*)&rStrk.Last,StrkSize);
185 : #if defined OSL_BIGENDIAN
186 : SWAPOBJK (rStrk);
187 : SWAPLINE (rStrk.L);
188 : SWAPPOINT(rStrk.Pos1);
189 : SWAPPOINT(rStrk.Pos2);
190 : #endif
191 0 : return rInp;
192 : }
193 0 : SvStream& ReadRectType(SvStream& rInp, RectType& rRect)
194 : {
195 0 : rInp.Read((char*)&rRect.Last,RectSize);
196 : #if defined OSL_BIGENDIAN
197 : SWAPOBJK (rRect);
198 : SWAPLINE (rRect.L);
199 : SWAPAREA (rRect.F);
200 : SWAPPOINT(rRect.Pos1);
201 : SWAPPOINT(rRect.Pos2);
202 : rRect.Radius =OSL_SWAPWORD(rRect.Radius );
203 : rRect.DrehWink=OSL_SWAPWORD(rRect.DrehWink);
204 : rRect.Slant =OSL_SWAPWORD(rRect.Slant );
205 : #endif
206 0 : return rInp;
207 : }
208 6 : SvStream& ReadPolyType(SvStream& rInp, PolyType& rPoly)
209 : {
210 6 : rInp.Read((char*)&rPoly.Last,PolySize);
211 : #if defined OSL_BIGENDIAN
212 : SWAPOBJK (rPoly);
213 : SWAPLINE (rPoly.L);
214 : SWAPAREA (rPoly.F);
215 : #endif
216 6 : return rInp;
217 : }
218 6 : SvStream& ReadSplnType(SvStream& rInp, SplnType& rSpln)
219 : {
220 6 : rInp.Read((char*)&rSpln.Last,SplnSize);
221 : #if defined OSL_BIGENDIAN
222 : SWAPOBJK (rSpln);
223 : SWAPLINE (rSpln.L);
224 : SWAPAREA (rSpln.F);
225 : #endif
226 6 : return rInp;
227 : }
228 2 : SvStream& ReadCircType(SvStream& rInp, CircType& rCirc)
229 : {
230 2 : rInp.Read((char*)&rCirc.Last,CircSize);
231 : #if defined OSL_BIGENDIAN
232 : SWAPOBJK (rCirc);
233 : SWAPLINE (rCirc.L);
234 : SWAPAREA (rCirc.F);
235 : SWAPPOINT(rCirc.Radius);
236 : SWAPPOINT(rCirc.Center);
237 : rCirc.DrehWink =OSL_SWAPWORD(rCirc.DrehWink );
238 : rCirc.StartWink=OSL_SWAPWORD(rCirc.StartWink);
239 : rCirc.RelWink =OSL_SWAPWORD(rCirc.RelWink );
240 : #endif
241 2 : return rInp;
242 : }
243 0 : SvStream& ReadTextType(SvStream& rInp, TextType& rText)
244 : {
245 0 : rInp.Read((char*)&rText.Last,TextSize);
246 : #if defined OSL_BIGENDIAN
247 : SWAPOBJK (rText);
248 : SWAPTEXT (rText.T);
249 : SWAPPOINT(rText.Pos1);
250 : SWAPPOINT(rText.Pos2);
251 : rText.TopOfs =OSL_SWAPWORD(rText.TopOfs );
252 : rText.DrehWink=OSL_SWAPWORD(rText.DrehWink);
253 : rText.BoxSlant=OSL_SWAPWORD(rText.BoxSlant);
254 : rText.BufSize =OSL_SWAPWORD(rText.BufSize );
255 : SWAPPOINT(rText.FitSize);
256 : rText.FitBreit=OSL_SWAPWORD(rText.FitBreit);
257 : #endif
258 0 : rText.Buffer=NULL;
259 0 : return rInp;
260 : }
261 0 : SvStream& ReadBmapType(SvStream& rInp, BmapType& rBmap)
262 : {
263 0 : rInp.Read((char*)&rBmap.Last,BmapSize);
264 : #if defined OSL_BIGENDIAN
265 : SWAPOBJK (rBmap);
266 : SWAPAREA (rBmap.F);
267 : SWAPPOINT(rBmap.Pos1);
268 : SWAPPOINT(rBmap.Pos2);
269 : rBmap.DrehWink=OSL_SWAPWORD(rBmap.DrehWink);
270 : rBmap.Slant =OSL_SWAPWORD(rBmap.Slant );
271 : SWAPPOINT(rBmap.PixSize);
272 : #endif
273 0 : return rInp;
274 : }
275 2 : SvStream& ReadGrupType(SvStream& rInp, GrupType& rGrup)
276 : {
277 2 : rInp.Read((char*)&rGrup.Last,GrupSize);
278 : #if defined OSL_BIGENDIAN
279 : SWAPOBJK (rGrup);
280 : rGrup.SbLo =OSL_SWAPWORD(rGrup.SbLo );
281 : rGrup.SbHi =OSL_SWAPWORD(rGrup.SbHi );
282 : rGrup.UpLo =OSL_SWAPWORD(rGrup.UpLo );
283 : rGrup.UpHi =OSL_SWAPWORD(rGrup.UpHi );
284 : rGrup.ChartSize=OSL_SWAPWORD(rGrup.ChartSize);
285 : rGrup.ChartPtr =OSL_SWAPDWORD (rGrup.ChartPtr );
286 : #endif
287 2 : return rInp;
288 : }
289 :
290 24 : Color Sgv2SvFarbe(sal_uInt8 nFrb1, sal_uInt8 nFrb2, sal_uInt8 nInts)
291 : {
292 24 : sal_uInt16 r1=0,g1=0,b1=0,r2=0,g2=0,b2=0;
293 24 : sal_uInt8 nInt2=100-nInts;
294 24 : switch(nFrb1 & 0x07) {
295 2 : case 0: r1=0xFF; g1=0xFF; b1=0xFF; break;
296 0 : case 1: r1=0xFF; g1=0xFF; break;
297 0 : case 2: g1=0xFF; b1=0xFF; break;
298 2 : case 3: g1=0xFF; break;
299 2 : case 4: r1=0xFF; b1=0xFF; break;
300 0 : case 5: r1=0xFF; break;
301 2 : case 6: b1=0xFF; break;
302 16 : case 7: break;
303 : }
304 24 : switch(nFrb2 & 0x07) {
305 24 : case 0: r2=0xFF; g2=0xFF; b2=0xFF; break;
306 0 : case 1: r2=0xFF; g2=0xFF; break;
307 0 : case 2: g2=0xFF; b2=0xFF; break;
308 0 : case 3: g2=0xFF; break;
309 0 : case 4: r2=0xFF; b2=0xFF; break;
310 0 : case 5: r2=0xFF; break;
311 0 : case 6: b2=0xFF; break;
312 0 : case 7: break;
313 : }
314 24 : r1=(sal_uInt16)((sal_uInt32)r1*nInts/100+(sal_uInt32)r2*nInt2/100);
315 24 : g1=(sal_uInt16)((sal_uInt32)g1*nInts/100+(sal_uInt32)g2*nInt2/100);
316 24 : b1=(sal_uInt16)((sal_uInt32)b1*nInts/100+(sal_uInt32)b2*nInt2/100);
317 24 : Color aColor( (sal_uInt8)r1, (sal_uInt8)g1, (sal_uInt8)b1 );
318 24 : return aColor;
319 : }
320 :
321 14 : void SetLine(ObjLineType& rLine, OutputDevice& rOut)
322 : {
323 14 : if( 0 == ( rLine.LMuster & 0x07 ) )
324 0 : rOut.SetLineColor();
325 : else
326 14 : rOut.SetLineColor( Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens) );
327 14 : }
328 :
329 14 : void SetArea(ObjAreaType& rArea, OutputDevice& rOut)
330 : {
331 14 : if( 0 == ( rArea.FMuster & 0x00FF ) )
332 4 : rOut.SetFillColor();
333 : else
334 10 : rOut.SetFillColor( Sgv2SvFarbe( rArea.FFarbe,rArea.FBFarbe,rArea.FIntens ) );
335 14 : }
336 :
337 0 : void ObjkType::Draw(OutputDevice&)
338 : {
339 0 : }
340 :
341 0 : void Obj0Type::Draw(OutputDevice&) {}
342 :
343 0 : void StrkType::Draw(OutputDevice& rOut)
344 : {
345 0 : SetLine(L,rOut);
346 0 : rOut.DrawLine(Point(Pos1.x,Pos1.y),Point(Pos2.x,Pos2.y)); // !!!
347 0 : }
348 :
349 0 : void SgfAreaColorIntens(sal_uInt16 Muster, sal_uInt8 Col1, sal_uInt8 Col2, sal_uInt8 Int, OutputDevice& rOut)
350 : {
351 0 : ObjAreaType F;
352 0 : F.FMuster=Muster;
353 0 : F.FFarbe=Col2;
354 0 : F.FBFarbe=Col1;
355 0 : F.FIntens=Int;
356 0 : SetArea(F,rOut);
357 0 : }
358 :
359 0 : void DrawSlideRect(sal_Int16 x1, sal_Int16 y1, sal_Int16 x2, sal_Int16 y2, ObjAreaType& F, OutputDevice& rOut)
360 : {
361 : sal_Int16 i,i0,b,b0;
362 : sal_Int16 Int1,Int2;
363 : sal_Int16 Col1,Col2;
364 : // ClipMerk: HgdClipRec;
365 : sal_Int16 cx,cy;
366 : sal_Int16 MaxR;
367 : sal_Int32 dx,dy;
368 :
369 0 : rOut.SetLineColor();
370 0 : if (x1>x2) { i=x1; x1=x2; x2=i; }
371 0 : if (y1>y2) { i=y1; y1=y2; y2=i; }
372 0 : Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
373 0 : Int1=100-F.FIntens; Int2=F.FIntens;
374 0 : if (Int1==Int2) {
375 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
376 0 : rOut.DrawRect(Rectangle(x1,y1,x2,y2));
377 : } else {
378 0 : b0=Int1;
379 0 : switch (F.FBFarbe & 0x38) {
380 : case 0x08: { // vertikal
381 0 : i0=y1;
382 0 : i=y1;
383 0 : while (i<=y2) {
384 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-y1) /(sal_Int32)(y2-y1+1));
385 0 : if (b!=b0) {
386 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
387 0 : rOut.DrawRect(Rectangle(x1,i0,x2,i-1));
388 0 : i0=i; b0=b;
389 : }
390 0 : i++;
391 : }
392 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
393 0 : rOut.DrawRect(Rectangle(x1,i0,x2,y2));
394 0 : } break;
395 : case 0x28: { // horizontal
396 0 : i0=x1;
397 0 : i=x1;
398 0 : while (i<=x2) {
399 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-x1) /(sal_Int32)(x2-x1+1));
400 0 : if (b!=b0) {
401 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
402 0 : rOut.DrawRect(Rectangle(i0,y1,i-1,y2));
403 0 : i0=i; b0=b;
404 : }
405 0 : i++;
406 : }
407 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
408 0 : rOut.DrawRect(Rectangle(i0,y1,x2,y2));
409 0 : } break;
410 :
411 : case 0x18: case 0x38: { // circle
412 0 : vcl::Region ClipMerk=rOut.GetClipRegion();
413 : double a;
414 :
415 0 : rOut.SetClipRegion(vcl::Region(Rectangle(x1,y1,x2,y2)));
416 0 : cx=(x1+x2) /2;
417 0 : cy=(y1+y2) /2;
418 0 : dx=x2-x1+1;
419 0 : dy=y2-y1+1;
420 0 : a=sqrt((double)(dx*dx+dy*dy));
421 0 : MaxR=sal_Int16(a) /2 +1;
422 0 : b0=Int2;
423 0 : i0=MaxR; if (MaxR<1) MaxR=1;
424 0 : i=MaxR;
425 0 : while (i>=0) {
426 0 : b=Int1+sal_Int16((sal_Int32(Int2-Int1)*sal_Int32(i)) /sal_Int32(MaxR));
427 0 : if (b!=b0) {
428 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
429 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
430 0 : i0=i; b0=b;
431 : }
432 0 : i--;
433 : }
434 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int1,rOut);
435 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
436 0 : rOut.SetClipRegion(ClipMerk);
437 0 : } break; // circle
438 : }
439 : }
440 0 : }
441 :
442 0 : void RectType::Draw(OutputDevice& rOut)
443 : {
444 0 : if (L.LMuster!=0) L.LMuster=1; // no line separator here, only on or off
445 0 : SetArea(F,rOut);
446 0 : if (DrehWink==0) {
447 0 : if ((F.FBFarbe & 0x38)==0 || Radius!=0) {
448 0 : SetLine(L,rOut);
449 0 : rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y),Radius,Radius);
450 : } else {
451 0 : DrawSlideRect(Pos1.x,Pos1.y,Pos2.x,Pos2.y,F,rOut);
452 0 : if (L.LMuster!=0) {
453 0 : SetLine(L,rOut);
454 0 : rOut.SetFillColor();
455 0 : rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y));
456 : }
457 : }
458 : } else {
459 0 : Point aPts[4];
460 : sal_uInt16 i;
461 : double sn,cs;
462 0 : sn=sin(double(DrehWink)*3.14159265359/18000);
463 0 : cs=cos(double(DrehWink)*3.14159265359/18000);
464 0 : aPts[0]=Point(Pos1.x,Pos1.y);
465 0 : aPts[1]=Point(Pos2.x,Pos1.y);
466 0 : aPts[2]=Point(Pos2.x,Pos2.y);
467 0 : aPts[3]=Point(Pos1.x,Pos2.y);
468 0 : for (i=0;i<4;i++) {
469 0 : RotatePoint(aPts[i],Pos1.x,Pos1.y,sn,cs);
470 : }
471 0 : SetLine(L,rOut);
472 0 : Polygon aPoly(4,aPts);
473 0 : rOut.DrawPolygon(aPoly);
474 : }
475 0 : }
476 :
477 6 : void PolyType::Draw(OutputDevice& rOut)
478 : {
479 6 : if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
480 6 : SetLine(L,rOut);
481 6 : Polygon aPoly(nPoints);
482 : sal_uInt16 i;
483 6 : for(i=0;i<nPoints;i++) aPoly.SetPoint(Point(EckP[i].x,EckP[i].y),i);
484 6 : if ((Flags & PolyClosBit) !=0) {
485 6 : rOut.DrawPolygon(aPoly);
486 : } else {
487 0 : rOut.DrawPolyLine(aPoly);
488 6 : }
489 6 : }
490 :
491 6 : void SplnType::Draw(OutputDevice& rOut)
492 : {
493 6 : if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
494 6 : SetLine(L,rOut);
495 6 : Polygon aPoly(0);
496 12 : Polygon aSpln(nPoints);
497 : sal_uInt16 i;
498 6 : for(i=0;i<nPoints;i++) aSpln.SetPoint(Point(EckP[i].x,EckP[i].y),i);
499 6 : if ((Flags & PolyClosBit) !=0) {
500 6 : Spline2Poly(aSpln,true,aPoly);
501 6 : if (aPoly.GetSize()>0) rOut.DrawPolygon(aPoly);
502 : } else {
503 0 : Spline2Poly(aSpln,false,aPoly);
504 0 : if (aPoly.GetSize()>0) rOut.DrawPolyLine(aPoly);
505 6 : }
506 6 : }
507 :
508 0 : void DrawSlideCirc(sal_Int16 cx, sal_Int16 cy, sal_Int16 rx, sal_Int16 ry, ObjAreaType& F, OutputDevice& rOut)
509 : {
510 0 : sal_Int16 x1=cx-rx;
511 0 : sal_Int16 y1=cy-ry;
512 0 : sal_Int16 x2=cx+rx;
513 0 : sal_Int16 y2=cy+ry;
514 :
515 : sal_Int16 i,i0,b,b0;
516 : sal_Int16 Int1,Int2;
517 : sal_Int16 Col1,Col2;
518 :
519 0 : rOut.SetLineColor();
520 0 : Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
521 0 : Int1=100-F.FIntens; Int2=F.FIntens;
522 0 : if (Int1==Int2) {
523 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
524 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
525 : } else {
526 0 : b0=Int1;
527 0 : switch (F.FBFarbe & 0x38) {
528 : case 0x08: { // vertical
529 0 : vcl::Region ClipMerk=rOut.GetClipRegion();
530 0 : i0=y1;
531 0 : i=y1;
532 0 : while (i<=y2) {
533 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-y1) /(sal_Int32)(y2-y1+1));
534 0 : if (b!=b0) {
535 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
536 0 : rOut.SetClipRegion(vcl::Region(Rectangle(x1,i0,x2,i-1)));
537 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
538 0 : i0=i; b0=b;
539 : }
540 0 : i++;
541 : }
542 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
543 0 : rOut.SetClipRegion(vcl::Region(Rectangle(x1,i0,x2,y2)));
544 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
545 0 : rOut.SetClipRegion(ClipMerk);
546 0 : } break;
547 : case 0x28: { // horizontal
548 0 : vcl::Region ClipMerk=rOut.GetClipRegion();
549 0 : i0=x1;
550 0 : i=x1;
551 0 : while (i<=x2) {
552 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-x1) /(sal_Int32)(x2-x1+1));
553 0 : if (b!=b0) {
554 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
555 0 : rOut.SetClipRegion(vcl::Region(Rectangle(i0,y1,i-1,y2)));
556 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
557 0 : i0=i; b0=b;
558 : }
559 0 : i++;
560 : }
561 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
562 0 : rOut.SetClipRegion(vcl::Region(Rectangle(i0,y1,x2,y2)));
563 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
564 0 : rOut.SetClipRegion(ClipMerk);
565 0 : } break;
566 :
567 : case 0x18: case 0x38: { // circle
568 : sal_Int16 MaxR;
569 :
570 0 : if (rx<1) rx=1;
571 0 : if (ry<1) ry=1;
572 0 : MaxR=rx;
573 0 : b0=Int2;
574 0 : i0=MaxR;
575 0 : i=MaxR;
576 0 : while (i>=0) {
577 0 : b=Int1+sal_Int16((sal_Int32(Int2-Int1)*sal_Int32(i)) /sal_Int32(MaxR));
578 0 : if (b!=b0) {
579 0 : sal_Int32 temp=sal_Int32(i0)*sal_Int32(ry)/sal_Int32(rx);
580 0 : sal_Int16 j0=sal_Int16(temp);
581 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
582 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-j0,cx+i0,cy+j0));
583 0 : i0=i; b0=b;
584 : }
585 0 : i--;
586 : }
587 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int1,rOut);
588 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
589 0 : } break; // circle
590 : }
591 : }
592 0 : }
593 :
594 2 : void CircType::Draw(OutputDevice& rOut)
595 : {
596 2 : Rectangle aRect(Center.x-Radius.x,Center.y-Radius.y,Center.x+Radius.x,Center.y+Radius.y);
597 :
598 2 : if (L.LMuster!=0) L.LMuster=1; // no line pattern here, only on or off
599 2 : SetArea(F,rOut);
600 2 : if ((Flags & 0x03)==CircFull) {
601 2 : if ((F.FBFarbe & 0x38)==0) {
602 2 : SetLine(L,rOut);
603 2 : rOut.DrawEllipse(aRect);
604 : } else {
605 0 : DrawSlideCirc(Center.x,Center.y,Radius.x,Radius.y,F,rOut);
606 0 : if (L.LMuster!=0) {
607 0 : SetLine(L,rOut);
608 0 : rOut.SetFillColor();
609 0 : rOut.DrawEllipse(aRect);
610 : }
611 : }
612 : } else {
613 0 : PointType a,b;
614 0 : Point aStrt,aEnde;
615 : double sn,cs;
616 :
617 0 : a.x=Center.x+Radius.x; a.y=Center.y; b=a;
618 0 : sn=sin(double(StartWink)*3.14159265359/18000);
619 0 : cs=cos(double(StartWink)*3.14159265359/18000);
620 0 : RotatePoint(a,Center.x,Center.y,sn,cs);
621 0 : sn=sin(double(StartWink+RelWink)*3.14159265359/18000);
622 0 : cs=cos(double(StartWink+RelWink)*3.14159265359/18000);
623 0 : RotatePoint(b,Center.x,Center.y,sn,cs);
624 0 : if (Radius.x!=Radius.y) {
625 0 : if (Radius.x<1) Radius.x=1;
626 0 : if (Radius.y<1) Radius.y=1;
627 0 : a.y = a.y - Center.y;
628 0 : b.y = b.y - Center.y;
629 0 : a.y=iMulDiv(a.y,Radius.y,Radius.x);
630 0 : b.y=iMulDiv(b.y,Radius.y,Radius.x);
631 0 : a.y = a.y + Center.y;
632 0 : b.y = b.y + Center.y;
633 : }
634 0 : aStrt=Point(a.x,a.y);
635 0 : aEnde=Point(b.x,b.y);
636 0 : SetLine(L,rOut);
637 0 : switch (Flags & 0x03) {
638 0 : case CircArc : rOut.DrawArc(aRect,aEnde,aStrt); break;
639 : case CircSect:
640 0 : case CircAbsn: rOut.DrawPie(aRect,aEnde,aStrt); break;
641 : }
642 : }
643 2 : }
644 :
645 0 : void BmapType::Draw(OutputDevice& rOut)
646 : {
647 : //ifstream aInp;
648 : unsigned char nSgfTyp;
649 : sal_uInt16 nVersion;
650 : OUString aStr(
651 : reinterpret_cast< char const * >(&Filename[ 1 ]),
652 0 : (sal_Int32)Filename[ 0 ], RTL_TEXTENCODING_UTF8 );
653 0 : INetURLObject aFNam( aStr );
654 :
655 0 : SvStream* pInp = ::utl::UcbStreamHelper::CreateStream( aFNam.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
656 0 : if ( pInp )
657 : {
658 0 : nSgfTyp=CheckSgfTyp( *pInp,nVersion);
659 0 : switch(nSgfTyp) {
660 : case SGF_BITIMAGE: {
661 0 : GraphicFilter aFlt;
662 0 : Graphic aGrf;
663 0 : aFlt.ImportGraphic(aGrf,aFNam);
664 0 : aGrf.Draw(&rOut,Point(Pos1.x,Pos1.y),Size(Pos2.x-Pos1.x,Pos2.y-Pos1.y));
665 0 : } break;
666 : case SGF_SIMPVECT: {
667 0 : GDIMetaFile aMtf;
668 0 : SgfVectXofs=Pos1.x;
669 0 : SgfVectYofs=Pos1.y;
670 0 : SgfVectXmul=Pos2.x-Pos1.x;
671 0 : SgfVectYmul=Pos2.y-Pos1.y;
672 0 : SgfVectXdiv=0;
673 0 : SgfVectYdiv=0;
674 0 : SgfVectScal=true;
675 0 : SgfVectFilter(*pInp,aMtf);
676 0 : SgfVectXofs=0;
677 0 : SgfVectYofs=0;
678 0 : SgfVectXmul=0;
679 0 : SgfVectYmul=0;
680 0 : SgfVectXdiv=0;
681 0 : SgfVectYdiv=0;
682 0 : SgfVectScal=false;
683 0 : aMtf.Play(&rOut);
684 0 : } break;
685 : }
686 0 : delete pInp;
687 0 : }
688 0 : }
689 :
690 2 : sal_uInt32 GrupType::GetSubPtr()
691 : {
692 2 : return sal_uInt32(SbLo)+0x00010000*sal_uInt32(SbHi);
693 : }
694 :
695 4 : void DrawObjkList( SvStream& rInp, OutputDevice& rOut )
696 : {
697 4 : ObjkType aObjk;
698 4 : sal_uInt16 nGrpCnt=0;
699 4 : bool bEnd=false;
700 16 : do {
701 16 : ReadObjkType( rInp, aObjk );
702 16 : if (!rInp.GetError()) {
703 16 : switch(aObjk.Art) {
704 0 : case ObjStrk: { StrkType aStrk; ReadStrkType( rInp, aStrk ); if (!rInp.GetError()) aStrk.Draw(rOut); } break;
705 0 : case ObjRect: { RectType aRect; ReadRectType( rInp, aRect ); if (!rInp.GetError()) aRect.Draw(rOut); } break;
706 2 : case ObjCirc: { CircType aCirc; ReadCircType( rInp, aCirc ); if (!rInp.GetError()) aCirc.Draw(rOut); } break;
707 : case ObjText: {
708 0 : TextType aText;
709 0 : ReadTextType( rInp, aText );
710 0 : if (!rInp.GetError()) {
711 0 : aText.Buffer=new UCHAR[aText.BufSize+1]; // add one for LookAhead at CK-separation
712 0 : rInp.Read((char* )aText.Buffer,aText.BufSize);
713 0 : if (!rInp.GetError()) aText.Draw(rOut);
714 0 : delete[] aText.Buffer;
715 0 : }
716 0 : } break;
717 : case ObjBmap: {
718 0 : BmapType aBmap;
719 0 : ReadBmapType( rInp, aBmap );
720 0 : if (!rInp.GetError()) {
721 0 : aBmap.Draw(rOut);
722 0 : }
723 0 : } break;
724 : case ObjPoly: {
725 6 : PolyType aPoly;
726 6 : ReadPolyType( rInp, aPoly );
727 6 : if (!rInp.GetError()) {
728 6 : aPoly.EckP=new PointType[aPoly.nPoints];
729 6 : rInp.Read((char*)aPoly.EckP,4*aPoly.nPoints);
730 : #if defined OSL_BIGENDIAN
731 : for(short i=0;i<aPoly.nPoints;i++) SWAPPOINT(aPoly.EckP[i]);
732 : #endif
733 6 : if (!rInp.GetError()) aPoly.Draw(rOut);
734 6 : delete[] aPoly.EckP;
735 6 : }
736 6 : } break;
737 : case ObjSpln: {
738 6 : SplnType aSpln;
739 6 : ReadSplnType( rInp, aSpln );
740 6 : if (!rInp.GetError()) {
741 6 : aSpln.EckP=new PointType[aSpln.nPoints];
742 6 : rInp.Read((char*)aSpln.EckP,4*aSpln.nPoints);
743 : #if defined OSL_BIGENDIAN
744 : for(short i=0;i<aSpln.nPoints;i++) SWAPPOINT(aSpln.EckP[i]);
745 : #endif
746 6 : if (!rInp.GetError()) aSpln.Draw(rOut);
747 6 : delete[] aSpln.EckP;
748 6 : }
749 6 : } break;
750 : case ObjGrup: {
751 2 : GrupType aGrup;
752 2 : ReadGrupType( rInp, aGrup );
753 2 : if (!rInp.GetError()) {
754 2 : rInp.Seek(rInp.Tell()+aGrup.Last); // object appendix
755 2 : if(aGrup.GetSubPtr()!=0L) nGrpCnt++; // DrawObjkList(rInp,rOut );
756 2 : }
757 2 : } break;
758 : default: {
759 0 : aObjk.Draw(rOut); // object name on 2. Screen
760 0 : ObjkOverSeek(rInp,aObjk); // to next object
761 : }
762 : }
763 : } // if rInp
764 16 : if (!rInp.GetError()) {
765 16 : if (aObjk.Next==0L) {
766 6 : if (nGrpCnt==0) bEnd=true;
767 2 : else nGrpCnt--;
768 : }
769 : } else {
770 0 : bEnd=true; // read error
771 : }
772 20 : } while (!bEnd);
773 4 : }
774 :
775 0 : void SkipObjkList(SvStream& rInp)
776 : {
777 0 : ObjkType aObjk;
778 0 : do
779 : {
780 0 : ReadObjkType( rInp, aObjk );
781 0 : if(aObjk.Art==ObjGrup) {
782 0 : GrupType aGrup;
783 0 : ReadGrupType( rInp, aGrup );
784 0 : rInp.Seek(rInp.Tell()+aGrup.Last); // object appendix
785 0 : if(aGrup.GetSubPtr()!=0L) SkipObjkList(rInp);
786 : } else {
787 0 : ObjkOverSeek(rInp,aObjk); // to next object
788 : }
789 0 : } while (aObjk.Next!=0L && !rInp.GetError());
790 0 : }
791 :
792 4 : bool SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf )
793 : {
794 4 : bool bRet = false;
795 4 : PageType aPage;
796 4 : VirtualDevice aOutDev;
797 : OutputDevice* pOutDev;
798 : sal_uLong nStdPos;
799 : sal_uLong nCharPos;
800 : sal_uInt16 Num;
801 :
802 4 : pOutDev=&aOutDev;
803 4 : DtHdOverSeek(rInp); // read dataheader
804 :
805 4 : nStdPos=rInp.Tell();
806 4 : do { // read standard page
807 4 : ReadPageType( rInp, aPage );
808 4 : if (aPage.nList!=0) SkipObjkList(rInp);
809 4 : } while (aPage.Next!=0L && !rInp.GetError());
810 :
811 4 : nCharPos=rInp.Tell();
812 4 : ReadPageType( rInp, aPage );
813 :
814 4 : rMtf.Record(pOutDev);
815 4 : Num=aPage.StdPg;
816 4 : if (Num!=0) {
817 4 : rInp.Seek(nStdPos);
818 8 : while(Num>1 && aPage.Next!=0L && !rInp.GetError()) { // search standard page
819 0 : ReadPageType( rInp, aPage );
820 0 : if (aPage.nList!=0) SkipObjkList(rInp);
821 0 : Num--;
822 : }
823 4 : ReadPageType( rInp, aPage );
824 4 : if(Num==1 && aPage.nList!=0L) DrawObjkList( rInp,*pOutDev );
825 4 : rInp.Seek(nCharPos);
826 4 : nCharPos=rInp.Tell();
827 4 : ReadPageType( rInp, aPage );
828 : }
829 4 : if (aPage.nList!=0L) DrawObjkList(rInp,*pOutDev );
830 :
831 4 : rMtf.Stop();
832 4 : rMtf.WindStart();
833 8 : MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4));
834 4 : rMtf.SetPrefMapMode(aMap);
835 4 : rMtf.SetPrefSize(Size((sal_Int16)aPage.Paper.Size.x,(sal_Int16)aPage.Paper.Size.y));
836 4 : bRet=true;
837 8 : return bRet;
838 : }
839 :
840 4 : bool SgfSDrwFilter(SvStream& rInp, GDIMetaFile& rMtf, const INetURLObject& _aIniPath )
841 : {
842 : #if OSL_DEBUG_LEVEL > 1 // check record size. New compiler possibly aligns different!
843 : if (sizeof(ObjTextType)!=ObjTextTypeSize) return false;
844 : #endif
845 :
846 : sal_uLong nFileStart; // offset of SgfHeaders. In general 0.
847 4 : SgfHeader aHead;
848 4 : SgfEntry aEntr;
849 : sal_uLong nNext;
850 4 : bool bRet=false; // return value
851 :
852 4 : INetURLObject aIniPath = _aIniPath;
853 4 : aIniPath.Append(OUString("sgf.ini"));
854 :
855 4 : pSgfFonts = new SgfFontLst;
856 :
857 4 : pSgfFonts->AssignFN( aIniPath.GetMainURL( INetURLObject::NO_DECODE ) );
858 4 : nFileStart=rInp.Tell();
859 4 : ReadSgfHeader( rInp, aHead );
860 4 : if (aHead.ChkMagic() && aHead.Typ==SgfStarDraw && aHead.Version==SGV_VERSION) {
861 4 : nNext=aHead.GetOffset();
862 16 : while (nNext && !rInp.GetError()) {
863 8 : rInp.Seek(nFileStart+nNext);
864 8 : ReadSgfEntry( rInp, aEntr );
865 8 : nNext=aEntr.GetOffset();
866 8 : if (aEntr.Typ==aHead.Typ) {
867 4 : bRet=SgfFilterSDrw( rInp,aHead,aEntr,rMtf );
868 : }
869 : } // while(nNext)
870 : }
871 4 : delete pSgfFonts;
872 4 : return(bRet);
873 1233 : }
874 :
875 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|