update dev300-m58
[ooovba.git] / svtools / source / filter.vcl / filter / sgvmain.cxx
blob4490c38a269f75ab9e360b4b12d6dab49733c866
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sgvmain.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <rtl/math.hxx>
35 #include <osl/endian.h>
36 #include <vcl/graph.hxx>
37 #include <tools/poly.hxx>
38 #include <svtools/filter.hxx>
39 #include "sgffilt.hxx"
40 #include "sgfbram.hxx"
41 #include "sgvmain.hxx"
42 #include "sgvspln.hxx"
43 #include <unotools/ucbstreamhelper.hxx>
45 //#if OSL_DEBUG_LEVEL > 1
46 //#include "Debug.c"
47 //#endif
49 #define SWAPPOINT(p) { \
50 p.x=SWAPSHORT(p.x); \
51 p.y=SWAPSHORT(p.y); }
53 #define SWAPPAGE(p) { \
54 p.Next =SWAPLONG (p.Next ); \
55 p.nList =SWAPLONG (p.nList ); \
56 p.ListEnd=SWAPLONG (p.ListEnd); \
57 p.Paper.Size.x=SWAPSHORT(p.Paper.Size.x); \
58 p.Paper.Size.y=SWAPSHORT(p.Paper.Size.y); \
59 p.Paper.RandL =SWAPSHORT(p.Paper.RandL ); \
60 p.Paper.RandR =SWAPSHORT(p.Paper.RandR ); \
61 p.Paper.RandO =SWAPSHORT(p.Paper.RandO ); \
62 p.Paper.RandU =SWAPSHORT(p.Paper.RandU ); \
63 SWAPPOINT(p.U); \
64 UINT16 iTemp; \
65 for (iTemp=0;iTemp<20;iTemp++) { \
66 rPage.HlpLnH[iTemp]=SWAPSHORT(rPage.HlpLnH[iTemp]); \
67 rPage.HlpLnV[iTemp]=SWAPSHORT(rPage.HlpLnV[iTemp]); }}
69 #define SWAPOBJK(o) { \
70 o.Last =SWAPLONG (o.Last ); \
71 o.Next =SWAPLONG (o.Next ); \
72 o.MemSize =SWAPSHORT(o.MemSize ); \
73 SWAPPOINT(o.ObjMin); \
74 SWAPPOINT(o.ObjMax); }
76 #define SWAPLINE(l) { \
77 l.LMSize=SWAPSHORT(l.LMSize); \
78 l.LDicke=SWAPSHORT(l.LDicke); }
80 #define SWAPAREA(a) { \
81 a.FDummy2=SWAPSHORT(a.FDummy2); \
82 a.FMuster=SWAPSHORT(a.FMuster); }
84 #define SWAPTEXT(t) { \
85 SWAPLINE(t.L); \
86 SWAPAREA(t.F); \
87 t.FontLo =SWAPSHORT(t.FontLo ); \
88 t.FontHi =SWAPSHORT(t.FontHi ); \
89 t.Grad =SWAPSHORT(t.Grad ); \
90 t.Breite =SWAPSHORT(t.Breite ); \
91 t.Schnitt=SWAPSHORT(t.Schnitt); \
92 t.LnFeed =SWAPSHORT(t.LnFeed ); \
93 t.Slant =SWAPSHORT(t.Slant ); \
94 SWAPLINE(t.ShdL); \
95 SWAPAREA(t.ShdF); \
96 SWAPPOINT(t.ShdVers); \
97 SWAPAREA(t.BackF); }
100 ////////////////////////////////////////////////////////////////////////////////////////////////////
102 // Einschraenkungen:
104 // - Flaechenmuster werden den unter StarView verfuegbaren Mustern angenaehert.
105 // - Linienenden werden unter StarView immer rund dargestellt und gehen ueber
106 // den Endpunkt der Linie hinaus.
107 // - Linienmuster werden den unter StarView verfuegbaren Mustern angenaehert.
108 // Transparent/Opak wird zur Zeit noch nicht beruecksichtigt.
109 // - Keine gedrehten Ellipsen
114 ////////////////////////////////////////////////////////////////////////////////////////////////////
116 #if defined( WIN ) && defined( MSC )
117 #pragma code_seg( "svtools", "AUTO_CODE" )
118 #endif
120 ////////////////////////////////////////////////////////////////////////////////////////////////////
121 // Fuer Fontuebersetzung ///////////////////////////////////////////////////////////////////////////
122 ////////////////////////////////////////////////////////////////////////////////////////////////////
123 SgfFontLst* pSgfFonts = 0;
125 #if defined( WIN ) && defined( MSC )
126 #pragma code_seg( "SVTOOLS_FILTER3", "SVTOOLS_CODE" )
127 static void AntiMscBug() {}
128 #endif
130 ////////////////////////////////////////////////////////////////////////////////////////////////////
131 // Fuer Kreisunterarten, Text und gedrehte Rechtecke ///////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////////////////////////////////////////////
133 void RotatePoint(PointType& P, INT16 cx, INT16 cy, double sn, double cs)
135 INT16 dx,dy;
136 double x1,y1;
137 dx=P.x-cx;
138 dy=P.y-cy;
139 x1=dx*cs-dy*sn;
140 y1=dy*cs+dx*sn;
141 P.x=cx+INT16(x1);
142 P.y=cy+INT16(y1);
145 void RotatePoint(Point& P, INT16 cx, INT16 cy, double sn, double cs)
147 INT16 dx,dy;
148 double x1,y1;
149 dx=(INT16)(P.X()-cx);
150 dy=(INT16)(P.Y()-cy);
151 x1=dx*cs-dy*sn;
152 y1=dy*cs+dx*sn;
153 P=Point(cx+INT16(x1),cy+INT16(y1));
156 INT16 iMulDiv(INT16 a, INT16 Mul, INT16 Div)
158 INT32 Temp;
159 Temp=INT32(a)*INT32(Mul)/INT32(Div);
160 return INT16(Temp);
163 UINT16 MulDiv(UINT16 a, UINT16 Mul, UINT16 Div)
165 UINT32 Temp;
166 Temp=UINT32(a)*UINT32(Mul)/UINT32(Div);
167 return UINT16(Temp);
170 ////////////////////////////////////////////////////////////////////////////////////////////////////
171 // SgfFilterSDrw ///////////////////////////////////////////////////////////////////////////////////
172 ////////////////////////////////////////////////////////////////////////////////////////////////////
174 SvStream& operator>>(SvStream& rIStream, DtHdType& rDtHd)
176 rIStream.Read((char*)&rDtHd.Reserved[0],DtHdSize);
177 return rIStream;
180 void DtHdOverSeek(SvStream& rInp)
182 ULONG FPos=rInp.Tell();
183 FPos+=(ULONG)DtHdSize;
184 rInp.Seek(FPos);
185 // rInp.seekg(rInp.tellg()+(ULONG)DtHdSize);
189 SvStream& operator>>(SvStream& rIStream, PageType& rPage)
191 rIStream.Read((char*)&rPage.Next,PageSize);
192 #if defined OSL_BIGENDIAN
193 SWAPPAGE(rPage);
194 #endif
195 return rIStream;
198 void ObjkOverSeek(SvStream& rInp, ObjkType& rObjk)
200 ULONG Siz;
201 Siz=(ULONG)rObjk.MemSize+rObjk.Last; // ObjSize+ObjAnhSize
202 rInp.Seek(rInp.Tell()+Siz);
205 SvStream& operator>>(SvStream& rInp, ObjkType& rObjk)
206 { // Die Fileposition im Stream bleibt unveraendert!
207 ULONG nPos;
208 nPos=rInp.Tell();
209 rInp.Read((char*)&rObjk.Last,ObjkSize);
210 #if defined OSL_BIGENDIAN
211 SWAPOBJK(rObjk);
212 #endif
213 #ifdef InArbeit
214 ULONG nPos1=rInp.Tell();
215 if(nPos == nPos1) InfoBox( NULL, "tellg funkt nich" ).Execute();
216 #endif
217 rInp.Seek(nPos);
218 #ifdef InArbeit
219 if (rInp.Tell() != nPos) InfoBox( NULL, "seekg funkt nich" ).Execute();
220 #endif
221 return rInp;
223 SvStream& operator>>(SvStream& rInp, StrkType& rStrk)
225 rInp.Read((char*)&rStrk.Last,StrkSize);
226 #if defined OSL_BIGENDIAN
227 SWAPOBJK (rStrk);
228 SWAPLINE (rStrk.L);
229 SWAPPOINT(rStrk.Pos1);
230 SWAPPOINT(rStrk.Pos2);
231 #endif
232 return rInp;
234 SvStream& operator>>(SvStream& rInp, RectType& rRect)
236 rInp.Read((char*)&rRect.Last,RectSize);
237 #if defined OSL_BIGENDIAN
238 SWAPOBJK (rRect);
239 SWAPLINE (rRect.L);
240 SWAPAREA (rRect.F);
241 SWAPPOINT(rRect.Pos1);
242 SWAPPOINT(rRect.Pos2);
243 rRect.Radius =SWAPSHORT(rRect.Radius );
244 rRect.DrehWink=SWAPSHORT(rRect.DrehWink);
245 rRect.Slant =SWAPSHORT(rRect.Slant );
246 #endif
247 return rInp;
249 SvStream& operator>>(SvStream& rInp, PolyType& rPoly)
251 rInp.Read((char*)&rPoly.Last,PolySize);
252 #if defined OSL_BIGENDIAN
253 SWAPOBJK (rPoly);
254 SWAPLINE (rPoly.L);
255 SWAPAREA (rPoly.F);
256 // rPoly.EckP=SWAPLONG(rPoly.EckP);
257 #endif
258 return rInp;
260 SvStream& operator>>(SvStream& rInp, SplnType& rSpln)
262 rInp.Read((char*)&rSpln.Last,SplnSize);
263 #if defined OSL_BIGENDIAN
264 SWAPOBJK (rSpln);
265 SWAPLINE (rSpln.L);
266 SWAPAREA (rSpln.F);
267 // rSpln.EckP=SWAPLONG(rSpln.EckP);
268 #endif
269 return rInp;
271 SvStream& operator>>(SvStream& rInp, CircType& rCirc)
273 rInp.Read((char*)&rCirc.Last,CircSize);
274 #if defined OSL_BIGENDIAN
275 SWAPOBJK (rCirc);
276 SWAPLINE (rCirc.L);
277 SWAPAREA (rCirc.F);
278 SWAPPOINT(rCirc.Radius);
279 SWAPPOINT(rCirc.Center);
280 rCirc.DrehWink =SWAPSHORT(rCirc.DrehWink );
281 rCirc.StartWink=SWAPSHORT(rCirc.StartWink);
282 rCirc.RelWink =SWAPSHORT(rCirc.RelWink );
283 #endif
284 return rInp;
286 SvStream& operator>>(SvStream& rInp, TextType& rText)
288 rInp.Read((char*)&rText.Last,TextSize);
289 #if defined OSL_BIGENDIAN
290 SWAPOBJK (rText);
291 SWAPTEXT (rText.T);
292 SWAPPOINT(rText.Pos1);
293 SWAPPOINT(rText.Pos2);
294 rText.TopOfs =SWAPSHORT(rText.TopOfs );
295 rText.DrehWink=SWAPSHORT(rText.DrehWink);
296 rText.BoxSlant=SWAPSHORT(rText.BoxSlant);
297 rText.BufSize =SWAPSHORT(rText.BufSize );
298 //rText.Buf =SWAPLONG (rText.Buf );
299 //rText.Ext =SWAPLONG (rText.Ext );
300 SWAPPOINT(rText.FitSize);
301 rText.FitBreit=SWAPSHORT(rText.FitBreit);
302 #endif
303 rText.Buffer=NULL;
304 return rInp;
306 SvStream& operator>>(SvStream& rInp, BmapType& rBmap)
308 rInp.Read((char*)&rBmap.Last,BmapSize);
309 #if defined OSL_BIGENDIAN
310 SWAPOBJK (rBmap);
311 SWAPAREA (rBmap.F);
312 SWAPPOINT(rBmap.Pos1);
313 SWAPPOINT(rBmap.Pos2);
314 rBmap.DrehWink=SWAPSHORT(rBmap.DrehWink);
315 rBmap.Slant =SWAPSHORT(rBmap.Slant );
316 SWAPPOINT(rBmap.PixSize);
317 #endif
318 return rInp;
320 SvStream& operator>>(SvStream& rInp, GrupType& rGrup)
322 rInp.Read((char*)&rGrup.Last,GrupSize);
323 #if defined OSL_BIGENDIAN
324 SWAPOBJK (rGrup);
325 rGrup.SbLo =SWAPSHORT(rGrup.SbLo );
326 rGrup.SbHi =SWAPSHORT(rGrup.SbHi );
327 rGrup.UpLo =SWAPSHORT(rGrup.UpLo );
328 rGrup.UpHi =SWAPSHORT(rGrup.UpHi );
329 rGrup.ChartSize=SWAPSHORT(rGrup.ChartSize);
330 rGrup.ChartPtr =SWAPLONG (rGrup.ChartPtr );
331 #endif
332 return rInp;
337 /*************************************************************************
339 |* Sgv2SvFarbe()
341 |* Beschreibung
342 |* Ersterstellung JOE 23.06.93
343 |* Letzte Aenderung JOE 23.06.93
345 *************************************************************************/
346 Color Sgv2SvFarbe(BYTE nFrb1, BYTE nFrb2, BYTE nInts)
348 UINT16 r1=0,g1=0,b1=0,r2=0,g2=0,b2=0;
349 BYTE nInt2=100-nInts;
350 switch(nFrb1 & 0x07) {
351 case 0: r1=0xFF; g1=0xFF; b1=0xFF; break;
352 case 1: r1=0xFF; g1=0xFF; break;
353 case 2: g1=0xFF; b1=0xFF; break;
354 case 3: g1=0xFF; break;
355 case 4: r1=0xFF; b1=0xFF; break;
356 case 5: r1=0xFF; break;
357 case 6: b1=0xFF; break;
358 case 7: break;
360 switch(nFrb2 & 0x07) {
361 case 0: r2=0xFF; g2=0xFF; b2=0xFF; break;
362 case 1: r2=0xFF; g2=0xFF; break;
363 case 2: g2=0xFF; b2=0xFF; break;
364 case 3: g2=0xFF; break;
365 case 4: r2=0xFF; b2=0xFF; break;
366 case 5: r2=0xFF; break;
367 case 6: b2=0xFF; break;
368 case 7: break;
370 r1=(UINT16)((UINT32)r1*nInts/100+(UINT32)r2*nInt2/100);
371 g1=(UINT16)((UINT32)g1*nInts/100+(UINT32)g2*nInt2/100);
372 b1=(UINT16)((UINT32)b1*nInts/100+(UINT32)b2*nInt2/100);
373 Color aColor( (sal_uInt8)r1, (sal_uInt8)g1, (sal_uInt8)b1 );
374 return aColor;
377 void SetLine(ObjLineType& rLine, OutputDevice& rOut)
379 /* !!!
380 PenStyle aStyle=PEN_SOLID;
381 switch(rLine.LMuster & 0x07) {
382 case 0: aStyle=PEN_NULL; break;
383 case 1: aStyle=PEN_SOLID; break;
384 case 2: aStyle=PEN_DOT; break; // . . . . . . . . . . . . . .
385 case 3: aStyle=PEN_DASH; break; // __ __ __ __ __ __ __ __ __
386 case 4: aStyle=PEN_DASH; break; // ___ ___ ___ ___ ___ ___ ___
387 case 5: aStyle=PEN_DASHDOT; break; // __ . __ . __ . __ . __ . __
388 case 6: aStyle=PEN_DASHDOT; break; // __ _ __ _ __ _ __ _ __ _ __
389 case 7: aStyle=PEN_DASHDOT; break; // ___ _ _ ___ _ _ ___ _ _ ___
391 Pen aPen(Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens),rLine.LDicke,aStyle);
392 SetPen(aPen,rOut);
394 if( 0 == ( rLine.LMuster & 0x07 ) )
395 rOut.SetLineColor();
396 else
397 rOut.SetLineColor( Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens) );
400 void SetArea(ObjAreaType& rArea, OutputDevice& rOut)
403 BrushStyle aStyle=BRUSH_SOLID;
404 switch(rArea.FMuster & 0x00FF) {
405 case 0: aStyle=BRUSH_NULL; break;
406 case 1: aStyle=BRUSH_SOLID; break;
407 case 2: case 4: case 6: case 8:
408 case 10: case 12: case 14: case 16:
409 case 43: case 45: aStyle=BRUSH_VERT; break;
410 case 3: case 5: case 7: case 9:
411 case 11: case 13: case 15: case 17:
412 case 42: case 44: aStyle=BRUSH_HORZ; break;
413 case 18: case 20: case 22: case 24:
414 case 26: case 28: case 30: case 32:
415 case 46: case 48: aStyle=BRUSH_UPDIAG; break;
416 case 19: case 21: case 23: case 25:
417 case 27: case 29: case 31: case 33:
418 case 47: case 49: aStyle=BRUSH_DOWNDIAG; break;
419 case 34: case 35: case 36: case 37: aStyle=BRUSH_CROSS; break;
420 case 38: case 39: case 40: case 41: aStyle=BRUSH_DIAGCROSS; break;
421 default: aStyle=BRUSH_DIAGCROSS; break;
423 Brush aBrush(Sgv2SvFarbe(rArea.FFarbe,rArea.FBFarbe,rArea.FIntens),aStyle);
424 aBrush.SetTransparent((rArea.FMuster & 0x80) !=0L);
425 SetBrush(aBrush,rOut);
427 if( 0 == ( rArea.FMuster & 0x00FF ) )
428 rOut.SetFillColor();
429 else
430 rOut.SetFillColor( Sgv2SvFarbe( rArea.FFarbe,rArea.FBFarbe,rArea.FIntens ) );
433 /*************************************************************************
435 |* ObjkType::DrawObjekt()
437 |* Beschreibung
438 |* Ersterstellung JOE 23.06.93
439 |* Letzte Aenderung JOE 23.06.93
441 *************************************************************************/
442 void ObjkType::Draw(OutputDevice&)
444 // ShowSDObjk(*this);
447 void Obj0Type::Draw(OutputDevice&) {}
449 /*************************************************************************
451 |* StrkType::DrawObjekt()
453 |* Beschreibung
454 |* Ersterstellung JOE 23.06.93
455 |* Letzte Aenderung JOE 23.06.93
457 *************************************************************************/
458 void StrkType::Draw(OutputDevice& rOut)
460 SetLine(L,rOut);
461 rOut.DrawLine(Point(Pos1.x,Pos1.y),Point(Pos2.x,Pos2.y)); // !!!
464 /*************************************************************************
466 |* RectType::DrawObjekt()
468 |* Beschreibung
469 |* Ersterstellung JOE 23.06.93
470 |* Letzte Aenderung JOE 23.06.93
472 *************************************************************************/
473 void SgfAreaColorIntens(UINT16 Muster, BYTE Col1, BYTE Col2, BYTE Int, OutputDevice& rOut)
475 ObjAreaType F;
476 F.FMuster=Muster;
477 F.FFarbe=Col2;
478 F.FBFarbe=Col1;
479 F.FIntens=Int;
480 SetArea(F,rOut);
483 void DrawSlideRect(INT16 x1, INT16 y1, INT16 x2, INT16 y2, ObjAreaType& F, OutputDevice& rOut)
485 INT16 i,i0,b,b0;
486 INT16 Int1,Int2;
487 INT16 Col1,Col2;
488 // ClipMerk: HgdClipRec;
489 INT16 cx,cy;
490 INT16 MaxR;
491 INT32 dx,dy;
493 rOut.SetLineColor();
494 if (x1>x2) { i=x1; x1=x2; x2=i; }
495 if (y1>y2) { i=y1; y1=y2; y2=i; }
496 Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
497 Int1=100-F.FIntens; Int2=F.FIntens;
498 if (Int1==Int2) {
499 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
500 rOut.DrawRect(Rectangle(x1,y1,x2,y2));
501 } else {
502 b0=Int1;
503 switch (F.FBFarbe & 0x38) {
504 case 0x08: { // vertikal
505 i0=y1;
506 i=y1;
507 while (i<=y2) {
508 b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1));
509 if (b!=b0) {
510 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
511 rOut.DrawRect(Rectangle(x1,i0,x2,i-1));
512 i0=i; b0=b;
514 i++;
516 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
517 rOut.DrawRect(Rectangle(x1,i0,x2,y2));
518 } break;
519 case 0x28: { // horizontal
520 i0=x1;
521 i=x1;
522 while (i<=x2) {
523 b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1));
524 if (b!=b0) {
525 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
526 rOut.DrawRect(Rectangle(i0,y1,i-1,y2));
527 i0=i; b0=b;
529 i++;
531 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
532 rOut.DrawRect(Rectangle(i0,y1,x2,y2));
533 } break;
535 case 0x18: case 0x38: { // Kreis
536 Region ClipMerk=rOut.GetClipRegion();
537 double a;
539 rOut.SetClipRegion(Region(Rectangle(x1,y1,x2,y2)));
540 cx=(x1+x2) /2;
541 cy=(y1+y2) /2;
542 dx=x2-x1+1;
543 dy=y2-y1+1;
544 a=sqrt((double)(dx*dx+dy*dy));
545 MaxR=INT16(a) /2 +1;
546 b0=Int2;
547 i0=MaxR; if (MaxR<1) MaxR=1;
548 i=MaxR;
549 while (i>=0) {
550 b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR));
551 if (b!=b0) {
552 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
553 //if (i0>200 || (Col1 & $80)!=0 || (Col2 & $80)!=0) {
554 // then begin { Fallunterscheidung fuer etwas bessere Performance }
555 // s2:=i0-i+2;
556 // SetPenSize(s2);
557 // s2:=s2 div 2;
558 // Circle(cx,cy,i0-s2,i0-s2);{}
559 // else
560 rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
561 i0=i; b0=b;
563 i--;
565 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut);
566 rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
567 rOut.SetClipRegion(ClipMerk);
568 } break; // Kreis
574 void RectType::Draw(OutputDevice& rOut)
576 if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus
577 SetArea(F,rOut);
578 if (DrehWink==0) {
579 if ((F.FBFarbe & 0x38)==0 || Radius!=0) {
580 SetLine(L,rOut);
581 rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y),Radius,Radius);
582 } else {
583 DrawSlideRect(Pos1.x,Pos1.y,Pos2.x,Pos2.y,F,rOut);
584 if (L.LMuster!=0) {
585 SetLine(L,rOut);
586 rOut.SetFillColor();
587 rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y));
590 } else {
591 Point aPts[4];
592 USHORT i;
593 double sn,cs;
594 sn=sin(double(DrehWink)*3.14159265359/18000);
595 cs=cos(double(DrehWink)*3.14159265359/18000);
596 aPts[0]=Point(Pos1.x,Pos1.y);
597 aPts[1]=Point(Pos2.x,Pos1.y);
598 aPts[2]=Point(Pos2.x,Pos2.y);
599 aPts[3]=Point(Pos1.x,Pos2.y);
600 for (i=0;i<4;i++) {
601 RotatePoint(aPts[i],Pos1.x,Pos1.y,sn,cs);
603 SetLine(L,rOut);
604 Polygon aPoly(4,aPts);
605 rOut.DrawPolygon(aPoly);
609 /*************************************************************************
611 |* PolyType::Draw()
613 |* Beschreibung
614 |* Ersterstellung JOE 23.06.93
615 |* Letzte Aenderung JOE 23.06.93
617 *************************************************************************/
618 void PolyType::Draw(OutputDevice& rOut)
620 if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
621 SetLine(L,rOut);
622 Polygon aPoly(nPoints);
623 USHORT i;
624 for(i=0;i<nPoints;i++) aPoly.SetPoint(Point(EckP[i].x,EckP[i].y),i);
625 if ((Flags & PolyClosBit) !=0) {
626 rOut.DrawPolygon(aPoly);
627 } else {
628 rOut.DrawPolyLine(aPoly);
632 /*************************************************************************
634 |* SplnType::Draw()
636 |* Beschreibung
637 |* Ersterstellung JOE 23.06.93
638 |* Letzte Aenderung JOE 23.06.93
640 *************************************************************************/
641 void SplnType::Draw(OutputDevice& rOut)
643 if ((Flags & PolyClosBit) !=0) SetArea(F,rOut);
644 SetLine(L,rOut);
645 Polygon aPoly(0);
646 Polygon aSpln(nPoints);
647 USHORT i;
648 for(i=0;i<nPoints;i++) aSpln.SetPoint(Point(EckP[i].x,EckP[i].y),i);
649 if ((Flags & PolyClosBit) !=0) {
650 Spline2Poly(aSpln,TRUE,aPoly);
651 if (aPoly.GetSize()>0) rOut.DrawPolygon(aPoly);
652 } else {
653 Spline2Poly(aSpln,FALSE,aPoly);
654 if (aPoly.GetSize()>0) rOut.DrawPolyLine(aPoly);
658 /*************************************************************************
660 |* CircType::Draw()
662 |* Beschreibung
663 |* Ersterstellung JOE 23.06.93
664 |* Letzte Aenderung JOE 23.06.93
666 *************************************************************************/
667 void DrawSlideCirc(INT16 cx, INT16 cy, INT16 rx, INT16 ry, ObjAreaType& F, OutputDevice& rOut)
669 INT16 x1=cx-rx;
670 INT16 y1=cy-ry;
671 INT16 x2=cx+rx;
672 INT16 y2=cy+ry;
674 INT16 i,i0,b,b0;
675 INT16 Int1,Int2;
676 INT16 Col1,Col2;
678 rOut.SetLineColor();
679 Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87;
680 Int1=100-F.FIntens; Int2=F.FIntens;
681 if (Int1==Int2) {
682 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
683 rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
684 } else {
685 b0=Int1;
686 switch (F.FBFarbe & 0x38) {
687 case 0x08: { // vertikal
688 Region ClipMerk=rOut.GetClipRegion();
689 i0=y1;
690 i=y1;
691 while (i<=y2) {
692 b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1));
693 if (b!=b0) {
694 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
695 rOut.SetClipRegion(Rectangle(x1,i0,x2,i-1));
696 rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
697 i0=i; b0=b;
699 i++;
701 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
702 rOut.SetClipRegion(Rectangle(x1,i0,x2,y2));
703 rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
704 rOut.SetClipRegion(ClipMerk);
705 } break;
706 case 0x28: { // horizontal
707 Region ClipMerk=rOut.GetClipRegion();
708 i0=x1;
709 i=x1;
710 while (i<=x2) {
711 b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1));
712 if (b!=b0) {
713 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
714 rOut.SetClipRegion(Rectangle(i0,y1,i-1,y2));
715 rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
716 i0=i; b0=b;
718 i++;
720 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut);
721 rOut.SetClipRegion(Rectangle(i0,y1,x2,y2));
722 rOut.DrawEllipse(Rectangle(x1,y1,x2,y2));
723 rOut.SetClipRegion(ClipMerk);
724 } break;
726 case 0x18: case 0x38: { // Kreis
727 INT16 MaxR;
729 if (rx<1) rx=1;
730 if (ry<1) ry=1;
731 MaxR=rx;
732 b0=Int2;
733 i0=MaxR; if (MaxR<1) MaxR=1;
734 i=MaxR;
735 while (i>=0) {
736 b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR));
737 if (b!=b0) {
738 INT32 temp=INT32(i0)*INT32(ry)/INT32(rx);
739 INT16 j0=INT16(temp);
740 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut);
741 rOut.DrawEllipse(Rectangle(cx-i0,cy-j0,cx+i0,cy+j0));
742 i0=i; b0=b;
744 i--;
746 SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut);
747 rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0));
748 } break; // Kreis
754 void CircType::Draw(OutputDevice& rOut)
756 Rectangle aRect(Center.x-Radius.x,Center.y-Radius.y,Center.x+Radius.x,Center.y+Radius.y);
758 if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus
759 SetArea(F,rOut);
760 if ((Flags & 0x03)==CircFull) {
761 if ((F.FBFarbe & 0x38)==0) {
762 SetLine(L,rOut);
763 rOut.DrawEllipse(aRect);
764 } else {
765 DrawSlideCirc(Center.x,Center.y,Radius.x,Radius.y,F,rOut);
766 if (L.LMuster!=0) {
767 SetLine(L,rOut);
768 rOut.SetFillColor();
769 rOut.DrawEllipse(aRect);
772 } else {
773 PointType a,b;
774 Point aStrt,aEnde;
775 double sn,cs;
777 a.x=Center.x+Radius.x; a.y=Center.y; b=a;
778 sn=sin(double(StartWink)*3.14159265359/18000);
779 cs=cos(double(StartWink)*3.14159265359/18000);
780 RotatePoint(a,Center.x,Center.y,sn,cs);
781 sn=sin(double(StartWink+RelWink)*3.14159265359/18000);
782 cs=cos(double(StartWink+RelWink)*3.14159265359/18000);
783 RotatePoint(b,Center.x,Center.y,sn,cs);
784 if (Radius.x!=Radius.y) {
785 if (Radius.x<1) Radius.x=1;
786 if (Radius.y<1) Radius.y=1;
787 a.y = a.y - Center.y;
788 b.y = b.y - Center.y;
789 a.y=iMulDiv(a.y,Radius.y,Radius.x);
790 b.y=iMulDiv(b.y,Radius.y,Radius.x);
791 a.y = a.y + Center.y;
792 b.y = b.y + Center.y;
794 aStrt=Point(a.x,a.y);
795 aEnde=Point(b.x,b.y);
796 SetLine(L,rOut);
797 switch (Flags & 0x03) {
798 case CircArc : rOut.DrawArc(aRect,aEnde,aStrt); break;
799 case CircSect:
800 case CircAbsn: rOut.DrawPie(aRect,aEnde,aStrt); break;
805 /*************************************************************************
807 |* BmapType::Draw()
809 |* Beschreibung
810 |* Ersterstellung JOE 23.06.93
811 |* Letzte Aenderung JOE 23.06.93
813 *************************************************************************/
815 void BmapType::Draw(OutputDevice& rOut)
817 //ifstream aInp;
818 unsigned char nSgfTyp;
819 USHORT nVersion;
820 String aStr(
821 reinterpret_cast< char const * >(&Filename[ 1 ]),
822 (xub_StrLen)Filename[ 0 ], RTL_TEXTENCODING_UTF8 );
823 INetURLObject aFNam( aStr );
825 SvStream* pInp = ::utl::UcbStreamHelper::CreateStream( aFNam.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
826 if ( pInp )
828 nSgfTyp=CheckSgfTyp( *pInp,nVersion);
829 switch(nSgfTyp) {
830 case SGF_BITIMAGE: {
831 GraphicFilter aFlt;
832 Graphic aGrf;
833 USHORT nRet;
834 nRet=aFlt.ImportGraphic(aGrf,aFNam);
835 aGrf.Draw(&rOut,Point(Pos1.x,Pos1.y),Size(Pos2.x-Pos1.x,Pos2.y-Pos1.y));
836 } break;
837 case SGF_SIMPVECT: {
838 GDIMetaFile aMtf;
839 SgfVectXofs=Pos1.x;
840 SgfVectYofs=Pos1.y;
841 SgfVectXmul=Pos2.x-Pos1.x;
842 SgfVectYmul=Pos2.y-Pos1.y;
843 SgfVectXdiv=0;
844 SgfVectYdiv=0;
845 SgfVectScal=TRUE;
846 SgfVectFilter(*pInp,aMtf);
847 SgfVectXofs=0;
848 SgfVectYofs=0;
849 SgfVectXmul=0;
850 SgfVectYmul=0;
851 SgfVectXdiv=0;
852 SgfVectYdiv=0;
853 SgfVectScal=FALSE;
854 aMtf.Play(&rOut);
855 } break;
857 delete pInp;
862 /*************************************************************************
864 |* GrupType::...
866 |* Beschreibung
867 |* Ersterstellung JOE 23.06.93
868 |* Letzte Aenderung JOE 23.06.93
870 *************************************************************************/
871 UINT32 GrupType::GetSubPtr()
873 return UINT32(SbLo)+0x00010000*UINT32(SbHi);
876 /*************************************************************************
878 |* DrawObjkList()
880 |* Beschreibung
881 |* Ersterstellung JOE 23.06.93
882 |* Letzte Aenderung JOE 23.06.93
884 *************************************************************************/
885 void DrawObjkList( SvStream& rInp, OutputDevice& rOut )
887 ObjkType aObjk;
888 USHORT nGrpCnt=0;
889 BOOL bEnde=FALSE;
890 do {
891 rInp>>aObjk;
892 if (!rInp.GetError()) {
893 switch(aObjk.Art) {
894 case ObjStrk: { StrkType aStrk; rInp>>aStrk; if (!rInp.GetError()) aStrk.Draw(rOut); } break;
895 case ObjRect: { RectType aRect; rInp>>aRect; if (!rInp.GetError()) aRect.Draw(rOut); } break;
896 case ObjCirc: { CircType aCirc; rInp>>aCirc; if (!rInp.GetError()) aCirc.Draw(rOut); } break;
897 case ObjText: {
898 TextType aText;
899 rInp>>aText;
900 if (!rInp.GetError()) {
901 aText.Buffer=new UCHAR[aText.BufSize+1]; // Ein mehr fuer LookAhead bei CK-Trennung
902 rInp.Read((char* )aText.Buffer,aText.BufSize);
903 if (!rInp.GetError()) aText.Draw(rOut);
904 delete[] aText.Buffer;
906 } break;
907 case ObjBmap: {
908 BmapType aBmap;
909 rInp>>aBmap;
910 if (!rInp.GetError()) {
911 aBmap.Draw(rOut);
913 } break;
914 case ObjPoly: {
915 PolyType aPoly;
916 rInp>>aPoly;
917 if (!rInp.GetError()) {
918 aPoly.EckP=new PointType[aPoly.nPoints];
919 rInp.Read((char*)aPoly.EckP,4*aPoly.nPoints);
920 #if defined OSL_BIGENDIAN
921 for(short i=0;i<aPoly.nPoints;i++) SWAPPOINT(aPoly.EckP[i]);
922 #endif
923 if (!rInp.GetError()) aPoly.Draw(rOut);
924 delete[] aPoly.EckP;
926 } break;
927 case ObjSpln: {
928 SplnType aSpln;
929 rInp>>aSpln;
930 if (!rInp.GetError()) {
931 aSpln.EckP=new PointType[aSpln.nPoints];
932 rInp.Read((char*)aSpln.EckP,4*aSpln.nPoints);
933 #if defined OSL_BIGENDIAN
934 for(short i=0;i<aSpln.nPoints;i++) SWAPPOINT(aSpln.EckP[i]);
935 #endif
936 if (!rInp.GetError()) aSpln.Draw(rOut);
937 delete[] aSpln.EckP;
939 } break;
940 case ObjGrup: {
941 GrupType aGrup;
942 rInp>>aGrup;
943 if (!rInp.GetError()) {
944 rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel
945 if(aGrup.GetSubPtr()!=0L) nGrpCnt++;// DrawObjkList(rInp,rOut );
947 } break;
948 default: {
949 aObjk.Draw(rOut); // Objektbezeichnung auf 2. Screen
950 ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt
953 } // if rInp
954 if (!rInp.GetError()) {
955 if (aObjk.Next==0L) {
956 if (nGrpCnt==0) bEnde=TRUE;
957 else nGrpCnt--;
959 } else {
960 bEnde=TRUE; // Lesefehler
962 } while (!bEnde);
965 /*************************************************************************
967 |* SkipObjkList()
969 |* Beschreibung
970 |* Ersterstellung JOE 23.06.93
971 |* Letzte Aenderung JOE 23.06.93
973 *************************************************************************/
974 void SkipObjkList(SvStream& rInp)
976 ObjkType aObjk;
979 rInp>>aObjk;
980 if(aObjk.Art==ObjGrup) {
981 GrupType aGrup;
982 rInp>>aGrup;
983 rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel
984 if(aGrup.GetSubPtr()!=0L) SkipObjkList(rInp);
985 } else {
986 ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt
988 } while (aObjk.Next!=0L && !rInp.GetError());
991 /*************************************************************************
993 |* SgfFilterSDrw()
995 |* Beschreibung
996 |* Ersterstellung JOE 23.06.93
997 |* Letzte Aenderung JOE 23.06.93
999 *************************************************************************/
1000 BOOL SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf )
1002 BOOL bRet = FALSE;
1003 PageType aPage;
1004 VirtualDevice aOutDev;
1005 OutputDevice* pOutDev;
1006 ULONG nStdPos;
1007 ULONG nZchPos;
1008 USHORT Num;
1010 pOutDev=&aOutDev;
1011 DtHdOverSeek(rInp); // DataHeader weglesen
1013 nStdPos=rInp.Tell();
1014 do { // Standardseiten weglesen
1015 rInp>>aPage;
1016 if (aPage.nList!=0) SkipObjkList(rInp);
1017 } while (aPage.Next!=0L && !rInp.GetError());
1019 // ShowMsg("Zeichnungseite(n)\n");
1020 nZchPos=rInp.Tell();
1021 rInp>>aPage;
1023 rMtf.Record(pOutDev);
1024 Num=aPage.StdPg;
1025 if (Num!=0) {
1026 rInp.Seek(nStdPos);
1027 while(Num>1 && aPage.Next!=0L && !rInp.GetError()) { // Standardseite suchen
1028 rInp>>aPage;
1029 if (aPage.nList!=0) SkipObjkList(rInp);
1030 Num--;
1032 rInp>>aPage;
1033 if(Num==1 && aPage.nList!=0L) DrawObjkList( rInp,*pOutDev );
1034 rInp.Seek(nZchPos);
1035 nZchPos=rInp.Tell();
1036 rInp>>aPage;
1038 if (aPage.nList!=0L) DrawObjkList(rInp,*pOutDev );
1040 rMtf.Stop();
1041 rMtf.WindStart();
1042 MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4));
1043 rMtf.SetPrefMapMode(aMap);
1044 rMtf.SetPrefSize(Size((INT16)aPage.Paper.Size.x,(INT16)aPage.Paper.Size.y));
1045 bRet=TRUE;
1046 return bRet;
1051 /*************************************************************************
1053 |* SgfSDrwFilter()
1055 |* Beschreibung
1056 |* Ersterstellung JOE 23.06.93
1057 |* Letzte Aenderung JOE 23.06.93
1059 *************************************************************************/
1060 BOOL SgfSDrwFilter(SvStream& rInp, GDIMetaFile& rMtf, INetURLObject aIniPath )
1062 #if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Alignment!
1063 if (sizeof(ObjTextType)!=ObjTextTypeSize) return FALSE;
1064 #endif
1066 ULONG nFileStart; // Offset des SgfHeaders. Im allgemeinen 0.
1067 SgfHeader aHead;
1068 SgfEntry aEntr;
1069 ULONG nNext;
1070 BOOL bRdFlag=FALSE; // Grafikentry gelesen ?
1071 BOOL bRet=FALSE; // Returncode
1073 aIniPath.Append( String::CreateFromAscii( "sgf.ini", 7 ) );
1074 // aIniPath.ToAbs();
1076 pSgfFonts = new SgfFontLst;
1078 pSgfFonts->AssignFN( aIniPath.GetMainURL( INetURLObject::NO_DECODE ) );
1079 nFileStart=rInp.Tell();
1080 rInp>>aHead;
1081 if (aHead.ChkMagic() && aHead.Typ==SgfStarDraw && aHead.Version==SGV_VERSION) {
1082 nNext=aHead.GetOffset();
1083 while (nNext && !bRdFlag && !rInp.GetError()) {
1084 rInp.Seek(nFileStart+nNext);
1085 rInp>>aEntr;
1086 nNext=aEntr.GetOffset();
1087 if (aEntr.Typ==aHead.Typ) {
1088 bRet=SgfFilterSDrw( rInp,aHead,aEntr,rMtf );
1090 } // while(nNext)
1091 if (bRdFlag) {
1092 if (!rInp.GetError()) bRet=TRUE; // Scheinbar Ok
1095 delete pSgfFonts;
1096 return(bRet);
1100 Bitmap Dither(BYTE Intens)
1102 Bitmap aBmp;
1103 BmpInfoHeader Info;
1106 const dmatrix: array[0..7,0..7] of byte =
1107 (( 0, 48, 12, 60, 3, 51, 15, 63 ),
1108 ( 32, 16, 44, 28, 35, 19, 47, 31 ),
1109 ( 8, 56, 4, 52, 11, 59, 7, 55 ),
1110 ( 40, 24, 36, 20, 43, 27, 39, 23 ),
1111 ( 2, 50, 14, 62, 1, 49, 13, 61 ),
1112 ( 34, 18, 46, 30, 33, 17, 45, 29 ),
1113 ( 10, 58, 6, 54, 9, 57, 5, 53 ),
1114 ( 42, 26, 38, 22, 41, 25, 37, 21 ));
1117 cmatrix: array[0..7,0..7] of byte;
1118 dmatrixn,dmatrixi: array[0..7] of byte;
1121 procedure SetColorIntens(col0,col1,bal: integer);
1122 var cmatrix0: array[0..63] of byte absolute cmatrix;
1123 dmatrix0: array[0..63] of byte absolute dmatrix;
1124 n,i: integer;
1125 b,bit: byte;
1126 begin
1127 if col0=col1 then bal:=0;
1128 if bal<=32 then
1129 begin
1130 plotcolor0:=col0 and $1F; plotcolor1:=col1 and $1F;
1131 plotbal:=bal;
1133 else
1134 begin
1135 plotcolor0:=col1 and $1F; plotcolor1:=col0 and $1F;
1136 plotbal:=64-bal;
1137 end;
1138 for n:=0 to 63 do
1139 if plotbal<=dmatrix0[n] then cmatrix0[n]:=col0 else cmatrix0[n]:=col1;
1140 end;
1143 #if defined( WIN ) && defined( MSC )
1144 #pragma code_seg( "svtools", "AUTO_CODE" )
1145 #endif