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 2 : void DtHdOverSeek(SvStream& rInp)
143 : {
144 2 : sal_uLong FPos=rInp.Tell();
145 2 : FPos+=(sal_uLong)DtHdSize;
146 2 : rInp.Seek(FPos);
147 2 : }
148 :
149 2 : PageType::PageType()
150 : {
151 2 : memset( this, 0, sizeof( PageType ) );
152 2 : }
153 :
154 8 : SvStream& ReadPageType(SvStream& rIStream, PageType& rPage)
155 : {
156 8 : rIStream.Read((char*)&rPage.Next,PageSize);
157 : #if defined OSL_BIGENDIAN
158 : SWAPPAGE(rPage);
159 : #endif
160 8 : 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 8 : SvStream& ReadObjkType(SvStream& rInp, ObjkType& rObjk)
171 : {
172 : // fileposition in stream is not changed!
173 : sal_uLong nPos;
174 8 : nPos=rInp.Tell();
175 8 : rInp.Read((char*)&rObjk.Last,ObjkSize);
176 : #if defined OSL_BIGENDIAN
177 : SWAPOBJK(rObjk);
178 : #endif
179 : #ifdef InArbeit
180 : sal_uLong nPos1=rInp.Tell();
181 : if(nPos == nPos1) InfoBox( NULL, "tellg is not working" ).Execute();
182 : #endif
183 8 : rInp.Seek(nPos);
184 : #ifdef InArbeit
185 : if (rInp.Tell() != nPos) InfoBox( NULL, "seekg is not working" ).Execute();
186 : #endif
187 8 : return rInp;
188 : }
189 0 : SvStream& ReadStrkType(SvStream& rInp, StrkType& rStrk)
190 : {
191 0 : rInp.Read((char*)&rStrk.Last,StrkSize);
192 : #if defined OSL_BIGENDIAN
193 : SWAPOBJK (rStrk);
194 : SWAPLINE (rStrk.L);
195 : SWAPPOINT(rStrk.Pos1);
196 : SWAPPOINT(rStrk.Pos2);
197 : #endif
198 0 : return rInp;
199 : }
200 0 : SvStream& ReadRectType(SvStream& rInp, RectType& rRect)
201 : {
202 0 : rInp.Read((char*)&rRect.Last,RectSize);
203 : #if defined OSL_BIGENDIAN
204 : SWAPOBJK (rRect);
205 : SWAPLINE (rRect.L);
206 : SWAPAREA (rRect.F);
207 : SWAPPOINT(rRect.Pos1);
208 : SWAPPOINT(rRect.Pos2);
209 : rRect.Radius =OSL_SWAPWORD(rRect.Radius );
210 : rRect.DrehWink=OSL_SWAPWORD(rRect.DrehWink);
211 : rRect.Slant =OSL_SWAPWORD(rRect.Slant );
212 : #endif
213 0 : return rInp;
214 : }
215 3 : SvStream& ReadPolyType(SvStream& rInp, PolyType& rPoly)
216 : {
217 3 : rInp.Read((char*)&rPoly.Last,PolySize);
218 : #if defined OSL_BIGENDIAN
219 : SWAPOBJK (rPoly);
220 : SWAPLINE (rPoly.L);
221 : SWAPAREA (rPoly.F);
222 : #endif
223 3 : return rInp;
224 : }
225 3 : SvStream& ReadSplnType(SvStream& rInp, SplnType& rSpln)
226 : {
227 3 : rInp.Read((char*)&rSpln.Last,SplnSize);
228 : #if defined OSL_BIGENDIAN
229 : SWAPOBJK (rSpln);
230 : SWAPLINE (rSpln.L);
231 : SWAPAREA (rSpln.F);
232 : #endif
233 3 : return rInp;
234 : }
235 1 : SvStream& ReadCircType(SvStream& rInp, CircType& rCirc)
236 : {
237 1 : rInp.Read((char*)&rCirc.Last,CircSize);
238 : #if defined OSL_BIGENDIAN
239 : SWAPOBJK (rCirc);
240 : SWAPLINE (rCirc.L);
241 : SWAPAREA (rCirc.F);
242 : SWAPPOINT(rCirc.Radius);
243 : SWAPPOINT(rCirc.Center);
244 : rCirc.DrehWink =OSL_SWAPWORD(rCirc.DrehWink );
245 : rCirc.StartWink=OSL_SWAPWORD(rCirc.StartWink);
246 : rCirc.RelWink =OSL_SWAPWORD(rCirc.RelWink );
247 : #endif
248 1 : return rInp;
249 : }
250 0 : SvStream& ReadTextType(SvStream& rInp, TextType& rText)
251 : {
252 0 : rInp.Read((char*)&rText.Last,TextSize);
253 : #if defined OSL_BIGENDIAN
254 : SWAPOBJK (rText);
255 : SWAPTEXT (rText.T);
256 : SWAPPOINT(rText.Pos1);
257 : SWAPPOINT(rText.Pos2);
258 : rText.TopOfs =OSL_SWAPWORD(rText.TopOfs );
259 : rText.DrehWink=OSL_SWAPWORD(rText.DrehWink);
260 : rText.BoxSlant=OSL_SWAPWORD(rText.BoxSlant);
261 : rText.BufSize =OSL_SWAPWORD(rText.BufSize );
262 : SWAPPOINT(rText.FitSize);
263 : rText.FitBreit=OSL_SWAPWORD(rText.FitBreit);
264 : #endif
265 0 : rText.Buffer=NULL;
266 0 : return rInp;
267 : }
268 0 : SvStream& ReadBmapType(SvStream& rInp, BmapType& rBmap)
269 : {
270 0 : rInp.Read((char*)&rBmap.Last,BmapSize);
271 : #if defined OSL_BIGENDIAN
272 : SWAPOBJK (rBmap);
273 : SWAPAREA (rBmap.F);
274 : SWAPPOINT(rBmap.Pos1);
275 : SWAPPOINT(rBmap.Pos2);
276 : rBmap.DrehWink=OSL_SWAPWORD(rBmap.DrehWink);
277 : rBmap.Slant =OSL_SWAPWORD(rBmap.Slant );
278 : SWAPPOINT(rBmap.PixSize);
279 : #endif
280 0 : return rInp;
281 : }
282 1 : SvStream& ReadGrupType(SvStream& rInp, GrupType& rGrup)
283 : {
284 1 : rInp.Read((char*)&rGrup.Last,GrupSize);
285 : #if defined OSL_BIGENDIAN
286 : SWAPOBJK (rGrup);
287 : rGrup.SbLo =OSL_SWAPWORD(rGrup.SbLo );
288 : rGrup.SbHi =OSL_SWAPWORD(rGrup.SbHi );
289 : rGrup.UpLo =OSL_SWAPWORD(rGrup.UpLo );
290 : rGrup.UpHi =OSL_SWAPWORD(rGrup.UpHi );
291 : rGrup.ChartSize=OSL_SWAPWORD(rGrup.ChartSize);
292 : rGrup.ChartPtr =OSL_SWAPDWORD (rGrup.ChartPtr );
293 : #endif
294 1 : return rInp;
295 : }
296 :
297 12 : Color Sgv2SvFarbe(sal_uInt8 nFrb1, sal_uInt8 nFrb2, sal_uInt8 nInts)
298 : {
299 12 : sal_uInt16 r1=0,g1=0,b1=0,r2=0,g2=0,b2=0;
300 12 : sal_uInt8 nInt2=100-nInts;
301 12 : switch(nFrb1 & 0x07) {
302 1 : case 0: r1=0xFF; g1=0xFF; b1=0xFF; break;
303 0 : case 1: r1=0xFF; g1=0xFF; break;
304 0 : case 2: g1=0xFF; b1=0xFF; break;
305 1 : case 3: g1=0xFF; break;
306 1 : case 4: r1=0xFF; b1=0xFF; break;
307 0 : case 5: r1=0xFF; break;
308 1 : case 6: b1=0xFF; break;
309 8 : case 7: break;
310 : }
311 12 : switch(nFrb2 & 0x07) {
312 12 : case 0: r2=0xFF; g2=0xFF; b2=0xFF; break;
313 0 : case 1: r2=0xFF; g2=0xFF; break;
314 0 : case 2: g2=0xFF; b2=0xFF; break;
315 0 : case 3: g2=0xFF; break;
316 0 : case 4: r2=0xFF; b2=0xFF; break;
317 0 : case 5: r2=0xFF; break;
318 0 : case 6: b2=0xFF; break;
319 0 : case 7: break;
320 : }
321 12 : r1=(sal_uInt16)((sal_uInt32)r1*nInts/100+(sal_uInt32)r2*nInt2/100);
322 12 : g1=(sal_uInt16)((sal_uInt32)g1*nInts/100+(sal_uInt32)g2*nInt2/100);
323 12 : b1=(sal_uInt16)((sal_uInt32)b1*nInts/100+(sal_uInt32)b2*nInt2/100);
324 12 : Color aColor( (sal_uInt8)r1, (sal_uInt8)g1, (sal_uInt8)b1 );
325 12 : return aColor;
326 : }
327 :
328 7 : void SetLine(ObjLineType& rLine, OutputDevice& rOut)
329 : {
330 7 : if( 0 == ( rLine.LMuster & 0x07 ) )
331 0 : rOut.SetLineColor();
332 : else
333 7 : rOut.SetLineColor( Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens) );
334 7 : }
335 :
336 7 : void SetArea(ObjAreaType& rArea, OutputDevice& rOut)
337 : {
338 7 : if( 0 == ( rArea.FMuster & 0x00FF ) )
339 2 : rOut.SetFillColor();
340 : else
341 5 : rOut.SetFillColor( Sgv2SvFarbe( rArea.FFarbe,rArea.FBFarbe,rArea.FIntens ) );
342 7 : }
343 :
344 0 : void ObjkType::Draw(OutputDevice&)
345 : {
346 0 : }
347 :
348 0 : void Obj0Type::Draw(OutputDevice&) {}
349 :
350 0 : void StrkType::Draw(OutputDevice& rOut)
351 : {
352 0 : SetLine(L,rOut);
353 0 : rOut.DrawLine(Point(Pos1.x,Pos1.y),Point(Pos2.x,Pos2.y)); // !!!
354 0 : }
355 :
356 0 : void SgfAreaColorIntens(sal_uInt16 Muster, sal_uInt8 Col1, sal_uInt8 Col2, sal_uInt8 Int, OutputDevice& rOut)
357 : {
358 : ObjAreaType F;
359 0 : F.FMuster=Muster;
360 0 : F.FFarbe=Col2;
361 0 : F.FBFarbe=Col1;
362 0 : F.FIntens=Int;
363 0 : SetArea(F,rOut);
364 0 : }
365 :
366 0 : void DrawSlideRect(sal_Int16 x1, sal_Int16 y1, sal_Int16 x2, sal_Int16 y2, ObjAreaType& F, OutputDevice& rOut)
367 : {
368 : sal_Int16 i,i0,b,b0;
369 : sal_Int16 Int1,Int2;
370 : sal_Int16 Col1,Col2;
371 : // ClipMerk: HgdClipRec;
372 : sal_Int16 cx,cy;
373 : sal_Int16 MaxR;
374 : sal_Int32 dx,dy;
375 :
376 0 : rOut.SetLineColor();
377 0 : if (x1>x2) { i=x1; x1=x2; x2=i; }
378 0 : if (y1>y2) { i=y1; y1=y2; y2=i; }
379 0 : Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
380 0 : Int1=100-F.FIntens; Int2=F.FIntens;
381 0 : if (Int1==Int2) {
382 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
383 0 : rOut.DrawRect(Rectangle(x1,y1,x2,y2));
384 : } else {
385 0 : b0=Int1;
386 0 : switch (F.FBFarbe & 0x38) {
387 : case 0x08: { // vertikal
388 0 : i0=y1;
389 0 : i=y1;
390 0 : while (i<=y2) {
391 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-y1) /(sal_Int32)(y2-y1+1));
392 0 : if (b!=b0) {
393 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
394 0 : rOut.DrawRect(Rectangle(x1,i0,x2,i-1));
395 0 : i0=i; b0=b;
396 : }
397 0 : i++;
398 : }
399 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
400 0 : rOut.DrawRect(Rectangle(x1,i0,x2,y2));
401 0 : } break;
402 : case 0x28: { // horizontal
403 0 : i0=x1;
404 0 : i=x1;
405 0 : while (i<=x2) {
406 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-x1) /(sal_Int32)(x2-x1+1));
407 0 : if (b!=b0) {
408 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
409 0 : rOut.DrawRect(Rectangle(i0,y1,i-1,y2));
410 0 : i0=i; b0=b;
411 : }
412 0 : i++;
413 : }
414 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
415 0 : rOut.DrawRect(Rectangle(i0,y1,x2,y2));
416 0 : } break;
417 :
418 : case 0x18: case 0x38: { // circle
419 0 : Region ClipMerk=rOut.GetClipRegion();
420 : double a;
421 :
422 0 : rOut.SetClipRegion(Region(Rectangle(x1,y1,x2,y2)));
423 0 : cx=(x1+x2) /2;
424 0 : cy=(y1+y2) /2;
425 0 : dx=x2-x1+1;
426 0 : dy=y2-y1+1;
427 0 : a=sqrt((double)(dx*dx+dy*dy));
428 0 : MaxR=sal_Int16(a) /2 +1;
429 0 : b0=Int2;
430 0 : i0=MaxR; if (MaxR<1) MaxR=1;
431 0 : i=MaxR;
432 0 : while (i>=0) {
433 0 : b=Int1+sal_Int16((sal_Int32(Int2-Int1)*sal_Int32(i)) /sal_Int32(MaxR));
434 0 : if (b!=b0) {
435 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
436 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
437 0 : i0=i; b0=b;
438 : }
439 0 : i--;
440 : }
441 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int1,rOut);
442 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
443 0 : rOut.SetClipRegion(ClipMerk);
444 0 : } break; // circle
445 : }
446 : }
447 0 : }
448 :
449 0 : void RectType::Draw(OutputDevice& rOut)
450 : {
451 0 : if (L.LMuster!=0) L.LMuster=1; // no line separator here, only on or off
452 0 : SetArea(F,rOut);
453 0 : if (DrehWink==0) {
454 0 : if ((F.FBFarbe & 0x38)==0 || Radius!=0) {
455 0 : SetLine(L,rOut);
456 0 : rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y),Radius,Radius);
457 : } else {
458 0 : DrawSlideRect(Pos1.x,Pos1.y,Pos2.x,Pos2.y,F,rOut);
459 0 : if (L.LMuster!=0) {
460 0 : SetLine(L,rOut);
461 0 : rOut.SetFillColor();
462 0 : rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y));
463 : }
464 : }
465 : } else {
466 0 : Point aPts[4];
467 : sal_uInt16 i;
468 : double sn,cs;
469 0 : sn=sin(double(DrehWink)*3.14159265359/18000);
470 0 : cs=cos(double(DrehWink)*3.14159265359/18000);
471 0 : aPts[0]=Point(Pos1.x,Pos1.y);
472 0 : aPts[1]=Point(Pos2.x,Pos1.y);
473 0 : aPts[2]=Point(Pos2.x,Pos2.y);
474 0 : aPts[3]=Point(Pos1.x,Pos2.y);
475 0 : for (i=0;i<4;i++) {
476 0 : RotatePoint(aPts[i],Pos1.x,Pos1.y,sn,cs);
477 : }
478 0 : SetLine(L,rOut);
479 0 : Polygon aPoly(4,aPts);
480 0 : rOut.DrawPolygon(aPoly);
481 : }
482 0 : }
483 :
484 3 : void PolyType::Draw(OutputDevice& rOut)
485 : {
486 3 : if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
487 3 : SetLine(L,rOut);
488 3 : Polygon aPoly(nPoints);
489 : sal_uInt16 i;
490 3 : for(i=0;i<nPoints;i++) aPoly.SetPoint(Point(EckP[i].x,EckP[i].y),i);
491 3 : if ((Flags & PolyClosBit) !=0) {
492 3 : rOut.DrawPolygon(aPoly);
493 : } else {
494 0 : rOut.DrawPolyLine(aPoly);
495 3 : }
496 3 : }
497 :
498 3 : void SplnType::Draw(OutputDevice& rOut)
499 : {
500 3 : if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
501 3 : SetLine(L,rOut);
502 3 : Polygon aPoly(0);
503 6 : Polygon aSpln(nPoints);
504 : sal_uInt16 i;
505 3 : for(i=0;i<nPoints;i++) aSpln.SetPoint(Point(EckP[i].x,EckP[i].y),i);
506 3 : if ((Flags & PolyClosBit) !=0) {
507 3 : Spline2Poly(aSpln,true,aPoly);
508 3 : if (aPoly.GetSize()>0) rOut.DrawPolygon(aPoly);
509 : } else {
510 0 : Spline2Poly(aSpln,false,aPoly);
511 0 : if (aPoly.GetSize()>0) rOut.DrawPolyLine(aPoly);
512 3 : }
513 3 : }
514 :
515 0 : void DrawSlideCirc(sal_Int16 cx, sal_Int16 cy, sal_Int16 rx, sal_Int16 ry, ObjAreaType& F, OutputDevice& rOut)
516 : {
517 0 : sal_Int16 x1=cx-rx;
518 0 : sal_Int16 y1=cy-ry;
519 0 : sal_Int16 x2=cx+rx;
520 0 : sal_Int16 y2=cy+ry;
521 :
522 : sal_Int16 i,i0,b,b0;
523 : sal_Int16 Int1,Int2;
524 : sal_Int16 Col1,Col2;
525 :
526 0 : rOut.SetLineColor();
527 0 : Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
528 0 : Int1=100-F.FIntens; Int2=F.FIntens;
529 0 : if (Int1==Int2) {
530 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
531 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
532 : } else {
533 0 : b0=Int1;
534 0 : switch (F.FBFarbe & 0x38) {
535 : case 0x08: { // vertical
536 0 : Region ClipMerk=rOut.GetClipRegion();
537 0 : i0=y1;
538 0 : i=y1;
539 0 : while (i<=y2) {
540 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-y1) /(sal_Int32)(y2-y1+1));
541 0 : if (b!=b0) {
542 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
543 0 : rOut.SetClipRegion(Region(Rectangle(x1,i0,x2,i-1)));
544 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
545 0 : i0=i; b0=b;
546 : }
547 0 : i++;
548 : }
549 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
550 0 : rOut.SetClipRegion(Region(Rectangle(x1,i0,x2,y2)));
551 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
552 0 : rOut.SetClipRegion(ClipMerk);
553 0 : } break;
554 : case 0x28: { // horizontal
555 0 : Region ClipMerk=rOut.GetClipRegion();
556 0 : i0=x1;
557 0 : i=x1;
558 0 : while (i<=x2) {
559 0 : b=Int1+sal_Int16((sal_Int32)(Int2-Int1)*(sal_Int32)(i-x1) /(sal_Int32)(x2-x1+1));
560 0 : if (b!=b0) {
561 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
562 0 : rOut.SetClipRegion(Region(Rectangle(i0,y1,i-1,y2)));
563 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
564 0 : i0=i; b0=b;
565 : }
566 0 : i++;
567 : }
568 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int2,rOut);
569 0 : rOut.SetClipRegion(Region(Rectangle(i0,y1,x2,y2)));
570 0 : rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
571 0 : rOut.SetClipRegion(ClipMerk);
572 0 : } break;
573 :
574 : case 0x18: case 0x38: { // circle
575 : sal_Int16 MaxR;
576 :
577 0 : if (rx<1) rx=1;
578 0 : if (ry<1) ry=1;
579 0 : MaxR=rx;
580 0 : b0=Int2;
581 0 : i0=MaxR;
582 0 : i=MaxR;
583 0 : while (i>=0) {
584 0 : b=Int1+sal_Int16((sal_Int32(Int2-Int1)*sal_Int32(i)) /sal_Int32(MaxR));
585 0 : if (b!=b0) {
586 0 : sal_Int32 temp=sal_Int32(i0)*sal_Int32(ry)/sal_Int32(rx);
587 0 : sal_Int16 j0=sal_Int16(temp);
588 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)b0,rOut);
589 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-j0,cx+i0,cy+j0));
590 0 : i0=i; b0=b;
591 : }
592 0 : i--;
593 : }
594 0 : SgfAreaColorIntens(F.FMuster,(sal_uInt8)Col1,(sal_uInt8)Col2,(sal_uInt8)Int1,rOut);
595 0 : rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
596 0 : } break; // circle
597 : }
598 : }
599 0 : }
600 :
601 1 : void CircType::Draw(OutputDevice& rOut)
602 : {
603 1 : Rectangle aRect(Center.x-Radius.x,Center.y-Radius.y,Center.x+Radius.x,Center.y+Radius.y);
604 :
605 1 : if (L.LMuster!=0) L.LMuster=1; // no line pattern here, only on or off
606 1 : SetArea(F,rOut);
607 1 : if ((Flags & 0x03)==CircFull) {
608 1 : if ((F.FBFarbe & 0x38)==0) {
609 1 : SetLine(L,rOut);
610 1 : rOut.DrawEllipse(aRect);
611 : } else {
612 0 : DrawSlideCirc(Center.x,Center.y,Radius.x,Radius.y,F,rOut);
613 0 : if (L.LMuster!=0) {
614 0 : SetLine(L,rOut);
615 0 : rOut.SetFillColor();
616 0 : rOut.DrawEllipse(aRect);
617 : }
618 : }
619 : } else {
620 : PointType a,b;
621 0 : Point aStrt,aEnde;
622 : double sn,cs;
623 :
624 0 : a.x=Center.x+Radius.x; a.y=Center.y; b=a;
625 0 : sn=sin(double(StartWink)*3.14159265359/18000);
626 0 : cs=cos(double(StartWink)*3.14159265359/18000);
627 0 : RotatePoint(a,Center.x,Center.y,sn,cs);
628 0 : sn=sin(double(StartWink+RelWink)*3.14159265359/18000);
629 0 : cs=cos(double(StartWink+RelWink)*3.14159265359/18000);
630 0 : RotatePoint(b,Center.x,Center.y,sn,cs);
631 0 : if (Radius.x!=Radius.y) {
632 0 : if (Radius.x<1) Radius.x=1;
633 0 : if (Radius.y<1) Radius.y=1;
634 0 : a.y = a.y - Center.y;
635 0 : b.y = b.y - Center.y;
636 0 : a.y=iMulDiv(a.y,Radius.y,Radius.x);
637 0 : b.y=iMulDiv(b.y,Radius.y,Radius.x);
638 0 : a.y = a.y + Center.y;
639 0 : b.y = b.y + Center.y;
640 : }
641 0 : aStrt=Point(a.x,a.y);
642 0 : aEnde=Point(b.x,b.y);
643 0 : SetLine(L,rOut);
644 0 : switch (Flags & 0x03) {
645 0 : case CircArc : rOut.DrawArc(aRect,aEnde,aStrt); break;
646 : case CircSect:
647 0 : case CircAbsn: rOut.DrawPie(aRect,aEnde,aStrt); break;
648 : }
649 : }
650 1 : }
651 :
652 0 : void BmapType::Draw(OutputDevice& rOut)
653 : {
654 : //ifstream aInp;
655 : unsigned char nSgfTyp;
656 : sal_uInt16 nVersion;
657 : OUString aStr(
658 : reinterpret_cast< char const * >(&Filename[ 1 ]),
659 0 : (sal_Int32)Filename[ 0 ], RTL_TEXTENCODING_UTF8 );
660 0 : INetURLObject aFNam( aStr );
661 :
662 0 : SvStream* pInp = ::utl::UcbStreamHelper::CreateStream( aFNam.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
663 0 : if ( pInp )
664 : {
665 0 : nSgfTyp=CheckSgfTyp( *pInp,nVersion);
666 0 : switch(nSgfTyp) {
667 : case SGF_BITIMAGE: {
668 0 : GraphicFilter aFlt;
669 0 : Graphic aGrf;
670 0 : aFlt.ImportGraphic(aGrf,aFNam);
671 0 : aGrf.Draw(&rOut,Point(Pos1.x,Pos1.y),Size(Pos2.x-Pos1.x,Pos2.y-Pos1.y));
672 0 : } break;
673 : case SGF_SIMPVECT: {
674 0 : GDIMetaFile aMtf;
675 0 : SgfVectXofs=Pos1.x;
676 0 : SgfVectYofs=Pos1.y;
677 0 : SgfVectXmul=Pos2.x-Pos1.x;
678 0 : SgfVectYmul=Pos2.y-Pos1.y;
679 0 : SgfVectXdiv=0;
680 0 : SgfVectYdiv=0;
681 0 : SgfVectScal=true;
682 0 : SgfVectFilter(*pInp,aMtf);
683 0 : SgfVectXofs=0;
684 0 : SgfVectYofs=0;
685 0 : SgfVectXmul=0;
686 0 : SgfVectYmul=0;
687 0 : SgfVectXdiv=0;
688 0 : SgfVectYdiv=0;
689 0 : SgfVectScal=false;
690 0 : aMtf.Play(&rOut);
691 0 : } break;
692 : }
693 0 : delete pInp;
694 0 : }
695 0 : }
696 :
697 1 : sal_uInt32 GrupType::GetSubPtr()
698 : {
699 1 : return sal_uInt32(SbLo)+0x00010000*sal_uInt32(SbHi);
700 : }
701 :
702 2 : void DrawObjkList( SvStream& rInp, OutputDevice& rOut )
703 : {
704 2 : ObjkType aObjk;
705 2 : sal_uInt16 nGrpCnt=0;
706 2 : bool bEnd=false;
707 8 : do {
708 8 : ReadObjkType( rInp, aObjk );
709 8 : if (!rInp.GetError()) {
710 8 : switch(aObjk.Art) {
711 0 : case ObjStrk: { StrkType aStrk; ReadStrkType( rInp, aStrk ); if (!rInp.GetError()) aStrk.Draw(rOut); } break;
712 0 : case ObjRect: { RectType aRect; ReadRectType( rInp, aRect ); if (!rInp.GetError()) aRect.Draw(rOut); } break;
713 1 : case ObjCirc: { CircType aCirc; ReadCircType( rInp, aCirc ); if (!rInp.GetError()) aCirc.Draw(rOut); } break;
714 : case ObjText: {
715 0 : TextType aText;
716 0 : ReadTextType( rInp, aText );
717 0 : if (!rInp.GetError()) {
718 0 : aText.Buffer=new UCHAR[aText.BufSize+1]; // add one for LookAhead at CK-separation
719 0 : rInp.Read((char* )aText.Buffer,aText.BufSize);
720 0 : if (!rInp.GetError()) aText.Draw(rOut);
721 0 : delete[] aText.Buffer;
722 0 : }
723 0 : } break;
724 : case ObjBmap: {
725 0 : BmapType aBmap;
726 0 : ReadBmapType( rInp, aBmap );
727 0 : if (!rInp.GetError()) {
728 0 : aBmap.Draw(rOut);
729 0 : }
730 0 : } break;
731 : case ObjPoly: {
732 3 : PolyType aPoly;
733 3 : ReadPolyType( rInp, aPoly );
734 3 : if (!rInp.GetError()) {
735 3 : aPoly.EckP=new PointType[aPoly.nPoints];
736 3 : rInp.Read((char*)aPoly.EckP,4*aPoly.nPoints);
737 : #if defined OSL_BIGENDIAN
738 : for(short i=0;i<aPoly.nPoints;i++) SWAPPOINT(aPoly.EckP[i]);
739 : #endif
740 3 : if (!rInp.GetError()) aPoly.Draw(rOut);
741 3 : delete[] aPoly.EckP;
742 3 : }
743 3 : } break;
744 : case ObjSpln: {
745 3 : SplnType aSpln;
746 3 : ReadSplnType( rInp, aSpln );
747 3 : if (!rInp.GetError()) {
748 3 : aSpln.EckP=new PointType[aSpln.nPoints];
749 3 : rInp.Read((char*)aSpln.EckP,4*aSpln.nPoints);
750 : #if defined OSL_BIGENDIAN
751 : for(short i=0;i<aSpln.nPoints;i++) SWAPPOINT(aSpln.EckP[i]);
752 : #endif
753 3 : if (!rInp.GetError()) aSpln.Draw(rOut);
754 3 : delete[] aSpln.EckP;
755 3 : }
756 3 : } break;
757 : case ObjGrup: {
758 1 : GrupType aGrup;
759 1 : ReadGrupType( rInp, aGrup );
760 1 : if (!rInp.GetError()) {
761 1 : rInp.Seek(rInp.Tell()+aGrup.Last); // object appendix
762 1 : if(aGrup.GetSubPtr()!=0L) nGrpCnt++; // DrawObjkList(rInp,rOut );
763 1 : }
764 1 : } break;
765 : default: {
766 0 : aObjk.Draw(rOut); // object name on 2. Screen
767 0 : ObjkOverSeek(rInp,aObjk); // to next object
768 : }
769 : }
770 : } // if rInp
771 8 : if (!rInp.GetError()) {
772 8 : if (aObjk.Next==0L) {
773 3 : if (nGrpCnt==0) bEnd=true;
774 1 : else nGrpCnt--;
775 : }
776 : } else {
777 0 : bEnd=true; // read error
778 : }
779 10 : } while (!bEnd);
780 2 : }
781 :
782 0 : void SkipObjkList(SvStream& rInp)
783 : {
784 0 : ObjkType aObjk;
785 0 : do
786 : {
787 0 : ReadObjkType( rInp, aObjk );
788 0 : if(aObjk.Art==ObjGrup) {
789 0 : GrupType aGrup;
790 0 : ReadGrupType( rInp, aGrup );
791 0 : rInp.Seek(rInp.Tell()+aGrup.Last); // object appendix
792 0 : if(aGrup.GetSubPtr()!=0L) SkipObjkList(rInp);
793 : } else {
794 0 : ObjkOverSeek(rInp,aObjk); // to next object
795 : }
796 0 : } while (aObjk.Next!=0L && !rInp.GetError());
797 0 : }
798 :
799 2 : bool SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf )
800 : {
801 2 : bool bRet = false;
802 2 : PageType aPage;
803 2 : VirtualDevice aOutDev;
804 : OutputDevice* pOutDev;
805 : sal_uLong nStdPos;
806 : sal_uLong nCharPos;
807 : sal_uInt16 Num;
808 :
809 2 : pOutDev=&aOutDev;
810 2 : DtHdOverSeek(rInp); // read dataheader
811 :
812 2 : nStdPos=rInp.Tell();
813 2 : do { // read standard page
814 2 : ReadPageType( rInp, aPage );
815 2 : if (aPage.nList!=0) SkipObjkList(rInp);
816 2 : } while (aPage.Next!=0L && !rInp.GetError());
817 :
818 : // ShowMsg("Drawingpage(n)\n");
819 2 : nCharPos=rInp.Tell();
820 2 : ReadPageType( rInp, aPage );
821 :
822 2 : rMtf.Record(pOutDev);
823 2 : Num=aPage.StdPg;
824 2 : if (Num!=0) {
825 2 : rInp.Seek(nStdPos);
826 4 : while(Num>1 && aPage.Next!=0L && !rInp.GetError()) { // search standard page
827 0 : ReadPageType( rInp, aPage );
828 0 : if (aPage.nList!=0) SkipObjkList(rInp);
829 0 : Num--;
830 : }
831 2 : ReadPageType( rInp, aPage );
832 2 : if(Num==1 && aPage.nList!=0L) DrawObjkList( rInp,*pOutDev );
833 2 : rInp.Seek(nCharPos);
834 2 : nCharPos=rInp.Tell();
835 2 : ReadPageType( rInp, aPage );
836 : }
837 2 : if (aPage.nList!=0L) DrawObjkList(rInp,*pOutDev );
838 :
839 2 : rMtf.Stop();
840 2 : rMtf.WindStart();
841 4 : MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4));
842 2 : rMtf.SetPrefMapMode(aMap);
843 2 : rMtf.SetPrefSize(Size((sal_Int16)aPage.Paper.Size.x,(sal_Int16)aPage.Paper.Size.y));
844 2 : bRet=true;
845 4 : return bRet;
846 : }
847 :
848 2 : bool SgfSDrwFilter(SvStream& rInp, GDIMetaFile& rMtf, INetURLObject aIniPath )
849 : {
850 : #if OSL_DEBUG_LEVEL > 1 // check record size. New compiler possibly aligns different!
851 : if (sizeof(ObjTextType)!=ObjTextTypeSize) return false;
852 : #endif
853 :
854 : sal_uLong nFileStart; // offset of SgfHeaders. In general 0.
855 2 : SgfHeader aHead;
856 2 : SgfEntry aEntr;
857 : sal_uLong nNext;
858 2 : bool bRet=false; // return value
859 :
860 2 : aIniPath.Append(OUString("sgf.ini"));
861 :
862 2 : pSgfFonts = new SgfFontLst;
863 :
864 2 : pSgfFonts->AssignFN( aIniPath.GetMainURL( INetURLObject::NO_DECODE ) );
865 2 : nFileStart=rInp.Tell();
866 2 : ReadSgfHeader( rInp, aHead );
867 2 : if (aHead.ChkMagic() && aHead.Typ==SgfStarDraw && aHead.Version==SGV_VERSION) {
868 2 : nNext=aHead.GetOffset();
869 8 : while (nNext && !rInp.GetError()) {
870 4 : rInp.Seek(nFileStart+nNext);
871 4 : ReadSgfEntry( rInp, aEntr );
872 4 : nNext=aEntr.GetOffset();
873 4 : if (aEntr.Typ==aHead.Typ) {
874 2 : bRet=SgfFilterSDrw( rInp,aHead,aEntr,rMtf );
875 : }
876 : } // while(nNext)
877 : }
878 2 : delete pSgfFonts;
879 2 : return(bRet);
880 : }
881 :
882 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|