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